def portcontext_to_nwa_info(context, resource_groups, use_original_port=False): tenant_id, nwa_tenant_id = nwa_com_utils.get_tenant_info(context) network_name, network_id = get_network_info(context) port = context.original if use_original_port else context.current device_owner = port['device_owner'] resource_group_name = _get_resource_group_name(context, resource_groups, use_original_port) physical_network = get_physical_network(device_owner, resource_groups, resource_group_name) vlan_id = get_vlan_id_of_physical_network(context, network_id, physical_network) vlan_type = 'PublicVLAN' if is_external_network(context, network_id) \ else 'BusinessVLAN' dbcontext = context._plugin_context nwa_info = { 'tenant_id': tenant_id, 'nwa_tenant_id': nwa_tenant_id, 'network': { 'id': network_id, 'name': network_name, 'vlan_id': vlan_id, 'vlan_type': vlan_type }, 'device': { 'owner': device_owner, 'id': port['device_id'] }, } if port['fixed_ips']: subnet_id = port['fixed_ips'][0]['subnet_id'] subnet = context._plugin.get_subnet(dbcontext, subnet_id) nwa_info['subnet'] = { 'id': subnet_id, 'netaddr': subnet['cidr'].split('/')[0], 'mask': subnet['cidr'].split('/')[1] } nwa_info['port'] = { 'id': port['id'], 'ip': port['fixed_ips'][0]['ip_address'], 'mac': port['mac_address'] } else: nwa_info['subnet'] = {'id': '', 'netaddr': '', 'mask': ''} nwa_info['port'] = { 'id': port['id'], 'ip': '', 'mac': port['mac_address'] } nwa_info['resource_group_name'] = resource_group_name nwa_info['resource_group_name_nw'] = cfg.CONF.NWA.resource_group_name nwa_info['physical_network'] = physical_network return nwa_info
def _make_l2api_kwargs(self, context, use_original_port=False): tenant_id, nwa_tenant_id = nwa_com_utils.get_tenant_info(context) nwa_info = nwa_l2_utils.portcontext_to_nwa_info( context, self.resource_groups, use_original_port) return { 'tenant_id': tenant_id, 'nwa_tenant_id': nwa_tenant_id, 'nwa_info': nwa_info }
def portcontext_to_nwa_info(context, resource_groups, use_original_port=False): tenant_id, nwa_tenant_id = nwa_com_utils.get_tenant_info(context) network_name, network_id = get_network_info(context) port = context.original if use_original_port else context.current device_owner = port['device_owner'] resource_group_name = _get_resource_group_name(context, resource_groups, use_original_port) physical_network = get_physical_network(device_owner, resource_groups, resource_group_name) vlan_id = get_vlan_id_of_physical_network(context, network_id, physical_network) vlan_type = 'PublicVLAN' if is_external_network(context, network_id) \ else 'BusinessVLAN' dbcontext = context._plugin_context nwa_info = { 'tenant_id': tenant_id, 'nwa_tenant_id': nwa_tenant_id, 'network': {'id': network_id, 'name': network_name, 'vlan_id': vlan_id, 'vlan_type': vlan_type}, 'device': {'owner': device_owner, 'id': port['device_id']}, } if port['fixed_ips']: subnet_id = port['fixed_ips'][0]['subnet_id'] subnet = context._plugin.get_subnet(dbcontext, subnet_id) nwa_info['subnet'] = {'id': subnet_id, 'netaddr': subnet['cidr'].split('/')[0], 'mask': subnet['cidr'].split('/')[1]} nwa_info['port'] = {'id': port['id'], 'ip': port['fixed_ips'][0]['ip_address'], 'mac': port['mac_address']} else: nwa_info['subnet'] = {'id': '', 'netaddr': '', 'mask': ''} nwa_info['port'] = {'id': port['id'], 'ip': '', 'mac': port['mac_address']} nwa_info['resource_group_name'] = resource_group_name nwa_info['resource_group_name_nw'] = cfg.CONF.NWA.resource_group_name nwa_info['physical_network'] = physical_network return nwa_info
def test_get_tenant_info(self): class network_context(object): network = mock.MagicMock() current = mock.MagicMock() _plugin = mock.MagicMock() _plugin_context = mock.MagicMock() context = network_context() context.network.current = {} context.network.current['tenant_id'] = 'T1' context.network.current['name'] = 'PublicVLAN_100' context.network.current['id'] = 'Uuid-PublicVLAN_100' tid, nid = nwa_com_utils.get_tenant_info(context) self.assertEqual(tid, 'T1') self.assertEqual(nid, 'RegionOneT1')
def delete_port_precommit(self, context): tenant_id, nwa_tenant_id = nwa_com_utils.get_tenant_info(context) device_owner = context._port['device_owner'] device_id = context._port['device_id'] LOG.debug("tenant_id=%(tid)s, nwa_tenant_id=%(nid)s, " "device_owner=%(dev)s", {'tid': tenant_id, 'nid': nwa_tenant_id, 'dev': device_owner}) if self.necnwa_router and self.is_router(device_owner): self._l3_delete_tenant_fw(context) elif device_owner == constants.DEVICE_OWNER_FLOATINGIP: pass elif device_owner == '' and device_id == '': pass else: self._l2_delete_general_dev(context)
def delete_port_precommit(self, context): tenant_id, nwa_tenant_id = nwa_com_utils.get_tenant_info(context) device_owner = context._port['device_owner'] device_id = context._port['device_id'] LOG.debug( "tenant_id=%(tid)s, nwa_tenant_id=%(nid)s, " "device_owner=%(dev)s", { 'tid': tenant_id, 'nid': nwa_tenant_id, 'dev': device_owner }) if self.necnwa_router and self.is_router(device_owner): self._l3_delete_tenant_fw(context) elif device_owner == constants.DEVICE_OWNER_FLOATINGIP: pass elif device_owner == '' and device_id == '': pass else: self._l2_delete_general_dev(context)