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
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
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:
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
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)
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):
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)
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)
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)
#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()
# 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()