Merge "Fix delete_port case in handle_port_metadata_access"
This commit is contained in:
commit
bcb424ac8d
@ -48,41 +48,51 @@ def handle_port_dhcp_access(plugin, context, port_data, action):
|
|||||||
|
|
||||||
|
|
||||||
def handle_port_metadata_access(plugin, context, port, is_delete=False):
|
def handle_port_metadata_access(plugin, context, port, is_delete=False):
|
||||||
|
# For instances supporting DHCP option 121 and created in a
|
||||||
|
# DHCP-enabled but isolated network. This method is useful
|
||||||
|
# only when no network namespace support.
|
||||||
if (cfg.CONF.NSX.metadata_mode == config.MetadataModes.INDIRECT and
|
if (cfg.CONF.NSX.metadata_mode == config.MetadataModes.INDIRECT and
|
||||||
port.get('device_owner') == const.DEVICE_OWNER_DHCP):
|
port.get('device_owner') == const.DEVICE_OWNER_DHCP):
|
||||||
if port.get('fixed_ips', []) or is_delete:
|
if not port.get('fixed_ips'):
|
||||||
fixed_ip = port['fixed_ips'][0]
|
# If port does not have an IP, the associated subnet is in
|
||||||
query = context.session.query(models_v2.Subnet)
|
# deleting state.
|
||||||
subnet = query.filter(
|
LOG.info(_LI('Port %s has no IP due to subnet in deleting state'),
|
||||||
models_v2.Subnet.id == fixed_ip['subnet_id']).one()
|
port['id'])
|
||||||
# If subnet does not have a gateway do not create metadata
|
return
|
||||||
# route. This is done via the enable_isolated_metadata
|
fixed_ip = port['fixed_ips'][0]
|
||||||
# option if desired.
|
query = context.session.query(models_v2.Subnet)
|
||||||
if not subnet.get('gateway_ip'):
|
subnet = query.filter(
|
||||||
LOG.info(_LI('Subnet %s does not have a gateway, the '
|
models_v2.Subnet.id == fixed_ip['subnet_id']).one()
|
||||||
'metadata route will not be created'),
|
# If subnet does not have a gateway, do not create metadata
|
||||||
subnet['id'])
|
# route. This is done via the enable_isolated_metadata
|
||||||
return
|
# option if desired.
|
||||||
metadata_routes = [r for r in subnet.routes
|
if not subnet.get('gateway_ip'):
|
||||||
if r['destination'] == METADATA_DHCP_ROUTE]
|
LOG.info(_LI('Subnet %s does not have a gateway, the '
|
||||||
if metadata_routes:
|
'metadata route will not be created'),
|
||||||
# We should have only a single metadata route at any time
|
subnet['id'])
|
||||||
# because the route logic forbids two routes with the same
|
return
|
||||||
# destination. Update next hop with the provided IP address
|
metadata_routes = [r for r in subnet.routes
|
||||||
if not is_delete:
|
if r['destination'] == METADATA_DHCP_ROUTE]
|
||||||
metadata_routes[0].nexthop = fixed_ip['ip_address']
|
if metadata_routes:
|
||||||
else:
|
# We should have only a single metadata route at any time
|
||||||
context.session.delete(metadata_routes[0])
|
# because the route logic forbids two routes with the same
|
||||||
|
# destination. Update next hop with the provided IP address
|
||||||
|
if not is_delete:
|
||||||
|
metadata_routes[0].nexthop = fixed_ip['ip_address']
|
||||||
else:
|
else:
|
||||||
# add the metadata route
|
context.session.delete(metadata_routes[0])
|
||||||
route = models_v2.SubnetRoute(
|
else:
|
||||||
subnet_id=subnet.id,
|
# add the metadata route
|
||||||
destination=METADATA_DHCP_ROUTE,
|
route = models_v2.SubnetRoute(
|
||||||
nexthop=fixed_ip['ip_address'])
|
subnet_id=subnet.id,
|
||||||
context.session.add(route)
|
destination=METADATA_DHCP_ROUTE,
|
||||||
|
nexthop=fixed_ip['ip_address'])
|
||||||
|
context.session.add(route)
|
||||||
|
|
||||||
|
|
||||||
def handle_router_metadata_access(plugin, context, router_id, interface=None):
|
def handle_router_metadata_access(plugin, context, router_id, interface=None):
|
||||||
|
# For instances created in a DHCP-disabled network but connected to
|
||||||
|
# a router.
|
||||||
if cfg.CONF.NSX.metadata_mode != config.MetadataModes.DIRECT:
|
if cfg.CONF.NSX.metadata_mode != config.MetadataModes.DIRECT:
|
||||||
LOG.debug("Metadata access network is disabled")
|
LOG.debug("Metadata access network is disabled")
|
||||||
return
|
return
|
||||||
|
Loading…
x
Reference in New Issue
Block a user