Changeset 120 for trunk/pxeconfig.in


Ignore:
Timestamp:
04/11/08 10:48:46 (16 years ago)
Author:
bas
Message:

configure.in:

  • removed C-compiler requirement

debian/changelog:

  • version 2.0.0

pxeconfig.in:

  • working host-range with padding

pxeconfigd.in:

  • new version
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/pxeconfig.in

    r119 r120  
    8888INTERACTIVE='interactive'
    8989EQUALWIDTH='equalwidth'
    90 VERSION='1.1.0'
     90VERSION='2.0.0'
    9191
    9292SHORTOPT_LIST='b:e:f:hin:s:rwvH:V'
     
    9898def verbose(str):
    9999        if VERBOSE:
    100                 print '%s'
     100                print '%s' %str
    101101
    102102class PxeConfig(Exception):
     
    239239                 else it must be a valid number.
    240240        """
    241 
    242241        try:
    243242                n = int(number_str)
     
    304303        manage_links(binfo)
    305304
    306 def check_command_line(binfo, hostnames):
     305def check_args(binfo, hostnames):
    307306        """
    308307        Do you we have the right and propper values
     
    310309        ### check_filename
    311310        #
     311        str = 'check_args: '
     312        verbose(str)   
    312313        try:
    313314                if not os.path.isfile(os.path.join(PXE_CONF_DIR, binfo[FILENAME])):
     
    329330
    330331        if binfo.has_key(BASENAME):
    331                 network_number = False
     332                set_padding(binfo)
    332333                create_links =  base_2_net
    333334
    334335        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)
    336338                create_links = manage_links
    337339
     
    340342                raise PxeConfig, error
    341343
    342         binfo[START] = check_number(binfo[START], network_number)
    343         binfo[END] = check_number(binfo[END], network_number)
    344 
    345344        if DEBUG:
    346345                print binfo
     
    348347        create_links(binfo)
    349348
    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):
     349def 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
     386def parse_host_range(binfo, arg):
    364387        """
    365388        Parse if arg is of format <digit-digit>, if it starts
     
    374397                raise PxeConfig, error
    375398
    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       
     403def parse_args(argv, binfo):
    384404        """
    385405        This function parses the command line options and returns the rest as
     
    439459
    440460                elif opt in ['-w', '--equal-width']:
    441                         binfo[EQUALWIDTH] = True
     461                        binfo[EQUALWIDTH] = [True, 0]
    442462
    443463                elif opt in ['-v', '--verbose']:
     
    445465
    446466                elif opt in ['-H', '--host-range']:
    447                         parse_hostrange(binfo, value)
     467                        parse_host_range(binfo, value)
    448468                       
    449469                elif opt in ['-V', '--version']:
     
    451471                        sys.exit(0)
    452472
    453         check_command_line(binfo, args)
     473        check_args(binfo, args)
    454474
    455475def host_2_net(hosts, binfo):
     
    483503                raise PxeConfig, error
    484504
    485         if binfo[EQUALWIDTH]:
    486                 width = len(str(end))
    487 
    488505        hostnames = list()
    489506        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)
    492509                else:
    493510                        hostname = '%s%d' %(binfo[BASENAME], i)
     
    507524        bootinfo = {}
    508525        bootinfo[REMOVE] = False
    509         bootinfo[EQUALWIDTH] = False
     526        bootinfo[EQUALWIDTH] = [ False, 0 ]
    510527       
    511528        configfile = '@pxeconfig_conf@'
     
    522539        PXE_CONF_DIR = os.path.realpath(PXE_CONF_DIR)
    523540        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       
     546if __name__ == '__main__':
    527547        try:
    528                 check_args(sys.argv, bootinfo)
     548                main()
    529549        except PxeConfig, detail:
    530550                print detail
    531551                sys.exit(1)
    532        
    533 if __name__ == '__main__':
    534         main()
Note: See TracChangeset for help on using the changeset viewer.