Changeset 47 for trunk


Ignore:
Timestamp:
12/13/04 16:02:35 (18 years ago)
Author:
bas
Message:

pxeconfig:

  • Added hostname support instead of C-class types
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/pxeconfig/pxeconfig

    r45 r47  
    3232 [-V|--version]
    3333 [-n|--net <C-net> -s|--start <number> -e|--end <number> -f|--file <filename>]
     34 [hostname(s)]
    3435
    3536With this program you can configure which PXE configuration file a node
     
    6061import glob
    6162import getopt
     63import socket
    6264
    6365# DEBUG
     
    7274START='start'
    7375END='end'
    74 VERSION='0.4.4'
     76VERSION='0.5'
    7577
    7678SHORTOPT_LIST='hVd:n:s:e:f:'
     
    142144
    143145
    144 def check_network(net, prefix=''):
     146def convert_network(net, prefix=''):
    145147  """
    146148  This function checks if the give network is a Class C-network and will
     
    201203
    202204  network = raw_input('Give network address (xxx.xxx.xxx): ')
    203   naddr = check_network(network)
     205  naddr = convert_network(network)
    204206
    205207  start = raw_input('Starting number: ')
     
    233235def check_args(argv, binfo):
    234236  """
    235   This function parses the command line options:
    236     argv : a list of command line options.
    237     binfo: returning a dict with the netinfo. if used non-interactively
     237  This function parses the command line options and returns the rest as
     238  an list of hostnames:
     239    argv     : a list of command line options.
     240    binfo    : returning a dict with the netinfo. if used non-interactively
     241    hostnames: the rest of the command lines options that are not-parseble.
    238242  """
    239243  global PXE_CONF_DIR
     
    258262    elif opt in ['-n', '--net']:
    259263      network = value
    260       binfo[NETWORK] = check_network(value, opt)
     264      binfo[NETWORK] = convert_network(value, opt)
    261265
    262266    elif opt in ['-s', '--start']:
     
    277281      sys.exit(0)
    278282
     283    if args:
     284        return args
     285
     286def hosts_links(hosts, binfo):
     287        for host in hosts:
     288                try:
     289                        addr = socket.gethostbyname(host)
     290                except socket.error,detail:
     291                        print '%s not an valid hostname: %s' %(host,detail)
     292                        sys.exit(1)
     293                       
     294                net = string.splitfields(addr, '.')
     295                cnet = string.joinfields(net[0:3], '.')
     296
     297                binfo[NETWORK] = convert_network(cnet)
     298                binfo[START] = int(net[3])
     299                binfo[END] =  int(net[3])
     300                create_links(binfo)
     301
    279302
    280303def main():
     
    282305  #
    283306  bootinfo = {}
    284   check_args(sys.argv, bootinfo)
    285 
    286   if bootinfo:   
    287     check_cmd_line(bootinfo)
     307
     308  hostnames = check_args(sys.argv, bootinfo)
     309
     310
     311  # If we supplied args then make links for the supplied hosts
     312  # else make links for class C-networks
     313  #
     314  if hostnames:
     315        if not bootinfo.has_key(FILENAME):
     316                bootinfo[FILENAME] = select_pxe_configfile()
     317        hosts_links(hostnames,bootinfo)
    288318  else:
    289     interactive(bootinfo)
    290 
    291   create_links(bootinfo)
     319        if bootinfo:   
     320                check_cmd_line(bootinfo)
     321        else:
     322                interactive(bootinfo)
     323        create_links(bootinfo)
    292324
    293325if __name__ == '__main__':
Note: See TracChangeset for help on using the changeset viewer.