Skip to main content

Handling NIM Operations

This document explains the flow of handling different NIM operations. The main function is responsible for determining the action to be performed and calling the appropriate function to handle that action. It includes building NIM node information, registering new clients, and updating NIM clients.

The flow starts with the main function checking the action to be performed. If the action is 'update', it sets the necessary parameters and calls the nim_update function to handle the update operation. If the action is register_client, it sets the targets to the new targets and calls the register_client function to register a new client. For other actions, it calls build_nim_node to build the NIM node information.

Flow drill down


Handling different NIM operations

First, the main function checks if the action is 'update'. If it is, it sets the necessary parameters and calls the nim_update function to handle the update operation for NIM clients.

    # skip build nim node for actions: master_setup or show
if action != 'master_setup' and action != 'show' and action != 'register_client':
# Build nim node info
build_nim_node(module)

if action == 'register_client':
targets = module.params['new_targets']
register_client(module, targets)

if action == 'update':
params['targets'] = targets
params['lpp_source'] = lpp_source
params['asynchronous'] = asynchronous
params['force'] = force
params['alt_disk_update_name'] = alt_disk_update_name
nim_update(module, params)


Registering a new client

Next, if the action is register_client, the main function sets the targets to the new targets and calls the register_client function to register a new client.

    if action == 'register_client':
targets = module.params['new_targets']
register_client(module, targets)


Building NIM node information

Then, for actions other than master_setup, 'show', and register_client, the main function calls build_nim_node to build the NIM node information.

    if action != 'master_setup' and action != 'show' and action != 'register_client':
# Build nim node info
build_nim_node(module)


Performing NIM update

Diving into the nim_update function, it first logs the update operation and checks if the update should be asynchronous or synchronous. This decision affects how the update process will be handled.

def nim_update(module, params):
"""
Update nim clients (targets) with a specified lpp_source.

In case of updating to the latest TL or SP, the synchronous mode is forced.
Interim fixes that could block the install are removed.

arguments:
module (dict): The Ansible module
params (dict): The module parameters for the command.
note:
Exits with fail_json in case of error
"""

lpp_source = params['lpp_source']
alt_disk_update_name = params['alt_disk_update_name']
targets = params['targets']

async_update = 'no'
if params['asynchronous']:
async_update = 'yes'


Handling asynchronous updates

Next, if the update is asynchronous, the function checks if the specified lpp_source exists and performs the customization asynchronously. If the operation fails, it logs an error and exits.

    if async_update == 'yes':   # async update
if lpp_source not in results['nim_node']['lpp_source']:
debug_lpp_src = results['nim_node']['lpp_source']
results['msg'] = f'Cannot find lpp_source \'{ debug_lpp_src }\'.'
module.log('NIM - Error: ' + results['msg'])
module.fail_json(**results)

msg_target_list = ','.join(target_list)
msg = f'Asynchronous software customization for client(s) { msg_target_list } with resource { lpp_source }.'
results['meta']['messages'].append(msg)
module.log('NIM - ' + msg)

rc = perform_customization(module, lpp_source, target_list, True)
if rc:
results['msg'] = 'Asynchronous software customization operation failed. See status and meta for details.'
module.log('NIM - Error: ' + results['msg'])
module.fail_json(**results)



Handling synchronous updates

Then, if the update is synchronous, the function retrieves the current oslevel of the targets, determines the new lpp_source, and performs the customization synchronously. It logs the results and updates the status accordingly.

    else:    # synchronous update
# Get the oslevels of the specified targets only
oslevels = get_oslevels(module, target_list)
for (k, val) in oslevels.items():
if k != 'master':
results['nim_node']['standalone'][k]['oslevel'] = val
else:
results['nim_node']['master']['oslevel'] = val

for target in target_list:
# get current oslevel
cur_oslevel = ''
if target == 'master':
cur_oslevel = results['nim_node']['master']['oslevel']
else:
cur_oslevel = results['nim_node']['standalone'][target]['oslevel']
if (cur_oslevel is None) or (not cur_oslevel.strip()) or cur_oslevel == 'timedout':
msg = f'Invalid oslevel got: \'{ cur_oslevel }\'.'
results['meta'][target]['messages'].append(msg)
module.log(f'NIM - WARNING: On { target } with msg: { msg } ')
results['msg'] += f"{target} - {results['meta'][target]['messages']}"

 

This is an auto-generated document by Swimm 🌊 and has not yet been verified by a human