- Timestamp:
- 09/21/07 17:41:50 (16 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Changelog
r101 r104 12 12 Suggested by : Ole Holm Nielsen 13 13 Implemented by : Bas van der Vlies 14 15 - Added -b/--basename option. This is for host with a common prefix, eg: 16 pxeconfig --basename gb-r40n --start 1 --end 2 --filename default.install 17 18 Will create links to default.install for hosts: 19 gb-r40n1 20 gb-r40n2 21 22 Implemented by: Bas van der Vlies 14 23 15 24 0.7 -
trunk/pxeconfig.in
r103 r104 1 1 #!@PYTHON@ 2 # 3 # set ts=4, sw=4 2 4 # 3 5 # Author: Bas van der Vlies <basv@sara.nl> … … 33 35 [-i|--interactive] 34 36 [-n|--net <C-net> -s|--start <number> -e|--end <number> -f|--file <filename>] 37 [-b|--basename <string> s|--start <number> -e|--end <number> -f|--file <filename>] 35 38 [-r|--remove] 36 39 [-V|--version] … … 68 71 # DEBUG 69 72 # 70 DEBUG= 073 DEBUG=1 71 74 72 75 # Constants … … 74 77 PXE_CONF_DIR='/tftpboot/pxelinux.cfg' 75 78 NETWORK='network' 79 BASENAME='basename' 76 80 FILENAME='filename' 77 81 START='start' … … 79 83 REMOVE='remove' 80 84 INTERACTIVE='interactive' 81 VERSION= 0.8.082 83 SHORTOPT_LIST=' hVn:s:e:f:ri'84 LONGOPT_LIST=[' help', 'version', 'net=', 'start=', 'end=', 'file=', 'remove', 'debug' , 'interactive' ]85 VERSION='0.8.0' 86 87 SHORTOPT_LIST='be:f:hin:s:rV' 88 LONGOPT_LIST=['basename=', 'debug', 'end=', 'file=', 'help', 'interactive', 'net=', 'start=', 'remove', 'version' ] 85 89 86 90 def ReadConfig(file): … … 272 276 273 277 def check_args(argv, binfo): 274 """ 275 This function parses the command line options and returns the rest as 276 an list of hostnames: 277 argv : a list of command line options. 278 binfo : returning a dict with the netinfo. if used non-interactively 279 hostnames: the rest of the command lines options that are not-parseble. 280 """ 281 try: 282 opts, args = getopt.gnu_getopt(argv[1:], SHORTOPT_LIST, LONGOPT_LIST) 283 except getopt.error, detail: 284 print __doc__ 285 print detail 286 sys.exit(1) 287 288 # Check given options 289 # 290 for opt,value in opts: 291 if opt in ['-i', '--interactive']: 292 binfo[INTERACTIVE] = 1 293 294 elif opt in ['-n', '--net']: 295 network = value 296 binfo[NETWORK] = convert_network(value, opt) 297 298 elif opt in ['-s', '--start']: 299 binfo[START] = check_number(value, opt) 300 301 elif opt in ['-e', '--end']: 302 binfo[END] = check_number(value, opt) 303 304 elif opt in ['-f', '--file']: 305 binfo[FILENAME] = value 306 307 elif opt in ['-V', '--version']: 308 print VERSION 309 sys.exit(0) 310 311 elif opt in ['-r', '--remove']: 312 binfo[REMOVE] = 1 313 314 elif opt in ['--debug']: 315 DEBUG = 1 316 317 elif opt in ['-h', '--help']: 318 print __doc__ 319 sys.exit(0) 320 321 if args: 322 return args 323 324 def hosts_links(hosts, binfo): 278 """ 279 This function parses the command line options and returns the rest as 280 an list of hostnames: 281 argv : a list of command line options. 282 binfo : returning a dict with the netinfo. if used non-interactively 283 hostnames: the rest of the command lines options that are not-parseble. 284 """ 285 try: 286 opts, args = getopt.gnu_getopt(argv[1:], SHORTOPT_LIST, LONGOPT_LIST) 287 except getopt.error, detail: 288 print __doc__ 289 print detail 290 sys.exit(1) 291 292 global DEBUG 293 294 # Check given options 295 # 296 for opt,value in opts: 297 if opt in ['-i', '--interactive']: 298 binfo[INTERACTIVE] = 1 299 300 elif opt in ['-b', '--basename']: 301 binfo[BASENAME] = value 302 303 elif opt in ['--debug']: 304 DEBUG = 1 305 306 elif opt in ['-e', '--end']: 307 binfo[END] = check_number(value, opt) 308 309 elif opt in ['-f', '--file']: 310 binfo[FILENAME] = value 311 312 elif opt in ['-h', '--help']: 313 print __doc__ 314 sys.exit(0) 315 316 elif opt in ['-n', '--net']: 317 network = value 318 binfo[NETWORK] = convert_network(value, opt) 319 320 elif opt in ['-r', '--remove']: 321 binfo[REMOVE] = 1 322 323 elif opt in ['-s', '--start']: 324 binfo[START] = check_number(value, opt) 325 326 elif opt in ['-V', '--version']: 327 print VERSION 328 sys.exit(0) 329 330 if args: 331 return args 332 333 def host_2_net(hosts, binfo): 334 """ 335 Convert hostsname to a net address that can be handled by manage_links function 336 """ 325 337 for host in hosts: 326 338 try: … … 338 350 manage_links(binfo) 339 351 340 352 def base_2_net(binfo): 353 """ 354 Construct hostname(s) from the supplied basename and start and end numbers 355 """ 356 try: 357 if binfo[START] >= binfo[END]: 358 print __doc__ 359 print "Supplied wrong values for start and end" 360 sys.exit(1) 361 except KeyError, detail: 362 print __doc__ 363 print '%s is missing on the command line' %(detail) 364 sys.exit(1) 365 366 hostnames = list() 367 for i in xrange(binfo[START], binfo[END] + 1): 368 hostname = '%s%d' %(binfo[BASENAME], i) 369 if DEBUG: 370 print 'host =%s, Basename = %s, number = %d' %(hostname, binfo[BASENAME], i) 371 hostnames.append(hostname) 372 host_2_net(hostnames,binfo) 373 341 374 def main(): 342 # A dictionary holding the boot info 343 # 344 global PXE_CONF_DIR 345 global DEBUG 346 347 bootinfo = {} 348 bootinfo[REMOVE] = 0 349 350 configfile = '@pxeconfig_conf@' 351 settings = ReadConfig(configfile) 352 353 try: 354 PXE_CONF_DIR = settings['pxe_config_dir'] 355 DEBUG = int(settings['debug']) 356 except KeyError: 357 pass 358 359 hostnames = check_args(sys.argv, bootinfo) 360 361 if bootinfo[REMOVE]: 362 bootinfo[FILENAME] = 'remove_boot_file' 363 364 365 # If we have args then make links for the supplied hosts 366 # else make links for class C-networks 367 # 368 if hostnames: 369 if not bootinfo.has_key(FILENAME): 370 bootinfo[FILENAME] = select_pxe_configfile() 371 hosts_links(hostnames,bootinfo) 372 else: 373 if bootinfo.has_key(INTERACTIVE): 374 interactive(bootinfo) 375 else: 376 check_cmd_line(bootinfo) 377 manage_links(bootinfo) 375 # A dictionary holding the boot info 376 # 377 global DEBUG 378 379 bootinfo = {} 380 bootinfo[REMOVE] = 0 381 382 configfile = '@pxeconfig_conf@' 383 settings = ReadConfig(configfile) 384 385 try: 386 PXE_CONF_DIR = settings['pxe_config_dir'] 387 DEBUG = int(settings['debug']) 388 except KeyError: 389 pass 390 391 hostnames = check_args(sys.argv, bootinfo) 392 print hostnames 393 394 if bootinfo[REMOVE]: 395 bootinfo[FILENAME] = 'remove_boot_file' 396 397 # If we have args then make links for the supplied hosts 398 # else make links for class C-networks 399 # 400 if hostnames: 401 if not bootinfo.has_key(FILENAME): 402 bootinfo[FILENAME] = select_pxe_configfile() 403 host_2_net(hostnames,bootinfo) 404 405 elif bootinfo.has_key(BASENAME): 406 if not bootinfo.has_key(FILENAME): 407 bootinfo[FILENAME] = select_pxe_configfile() 408 base_2_net(bootinfo) 409 410 else: 411 if bootinfo.has_key(INTERACTIVE): 412 interactive(bootinfo) 413 else: 414 check_cmd_line(bootinfo) 415 manage_links(bootinfo) 378 416 379 417 if __name__ == '__main__': 380 418 main()
Note: See TracChangeset
for help on using the changeset viewer.