- Timestamp:
- Oct 4, 2008, 8:13:06 PM (16 years ago)
- Location:
- trunk/packages/sipb-xen-dhcp
- Files:
-
- 1 deleted
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/packages/sipb-xen-dhcp/code/dhcpserver.py
r506 r1033 17 17 import psycopg2 18 18 import time 19 import sipb_xen_database20 from sqlalchemy import create_engine21 22 dhcp_options = {'subnet_mask': '255.255.0.0',23 'router': '18.181.0.1',24 'domain_name_server': ' 18.70.0.160,18.71.0.151,18.72.0.3',19 from invirt import database 20 from invirt.config import structs as config 21 22 dhcp_options = {'subnet_mask': config.dhcp.netmask, 23 'router': config.dhcp.gateway, 24 'domain_name_server': ','.join(config.dhcp.dns), 25 25 'ip_address_lease_time': 60*60*24} 26 26 27 27 class DhcpBackend: 28 def __init__(self, database=None): 29 if database is not None: 30 self.database = database 31 sipb_xen_database.connect(create_engine(database)) 28 def __init__(self): 29 database.connect() 32 30 def findNIC(self, mac): 33 sipb_xen_database.clear_cache()31 database.clear_cache() 34 32 for i in range(3): 35 33 try: 36 value = sipb_xen_database.NIC.get_by(mac_addr=mac)34 value = database.NIC.query().filter_by(mac_addr=mac).one() 37 35 except psycopg2.OperationalError: 38 36 time.sleep(0.5) … … 40 38 raise 41 39 #Sigh. SQLAlchemy should do this itself. 42 sipb_xen_database.connect(create_engine(self.database))40 database.connect() 43 41 else: 44 42 break … … 48 46 nic = self.findNIC(str(chaddr)) 49 47 if nic is None or nic.ip is None: 50 return ("18.181.0.60", None)48 return 51 49 ipstr = ''.join(reversed(['%02X' % i for i in ipv4(nic.ip).list()])) 52 50 for line in open('/proc/net/route'): … … 54 52 if parts[1] == ipstr: 55 53 Log.Output(Log.debug, "find_interface found "+str(nic.ip)+" on "+parts[0]) 56 return ("18.181.0.60", parts[0])57 return ("18.181.0.60", None)54 return parts[0] 55 return 58 56 59 57 def getParameters(self, **extra): … … 124 122 elif nic.machine.name: 125 123 options['host_name'] = nic.machine.name 126 options['domain_name'] = 'xvm.mit.edu'124 options['domain_name'] = config.dns.domains[0] 127 125 else: 128 126 hostname = None … … 130 128 options['host_name'] += '.' + options['domain_name'] 131 129 del options['domain_name'] 132 options['domain_search'] = [ 'mit.edu']130 options['domain_search'] = [config.dhcp.search_domain] 133 131 if ip is not None: 134 132 ip = ipv4(ip) … … 178 176 179 177 def SendDhcpPacketTo(self, To, packet): 180 (ip, intf)= self.backend.find_interface(packet)178 intf = self.backend.find_interface(packet) 181 179 if intf: 182 180 out_socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) … … 275 273 "client_listen_port":68, 276 274 "listen_address":"0.0.0.0"} 277 backend = DhcpBackend( 'postgres://sipb-xen@sipb-xen-dev/sipb_xen')275 backend = DhcpBackend() 278 276 server = DhcpServer(backend, options) 279 277 -
trunk/packages/sipb-xen-dhcp/debian/changelog
r377 r1033 1 sipb-xen-dhcp (3) unstable; urgency=low 2 3 * invirt-configurize dhcp 4 5 -- Evan Broder <broder@mit.edu> Sat, 04 Oct 2008 19:55:49 -0400 6 1 7 sipb-xen-dhcp (2) unstable; urgency=low 2 8
Note: See TracChangeset
for help on using the changeset viewer.