Index: /trunk/Changelog
===================================================================
--- /trunk/Changelog	(revision 185)
+++ /trunk/Changelog	(revision 186)
@@ -1,3 +1,3 @@
-3.X.X:
+4.0.0:
   * Improved error handeling for AdvanceParser.py
     Author: Dennis Stam
@@ -18,5 +18,25 @@
      - Updates for SYSLINUX version 4.02.
      - Some obsolete menus (UBC,Ghost) have been removed.  
-    Applied by : Ole Holm Nielsen
+    Author: Ole Holm Nielsen
+
+  * Added support hosts that only can use mac address for
+    pxelinux configuration.  This is used in environments 
+    where dynamic ip's are used. To enable this you must set in
+    pxeconfig.conf:
+    	[DEFAULT]
+	arp_command        : /usr/sbin/arp -n
+
+
+    You must use hostname shortcuts.  Edit pxelinux.conf and add 
+    for eg:
+    	[bas]
+    	mac_address: 00:19:b9:de:21:47
+
+    Now you can use:
+	pxeconfig bas 
+
+    We can mix hostname and mac-address on the command line
+
+    Author: Bas van der Vlies 
 
 3.1.2:
Index: /trunk/debian/changelog
===================================================================
--- /trunk/debian/changelog	(revision 185)
+++ /trunk/debian/changelog	(revision 186)
@@ -1,2 +1,8 @@
+pxeconfig (4.0.0-1) stable; urgency=low
+
+  * See Changelog 
+
+ -- bas van der Vlies <basv@sara.nl>  Thu, 28 Oct 2010 16:00:54 +0200
+
 pxeconfig (3.1.2-1) stable; urgency=low
 
Index: /trunk/examples/pxeconfigd.xinetd
===================================================================
--- /trunk/examples/pxeconfigd.xinetd	(revision 185)
+++ /trunk/examples/pxeconfigd.xinetd	(revision 186)
@@ -7,5 +7,5 @@
 	group		= sys
 	wait		= no
-	server		= /usr/sbin/pxeconfigd
+	server		= /usr/local/sbin/pxeconfigd
 	server_args	= -d /tftpboot/pxelinux.cfg
 }
Index: /trunk/pxeconfig.spec
===================================================================
--- /trunk/pxeconfig.spec	(revision 185)
+++ /trunk/pxeconfig.spec	(revision 186)
@@ -4,5 +4,5 @@
 
 Name: pxeconfig
-Version: 3.1.2
+Version: 4.0.0 
 Release: 1%{?dist}
 License: See LICENSE
Index: /trunk/src/pxe_global.py.in
===================================================================
--- /trunk/src/pxe_global.py.in	(revision 185)
+++ /trunk/src/pxe_global.py.in	(revision 186)
@@ -44,3 +44,3 @@
 
 	stanza = config.defaults() 
-	return stanza
+	return config, stanza
Index: /trunk/src/pxeconfig.py
===================================================================
--- /trunk/src/pxeconfig.py	(revision 185)
+++ /trunk/src/pxeconfig.py	(revision 186)
@@ -174,5 +174,5 @@
 	return r
 
-def hosts_2_hex(hosts, options):
+def host_2_hex(host, options):
 	"""
 	Convert hostname(s) to a net address that can be handled by manage_links function
@@ -182,23 +182,34 @@
 		print str
 
-	for host in hosts:
-		try:
-			addr = socket.gethostbyname(host)
-		except socket.error,detail:
-			error =  '%s not an valid hostname: %s' %(host,detail)
-			raise PxeConfig, error
-
-		net = string.splitfields(addr, '.')
-		cnet = string.joinfields(net[0:3], '.')
-
-		if options.SCRIPT_HOOK:
-			if options.DEBUG or options.DRY_RUN or options.VERBOSE:
-				print 'Executing client script hook: %s with arg: %s' %(options.SCRIPT_HOOK, addr)
-			if not options.DRY_RUN:
-				cmd = '%s %s' %(options.SCRIPT_HOOK, addr)
-				os.system(cmd)
-
-		haddr = '%s%02X' %(net_2_hex(cnet, options), int(net[3])) 
-		manage_links(haddr, options)
+	try:
+		addr = socket.gethostbyname(host)
+	except socket.error,detail:
+		error =  '%s not an valid hostname: %s' %(host,detail)
+		raise PxeConfig, error
+
+	net = string.splitfields(addr, '.')
+	cnet = string.joinfields(net[0:3], '.')
+
+	if options.SCRIPT_HOOK:
+		if options.DEBUG or options.DRY_RUN or options.VERBOSE:
+			print 'Executing client script hook: %s with arg: %s' %(options.SCRIPT_HOOK, addr)
+		if not options.DRY_RUN:
+			cmd = '%s %s' %(options.SCRIPT_HOOK, addr)
+			os.system(cmd)
+
+	haddr = '%s%02X' %(net_2_hex(cnet, options), int(net[3])) 
+	manage_links(haddr, options)
+
+
+def mac_2_hex(mac_addr, options):
+	"""
+	Convert mac address to pxeconfig address
+	"""
+	if options.DEBUG:
+		str = 'mac_2_hex: %s' %mac_addr
+		print mac_addr
+
+	haddr = '01-%s' %(mac_addr.replace(':', '-').lower())
+	manage_links(haddr, options)
 
 def add_options(p):
@@ -251,5 +262,5 @@
 	)
 
-def parser(argv, settings): 
+def parser(argv, config, defaults): 
 	"""
 	Make use of sara advance parser module. It can handle regex in hostnames
