Populate subnet_mask and router options from individual NIC parameters,
authorMitchell E Berger <mitchb@mit.edu>
Wed, 16 May 2018 09:38:42 +0000 (05:38 -0400)
committerMitchell E Berger <mitchb@mit.edu>
Wed, 16 May 2018 09:38:42 +0000 (05:38 -0400)
make lease lifetime configurable per cluster, and eliminate a redundant
conditional block.

debian/changelog
invirt-dhcpserver

index ddf7343..3e53c21 100644 (file)
@@ -1,3 +1,11 @@
+invirt-dhcp (0.0.8) precise; urgency=low
+
+  * Populate subnet_mask and router options from individual NIC parameters
+  * Make lease lifetime configurable per cluster
+  * Eliminate a redundant conditional block
+
+ -- Mitchell Berger <mitchb@mit.edu>  Wed, 16 May 2018 05:37:00 -0400
+
 invirt-dhcp (0.0.7) precise; urgency=low
 
   * Fixing the version of package for prod.
index 2c36b22..438d80d 100755 (executable)
@@ -15,10 +15,8 @@ import time
 from invirt import database
 from invirt.config import structs as config
 
-dhcp_options = {'subnet_mask': config.dhcp.netmask,
-                'router': config.dhcp.gateway,
-                'domain_name_server': ','.join(config.dhcp.dns),
-                'ip_address_lease_time': 60*60*24}
+dhcp_options = {'domain_name_server': ','.join(config.dhcp.dns),
+                'ip_address_lease_time': config.dhcp.leasetime if config.dhcp.has_key('leasetime') else 60*60*24}
 
 class DhcpBackend:
     def __init__(self):
@@ -102,6 +100,8 @@ class DhcpBackend:
             return False
 
         options = {}
+        options['subnet_mask'] = nic.netmask.encode("utf-8")
+        options['router'] = nic.gateway.encode("utf-8")
         if nic.hostname and '.' in nic.hostname:
             options['host_name'], options['domain_name'] = nic.hostname.encode('utf-8').split('.', 1)
         elif nic.machine.name:
@@ -113,17 +113,15 @@ class DhcpBackend:
             options['host_name'] += '.' + options['domain_name']
             del options['domain_name']
             options['domain_search'] = [config.dhcp.search_domain]
-        if ip is not None:
-            ip = ipv4(ip)
-            s.syslog(s.LOG_DEBUG,"dhcp_backend : Discover result = "+str(ip))
-            packet_parameters = self.getParameters(**options)
+        ip = ipv4(ip)
+        s.syslog(s.LOG_DEBUG,"dhcp_backend : Discover result = "+str(ip))
+        packet_parameters = self.getParameters(**options)
 
-            # FIXME: Other offer parameters go here
-            packet_parameters["yiaddr"] = ip.list()
-            
-            packet.SetMultipleOptions(packet_parameters)
-            return True
-        return False
+        # FIXME: Other offer parameters go here
+        packet_parameters["yiaddr"] = ip.list()
+
+        packet.SetMultipleOptions(packet_parameters)
+        return True
         
     def Request(self, packet):
         s.syslog(s.LOG_DEBUG, "dhcp_backend : Request")