Merge "Support dhcp metadata service for all networks"

This commit is contained in:
Jenkins
2015-08-23 03:12:54 +00:00
committed by Gerrit Code Review
4 changed files with 26 additions and 4 deletions

View File

@@ -36,11 +36,19 @@
# use_namespaces = True will be enforced. # use_namespaces = True will be enforced.
# use_namespaces = True # use_namespaces = True
# In some cases the neutron router is not present to provide the metadata
# IP but the DHCP server can be used to provide this info. Setting this
# value will force the DHCP server to append specific host routes to the
# DHCP request. If this option is set, then the metadata service will be
# activated for all the networks.
# force_metadata = False
# The DHCP server can assist with providing metadata support on isolated # The DHCP server can assist with providing metadata support on isolated
# networks. Setting this value to True will cause the DHCP server to append # networks. Setting this value to True will cause the DHCP server to append
# specific host routes to the DHCP request. The metadata service will only # specific host routes to the DHCP request. The metadata service will only
# be activated when the subnet does not contain any router port. The guest # be activated when the subnet does not contain any router port. The guest
# instance must be configured to request host routes via DHCP (Option 121). # instance must be configured to request host routes via DHCP (Option 121).
# This option doesn't have any effect when force_metadata is set to True.
# enable_isolated_metadata = False # enable_isolated_metadata = False
# Allows for serving metadata requests coming from a dedicated metadata # Allows for serving metadata requests coming from a dedicated metadata

View File

@@ -24,6 +24,8 @@ DHCP_AGENT_OPTS = [
help=_("The driver used to manage the DHCP server.")), help=_("The driver used to manage the DHCP server.")),
cfg.BoolOpt('enable_isolated_metadata', default=False, cfg.BoolOpt('enable_isolated_metadata', default=False,
help=_("Support Metadata requests on isolated networks.")), help=_("Support Metadata requests on isolated networks.")),
cfg.BoolOpt('force_metadata', default=False,
help=_("Force to use DHCP to get Metadata on all networks.")),
cfg.BoolOpt('enable_metadata_network', default=False, cfg.BoolOpt('enable_metadata_network', default=False,
help=_("Allows for serving metadata requests from a " help=_("Allows for serving metadata requests from a "
"dedicated network. Requires " "dedicated network. Requires "

View File

@@ -761,9 +761,10 @@ class Dnsmasq(DhcpLocalProcess):
# Add host routes for isolated network segments # Add host routes for isolated network segments
if (isolated_subnets[subnet.id] and if (self.conf.force_metadata or
(isolated_subnets[subnet.id] and
self.conf.enable_isolated_metadata and self.conf.enable_isolated_metadata and
subnet.ip_version == 4): subnet.ip_version == 4)):
subnet_dhcp_ip = subnet_to_interface_ip[subnet.id] subnet_dhcp_ip = subnet_to_interface_ip[subnet.id]
host_routes.append( host_routes.append(
'%s/32,%s' % (METADATA_DEFAULT_IP, subnet_dhcp_ip) '%s/32,%s' % (METADATA_DEFAULT_IP, subnet_dhcp_ip)
@@ -900,7 +901,7 @@ class Dnsmasq(DhcpLocalProcess):
A subnet is considered non-isolated if there is a port connected to A subnet is considered non-isolated if there is a port connected to
the subnet, and the port's ip address matches that of the subnet's the subnet, and the port's ip address matches that of the subnet's
gateway. The port must be owned by a nuetron router. gateway. The port must be owned by a neutron router.
""" """
isolated_subnets = collections.defaultdict(lambda: True) isolated_subnets = collections.defaultdict(lambda: True)
subnets = dict((subnet.id, subnet) for subnet in network.subnets) subnets = dict((subnet.id, subnet) for subnet in network.subnets)
@@ -919,7 +920,8 @@ class Dnsmasq(DhcpLocalProcess):
"""Determine whether the metadata proxy is needed for a network """Determine whether the metadata proxy is needed for a network
This method returns True for truly isolated networks (ie: not attached This method returns True for truly isolated networks (ie: not attached
to a router), when the enable_isolated_metadata flag is True. to a router) when enable_isolated_metadata is True, or for all the
networks when the force_metadata flags is True.
This method also returns True when enable_metadata_network is True, This method also returns True when enable_metadata_network is True,
and the network passed as a parameter has a subnet in the link-local and the network passed as a parameter has a subnet in the link-local
@@ -928,6 +930,9 @@ class Dnsmasq(DhcpLocalProcess):
providing access to the metadata service via logical routers built providing access to the metadata service via logical routers built
with 3rd party backends. with 3rd party backends.
""" """
if conf.force_metadata:
return True
if conf.enable_metadata_network and conf.enable_isolated_metadata: if conf.enable_metadata_network and conf.enable_isolated_metadata:
# check if the network has a metadata subnet # check if the network has a metadata subnet
meta_cidr = netaddr.IPNetwork(METADATA_DEFAULT_CIDR) meta_cidr = netaddr.IPNetwork(METADATA_DEFAULT_CIDR)

View File

@@ -776,6 +776,8 @@ class TestBase(TestConfBase):
self.mock_mgr = instance.start() self.mock_mgr = instance.start()
self.conf.register_opt(cfg.BoolOpt('enable_isolated_metadata', self.conf.register_opt(cfg.BoolOpt('enable_isolated_metadata',
default=True)) default=True))
self.conf.register_opt(cfg.BoolOpt("force_metadata",
default=False))
self.conf.register_opt(cfg.BoolOpt('enable_metadata_network', self.conf.register_opt(cfg.BoolOpt('enable_metadata_network',
default=False)) default=False))
self.config_parse(self.conf) self.config_parse(self.conf)
@@ -1878,6 +1880,11 @@ class TestDnsmasq(TestBase):
self.assertTrue(dhcp.Dnsmasq.should_enable_metadata( self.assertTrue(dhcp.Dnsmasq.should_enable_metadata(
self.conf, FakeV4MetadataNetwork())) self.conf, FakeV4MetadataNetwork()))
def test_should_force_metadata_returns_true(self):
self.conf.set_override("force_metadata", True)
self.assertTrue(dhcp.Dnsmasq.should_enable_metadata(self.conf,
mock.ANY))
class TestDeviceManager(TestConfBase): class TestDeviceManager(TestConfBase):