Bug fix
[nodemanager.git] / plugins / planetstack-net.py
index 1a686d4..f47b63d 100644 (file)
@@ -1,10 +1,10 @@
 """
-This plugin sets up the NAT interfaces for PlanetStack. It processes
-each interface that has a 'nat' tag set.
+This plugin sets up dnsmasq and iptables to support the "Private-Nat"
+and "Public" network models for OpenCloud.  It communicates with OvS
+on the local node and Quantum to gather information about the virtual
+interfaces instantiated by Quantum.  It uses this information to:
 
-It communicates with OvS on the local node and Quantum to gather
-information about devices.  It uses this information to:
-* add the Quantum-assigned IP address to the interface via dnsmasq
+* add the Quantum-assigned IP address to the vif via dnsmasq
 * set up port forwarding rules through the NAT using iptables
 
 The iptables configuration uses a chain called 'planetstack-net' to
@@ -36,7 +36,7 @@ nat_net_name = "nat-net"
 nat_net_id = None
 site_net_id = None
 
-quantum_auth_url = "http://viccidev1:5000/v2.0/"
+quantum_auth_url = None
 quantum_username = None
 quantum_password = None
 quantum_tenant_name = None
@@ -157,7 +157,7 @@ def dnsmasq_sighup(dev):
 # Enable dnsmasq for this interface.
 # It's possible that we could get by with a single instance of dnsmasq running on
 # all devices but I haven't tried it.
-def start_dnsmasq(dev, interface):
+def start_dnsmasq(dev, interface, forward_dns=True):
     if not dnsmasq_running(dev):
         # The '--dhcp-range=<IP addr>,static' argument to dnsmasq ensures that it only
         # hands out IP addresses to clients listed in the hostsfile
@@ -175,6 +175,10 @@ def start_dnsmasq(dev, interface):
                '--dhcp-no-override',
                '--dhcp-range=%s,static' % interface['ip']]
 
+        # Turn off forwarding DNS queries, only do DHCP
+        if forward_dns == False:
+            cmd.append('--port=0')
+
         try:
             logger.log('%s: starting dnsmasq on device %s' % (plugin, dev))
             subprocess.check_call(cmd)
@@ -207,18 +211,9 @@ def convert_ovs_output_to_dict(out):
 
     return records
 
-# Do all processing associated with Quantum ports.  It first gets a
-# list of local VM interfaces and then queries Quantum to get Port
-# records for these interfaces.  Then for all interfaces on the NAT
-# network it does the following:
-#
-# 1) Generates a dhcp-hostsfile for dnsmasq.  The purpose is to make
-# sure that the IP address assigned by Quantum appears on NAT
-# interface.
-#
-# 2) Sets up iptables rules in the 'planetstack-net' chain based on 
-# the nat:forward_ports field in the Port record.  
 
+# Get a list of local VM interfaces and then query Quantum to get
+# Port records for these interfaces.
 def get_local_quantum_ports():
     ports = []
 
@@ -243,8 +238,9 @@ def get_local_quantum_ports():
     return ports
 
 
+# Generate a dhcp-hostsfile for dnsmasq.  The purpose is to make sure
+# that the IP address assigned by Quantum appears on NAT interface.
 def write_dnsmasq_hostsfile(dev, ports, net_id):
-    # Write relevant entries to dnsmasq hostsfile
     logger.log("%s: Writing hostsfile for %s" % (plugin, dev))
     f = open(get_hostsfile(dev), 'w')
     for port in ports:
@@ -257,10 +253,11 @@ def write_dnsmasq_hostsfile(dev, ports, net_id):
     # Send SIGHUP to dnsmasq to make it re-read hostsfile
     dnsmasq_sighup(dev)
 
+# Set up iptables rules in the 'planetstack-net' chain based on
+# the nat:forward_ports field in the Port record.
 def set_up_port_forwarding(dev, ports):
-    # Set up iptables rules for port forwarding
     for port in ports:
-        if port['network_id'] == nat_net_id:
+        if port['network_id'] == nat_net_id and port['nat:forward_ports']:
             for fw in port['nat:forward_ports']:
                 ipaddr = port['fixed_ips'][0]['ip_address']
                 protocol = fw['l4_protocol']
@@ -286,6 +283,7 @@ def start():
     global quantum_username
     global quantum_password
     global quantum_tenant_name
+    global quantum_auth_url
 
     logger.log("%s: plugin starting up..." % plugin)
 
@@ -294,7 +292,7 @@ def start():
     quantum_username = parser.get("DEFAULT", "quantum_admin_username")
     quantum_password = parser.get("DEFAULT", "quantum_admin_password")
     quantum_tenant_name = parser.get("DEFAULT", "quantum_admin_tenant_name")
-
+    quantum_auth_url = parser.get("DEFAULT", "quantum_admin_auth_url")
 
 def GetSlivers(data, config=None, plc=None):
     global nat_net_id
@@ -352,5 +350,5 @@ def GetSlivers(data, config=None, plc=None):
             if 'OVS_BRIDGE' in tags:
                 dev = tags['OVS_BRIDGE']
             write_dnsmasq_hostsfile(dev, ports, site_net_id)
-            start_dnsmasq(dev, interface)
+            start_dnsmasq(dev, interface, forward_dns=False)