Changeset 203 for trunk/src


Ignore:
Timestamp:
08/22/12 14:17:15 (12 years ago)
Author:
bas
Message:

added two new configuration options for client program, closes #17

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/pxeconfig.py

    r202 r203  
    125125    return files[index-1]
    126126
    127 def manage_links(haddr, options):
     127def manage_links(haddr, ip_addr, options):
    128128    """
    129129    Create the links in the PXE_CONF_DIR,
     
    141141            print 'removing %s/%s' %(PXE_CONF_DIR, haddr)
    142142
     143            if options.SCRIPT_HOOK_REMOVE and ip_addr:
     144                print 'Executing client script hook remove : %s with arg: %s' %(options.SCRIPT_HOOK_REMOVE, ip_addr)
     145
    143146        if os.path.exists(haddr) and not options.DRY_RUN:
    144147            os.unlink(haddr)
    145148
    146149    else:
     150
    147151        if options.DEBUG or options.DRY_RUN or options.VERBOSE:
    148152            print 'linking %s to %s' %(haddr, pxe_filename)
     153
     154            if options.SCRIPT_HOOK_ADD and ip_addr:
     155                print 'Executing client script hook add : %s with arg: %s' %(options.SCRIPT_HOOK_ADD, ip_addr)
    149156
    150157        if not options.DRY_RUN:
     
    152159                os.unlink(haddr)
    153160            os.symlink(pxe_filename, haddr)
     161   
     162            if options.SCRIPT_HOOK_ADD and ip_addr:
     163                cmd = '%s %s' %(options.SCRIPT_HOOK_ADD, ip_addr)
     164                os.system(cmd)
    154165
    155166def net_2_hex(net, options):
     
    194205    cnet = string.joinfields(net[0:3], '.')
    195206
    196     if options.SCRIPT_HOOK:
    197         if options.DEBUG or options.DRY_RUN or options.VERBOSE:
    198             print 'Executing client script hook: %s with arg: %s' %(options.SCRIPT_HOOK, addr)
    199         if not options.DRY_RUN:
    200             cmd = '%s %s' %(options.SCRIPT_HOOK, addr)
    201             os.system(cmd)
    202207
    203208    haddr = '%s%02X' %(net_2_hex(cnet, options), int(net[3]))
    204     manage_links(haddr, options)
     209    manage_links(haddr, addr, options)
    205210
    206211
     
    214219
    215220    haddr = '01-%s' %(mac_addr.replace(':', '-').lower())
    216     manage_links(haddr, options)
     221    manage_links(haddr, None, options)
    217222
    218223def add_options(p):
     
    226231        REMOVE  = False,
    227232        VERSION  = False,
    228         SCRIPT_HOOK = False,
     233        SCRIPT_HOOK_ADD = False,
     234        SCRIPT_HOOK_REMOVE = False,
    229235    )
    230236
     
    302308            options.filename = select_pxe_configfile()
    303309
    304     # ...
    305     try:
    306         options.SCRIPT_HOOK = defaults['client_script_hook']
     310
     311    ## This will be obsoleted by client_script_hook_add
     312    #
     313    try:
     314        options.SCRIPT_HOOK_ADD = defaults['client_script_hook']
     315    except KeyError, detail:
     316        pass
     317
     318    try:
     319        options.SCRIPT_HOOK_ADD = defaults['client_script_hook_add']
     320    except KeyError, detail:
     321        pass
     322
     323    try:
     324        options.SCRIPT_HOOK_REMOVE = defaults['client_script_hook_remove']
    307325    except KeyError, detail:
    308326        pass
Note: See TracChangeset for help on using the changeset viewer.