Changeset 1033


Ignore:
Timestamp:
Oct 4, 2008, 8:13:06 PM (16 years ago)
Author:
broder
Message:

invirt-configurize sipb-xen-dhcp

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  
    1717import psycopg2
    1818import time
    19 import sipb_xen_database
    20 from sqlalchemy import create_engine
    21 
    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',
     19from invirt import database
     20from invirt.config import structs as config
     21
     22dhcp_options = {'subnet_mask': config.dhcp.netmask,
     23                'router': config.dhcp.gateway,
     24                'domain_name_server': ','.join(config.dhcp.dns),
    2525                'ip_address_lease_time': 60*60*24}
    2626
    2727class 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()
    3230    def findNIC(self, mac):
    33         sipb_xen_database.clear_cache()
     31        database.clear_cache()
    3432        for i in range(3):
    3533            try:
    36                 value = sipb_xen_database.NIC.get_by(mac_addr=mac)
     34                value = database.NIC.query().filter_by(mac_addr=mac).one()
    3735            except psycopg2.OperationalError:
    3836                time.sleep(0.5)
     
    4038                    raise
    4139                #Sigh.  SQLAlchemy should do this itself.
    42                 sipb_xen_database.connect(create_engine(self.database))
     40                database.connect()
    4341            else:
    4442                break
     
    4846        nic = self.findNIC(str(chaddr))
    4947        if nic is None or nic.ip is None:
    50             return ("18.181.0.60", None)
     48            return
    5149        ipstr = ''.join(reversed(['%02X' % i for i in ipv4(nic.ip).list()]))
    5250        for line in open('/proc/net/route'):
     
    5452            if parts[1] == ipstr:
    5553                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
    5856                           
    5957    def getParameters(self, **extra):
     
    124122        elif nic.machine.name:
    125123            options['host_name'] = nic.machine.name
    126             options['domain_name'] = 'xvm.mit.edu'
     124            options['domain_name'] = config.dns.domains[0]
    127125        else:
    128126            hostname = None
     
    130128            options['host_name'] += '.' + options['domain_name']
    131129            del options['domain_name']
    132             options['domain_search'] = ['mit.edu']
     130            options['domain_search'] = [config.dhcp.search_domain]
    133131        if ip is not None:
    134132            ip = ipv4(ip)
     
    178176
    179177    def SendDhcpPacketTo(self, To, packet):
    180         (ip, intf) = self.backend.find_interface(packet)
     178        intf = self.backend.find_interface(packet)
    181179        if intf:
    182180            out_socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
     
    275273                "client_listen_port":68,
    276274                "listen_address":"0.0.0.0"}
    277     backend = DhcpBackend('postgres://sipb-xen@sipb-xen-dev/sipb_xen')
     275    backend = DhcpBackend()
    278276    server = DhcpServer(backend, options)
    279277
  • trunk/packages/sipb-xen-dhcp/debian/changelog

    r377 r1033  
     1sipb-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
    17sipb-xen-dhcp (2) unstable; urgency=low
    28
Note: See TracChangeset for help on using the changeset viewer.