self._snat_redirect_add(ri, gateway['fixed_ips'][0]
['ip_address'], p, id_name)
- if (self.conf.agent_mode == 'dvr_snat' and
+ if (self.conf.agent_mode == l3_constants.L3_AGENT_MODE_DVR_SNAT and
self.get_gw_port_host(ri.router) == self.host):
self._create_dvr_gateway(ri, ex_gw_port, interface_name,
snat_ports)
def external_gateway_updated(self, ri, ex_gw_port, interface_name):
preserve_ips = []
if ri.router['distributed']:
- if (self.conf.agent_mode == 'dvr_snat' and
+ if (self.conf.agent_mode == l3_constants.L3_AGENT_MODE_DVR_SNAT and
self.get_gw_port_host(ri.router) == self.host):
ns_name = self.get_snat_ns_name(ri.router['id'])
else:
internal_interface = self.get_internal_device_name(p['id'])
self._snat_redirect_remove(ri, p, internal_interface)
- if self.conf.agent_mode == 'dvr_snat' and (
- self.get_gw_port_host(ri.router) == self.host):
+ if (self.conf.agent_mode == l3_constants.L3_AGENT_MODE_DVR_SNAT
+ and self.get_gw_port_host(ri.router) == self.host):
ns_name = self.get_snat_ns_name(ri.router['id'])
else:
# not hosting agent - no work to do
if sn_port:
self._snat_redirect_add(ri, sn_port['fixed_ips'][0]
['ip_address'], port, interface_name)
- if (self.conf.agent_mode == 'dvr_snat' and
- self.get_gw_port_host(ri.router) == self.host):
+ if (self.conf.agent_mode == l3_constants.L3_AGENT_MODE_DVR_SNAT
+ and self.get_gw_port_host(ri.router) == self.host):
ns_name = self.get_snat_ns_name(ri.router['id'])
self._set_subnet_info(sn_port)
interface_name = (
if ri.router['distributed'] and ri.ex_gw_port:
# DVR handling code for SNAT
self._snat_redirect_remove(ri, port, interface_name)
- if self.conf.agent_mode == 'dvr_snat' and (
- ri.ex_gw_port['binding:host_id'] == self.host):
+ if (self.conf.agent_mode == l3_constants.L3_AGENT_MODE_DVR_SNAT
+ and ri.ex_gw_port['binding:host_id'] == self.host):
snat_port = self._map_internal_interfaces(ri, port,
ri.snat_ports)
if snat_port:
# DEVICE_OWNER_ROUTER_HA_INTF is a special case and so is not included.
ROUTER_INTERFACE_OWNERS = (DEVICE_OWNER_ROUTER_INTF,
DEVICE_OWNER_DVR_INTERFACE)
+L3_AGENT_MODE_DVR = 'dvr'
+L3_AGENT_MODE_DVR_SNAT = 'dvr_snat'
+L3_AGENT_MODE_LEGACY = 'legacy'
+L3_AGENT_MODE = 'agent_mode'
DEVICE_ID_RESERVED_DHCP_PORT = "reserved_dhcp_port"
"""
is_distributed = router.get('distributed')
agent_conf = self.get_configuration_dict(agent)
- agent_mode = agent_conf.get('agent_mode', 'legacy')
- router_type = ('distributed' if is_distributed else 'centralized')
+ agent_mode = agent_conf.get(constants.L3_AGENT_MODE,
+ constants.L3_AGENT_MODE_LEGACY)
+ router_type = (
+ 'distributed' if is_distributed else
+ 'centralized')
+
is_agent_router_types_incompatible = (
- agent_mode == 'dvr' and not is_distributed
- or agent_mode == 'legacy' and is_distributed
+ agent_mode == constants.L3_AGENT_MODE_DVR and not is_distributed
+ or agent_mode == constants.L3_AGENT_MODE_LEGACY and is_distributed
)
if is_agent_router_types_incompatible:
raise l3agentscheduler.RouterL3AgentMismatch(
router_type=router_type, router_id=router['id'],
agent_mode=agent_mode, agent_id=agent['id'])
- if agent_mode == 'dvr' and is_distributed:
+ if agent_mode == constants.L3_AGENT_MODE_DVR and is_distributed:
raise l3agentscheduler.DVRL3CannotAssignToDvrAgent(
router_type=router_type, router_id=router['id'],
agent_id=agent['id'])
continue
agent_conf = self.get_configuration_dict(l3_agent)
- agent_mode = agent_conf.get('agent_mode', 'legacy')
- if agent_mode != 'dvr_snat':
+ agent_mode = agent_conf.get(constants.L3_AGENT_MODE,
+ constants.L3_AGENT_MODE_LEGACY)
+ if agent_mode != constants.L3_AGENT_MODE_DVR_SNAT:
continue
router_id = agent_conf.get('router_id', None)
'handle_internal_only_routers', True)
gateway_external_network_id = agent_conf.get(
'gateway_external_network_id', None)
- agent_mode = agent_conf.get('agent_mode', 'legacy')
+ agent_mode = agent_conf.get(constants.L3_AGENT_MODE,
+ constants.L3_AGENT_MODE_LEGACY)
if not use_namespaces and router_id != sync_router['id']:
continue
ex_net_id = (sync_router['external_gateway_info'] or {}).get(
ex_net_id != gateway_external_network_id)):
continue
is_router_distributed = sync_router.get('distributed', False)
- if agent_mode in ('legacy', 'dvr_snat') and (
+ if agent_mode in (
+ constants.L3_AGENT_MODE_LEGACY,
+ constants.L3_AGENT_MODE_DVR_SNAT) and (
not is_router_distributed):
candidates.append(l3_agent)
- elif is_router_distributed and agent_mode.startswith('dvr') and (
+ elif is_router_distributed and agent_mode.startswith(
+ constants.L3_AGENT_MODE_DVR) and (
self.check_ports_exist_on_l3agent(
context, l3_agent, sync_router['id'])):
candidates.append(l3_agent)
min_agents = cfg.CONF.min_l3_agents_per_router
num_agents = len(self.get_l3_agents(context,
- filters={'agent_modes': ['legacy', 'dvr_snat']}))
+ filters={'agent_modes': [constants.L3_AGENT_MODE_LEGACY,
+ constants.L3_AGENT_MODE_DVR_SNAT]}))
max_agents = cfg.CONF.max_l3_agents_per_router
if max_agents:
if max_agents > num_agents: