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
find_valid_altdisk
get_pvs
Flow drill down
Main Function
First, the main
alt_disk_action
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
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
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
PVs
PVs
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