From 3c5cb9d050d09424c3f8eb3cd1ecd6876f50a6fe Mon Sep 17 00:00:00 2001 From: Carl Baldwin Date: Wed, 16 Sep 2015 21:53:54 +0000 Subject: [PATCH] Only get host data for floating ips on DVR routers First, we are only interested in setting the host attribute when the router is a DVR router. Second, we don't need to query all of the ports on the host, we just need to query the ports that are referenced by the set of floating ips that we already have. Closes-bug: #1496974 Change-Id: If611de14b2ab77d2eb9ce8c5b307ea6dd4403fe1 --- neutron/db/l3_dvr_db.py | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/neutron/db/l3_dvr_db.py b/neutron/db/l3_dvr_db.py index 8223e4e89..4bafc56b2 100644 --- a/neutron/db/l3_dvr_db.py +++ b/neutron/db/l3_dvr_db.py @@ -433,15 +433,22 @@ class L3_NAT_with_dvr_db_mixin(l3_db.L3_NAT_db_mixin, routers, interfaces, floating_ips = self._get_router_info_list( context, router_ids=router_ids, active=active, device_owners=l3_const.ROUTER_INTERFACE_OWNERS) - port_filter = {portbindings.HOST_ID: [host]} - ports = self._core_plugin.get_ports(context, port_filter) - port_dict = dict((port['id'], port) for port in ports) - # Add the port binding host to the floatingip dictionary - for fip in floating_ips: - vm_port = port_dict.get(fip['port_id'], None) - if vm_port: - fip['host'] = self._get_vm_port_hostid(context, fip['port_id'], - port=vm_port) + dvr_router_ids = set(router['id'] for router in routers + if is_distributed_router(router)) + floating_ip_port_ids = [fip['port_id'] for fip in floating_ips + if fip['router_id'] in dvr_router_ids] + if floating_ip_port_ids: + port_filter = {portbindings.HOST_ID: [host], + 'id': floating_ip_port_ids} + ports = self._core_plugin.get_ports(context, port_filter) + port_dict = dict((port['id'], port) for port in ports) + # Add the port binding host to the floatingip dictionary + for fip in floating_ips: + vm_port = port_dict.get(fip['port_id'], None) + if vm_port: + fip['host'] = self._get_vm_port_hostid(context, + fip['port_id'], + port=vm_port) routers_dict = self._process_routers(context, routers) self._process_floating_ips_dvr(context, routers_dict, floating_ips, host, agent) -- 2.45.2