Changeset 186
- Timestamp:
- 10/28/10 16:04:25 (13 years ago)
- Location:
- trunk
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Changelog
r185 r186 1 3.X.X:1 4.0.0: 2 2 * Improved error handeling for AdvanceParser.py 3 3 Author: Dennis Stam … … 18 18 - Updates for SYSLINUX version 4.02. 19 19 - Some obsolete menus (UBC,Ghost) have been removed. 20 Applied by : Ole Holm Nielsen 20 Author: Ole Holm Nielsen 21 22 * Added support hosts that only can use mac address for 23 pxelinux configuration. This is used in environments 24 where dynamic ip's are used. To enable this you must set in 25 pxeconfig.conf: 26 [DEFAULT] 27 arp_command : /usr/sbin/arp -n 28 29 30 You must use hostname shortcuts. Edit pxelinux.conf and add 31 for eg: 32 [bas] 33 mac_address: 00:19:b9:de:21:47 34 35 Now you can use: 36 pxeconfig bas 37 38 We can mix hostname and mac-address on the command line 39 40 Author: Bas van der Vlies 21 41 22 42 3.1.2: -
trunk/debian/changelog
r177 r186 1 pxeconfig (4.0.0-1) stable; urgency=low 2 3 * See Changelog 4 5 -- bas van der Vlies <basv@sara.nl> Thu, 28 Oct 2010 16:00:54 +0200 6 1 7 pxeconfig (3.1.2-1) stable; urgency=low 2 8 -
trunk/examples/pxeconfigd.xinetd
r172 r186 7 7 group = sys 8 8 wait = no 9 server = /usr/ sbin/pxeconfigd9 server = /usr/local/sbin/pxeconfigd 10 10 server_args = -d /tftpboot/pxelinux.cfg 11 11 } -
trunk/pxeconfig.spec
r177 r186 4 4 5 5 Name: pxeconfig 6 Version: 3.1.26 Version: 4.0.0 7 7 Release: 1%{?dist} 8 8 License: See LICENSE -
trunk/src/pxe_global.py.in
r170 r186 44 44 45 45 stanza = config.defaults() 46 return stanza46 return config, stanza -
trunk/src/pxeconfig.py
r179 r186 174 174 return r 175 175 176 def host s_2_hex(hosts, options):176 def host_2_hex(host, options): 177 177 """ 178 178 Convert hostname(s) to a net address that can be handled by manage_links function … … 182 182 print str 183 183 184 for host in hosts: 185 try: 186 addr = socket.gethostbyname(host) 187 except socket.error,detail: 188 error = '%s not an valid hostname: %s' %(host,detail) 189 raise PxeConfig, error 190 191 net = string.splitfields(addr, '.') 192 cnet = string.joinfields(net[0:3], '.') 193 194 if options.SCRIPT_HOOK: 195 if options.DEBUG or options.DRY_RUN or options.VERBOSE: 196 print 'Executing client script hook: %s with arg: %s' %(options.SCRIPT_HOOK, addr) 197 if not options.DRY_RUN: 198 cmd = '%s %s' %(options.SCRIPT_HOOK, addr) 199 os.system(cmd) 200 201 haddr = '%s%02X' %(net_2_hex(cnet, options), int(net[3])) 202 manage_links(haddr, options) 184 try: 185 addr = socket.gethostbyname(host) 186 except socket.error,detail: 187 error = '%s not an valid hostname: %s' %(host,detail) 188 raise PxeConfig, error 189 190 net = string.splitfields(addr, '.') 191 cnet = string.joinfields(net[0:3], '.') 192 193 if options.SCRIPT_HOOK: 194 if options.DEBUG or options.DRY_RUN or options.VERBOSE: 195 print 'Executing client script hook: %s with arg: %s' %(options.SCRIPT_HOOK, addr) 196 if not options.DRY_RUN: 197 cmd = '%s %s' %(options.SCRIPT_HOOK, addr) 198 os.system(cmd) 199 200 haddr = '%s%02X' %(net_2_hex(cnet, options), int(net[3])) 201 manage_links(haddr, options) 202 203 204 def mac_2_hex(mac_addr, options): 205 """ 206 Convert mac address to pxeconfig address 207 """ 208 if options.DEBUG: 209 str = 'mac_2_hex: %s' %mac_addr 210 print mac_addr 211 212 haddr = '01-%s' %(mac_addr.replace(':', '-').lower()) 213 manage_links(haddr, options) 203 214 204 215 def add_options(p): … … 251 262 ) 252 263 253 def parser(argv, settings):264 def parser(argv, config, defaults): 254 265 """ 255 266 Make use of sara advance parser module. It can handle regex in hostnames … … 272 283 if not options.DEBUG: 273 284 try: 274 if settings['debug']:275 options.DEBUG = int( settings['debug'])285 if defaults['debug']: 286 options.DEBUG = int(defaults['debug']) 276 287 except KeyError: 277 288 pass … … 290 301 # ... 291 302 try: 292 options.SCRIPT_HOOK = settings['client_script_hook']303 options.SCRIPT_HOOK = defaults['client_script_hook'] 293 304 except KeyError, detail: 294 305 pass … … 297 308 print args, options 298 309 299 hosts_2_hex(args, options) 300 310 ## 311 # Are the hosts wiht only mac addresses defined in the configuration file 312 313 for host in args: 314 if host in config.sections(): 315 mac_addr = config.get(host, 'mac_address') 316 mac_2_hex(mac_addr, options) 317 else: 318 host_2_hex(host, options) 301 319 302 320 def main(): … … 304 322 # 305 323 global PXE_CONF_DIR 306 settings = ReadConfig()307 308 try: 309 PXE_CONF_DIR = settings['pxe_config_dir']324 parser_config, default_settings = ReadConfig() 325 326 try: 327 PXE_CONF_DIR = default_settings['pxe_config_dir'] 310 328 311 329 except KeyError: … … 317 335 raise PxeConfig, error 318 336 319 parser(sys.argv, settings)337 parser(sys.argv, parser_config, default_settings) 320 338 321 339 -
trunk/src/pxeconfigd.py
r177 r186 67 67 68 68 69 def remove_link(filename): 70 """This removes the pxe config filename for the host that is connected: 71 filename : string 72 """ 69 def remove_link(ip, arp_cmd): 70 """ 71 This removes the pxe config filename for the host that is connected: 72 ip : ip address of the client host 73 arp_cmd : For Dynamic ips, look up the mac address via arp 74 """ 73 75 74 file = os.path.join(PXE_CONF_DIR, filename) 76 ## translate ip address ---> hex address 77 # 78 d = string.split(ip, '.') 79 haddr = '%02X%02X%02X%02X' %(int(d[0]), int(d[1]), int(d[2]), int(d[3])) 75 80 76 if DEBUG: 77 print 'file = %s' %file 81 file = os.path.join(PXE_CONF_DIR, haddr) 78 82 79 if not os.path.exists(file): return83 if not os.path.exists(file): 80 84 81 if os.path.islink(file): 82 try: 83 os.unlink(file) 84 syslog.openlog("pxeconfigd") 85 syslog.syslog(syslog.LOG_INFO, file) 86 syslog.closelog() 87 except OSError: 88 err_msg = "No permission at directory: %s" %PXE_CONF_DIR 89 os.write(STDOUT, err_msg) 90 sys.exit(1) 85 ## 86 # No ARP command set, just return 87 # 88 if not arp_cmd: 89 return 90 91 else: 92 ## 93 # arp -n 192.168.146.112 94 # Address HWtype HWaddress Flags Mask Iface 95 # 192.168.146.112 ether 00:23:ae:fd:cf:74 C vlan133 96 97 cmd = '%s %s' %(arp_cmd, ip) 98 lines = os.popen(cmd).readlines() 99 for line in lines: 100 if line.startswith(ip): 101 t = line.split() 102 mac_addr = t[2] 103 haddr = '01-%s' %(mac_addr.replace(':', '-').lower()) 104 file = os.path.join(PXE_CONF_DIR, haddr) 105 if not os.path.exists(file): 106 return 107 108 if DEBUG: 109 print 'file = %s' %file 110 111 if os.path.islink(file): 112 try: 113 os.unlink(file) 114 syslog.openlog("pxeconfigd") 115 syslog.syslog(syslog.LOG_INFO, file) 116 syslog.closelog() 117 except OSError: 118 err_msg = "No permission at directory: %s" %PXE_CONF_DIR 119 os.write(STDOUT, err_msg) 120 sys.exit(1) 121 91 122 92 123 # This function handles the client connection. It closes … … 108 139 raise PxeConfig, error 109 140 110 # translate ip address ---> hex address111 #112 d = string.split(client_ip, '.')113 client_haddr = '%02X%02X%02X%02X' %(int(d[0]), int(d[1]), int(d[2]), int(d[3]))114 141 115 142 if DEBUG: … … 123 150 pass 124 151 125 remove_link(client_haddr) 152 try: 153 arp_cmd = settings['arp_command'] 154 except KeyError: 155 arp_cmd = None 156 157 remove_link(client_ip, arp_cmd) 126 158 sys.exit(0) 127 159 … … 157 189 """Start the daemon 158 190 """ 159 config= ReadConfig()160 check_args(sys.argv, config)161 handleConnection( config)191 parser_config, default_settings = ReadConfig() 192 check_args(sys.argv, default_settings) 193 handleConnection(default_settings) 162 194 163 195 if __name__ == '__main__':
Note: See TracChangeset
for help on using the changeset viewer.