#!/usr/bin/python
import sys
-sys.path.append('pydhcplib/')
import pydhcplib
import pydhcplib.dhcp_network
from pydhcplib.dhcp_packet import *
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:
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)
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
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()