Merge "Only use dhcp if enable_dhcp is set on the network"

This commit is contained in:
Jenkins 2014-07-29 04:33:46 +00:00 committed by Gerrit Code Review
commit 79b38e2aee
2 changed files with 23 additions and 17 deletions

View File

@ -85,9 +85,8 @@ class LinuxNetL3(L3Driver):
networks = kwargs.get('networks', None)
if not fixed_range and networks is not None:
for network in networks:
if network['enable_dhcp']:
self.initialize_network(network['cidr'])
else:
linux_net.init_host()
linux_net.ensure_metadata_ip()
linux_net.metadata_forward()
self.initialized = True

View File

@ -1400,6 +1400,11 @@ class NetworkManager(manager.Manager):
network = objects.Network.get_by_id(context, network_id)
call_func(context, network)
def _initialize_network(self, network):
if network.enable_dhcp:
self.l3driver.initialize_network(network.cidr)
self.l3driver.initialize_gateway(network)
def _setup_network_on_host(self, context, network):
"""Sets up network on this host."""
raise NotImplementedError()
@ -1730,12 +1735,12 @@ class FlatDHCPManager(RPCAllocateFixedIP, floating_ips.FloatingIP,
def _setup_network_on_host(self, context, network):
"""Sets up network on this host."""
network['dhcp_server'] = self._get_dhcp_ip(context, network)
network.dhcp_server = self._get_dhcp_ip(context, network)
self.l3driver.initialize_network(network.get('cidr'))
self.l3driver.initialize_gateway(network)
self._initialize_network(network)
if not CONF.fake_network:
# NOTE(vish): if dhcp server is not set then don't dhcp
if not CONF.fake_network and network.enable_dhcp:
dev = self.driver.get_dev(network)
# NOTE(dprince): dhcp DB queries require elevated context
elevated = context.elevated()
@ -1747,7 +1752,8 @@ class FlatDHCPManager(RPCAllocateFixedIP, floating_ips.FloatingIP,
network.save()
def _teardown_network_on_host(self, context, network):
if not CONF.fake_network:
# NOTE(vish): if dhcp server is not set then don't dhcp
if not CONF.fake_network and network.enable_dhcp:
network['dhcp_server'] = self._get_dhcp_ip(context, network)
dev = self.driver.get_dev(network)
# NOTE(dprince): dhcp DB queries require elevated context
@ -1964,8 +1970,7 @@ class VlanManager(RPCAllocateFixedIP, floating_ips.FloatingIP, NetworkManager):
address = network.vpn_public_address
network.dhcp_server = self._get_dhcp_ip(context, network)
self.l3driver.initialize_network(network.get('cidr'))
self.l3driver.initialize_gateway(network)
self._initialize_network(network)
# NOTE(vish): only ensure this forward if the address hasn't been set
# manually.
@ -1977,6 +1982,7 @@ class VlanManager(RPCAllocateFixedIP, floating_ips.FloatingIP, NetworkManager):
if not CONF.fake_network:
dev = self.driver.get_dev(network)
# NOTE(dprince): dhcp DB queries require elevated context
if network.enable_dhcp:
elevated = context.elevated()
self.driver.update_dhcp(elevated, dev, network)
if CONF.use_ipv6:
@ -1990,9 +1996,6 @@ class VlanManager(RPCAllocateFixedIP, floating_ips.FloatingIP, NetworkManager):
if not CONF.fake_network:
network['dhcp_server'] = self._get_dhcp_ip(context, network)
dev = self.driver.get_dev(network)
# NOTE(dprince): dhcp DB queries require elevated context
elevated = context.elevated()
self.driver.update_dhcp(elevated, dev, network)
# NOTE(ethuleau): For multi hosted networks, if the network is no
# more used on this host and if VPN forwarding rule aren't handed
@ -2003,6 +2006,7 @@ class VlanManager(RPCAllocateFixedIP, floating_ips.FloatingIP, NetworkManager):
not objects.Network.in_use_on_host(context, network['id'],
self.host)):
LOG.debug("Remove unused gateway %s", network['bridge'])
if network.enable_dhcp:
self.driver.kill_dhcp(dev)
self.l3driver.remove_gateway(network)
if not self._uses_shared_ip(network):
@ -2011,7 +2015,10 @@ class VlanManager(RPCAllocateFixedIP, floating_ips.FloatingIP, NetworkManager):
fip.allocated = False
fip.host = None
fip.save()
else:
# NOTE(vish): if dhcp server is not set then don't dhcp
elif network.enable_dhcp:
# NOTE(dprince): dhcp DB queries require elevated context
elevated = context.elevated()
self.driver.update_dhcp(elevated, dev, network)
def _get_network_dict(self, network):