Changeset 123 for trunk


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

pxeconfig.in:

  • added --rack,-R and --node,-n option in combo with --basename,-b

Changelog:

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Changelog

    r120 r123  
    4545 - We do need the check for a C-compiler so remove it from the configure.in
    4646   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
    4768   Author: Bas van der Vlies
    4869
  • trunk/pxeconfig.in

    r122 r123  
    3232Usage: pxeconfig
    3333
    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
     39there are serveal ways to create a range of hostnames. they all start with:
     40 * -b,--base-name <string>
     41
     42The 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
     47opt:
    4148 -r,--remove
    42  -w,--equal-width
     49 -w,--equal-width
     50
     51If leading zeros are used for <number>, then host names will be padded
     52with zeros. --equal-width option will be enabled.
    4353
    4454With this program you can configure which PXE configuration file a node
     
    7181import socket
    7282import ConfigParser
     83import re
    7384
    7485# DEBUG
     
    8697END='end'
    8798REMOVE='remove'
     99RACK='rack'
     100NODE='node'
    88101INTERACTIVE='interactive'
    89102EQUALWIDTH='equalwidth'
    90103VERSION='2.0.0'
    91104
    92 SHORTOPT_LIST='b:e:f:hin:s:rwvH:V'
     105SHORTOPT_LIST='b:e:f:hin:s:rwvN:H:R:V'
    93106LONGOPT_LIST=[ 'basename=', 'debug', 'end=', 'equal-width',
    94107    'file=', 'help', 'host-range=', 'interactive', 'net=',
    95     'start=', 'remove', 'verbose', 'version', 'equal-width'
     108    'node=', 'start=', 'rack=', 'remove', 'verbose',
     109    'version', 'equal-width'
    96110        ]
     111
     112# regex definition
     113#
     114# A regulare expression to parse string for rack/node
     115id_re = re.compile(r"""
     116        (?P<basename>[a-zA-Z-_]*)
     117        (?P<number>[0-9]+)
     118     """, re.VERBOSE)
    97119
    98120def verbose(str):
     
    196218    haddr = '%s%02X' %(naddr, i)
    197219
    198     if dict[REMOVE]:
     220    if dict[REMOVE] == True:
    199221       if DEBUG:
    200222          print 'removing %s/%s' %(PXE_CONF_DIR, haddr)
     
    228250
    229251        if DEBUG:
    230                 print r
     252                print 'C-network in hex: ', r
    231253
    232254        return r
     
    330352
    331353        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
    334359
    335360        elif binfo.has_key(NETWORK):
     
    378403
    379404
    380 def parse_host_range(binfo, arg):
     405def parse_number_range(binfo, arg):
    381406        """
    382407        Parse if arg is of format <digit-digit>, if it starts
     
    394419        binfo[END] = l[1]
    395420
     421def 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]) 
    396460       
    397461def parse_args(argv, binfo):
     
    419483                sys.exit(1)
    420484
     485        # init vars
     486        #
     487        hostrange = node = rack = None
     488
    421489        # Check given options
    422490        #
     
    459527
    460528                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
    462536                       
    463537                elif opt in ['-V', '--version']:
    464538                        print VERSION
    465539                        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               
    466547
    467548        check_args(binfo, args)
     
    509590
    510591        host_2_net(hostnames,binfo)
    511                
     592
     593def 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
    512623def main():
    513624        # A dictionary holding the boot info
     
    517628       
    518629        bootinfo = {}
     630        bootinfo[NODE] = None
     631        bootinfo[RACK] = None
    519632        bootinfo[REMOVE] = False
    520633        bootinfo[EQUALWIDTH] = [ False, 0 ]
    521        
     634
    522635        configfile = '@pxeconfig_conf@'
    523636        settings = ReadConfig(configfile)
Note: See TracChangeset for help on using the changeset viewer.