- Timestamp:
- 04/11/08 17:10:23 (15 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Changelog
r120 r123 45 45 - We do need the check for a C-compiler so remove it from the configure.in 46 46 and made a new configure 47 Author: Bas van der Vlies 48 49 - Added -R,--rack and -N,--node option, eg: 50 pxeconfig --basename gb- --rack r1-r2 --node n1-n2 -f default.memtest 51 52 will produce links to file defaul.memtest for these hosts: 53 - gb-r1n1 54 - gb-r1n2 55 - gb-r2n1 56 - gb-r2n2 57 58 If leading zeros are used, then rack and/or node names will be padded with 59 zeros, eg: 60 pxeconfig --basename gb- --rack r01-r02 --node n01-n02 -f default.memtest 61 62 will produce links to file defaul.memtest for these hosts: 63 - gb-r01n01 64 - gb-r01n02 65 - gb-r02n01 66 - gb-r02n02 67 47 68 Author: Bas van der Vlies 48 69 -
trunk/pxeconfig.in
r122 r123 32 32 Usage: pxeconfig 33 33 34 [optional] -f|--file <filename> <hostname(s)> 35 [optional] -i|--interactive 36 [optional] -n|--net <C-net> -s|--start <number> -e|--end <number> -f|--file <filename> 37 [optional] -b|--basename <string> s|--start <number> -e|--end <number> -f|--file <filename> 38 -V|--version 39 40 options: 34 -V,--version 35 [-r,--remove] -i,--interactive 36 [-r,--remove] -f,--file <filename> <hostname(s)> 37 [-r,--remove] -n,--net <C-net> -s,--start <number> -e,--end <number> -f,--file <filename> 38 39 there are serveal ways to create a range of hostnames. they all start with: 40 * -b,--base-name <string> 41 42 The different formats are: 43 1 [opt] -H,--host-range <number>-<number> -f,--file <filename> 44 2 [opt] -s,--start <number> -e,--end <number> -f,--file <filename> 45 3 [opt] -R,--rack <string>-<string> -N,--node <string>-<string> -f,--file <filename> 46 47 opt: 41 48 -r,--remove 42 -w,--equal-width 49 -w,--equal-width 50 51 If leading zeros are used for <number>, then host names will be padded 52 with zeros. --equal-width option will be enabled. 43 53 44 54 With this program you can configure which PXE configuration file a node … … 71 81 import socket 72 82 import ConfigParser 83 import re 73 84 74 85 # DEBUG … … 86 97 END='end' 87 98 REMOVE='remove' 99 RACK='rack' 100 NODE='node' 88 101 INTERACTIVE='interactive' 89 102 EQUALWIDTH='equalwidth' 90 103 VERSION='2.0.0' 91 104 92 SHORTOPT_LIST='b:e:f:hin:s:rwv H:V'105 SHORTOPT_LIST='b:e:f:hin:s:rwvN:H:R:V' 93 106 LONGOPT_LIST=[ 'basename=', 'debug', 'end=', 'equal-width', 94 107 'file=', 'help', 'host-range=', 'interactive', 'net=', 95 'start=', 'remove', 'verbose', 'version', 'equal-width' 108 'node=', 'start=', 'rack=', 'remove', 'verbose', 109 'version', 'equal-width' 96 110 ] 111 112 # regex definition 113 # 114 # A regulare expression to parse string for rack/node 115 id_re = re.compile(r""" 116 (?P<basename>[a-zA-Z-_]*) 117 (?P<number>[0-9]+) 118 """, re.VERBOSE) 97 119 98 120 def verbose(str): … … 196 218 haddr = '%s%02X' %(naddr, i) 197 219 198 if dict[REMOVE] :220 if dict[REMOVE] == True: 199 221 if DEBUG: 200 222 print 'removing %s/%s' %(PXE_CONF_DIR, haddr) … … 228 250 229 251 if DEBUG: 230 print r252 print 'C-network in hex: ', r 231 253 232 254 return r … … 330 352 331 353 if binfo.has_key(BASENAME): 332 set_padding(binfo) 333 create_links = base_2_net 354 if binfo[RACK] and binfo[NODE]: 355 create_links = rack_2_net 356 else: 357 set_padding(binfo) 358 create_links = base_2_net 334 359 335 360 elif binfo.has_key(NETWORK): … … 378 403 379 404 380 def parse_ host_range(binfo, arg):405 def parse_number_range(binfo, arg): 381 406 """ 382 407 Parse if arg is of format <digit-digit>, if it starts … … 394 419 binfo[END] = l[1] 395 420 421 def parse_string_range(binfo, arg, id): 422 """ 423 Parse if arg is of format <(alpha)(digit)>-(alpha)(digit)> 424 if digit starts with a zero (0) then set EQUALWIDTH 425 """ 426 str = 'parse_string_range: %s %s' %(arg, id) 427 verbose(str) 428 429 l = arg.split('-') 430 if len(l) < 2: 431 error = '%s : range syntax not valid,eg <string>-<string>)' %(arg) 432 raise PxeConfig, error 433 434 binfo[id] = dict() 435 binfo[id][EQUALWIDTH] = [False, 0] 436 437 i = 0 438 for item in l: 439 result = id_re.match(item) 440 441 if result: 442 basename = result.group('basename') 443 number = result.group('number') 444 445 if DEBUG: 446 print 'basename = %s, number = %s' %(basename, number) 447 448 if i == 0: 449 binfo[id][BASENAME] = basename 450 binfo[id][START] = number 451 i += 1 452 else: 453 binfo[id][END] = number 454 455 else: 456 error = '%s : string syntax is not valid, eg: <alpa>*<digit>+' %(item) 457 raise PxeConfig, error 458 459 set_padding(binfo[id]) 396 460 397 461 def parse_args(argv, binfo): … … 419 483 sys.exit(1) 420 484 485 # init vars 486 # 487 hostrange = node = rack = None 488 421 489 # Check given options 422 490 # … … 459 527 460 528 elif opt in ['-H', '--host-range']: 461 parse_host_range(binfo, value) 529 hostrange = value 530 531 elif opt in ['-N', '--node']: 532 node = value 533 534 elif opt in ['-R', '--rack']: 535 rack = value 462 536 463 537 elif opt in ['-V', '--version']: 464 538 print VERSION 465 539 sys.exit(0) 540 541 if node and rack: 542 parse_string_range(binfo, node, NODE) 543 parse_string_range(binfo, rack, RACK) 544 elif hostrange: 545 parse_number_range(binfo, hostrange) 546 466 547 467 548 check_args(binfo, args) … … 509 590 510 591 host_2_net(hostnames,binfo) 511 592 593 def rack_2_net(binfo): 594 """ 595 """ 596 basename = binfo[BASENAME] 597 start = binfo[RACK][START] 598 end = binfo[RACK][END] 599 600 601 if start > end: 602 error = '%d >= %d : start value is greater then end value' %(start, end) 603 raise PxeConfig, error 604 605 for i in xrange(start, end + 1): 606 if binfo[RACK][EQUALWIDTH][0] == True: 607 new_base = '%s%s%0*d' %(basename, binfo[RACK][BASENAME], binfo[RACK][EQUALWIDTH][1], i) 608 else: 609 new_base = '%s%s%d' %(basename, binfo[RACK][BASENAME], i) 610 611 # Make copy and file in the appropiate values for creating/removing links 612 # 613 new_bootinfo = binfo[NODE].copy() 614 new_bootinfo[BASENAME] = '%s%s' %(new_base, binfo[NODE][BASENAME]) 615 new_bootinfo[FILENAME] = binfo[FILENAME] 616 new_bootinfo[REMOVE] = binfo[REMOVE] 617 618 if DEBUG: 619 print 'rack ', new_bootinfo 620 621 base_2_net(new_bootinfo) 622 512 623 def main(): 513 624 # A dictionary holding the boot info … … 517 628 518 629 bootinfo = {} 630 bootinfo[NODE] = None 631 bootinfo[RACK] = None 519 632 bootinfo[REMOVE] = False 520 633 bootinfo[EQUALWIDTH] = [ False, 0 ] 521 634 522 635 configfile = '@pxeconfig_conf@' 523 636 settings = ReadConfig(configfile)
Note: See TracChangeset
for help on using the changeset viewer.