@@ -272,6 +283,6 @@
 	if not options.DEBUG:
 		try:
-			if settings['debug']:
-				options.DEBUG = int(settings['debug'])
+			if defaults['debug']:
+				options.DEBUG = int(defaults['debug'])
 		except KeyError:
 			pass
@@ -290,5 +301,5 @@
 	# ...
 	try:
-		options.SCRIPT_HOOK = settings['client_script_hook']
+		options.SCRIPT_HOOK = defaults['client_script_hook']
 	except KeyError, detail:
 		pass
@@ -297,6 +308,13 @@
 		print args, options
 
-	hosts_2_hex(args, options)
-
+	##
+	# Are the hosts wiht only mac addresses defined in the configuration file
+
+	for host in args:
+		if host in config.sections():
+			mac_addr = config.get(host, 'mac_address') 
+			mac_2_hex(mac_addr, options)
+		else:
+			host_2_hex(host, options)
 
 def main():
@@ -304,8 +322,8 @@
 	#
 	global PXE_CONF_DIR
-	settings = ReadConfig() 
-	
-	try:
-		PXE_CONF_DIR = settings['pxe_config_dir']
+	parser_config, default_settings = ReadConfig() 
+	
+	try:
+		PXE_CONF_DIR = default_settings['pxe_config_dir']
 
 	except KeyError:
@@ -317,5 +335,5 @@
 		raise PxeConfig, error
 
-	parser(sys.argv, settings)
+	parser(sys.argv, parser_config, default_settings)
 
 	
Index: /trunk/src/pxeconfigd.py
===================================================================
--- /trunk/src/pxeconfigd.py	(revision 185)
+++ /trunk/src/pxeconfigd.py	(revision 186)
@@ -67,26 +67,57 @@
 
 
-def remove_link(filename):
-  """This removes the pxe config filename for the host that is connected:
-      filename : string
-  """
+def remove_link(ip, arp_cmd):
+	"""
+	This removes the pxe config filename for the host that is connected:
+		ip      : ip address of the client host
+		arp_cmd : For Dynamic ips, look up the mac address via arp
+	"""
 
-  file = os.path.join(PXE_CONF_DIR, filename)
+	## translate ip address ---> hex address 
+	#
+	d = string.split(ip, '.')
+	haddr = '%02X%02X%02X%02X' %(int(d[0]), int(d[1]), int(d[2]), int(d[3])) 
 
-  if DEBUG:
-    print 'file = %s' %file
+	file = os.path.join(PXE_CONF_DIR, haddr)
 
-  if not os.path.exists(file): return
+  	if not os.path.exists(file): 
 
-  if os.path.islink(file): 
-    try:
-      os.unlink(file)
-      syslog.openlog("pxeconfigd")
-      syslog.syslog(syslog.LOG_INFO, file)
-      syslog.closelog()
-    except OSError:
-      err_msg = "No permission at directory: %s" %PXE_CONF_DIR
-      os.write(STDOUT, err_msg)
-      sys.exit(1)
+		##
+		# No ARP command set, just return
+		#
+		if not arp_cmd:
+			return
+
+		else:
+			##
+			#  arp -n 192.168.146.112 
+			# Address          HWtype  HWaddress           Flags Mask Iface
+			# 192.168.146.112  ether   00:23:ae:fd:cf:74   C          vlan133
+
+			cmd = '%s %s' %(arp_cmd, ip)
+			lines = os.popen(cmd).readlines()
+			for line in lines:
+				if line.startswith(ip):
+					t = line.split()
+					mac_addr = t[2] 
+					haddr = '01-%s' %(mac_addr.replace(':', '-').lower())
+					file = os.path.join(PXE_CONF_DIR, haddr) 
+					if not os.path.exists(file): 
+						return
+
+	if DEBUG:
+		print 'file = %s' %file
+
+	if os.path.islink(file): 
+		try:
+			os.unlink(file)
+			syslog.openlog("pxeconfigd")
+			syslog.syslog(syslog.LOG_INFO, file)
+      			syslog.closelog()
+		except OSError:
+			err_msg = "No permission at directory: %s" %PXE_CONF_DIR
+      			os.write(STDOUT, err_msg)
+      			sys.exit(1)
+
 
 # This function handles the client connection. It closes
@@ -108,8 +139,4 @@
 		raise PxeConfig, error 
 		
-	# translate ip address ---> hex address
-	#
-	d = string.split(client_ip, '.')
-	client_haddr = '%02X%02X%02X%02X' %(int(d[0]), int(d[1]), int(d[2]), int(d[3])) 
 	
 	if DEBUG:
@@ -123,5 +150,10 @@
 		pass
 
-	remove_link(client_haddr)
+	try:
+		arp_cmd = settings['arp_command']
+	except KeyError:
+		arp_cmd = None
+
+	remove_link(client_ip, arp_cmd)
 	sys.exit(0)
 
@@ -157,7 +189,7 @@
   """Start the daemon
   """
-  config = ReadConfig()
-  check_args(sys.argv, config)
-  handleConnection(config)
+  parser_config, default_settings = ReadConfig()
+  check_args(sys.argv, default_settings)
+  handleConnection(default_settings)
 
 if __name__ == '__main__':
