Remove the hack to reconnect to the database if it goes away
[invirt/packages/invirt-dhcp.git] / files / usr / sbin / sipb-xen-dhcpserver
index d5f35eb..74e554f 100755 (executable)
@@ -11,7 +11,6 @@ import IN
 
 import syslog as s
 
-import psycopg2
 import time
 from invirt import database
 from invirt.config import structs as config
@@ -26,30 +25,19 @@ class DhcpBackend:
         database.connect()
     def findNIC(self, mac):
         database.clear_cache()
-        for i in range(3):
-            try:
-                value = database.NIC.query().filter_by(mac_addr=mac).one()
-            except psycopg2.OperationalError:
-                time.sleep(0.5)
-                if i == 2:  #Try twice to reconnect.
-                    raise
-                #Sigh.  SQLAlchemy should do this itself.
-                database.connect()
-            else:
-                break
-        return value
+        return database.NIC.query().filter_by(mac_addr=mac).one()
     def find_interface(self, packet):
         chaddr = hwmac(packet.GetHardwareAddress())
         nic = self.findNIC(str(chaddr))
         if nic is None or nic.ip is None:
-            return
+            return None
         ipstr = ''.join(reversed(['%02X' % i for i in ipv4(nic.ip).list()]))
         for line in open('/proc/net/route'):
             parts = line.split()
             if parts[1] == ipstr:
                 s.syslog(s.LOG_DEBUG, "find_interface found "+str(nic.ip)+" on "+parts[0])
                 return parts[0]
-        return
+        return None
                             
     def getParameters(self, **extra):
         all_options=dict(dhcp_options)