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.

(cherry picked from commit 3c5cb9d050)

Closes-bug: #1496974
Change-Id: If611de14b2ab77d2eb9ce8c5b307ea6dd4403fe1
This commit is contained in:
Carl Baldwin 2015-09-16 21:53:54 +00:00 committed by Carl Baldwin
parent d9398261ce
commit eec8c50219
1 changed files with 16 additions and 9 deletions

View File

@ -445,15 +445,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)