Changeset 126 for trunk


Ignore:
Timestamp:
04/14/08 09:44:08 (16 years ago)
Author:
bas
Message:

pxeconfig.in:

  • added --dry-run option
  • reformat manage_links function
Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Changelog

    r123 r126  
    6666       - gb-r02n02
    6767
     68   Author: Bas van der Vlies
     69
     70 - Added --dry-run mode
    6871   Author: Bas van der Vlies
    6972
  • trunk/pxeconfig.in

    r125 r126  
    4848 -r,--remove
    4949 -w,--equal-width
     50 --dry-run
    5051
    5152If leading zeros are used for <number>, then host names will be padded
     
    5657command line options.
    5758
    58 When this program is started interactive it will ask the following questions:
    59   1) Network address (Class C-network address only)
    60   2) Starting number
    61   3) Ending number
    62   4) Which PXE config file to use
    63 
    64 For example, if the answers are:
    65   1) 10.168.44
    66   2) 2
    67   3) 4
    68   4) default.node_install
    69 
    70 Then the result is that is create symbolic links in /tftpboot/pxelinux.cfg:
    71   0AA82C02 ----> default.node_install
    72   0AA82C03 ----> default.node_install
    73   0AA82C04 ----> default.node_install
     59See following link for usage and examples:
     60 - https://subtrac.sara.nl/oss/pxeconfig/wiki/PxeUsage
    7461"""
    7562
     
    8370import re
    8471
    85 # DEBUG
    86 #
    87 DEBUG=0
    88 VERBOSE=0
     72# Global Variables
     73#
     74DEBUG   = False
     75VERBOSE = False
     76DRY_RUN = False
    8977
    9078# Constants
     
    10492
    10593SHORTOPT_LIST='b:e:f:hin:s:rwvN:H:R:V'
    106 LONGOPT_LIST=[ 'basename=', 'debug', 'end=', 'equal-width',
    107     'file=', 'help', 'host-range=', 'interactive', 'net=',
    108     'node=', 'start=', 'rack=', 'remove', 'verbose',
    109     'version', 'equal-width'
     94LONGOPT_LIST=[ 'basename=', 'debug', 'dry-run', 'end=', 'equal-width',
     95    'file=', 'help', 'host-range=', 'interactive', 'net=', 'node=',
     96    'start=', 'rack=', 'remove', 'verbose', 'version', 'equal-width'
    11097        ]
    11198
     
    206193
    207194def manage_links(dict):
    208   """
    209   Create the links in the PXE_CONF_DIR,
    210     list : A list containing: network hex address, pxe config file,
     195        """
     196        Create the links in the PXE_CONF_DIR,
     197        list : A list containing: network hex address, pxe config file,
    211198           start number, end number
    212   """
    213   str = 'manage_links'
    214   verbose(str)
    215 
    216   os.chdir(PXE_CONF_DIR)
    217   naddr = dict[NETWORK]
    218   pxe_filename = dict[FILENAME]
    219 
    220   for i in range(dict[START], dict[END]+1):
    221     haddr = '%s%02X' %(naddr, i)
    222 
    223     if dict[REMOVE] == True:
    224        if DEBUG:
    225           print 'removing %s/%s' %(PXE_CONF_DIR, haddr)
    226        if os.path.exists(haddr):
    227           os.unlink(haddr)
    228     else:
    229        if DEBUG:
    230           print 'linking %s to %s' %(haddr, pxe_filename)
    231        if os.path.exists(haddr):
    232           os.unlink(haddr)
    233        os.symlink(pxe_filename, haddr)
     199        """
     200        str = 'manage_links'
     201        verbose(str)
     202       
     203        os.chdir(PXE_CONF_DIR)
     204        naddr = dict[NETWORK]
     205        pxe_filename = dict[FILENAME]
     206       
     207        for i in range(dict[START], dict[END]+1):
     208                haddr = '%s%02X' %(naddr, i)
     209               
     210                if dict[REMOVE] == True:
     211                        if DEBUG or DRY_RUN:
     212                                print 'removing %s/%s' %(PXE_CONF_DIR, haddr)
     213
     214                        if os.path.exists(haddr) and not DRY_RUN:
     215                                os.unlink(haddr)
     216
     217                else:
     218                        if DEBUG or DRY_RUN:
     219                                print 'linking %s to %s' %(haddr, pxe_filename)
     220
     221                        if not DRY_RUN:
     222                                if os.path.exists(haddr):
     223                                        os.unlink(haddr)
     224                                os.symlink(pxe_filename, haddr)
    234225
    235226def net_2_hex(net):
     
    479470        global DEBUG
    480471        global VERBOSE
     472        global DRY_RUN
    481473
    482474        # if nothing is specified then print usage and exit
     
    498490                       
    499491                elif opt in ['--debug']:
    500                         DEBUG = 1
     492                        DEBUG = True
     493
     494                elif opt in ['--dry-run']:
     495                        DRY_RUN = True
    501496                       
    502497                elif opt in ['-e', '--end']:
     
    527522
    528523                elif opt in ['-v', '--verbose']:
    529                         VERBOSE = 1
     524                        VERBOSE = True
    530525
    531526                elif opt in ['-H', '--host-range']:
Note: See TracChangeset for help on using the changeset viewer.