X-Git-Url: https://gerrit.opnfv.org/gerrit/gitweb?a=blobdiff_plain;ds=inline;f=snaps%2Fconfig%2Fnetwork.py;h=ffafbb6652882468fae997c139285ee28e137eb3;hb=90ca47a7027f37d7528ec0b022306ba6472fd412;hp=8148c610e907387cade6c597bc6fa9e6e4ad3de3;hpb=9e9e09590cce321f55996c1a31370ffdf28251b0;p=snaps.git diff --git a/snaps/config/network.py b/snaps/config/network.py index 8148c61..ffafbb6 100644 --- a/snaps/config/network.py +++ b/snaps/config/network.py @@ -46,6 +46,7 @@ class NetworkConfig(object): :param segmentation_id: the id of the segmentation (this is required when network_type is 'vlan') :param subnets or subnet_settings: List of SubnetConfig objects. + :param mtu: MTU setting (optional) :return: """ @@ -88,6 +89,8 @@ class NetworkConfig(object): if not self.name or len(self.name) < 1: raise NetworkConfigError('Name required for networks') + self.mtu = kwargs.get('mtu') + def get_project_id(self, os_creds): """ Returns the project ID for a given project_name or None @@ -144,6 +147,8 @@ class NetworkConfig(object): out['provider:segmentation_id'] = self.segmentation_id if self.external: out['router:external'] = self.external + if self.mtu: + out['mtu'] = self.mtu return {'network': out} @@ -412,22 +417,23 @@ class PortConfig(object): raise PortConfigError( 'The attribute network_name is required') - def __get_fixed_ips(self, neutron): + def __get_fixed_ips(self, neutron, network): """ Sets the self.fixed_ips value :param neutron: the Neutron client + :param network: the SNAPS-OO network domain object :return: None """ - fixed_ips = list() if self.ip_addrs: for ip_addr_dict in self.ip_addrs: subnet = neutron_utils.get_subnet( - neutron, subnet_name=ip_addr_dict['subnet_name']) - if subnet and 'ip' in ip_addr_dict: - fixed_ips.append({'ip_address': ip_addr_dict['ip'], - 'subnet_id': subnet.id}) + neutron, network, subnet_name=ip_addr_dict['subnet_name']) + if subnet: + if 'ip' in ip_addr_dict: + fixed_ips.append({'ip_address': ip_addr_dict['ip'], + 'subnet_id': subnet.id}) else: raise PortConfigError( 'Invalid port configuration, subnet does not exist ' @@ -446,22 +452,28 @@ class PortConfig(object): :param os_creds: the OpenStack credentials :return: the dictionary object """ - out = dict() - session = keystone_utils.keystone_session(os_creds) keystone = keystone_utils.keystone_client(os_creds, session) + + project_name = os_creds.project_name + if self.project_name: + project_name = project_name try: network = neutron_utils.get_network( - neutron, keystone, network_name=self.network_name, - project_name=self.project_name) + neutron, keystone, network_name=self.network_name) + if network and (not network.shared or not network.external): + network = neutron_utils.get_network( + neutron, keystone, network_name=self.network_name, + project_name=project_name) finally: - keystone_utils.close_session(session) + if session: + keystone_utils.close_session(session) if not network: raise PortConfigError( 'Cannot locate network with name - ' + self.network_name - + ' in project - ' + str(self.project_name)) + + ' in project - ' + str(project_name)) out['network_id'] = network.id @@ -484,7 +496,7 @@ class PortConfig(object): if self.mac_address: out['mac_address'] = self.mac_address - fixed_ips = self.__get_fixed_ips(neutron) + fixed_ips = self.__get_fixed_ips(neutron, network) if fixed_ips and len(fixed_ips) > 0: out['fixed_ips'] = fixed_ips