merge Andy's changes; only use --dhcp-authoritative on nat-net device
Scott Baker [Fri, 17 Oct 2014 18:30:35 +0000 (11:30 -0700)]
opencloud-net/opencloud-net.py [changed mode: 0755->0644]

old mode 100755 (executable)
new mode 100644 (file)
index 1994b73..77add86
@@ -43,8 +43,8 @@ site_net_name = "ext-net"
 site_net_dev = None
 # Handle differences between Ubuntu 14.04, 12.04, MAAS, etc.
 interfaces = netifaces.interfaces()
-for dev in ['em1', 'br0', 'eth0']:
-    if dev in interfaces:
+for dev in ['br-ex', 'em1', 'br0', 'eth0']:
+    if dev in interfaces and 2 in netifaces.ifaddresses(dev):
         site_net_dev = dev
         break
 
@@ -156,7 +156,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, ipaddr, forward_dns=True):
+def start_dnsmasq(dev, ipaddr, forward_dns=True, authoritative=False):
     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
@@ -169,12 +169,14 @@ def start_dnsmasq(dev, ipaddr, forward_dns=True):
                '--conf-file=',
                '--interface=%s' % dev,
                '--except-interface=lo',
-               '--dhcp-authoritative',
                '--dhcp-leasefile=%s' % get_leasefile(dev),
                '--dhcp-hostsfile=%s' % get_hostsfile(dev),
                '--dhcp-no-override',
                '--dhcp-range=%s,static' % ipaddr]
 
+        if authoritative:
+            cmd.append('--dhcp-authoritative')
+
         # Turn off forwarding DNS queries, only do DHCP
         if forward_dns == False:
             cmd.append('--port=0')
@@ -369,7 +371,7 @@ def main(argv):
         if e.errno == errno.EAGAIN:
             print >> sys.stderr, "Script is already running."
             sys.exit(-1)
-    
+
     start()
 
     if not nat_net_id:
@@ -400,7 +402,7 @@ def main(argv):
     add_iptables_masq(nat_net_dev, nat_cidr)
     write_dnsmasq_hostsfile(nat_net_dev, ports, nat_net_id)
     set_up_port_forwarding(nat_net_dev, ports)
-    start_dnsmasq(nat_net_dev, nat_ip_addr)
+    start_dnsmasq(nat_net_dev, nat_ip_addr, authoritative=True)
 
     # Process Public networks
     # Need iptables rule to block requests from outside...