Add common code for network interfaces queries
Change-Id: Id5205e31b550078db2ae34ffe3dde94d08e9f26f
This commit is contained in:
parent
df2dc98c8f
commit
3a5c2abc9b
@ -101,6 +101,15 @@ class NsxPluginBase(db_base_plugin_v2.NeutronDbPluginV2,
|
||||
'network_id': [network_id]}
|
||||
return self.get_ports(context, filters=port_filters)
|
||||
|
||||
def _get_network_interface_ports(self, context, net_id):
|
||||
port_filters = {'device_owner': [l3_db.DEVICE_OWNER_ROUTER_INTF],
|
||||
'network_id': [net_id]}
|
||||
return self.get_ports(context, filters=port_filters)
|
||||
|
||||
def _get_network_router_ids(self, context, net_id):
|
||||
intf_ports = self._get_network_interface_ports(context, net_id)
|
||||
return [port['device_id'] for port in intf_ports if port['device_id']]
|
||||
|
||||
def get_router_for_floatingip(self, context, internal_port,
|
||||
internal_subnet, external_network_id):
|
||||
router_id = super(NsxPluginBase, self).get_router_for_floatingip(
|
||||
|
@ -2793,11 +2793,10 @@ class NsxPluginV3Base(agentschedulers_db.AZDhcpAgentSchedulerDbMixin,
|
||||
"a logical router."))
|
||||
LOG.error(err_msg)
|
||||
raise n_exc.InvalidInput(error_message=err_msg)
|
||||
port_filters = {'device_owner': [l3_db.DEVICE_OWNER_ROUTER_INTF],
|
||||
'network_id': [net_id]}
|
||||
intf_ports = self.get_ports(context.elevated(), filters=port_filters)
|
||||
router_ids = [port['device_id']
|
||||
for port in intf_ports if port['device_id']]
|
||||
intf_ports = self._get_network_interface_ports(
|
||||
context.elevated(), net_id)
|
||||
router_ids = [port['device_id'] for port in intf_ports
|
||||
if port['device_id']]
|
||||
if len(router_ids) > 0:
|
||||
err_msg = _("Only one subnet of each IP version in a network "
|
||||
"%(net_id)s can be attached to router, one subnet "
|
||||
|
@ -15,8 +15,6 @@
|
||||
import netaddr
|
||||
from oslo_log import log as logging
|
||||
|
||||
from neutron.db import l3_db
|
||||
|
||||
from neutron_lib.api import validators
|
||||
from neutron_lib import constants
|
||||
from neutron_lib.db import api as db_api
|
||||
@ -225,12 +223,8 @@ class RouterDistributedDriver(router_driver.RouterBaseDriver):
|
||||
_nsxv_plugin = self.plugin
|
||||
net_id, subnet_id = _nsxv_plugin._get_interface_info(context,
|
||||
interface_info)
|
||||
|
||||
port_filters = {'device_owner': [l3_db.DEVICE_OWNER_ROUTER_INTF],
|
||||
'network_id': [net_id]}
|
||||
intf_ports = _nsxv_plugin.get_ports(context.elevated(),
|
||||
filters=port_filters)
|
||||
router_ids = [port['device_id'] for port in intf_ports]
|
||||
router_ids = _nsxv_plugin._get_network_router_ids(
|
||||
context.elevated(), net_id)
|
||||
all_routers = _nsxv_plugin.get_routers(context,
|
||||
filters={'id': router_ids})
|
||||
dist_routers = [router['id'] for router in all_routers
|
||||
|
@ -1491,9 +1491,8 @@ class NsxV3Plugin(nsx_plugin_common.NsxPluginV3Base,
|
||||
subnet_ids = (subnet['id'] for subnet in subnets)
|
||||
|
||||
# check if the subnet is attached to a router
|
||||
port_filters = {'device_owner': [l3_db.DEVICE_OWNER_ROUTER_INTF],
|
||||
'network_id': [original_port['network_id']]}
|
||||
interfaces = self.get_ports(context.elevated(), filters=port_filters)
|
||||
interfaces = self._get_network_interface_ports(
|
||||
context.elevated(), original_port['network_id'])
|
||||
for interface in interfaces:
|
||||
for fixed_ip in interface['fixed_ips']:
|
||||
if fixed_ip['subnet_id'] in subnet_ids:
|
||||
|
@ -15,7 +15,6 @@
|
||||
|
||||
import functools
|
||||
|
||||
from neutron.db import l3_db
|
||||
from neutron.services.flavors import flavors_plugin
|
||||
from neutron_lib import exceptions as n_exc
|
||||
from oslo_log import helpers as log_helpers
|
||||
@ -54,9 +53,8 @@ def get_network_from_subnet(context, plugin, subnet_id):
|
||||
def get_router_from_network(context, plugin, subnet_id):
|
||||
subnet = plugin.get_subnet(context, subnet_id)
|
||||
network_id = subnet['network_id']
|
||||
port_filters = {'device_owner': [l3_db.DEVICE_OWNER_ROUTER_INTF],
|
||||
'network_id': [network_id]}
|
||||
ports = plugin.get_ports(context.elevated(), filters=port_filters)
|
||||
ports = plugin._get_router_interface_ports_by_network(
|
||||
context.elevated(), network_id)
|
||||
if ports:
|
||||
router = plugin.get_router(context.elevated(), ports[0]['device_id'])
|
||||
if router.get('external_gateway_info'):
|
||||
|
@ -15,7 +15,6 @@
|
||||
import netaddr
|
||||
from oslo_log import log as logging
|
||||
|
||||
from neutron.db import l3_db
|
||||
from neutron_lib.api.definitions import allowedaddresspairs as addr_apidef
|
||||
from neutron_lib.api.definitions import provider_net as pnet
|
||||
from neutron_lib.api import validators
|
||||
@ -127,9 +126,8 @@ def validate_config_for_migration(resource, event, trigger, **kwargs):
|
||||
subnet['id'], transit_networks)
|
||||
|
||||
# Network attached to multiple routers
|
||||
port_filters = {'device_owner': [l3_db.DEVICE_OWNER_ROUTER_INTF],
|
||||
'network_id': [net['id']]}
|
||||
intf_ports = plugin.get_ports(admin_context, filters=port_filters)
|
||||
intf_ports = plugin._get_network_interface_ports(
|
||||
admin_context, net['id'])
|
||||
if len(intf_ports) > 1:
|
||||
n_errors = n_errors + 1
|
||||
LOG.error("Network %s has interfaces on multiple routers. "
|
||||
|
Loading…
Reference in New Issue
Block a user