Start using xvm.mit.edu for DHCP
[invirt/packages/invirt-dhcp.git] / code / dhcpserver.py
index 439a6f2..b8c5a9c 100755 (executable)
@@ -1,6 +1,5 @@
 #!/usr/bin/python
 import sys
-sys.path.append('pydhcplib/')
 import pydhcplib
 import pydhcplib.dhcp_network
 from pydhcplib.dhcp_packet import *
@@ -23,7 +22,6 @@ from sqlalchemy import create_engine
 dhcp_options = {'subnet_mask': '255.255.0.0',
                 'router': '18.181.0.1',
                 'domain_name_server': '18.70.0.160,18.71.0.151,18.72.0.3',
-                'domain_name': 'mit.edu',
                 'ip_address_lease_time': 60*60*24}
 
 class DhcpBackend:
@@ -96,7 +94,16 @@ class DhcpBackend:
                     
             elif option_type == "string" :
                 options[parameter] = strlist(value).list()
+            
+            elif option_type == "RFC3397" :
+                parsed_value = ""
+                for item in value:
+                    components = item.split('.')
+                    item_fmt = "".join(chr(len(elt)) + elt for elt in components) + "\x00"
+                    parsed_value += item_fmt
                 
+                options[parameter] = strlist(parsed_value).list()
+            
             else :
                 options[parameter] = strlist(value).list()
         return options
@@ -110,16 +117,23 @@ class DhcpBackend:
         ip = nic.ip
         if ip is None:  #Deactivated?
             return False
+
+        options = {}
         if nic.hostname and '.' in nic.hostname:
-            hostname = nic.hostname
+            options['host_name'], options['domain_name'] = nic.hostname.split('.', 1)
         elif nic.machine.name:
-            hostname = nic.machine.name + '.servers.csail.mit.edu'
+            options['host_name'] = nic.machine.name
+            options['domain_name'] = 'xvm.mit.edu'
         else:
             hostname = None
+        if DhcpOptions['domain_search'] in packet.GetOption('parameter_request_list'):
+            options['host_name'] += '.' + options['domain_name']
+            del options['domain_name']
+            options['domain_search'] = ['mit.edu']
         if ip is not None:
             ip = ipv4(ip)
             Log.Output(Log.debug,"dhcp_backend : Discover result = "+str(ip))
-            packet_parameters = self.getParameters(host_name=hostname)
+            packet_parameters = self.getParameters(**options)
 
             # FIXME: Other offer parameters go here
             packet_parameters["yiaddr"] = ip.list()