Use the syslog module instead of the event_logger module
[invirt/packages/invirt-dhcp.git] / code / dhcpserver.py
index 634cad6..d5f35eb 100755 (executable)
@@ -9,10 +9,7 @@ from pydhcplib.type_strlist import strlist
 import socket
 import IN
 
-import event_logger
-if '__main__' == __name__:
-    event_logger.init("stdout", 'DEBUG', {})
-from event_logger import Log
+import syslog as s
 
 import psycopg2
 import time
@@ -50,7 +47,7 @@ class DhcpBackend:
         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])
+                s.syslog(s.LOG_DEBUG, "find_interface found "+str(nic.ip)+" on "+parts[0])
                 return parts[0]
         return
                             
@@ -107,7 +104,7 @@ class DhcpBackend:
         return options
 
     def Discover(self, packet):
-        Log.Output(Log.debug,"dhcp_backend : Discover ")
+        s.syslog(s.LOG_DEBUG, "dhcp_backend : Discover ")
         chaddr = hwmac(packet.GetHardwareAddress())
         nic = self.findNIC(str(chaddr))
         if nic is None or nic.machine is None:
@@ -130,7 +127,7 @@ class DhcpBackend:
             options['domain_search'] = [config.dhcp.search_domain]
         if ip is not None:
             ip = ipv4(ip)
-            Log.Output(Log.debug,"dhcp_backend : Discover result = "+str(ip))
+            s.syslog(s.LOG_DEBUG,"dhcp_backend : Discover result = "+str(ip))
             packet_parameters = self.getParameters(**options)
 
             # FIXME: Other offer parameters go here
@@ -141,7 +138,7 @@ class DhcpBackend:
         return False
         
     def Request(self, packet):
-        Log.Output(Log.debug, "dhcp_backend : Request")
+        s.syslog(s.LOG_DEBUG, "dhcp_backend : Request")
         
         discover = self.Discover(packet)
         
@@ -152,14 +149,14 @@ class DhcpBackend:
         yiaddr = packet.GetOption("yiaddr")
 
         if not discover:
-            Log.Output(Log.info,"Unknown MAC address: "+str(chaddr))
+            s.syslog(s.LOG_INFO,"Unknown MAC address: "+str(chaddr))
             return False
         
         if yiaddr!="0.0.0.0" and yiaddr == request :
-            Log.Output(Log.info,"Ack ip "+str(yiaddr)+" for "+str(chaddr))
+            s.syslog(s.LOG_INFO,"Ack ip "+str(yiaddr)+" for "+str(chaddr))
             return True
         else:
-            Log.Output(Log.info,"Requested ip "+str(request)+" not available for "+str(chaddr))
+            s.syslog(s.LOG_INFO,"Requested ip "+str(request)+" not available for "+str(chaddr))
         return False
 
     def Decline(self, packet):
@@ -172,7 +169,7 @@ class DhcpServer(pydhcplib.dhcp_network.DhcpServer):
     def __init__(self, backend, options = {'client_listenport':68,'server_listenport':67}):
         pydhcplib.dhcp_network.DhcpServer.__init__(self,"0.0.0.0",options["client_listen_port"],options["server_listen_port"],)
         self.backend = backend
-        Log.Output(Log.debug, "__init__ DhcpServer")
+        s.syslog(s.LOG_DEBUG, "__init__ DhcpServer")
 
     def SendDhcpPacketTo(self, To, packet):
         intf = self.backend.find_interface(packet)
@@ -197,12 +194,12 @@ class DhcpServer(pydhcplib.dhcp_network.DhcpServer):
         if giaddr!=[0,0,0,0] :
             agent_ip = ".".join(map(str,giaddr))
             self.SendDhcpPacketTo(agent_ip,packet)
-            Log.Output(Log.debug, "SendPacket to agent : "+agent_ip)
+            s.syslog(s.LOG_DEBUG, "SendPacket to agent : "+agent_ip)
 
         # FIXME: This shouldn't broadcast if it has an IP address to send
         # it to instead. See RFC2131 part 4.1 for full details
         else :
-            Log.Output(Log.debug, "No agent, broadcast packet.")
+            s.syslog(s.LOG_DEBUG, "No agent, broadcast packet.")
             self.SendDhcpPacketTo("255.255.255.255",packet)
             
 
@@ -212,7 +209,7 @@ class DhcpServer(pydhcplib.dhcp_network.DhcpServer):
 
         logmsg = "Get DHCPDISCOVER packet from " + hwmac(packet.GetHardwareAddress()).str()
 
-        Log.Output(Log.info, logmsg)
+        s.syslog(s.LOG_INFO, logmsg)
         offer = DhcpPacket()
         offer.CreateDhcpOfferPacketFrom(packet)
         
@@ -232,15 +229,15 @@ class DhcpServer(pydhcplib.dhcp_network.DhcpServer):
         #packet.PrintOptions()
 
         if sid != [0,0,0,0] and ciaddr == [0,0,0,0] :
-            Log.Output(Log.info, "Get DHCPREQUEST_SELECTING_STATE packet")
+            s.syslog(s.LOG_INFO, "Get DHCPREQUEST_SELECTING_STATE packet")
 
         elif sid == [0,0,0,0] and ciaddr == [0,0,0,0] and ip :
-            Log.Output(Log.info, "Get DHCPREQUEST_INITREBOOT_STATE packet")
+            s.syslog(s.LOG_INFO, "Get DHCPREQUEST_INITREBOOT_STATE packet")
 
         elif sid == [0,0,0,0] and ciaddr != [0,0,0,0] and not ip :
-            Log.Output(Log.info,"Get DHCPREQUEST_INITREBOOT_STATE packet")
+            s.syslog(s.LOG_INFO,"Get DHCPREQUEST_INITREBOOT_STATE packet")
 
-        else : Log.Output(Log.info,"Get DHCPREQUEST_UNKNOWN_STATE packet : not implemented")
+        else : s.syslog(s.LOG_INFO,"Get DHCPREQUEST_UNKNOWN_STATE packet : not implemented")
 
         if self.backend.Request(packet) : packet.TransformToDhcpAckPacket()
         else : packet.TransformToDhcpNackPacket()
@@ -251,15 +248,15 @@ class DhcpServer(pydhcplib.dhcp_network.DhcpServer):
 
     # FIXME: These are not yet implemented.
     def HandleDhcpDecline(self, packet):
-        Log.Output(Log.info, "Get DHCPDECLINE packet")
+        s.syslog(s.LOG_INFO, "Get DHCPDECLINE packet")
         self.backend.Decline(packet)
         
     def HandleDhcpRelease(self, packet):
-        Log.Output(Log.info,"Get DHCPRELEASE packet")
+        s.syslog(s.LOG_INFO,"Get DHCPRELEASE packet")
         self.backend.Release(packet)
         
     def HandleDhcpInform(self, packet):
-        Log.Output(Log.info, "Get DHCPINFORM packet")
+        s.syslog(s.LOG_INFO, "Get DHCPINFORM packet")
 
         if self.backend.Request(packet) :
             packet.TransformToDhcpAckPacket()