Changeset 120 for trunk/pxeconfig.in
- Timestamp:
- 04/11/08 10:48:46 (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/pxeconfig.in
r119 r120 88 88 INTERACTIVE='interactive' 89 89 EQUALWIDTH='equalwidth' 90 VERSION=' 1.1.0'90 VERSION='2.0.0' 91 91 92 92 SHORTOPT_LIST='b:e:f:hin:s:rwvH:V' … … 98 98 def verbose(str): 99 99 if VERBOSE: 100 print '%s' 100 print '%s' %str 101 101 102 102 class PxeConfig(Exception): … … 239 239 else it must be a valid number. 240 240 """ 241 242 241 try: 243 242 n = int(number_str) … … 304 303 manage_links(binfo) 305 304 306 def check_ command_line(binfo, hostnames):305 def check_args(binfo, hostnames): 307 306 """ 308 307 Do you we have the right and propper values … … 310 309 ### check_filename 311 310 # 311 str = 'check_args: ' 312 verbose(str) 312 313 try: 313 314 if not os.path.isfile(os.path.join(PXE_CONF_DIR, binfo[FILENAME])): … … 329 330 330 331 if binfo.has_key(BASENAME): 331 network_number = False332 set_padding(binfo) 332 333 create_links = base_2_net 333 334 334 335 elif binfo.has_key(NETWORK): 335 network_number = True 336 binfo[START] = check_number(binfo[START], True) 337 binfo[END] = check_number(binfo[END], True) 336 338 create_links = manage_links 337 339 … … 340 342 raise PxeConfig, error 341 343 342 binfo[START] = check_number(binfo[START], network_number)343 binfo[END] = check_number(binfo[END], network_number)344 345 344 if DEBUG: 346 345 print binfo … … 348 347 create_links(binfo) 349 348 350 def set_padding(binfo, start, end): 351 """ 352 find out th 353 """ 354 if len(start) > 1 and start[0] == '0': 355 binfo[EQUALWIDTH] = True 356 elif end[0] == '0': 357 binfo[EQUALWIDTH] = True 358 359 if len(start) == len(end): 360 a =1 361 362 363 def parse_hostrange(binfo, arg): 349 def set_padding(binfo): 350 """ 351 binfo : boot info 352 network_number : must we check if start,end values are 353 valid network numbers 354 return: 355 - if equal_width is requested then the length will be set to end value 356 - if start value length > 1 and start with a zero (0), width is set to 357 the end value 358 - if end value starts with a zero (0), width will be set to the end 359 value 360 """ 361 start_str = binfo[START] 362 end_str = binfo[END] 363 364 print 'padding ', type(start_str), type(end_str) 365 366 start = check_number(start_str, False) 367 end = check_number(end_str, False) 368 369 370 print type(start_str), type(end_str) 371 372 373 if binfo[EQUALWIDTH][0] == True: 374 binfo[EQUALWIDTH][1] = len(end_str) 375 376 elif len(start_str) > 1 and start_str[0] == '0': 377 binfo[EQUALWIDTH] = [ True, len(end_str) ] 378 379 elif end_str[0] == '0': 380 binfo[EQUALWIDTH] = [ True, len(end_str) ] 381 382 binfo[START] = start 383 binfo[END] = end 384 385 386 def parse_host_range(binfo, arg): 364 387 """ 365 388 Parse if arg is of format <digit-digit>, if it starts … … 374 397 raise PxeConfig, error 375 398 376 start = l[0] 377 end = l[1] 378 379 380 binfo[START] = check_number(start, False) 381 binfo[END] = check_number(end, False) 382 383 def check_args(argv, binfo): 399 binfo[START] = l[0] 400 binfo[END] = l[1] 401 402 403 def parse_args(argv, binfo): 384 404 """ 385 405 This function parses the command line options and returns the rest as … … 439 459 440 460 elif opt in ['-w', '--equal-width']: 441 binfo[EQUALWIDTH] = True461 binfo[EQUALWIDTH] = [True, 0] 442 462 443 463 elif opt in ['-v', '--verbose']: … … 445 465 446 466 elif opt in ['-H', '--host-range']: 447 parse_host range(binfo, value)467 parse_host_range(binfo, value) 448 468 449 469 elif opt in ['-V', '--version']: … … 451 471 sys.exit(0) 452 472 453 check_ command_line(binfo, args)473 check_args(binfo, args) 454 474 455 475 def host_2_net(hosts, binfo): … … 483 503 raise PxeConfig, error 484 504 485 if binfo[EQUALWIDTH]:486 width = len(str(end))487 488 505 hostnames = list() 489 506 for i in xrange(start, end + 1): 490 if binfo[EQUALWIDTH] :491 hostname = '%s%0*d' %(binfo[BASENAME], width, i)507 if binfo[EQUALWIDTH][0] == True: 508 hostname = '%s%0*d' %(binfo[BASENAME], binfo[EQUALWIDTH][1], i) 492 509 else: 493 510 hostname = '%s%d' %(binfo[BASENAME], i) … … 507 524 bootinfo = {} 508 525 bootinfo[REMOVE] = False 509 bootinfo[EQUALWIDTH] = False526 bootinfo[EQUALWIDTH] = [ False, 0 ] 510 527 511 528 configfile = '@pxeconfig_conf@' … … 522 539 PXE_CONF_DIR = os.path.realpath(PXE_CONF_DIR) 523 540 if not os.path.isdir(PXE_CONF_DIR): 524 print 'pxeconfig directory: %s does not exists' %(PXE_CONF_DIR) 525 sys.exit(1) 526 541 error = 'pxeconfig directory: %s does not exists' %(PXE_CONF_DIR) 542 raise PxeConfig, error 543 544 parse_args(sys.argv, bootinfo) 545 546 if __name__ == '__main__': 527 547 try: 528 check_args(sys.argv, bootinfo)548 main() 529 549 except PxeConfig, detail: 530 550 print detail 531 551 sys.exit(1) 532 533 if __name__ == '__main__':534 main()
Note: See TracChangeset
for help on using the changeset viewer.