1 # Copyright (c) 2017 Cable Television Laboratories, Inc. ("CableLabs")
2 # and others. All rights reserved.
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at:
8 # http://www.apache.org/licenses/LICENSE-2.0
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
18 from neutronclient.common.exceptions import NetworkNotFoundClient
20 from snaps.config.network import NetworkConfig, SubnetConfig, PortConfig
21 from snaps.openstack.openstack_creator import OpenStackNetworkObject
22 from snaps.openstack.utils import neutron_utils
24 __author__ = 'spisarski'
26 logger = logging.getLogger('OpenStackNetwork')
29 class OpenStackNetwork(OpenStackNetworkObject):
31 Class responsible for managing a network in OpenStack
34 def __init__(self, os_creds, network_settings):
36 Constructor - all parameters are required
37 :param os_creds: The credentials to connect with OpenStack
38 :param network_settings: The settings used to create a network
40 super(self.__class__, self).__init__(os_creds)
42 self.network_settings = network_settings
44 # Attributes instantiated on create()
49 Loads the existing OpenStack network/subnet
50 :return: The Network domain object or None
52 super(self.__class__, self).initialize()
54 self.__network = neutron_utils.get_network(
55 self._neutron, network_settings=self.network_settings,
56 project_id=self.network_settings.get_project_id(self._os_creds))
62 Responsible for creating not only the network but then a private
63 subnet, router, and an interface to the router.
64 :return: the Network domain object
68 if not self.__network:
69 self.__network = neutron_utils.create_network(
70 self._neutron, self._os_creds, self.network_settings)
72 'Network [%s] created successfully' % self.__network.id)
78 Removes and deletes all items created in reverse order.
82 neutron_utils.delete_network(self._neutron, self.__network)
83 except NetworkNotFoundClient:
87 def get_network(self):
89 Returns the created OpenStack network object
90 :return: the OpenStack network object
95 class NetworkSettings(NetworkConfig):
97 Class to hold the configuration settings required for creating OpenStack
102 def __init__(self, **kwargs):
103 from warnings import warn
104 warn('Use snaps.config.network.NetworkConfig instead',
106 super(self.__class__, self).__init__(**kwargs)
109 class IPv6Mode(enum.Enum):
112 deprecated - use snaps.config.network.IPv6Mode
115 stateful = 'dhcpv6-stateful'
116 stateless = 'dhcpv6-stateless'
119 class SubnetSettings(SubnetConfig):
121 Class to hold the configuration settings required for creating OpenStack
126 def __init__(self, **kwargs):
127 from warnings import warn
128 warn('Use snaps.config.network.SubnetConfig instead',
130 super(self.__class__, self).__init__(**kwargs)
133 class PortSettings(PortConfig):
135 Class to hold the configuration settings required for creating OpenStack
140 def __init__(self, **kwargs):
141 from warnings import warn
142 warn('Use snaps.config.network.PortConfig instead',
144 super(self.__class__, self).__init__(**kwargs)