Skip to main content

Main Function Flow

This document explains the flow of the main function in the module. The main function initializes the Ansible module, sets up parameters, and handles the results. It calls other functions to perform specific tasks such as alternate disk actions, finding valid alternate disks, and getting physical volumes.

The flow starts with the main function initializing the module and setting up parameters. It then calls the alt_disk_action function to handle alternate disk operations. This function checks the status of the disks and performs necessary operations like copying or cleaning the disks. Next, the find_valid_altdisk function searches for a valid alternate disk that meets specific criteria. Finally, the get_pvs function retrieves the list of physical volumes on the system.

Flow drill down


Main Function

First, the main function initializes the Ansible module and sets up the parameters and results dictionary. It then retrieves the module parameters and builds the NIM node information. The function checks the validity of the VIOS targets and performs the alternate disk action by calling alt_disk_action. Finally, it handles the results and exits the module.

def main():

global results

module = AnsibleModule(
argument_spec=dict(
targets=dict(required=True, type='list', elements='dict'),
action=dict(required=True, type='str',
choices=['alt_disk_copy', 'alt_disk_clean']),
time_limit=dict(type='str'),
vios_status=dict(type='dict'),
nim_node=dict(type='dict'),
disk_size_policy=dict(type='str',
choices=['minimize', 'upper', 'lower', 'nearest'],
default='nearest'),
force=dict(type='bool', default=False),
)
)

results = dict(
changed=False,


Alternate Disk Action

Next, the alt_disk_action function handles the core logic for alternate disk operations. It retrieves the previous status of VIOS, checks the root volume group (rootvg), and performs the necessary operations like unmirroring rootvg, performing the alternate disk copy or cleanup, and remirroring rootvg if needed. The function updates the operation status and logs messages accordingly.

def alt_disk_action(module, params, action, targets, vios_status, time_limit):
"""
alt_disk_copy / alt_disk_clean operation

For each VIOS tuple,
- retrieve the previous status if any (looking for SUCCESS-HC and SUCCESS-UPDT)
- for each VIOS of the tuple, check the rootvg, find and valid the hdisk for the operation
- unmirror rootvg if necessary
- perform the alt disk copy or cleanup operation
- wait for the copy to finish
- mirror rootvg if necessary

arguments:
module (dict): The Ansible module
params (dict): The parameters for the provided action
action (str): The action to perform
targets (list): The list of VIOS dictionary to perform the action on
vios_status (dict): The previous operation status for each vios (if any)
time_limit (str): The limit of time to perform the operation

return: dictionary containing the altdisk status for each vios tuple


Finding Valid Alternate Disk

Then, the find_valid_altdisk function searches for a valid alternate disk that meets specific criteria such as existence, not being part of a volume group, and having the correct size. It updates the operation status based on the findings and logs the results.

def find_valid_altdisk(module, params, action, vios_dict, vios_key, rootvg_info, altdisk_op_tab):
"""
Find a valid alternate disk that:
- exists,
- is not part of a VG
- with a correct size
and so can be used.

Sets the altdisk_op_tab accordingly:
altdisk_op_tab[vios_key] = "FAILURE-ALTDC <error message>"
altdisk_op_tab[vios_key] = "SUCCESS-ALTDC"

arguments:
module (dict): The Ansible module
params (dict): The parameters for the provided action
action (str): The action to perform
vios_dict (dict): The list of VIOS dictionary with associated list of hdisks
vios_key (str): The key for altdisk_op_tab status dicionary
rootvg_info (dict): The rootvg information gathered with check_rootvg
altdisk_op_tab (dict): The operation status



Getting Physical Volumes

Finally, the get_pvs function retrieves the list of physical volumes (PVs) on the VIOS. It executes the command to list PVs and parses the output to build a dictionary of PV information, which is then used in the alternate disk operations.

def get_pvs(module, vios):
"""
Get the list of PVs on the VIOS.

arguments:
module (dict): The Ansible module
vios (str): The VIOS name
return: dictionary with PVs information
"""
module.debug(f'get_pvs vios: {vios}')

cmd = ['/usr/ios/cli/ioscli', 'lspv']
ret, stdout, stderr = nim_exec(module, vios, cmd)
if ret != 0:
msg = f'Failed to get the PV list on {vios}, lspv returned: {ret} {stderr}'
results['meta'][vios]['messages'].append(msg)
module.log(msg)
return None

# NAME PVID VG STATUS
# hdisk0 000018fa3b12f5cb rootvg active

 

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