- sipb_xen_database.connect(database)
- def findIP(self, mac):
- value = sipb_xen_database.NIC.get_by(mac_addr=mac)
- if value is None:
- return None
- ip = value.ip
- if ip is None: #Deactivated?
- return None
- return ip
- def getParameters(self):
+ self.database = database
+ sipb_xen_database.connect(create_engine(database))
+ def findNIC(self, mac):
+ for i in range(3):
+ try:
+ value = sipb_xen_database.NIC.get_by(mac_addr=mac)
+ except psycopg2.OperationalError:
+ time.sleep(0.5)
+ if i == 2: #Try twice to reconnect.
+ raise
+ #Sigh. SQLAlchemy should do this itself.
+ sipb_xen_database.connect(create_engine(self.database))
+ else:
+ break
+ return value
+ def find_interface(self, packet):
+ chaddr = hwmac(packet.GetHardwareAddress())
+ nic = self.findNIC(str(chaddr))
+ if nic is None or nic.ip is None:
+ return ("18.181.0.60", 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:
+ Log.Output(Log.debug, "find_interface found "+str(nic.ip)+" on "+parts[0])
+ return ("18.181.0.60", parts[0])
+ return ("18.181.0.60", None)
+
+ def getParameters(self, **extra):
+ all_options=dict(dhcp_options)
+ all_options.update(extra)