From b822159de88e3ec30f85aa4e981dfcd93a582dc9 Mon Sep 17 00:00:00 2001 From: Brad Hall Date: Thu, 8 Dec 2011 04:57:38 +0000 Subject: Fix network forwarding rule initialization in QuantumManager This moves the network init code from init to init_host() and breaks the snat rule cmd out of driver.init_host(). The network_create call can now just call the add_snat_rule function to set up the rule for the network when it is created. Change-Id: Id36dc42edd8b49938f85e16f16fce0416039fd50 --- nova/network/linux_net.py | 14 ++++++++++---- nova/network/quantum/manager.py | 11 ++++++++--- 2 files changed, 18 insertions(+), 7 deletions(-) (limited to 'nova') diff --git a/nova/network/linux_net.py b/nova/network/linux_net.py index 1577628df..7f79a92f8 100755 --- a/nova/network/linux_net.py +++ b/nova/network/linux_net.py @@ -393,16 +393,22 @@ def metadata_accept(): iptables_manager.apply() +def add_snat_rule(ip_range): + iptables_manager.ipv4['nat'].add_rule('snat', + '-s %s -j SNAT --to-source %s' % \ + (ip_range, + FLAGS.routing_source_ip)) + iptables_manager.apply() + + def init_host(ip_range=None): """Basic networking setup goes here.""" # NOTE(devcamcar): Cloud public SNAT entries and the default # SNAT rule for outbound traffic. if not ip_range: ip_range = FLAGS.fixed_range - iptables_manager.ipv4['nat'].add_rule('snat', - '-s %s -j SNAT --to-source %s' % \ - (ip_range, - FLAGS.routing_source_ip)) + + add_snat_rule(ip_range) iptables_manager.ipv4['nat'].add_rule('POSTROUTING', '-s %s -d %s -j ACCEPT' % \ diff --git a/nova/network/quantum/manager.py b/nova/network/quantum/manager.py index 9b6741e92..2c69efe1a 100644 --- a/nova/network/quantum/manager.py +++ b/nova/network/quantum/manager.py @@ -79,6 +79,7 @@ class QuantumManager(manager.FlatManager): super(QuantumManager, self).__init__(*args, **kwargs) + def init_host(self): # Initialize forwarding rules for anything specified in # FLAGS.fixed_range() self.driver.init_host() @@ -86,10 +87,10 @@ class QuantumManager(manager.FlatManager): # gateway set. networks = self.get_all_networks() for net in networks: - LOG.debug("Initializing network: %s (cidr: %s, gw: %s)" % ( - net['label'], net['cidr'], net['gateway'])) if net['gateway']: - self.driver.init_host(net['cidr']) + LOG.debug("Initializing NAT: %s (cidr: %s, gw: %s)" % ( + net['label'], net['cidr'], net['gateway'])) + self.driver.add_snat_rule(net['cidr']) self.driver.ensure_metadata_ip() self.driver.metadata_forward() @@ -135,6 +136,10 @@ class QuantumManager(manager.FlatManager): priority, cidr, gateway, gateway_v6, cidr_v6, dns1, dns2) + # Initialize forwarding if gateway is set + if gateway: + self.driver.add_snat_rule(cidr) + return [{'uuid': quantum_net_id}] def delete_network(self, context, fixed_range, uuid): -- cgit