X-Git-Url: http://xvm.mit.edu/gitweb/invirt/packages/invirt-dhcp.git/blobdiff_plain/9007b014f45be76bf183371353068bab12b749f6..7021dae6611601295521367d02953e99f9e08414:/code/dhcpserver.py diff --git a/code/dhcpserver.py b/code/dhcpserver.py old mode 100644 new mode 100755 index 3133643..b8c5a9c --- a/code/dhcpserver.py +++ b/code/dhcpserver.py @@ -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: @@ -32,6 +30,7 @@ class DhcpBackend: self.database = database sipb_xen_database.connect(create_engine(database)) def findNIC(self, mac): + sipb_xen_database.clear_cache() for i in range(3): try: value = sipb_xen_database.NIC.get_by(mac_addr=mac) @@ -95,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 @@ -109,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()