149
149
raise NotImplementedError
152
def get_isolated_subnets(cls, network):
153
"""Returns a dict indicating whether or not a subnet is isolated."""
154
raise NotImplementedError
157
def should_enable_metadata(cls, conf, network):
158
"""True if the metadata-proxy should be enabled for the network."""
159
raise NotImplementedError
152
162
class DhcpLocalProcess(DhcpBase):
539
550
# Add host routes for isolated network segments
541
if self._enable_metadata(subnet):
552
if (isolated_subnets[subnet.id] and
553
self.conf.enable_isolated_metadata and
554
subnet.ip_version == 4):
542
555
subnet_dhcp_ip = subnet_to_interface_ip[subnet.id]
543
556
host_routes.append(
544
557
'%s/32,%s' % (METADATA_DEFAULT_IP, subnet_dhcp_ip)
624
637
return ','.join((set_tag + tag, '%s' % option) + args)
626
def _enable_metadata(self, subnet):
627
'''Determine if the metadata route will be pushed to hosts on subnet.
629
If subnet has a Neutron router attached, we want the hosts to get
630
metadata from the router's proxy via their default route instead.
632
if self.conf.enable_isolated_metadata and subnet.ip_version == 4:
633
if subnet.gateway_ip is None:
636
for port in self.network.ports:
637
if port.device_owner == constants.DEVICE_OWNER_ROUTER_INTF:
638
for alloc in port.fixed_ips:
639
if alloc.subnet_id == subnet.id:
640
def get_isolated_subnets(cls, network):
641
"""Returns a dict indicating whether or not a subnet is isolated
643
A subnet is considered non-isolated if there is a port connected to
644
the subnet, and the port's ip address matches that of the subnet's
645
gateway. The port must be owned by a nuetron router.
647
isolated_subnets = collections.defaultdict(lambda: True)
648
subnets = dict((subnet.id, subnet) for subnet in network.subnets)
650
for port in network.ports:
651
if port.device_owner != constants.DEVICE_OWNER_ROUTER_INTF:
653
for alloc in port.fixed_ips:
654
if subnets[alloc.subnet_id].gateway_ip == alloc.ip_address:
655
isolated_subnets[alloc.subnet_id] = False
657
return isolated_subnets
660
def should_enable_metadata(cls, conf, network):
661
"""True if there exists a subnet for which a metadata proxy is needed
663
if not conf.use_namespaces or not conf.enable_isolated_metadata:
666
isolated_subnets = cls.get_isolated_subnets(network)
667
return any(isolated_subnets[subnet.id] for subnet in network.subnets)
646
670
def lease_update(cls):
647
671
network_id = os.environ.get(cls.NEUTRON_NETWORK_ID_KEY)