interfaces = self._core_plugin.get_ports(context.elevated(), filters)
LOG.debug("Return the FIP ports: %s ", interfaces)
if interfaces:
- self._populate_subnet_for_ports(context, interfaces)
+ self._populate_subnets_for_ports(context, interfaces)
return interfaces
- def get_sync_data(self, context, router_ids=None, active=None):
+ def get_dvr_sync_data(self, context, host, agent, router_ids=None,
+ active=None):
routers, interfaces, floating_ips = self._get_router_info_list(
context, router_ids=router_ids, active=active,
device_owners=l3_const.ROUTER_INTERFACE_OWNERS)
context, router_id, chosen_agent)
return chosen_agent
+ def _get_active_l3_agent_routers_sync_data(self, context, host, agent,
+ router_ids):
+ if n_utils.is_extension_supported(self, q_const.L3_HA_MODE_EXT_ALIAS):
+ return self.get_ha_sync_data_for_host(context, host,
+ router_ids=router_ids,
+ active=True)
+ return self.get_dvr_sync_data(context, host, agent,
+ router_ids=router_ids, active=True)
+
def _notify_l3_agent_new_port(resource, event, trigger, **kwargs):
- LOG.debug('Received %s %s' % (resource, event))
- port = kwargs['port']
+ LOG.debug('Received %(resource)s %(event)s', {
+ 'resource': resource,
+ 'event': event})
+ port = kwargs.get('port')
if not port:
return
def get_ha_sync_data_for_host(self, context, host=None, router_ids=None,
active=None):
- sync_data = super(L3_HA_NAT_db_mixin, self).get_sync_data(context,
- router_ids,
- active)
+ if n_utils.is_extension_supported(self,
+ constants.L3_DISTRIBUTED_EXT_ALIAS):
+ # DVR has to be handled differently
+ agent = self._get_agent_by_type_and_host(context,
+ constants.AGENT_TYPE_L3,
+ host)
+ sync_data = self.get_dvr_sync_data(context, host, agent,
+ router_ids, active)
+ else:
+ sync_data = super(L3_HA_NAT_db_mixin, self).get_sync_data(context,
+ router_ids, active)
return self._process_sync_ha_data(context, sync_data, host)
+
+ @classmethod
+ def _set_router_states(cls, context, bindings, states):
+ for binding in bindings:
+ try:
+ with context.session.begin(subtransactions=True):
+ binding.state = states[binding.router_id]
+ except (orm.exc.StaleDataError, orm.exc.ObjectDeletedError):
+ # Take concurrently deleted routers in to account
+ pass
+
+ def update_routers_states(self, context, states, host):
+ """Receive dict of router ID to state and update them all."""
+
+ bindings = self.get_ha_router_port_bindings(
+ context, router_ids=states.keys(), host=host)
+ self._set_router_states(context, bindings, states)