Handling Main Action in Alt Disk Module
In this document, we will explain the process of handling the main action in the alt_disk
The flow starts with initializing the Ansible module and checking if the script is running on a VIOS system. It then determines the action to perform and calls the appropriate function. The alt_disk_copy
find_valid_altdisk
get_free_pvs
Flow drill down
Handling the main action
First, the main
def main():
global results
module = AnsibleModule(
argument_spec=dict(
action=dict(type='str',
choices=['copy', 'clean', 'install'], default='copy'),
targets=dict(type='list', elements='str'),
disk_size_policy=dict(type='str',
choices=['minimize', 'upper', 'lower', 'nearest']),
existing_altinst_rootvg=dict(type='str'),
bundle_name=dict(type='str'),
apar_fixes=dict(type='str'),
filesets=dict(type='str'),
installp_flags=dict(type='str'),
image_location=dict(type='str'),
force=dict(type='bool', default=False),
bootlist=dict(type='bool', default=False),
remain_nim_client=dict(type='bool', default=False),
device_reset=dict(type='bool', default=False),
first_boot_script=dict(type='str'),
Validating parameters and performing alt disk copy
Next, the alt_disk_copy
disk_size_policy
find_valid_altdisk
def alt_disk_copy(module, params, hdisks, allow_old_rootvg):
"""
alt_disk_copy operation
- check the rootvg, find and validate the hdisks for the operation
- perform the alt disk copy operation
"""
global mirrors
# Either hdisks must be non-empty or disk_size_policy must be
# explicitly set. This ensures the user knows what he is doing.
if not hdisks and not params['disk_size_policy']:
results['msg'] = 'Either targets or disk_size_policy must be specified'
module.fail_json(**results)
rootvg_info = check_rootvg(module)
if rootvg_info is None:
module.fail_json(**results)
if hdisks is None:
hdisks = []
Finding a valid alternate disk
Then, the find_valid_altdisk
PVs
def find_valid_altdisk(module, hdisks, rootvg_info, disk_size_policy, force, allow_old_rootvg):
"""
Find a valid alternate disk that:
- exists,
- is not part of a VG
- with a correct size
and so can be used.
"""
# check rootvg
if rootvg_info['status'] != 0:
results['msg'] = 'Wrong rootvg state'
module.fail_json(**results)
# get pv list
pvs = get_pvs(module)
if pvs is None:
module.fail_json(**results)
# check an alternate disk does not already exist
found_altdisk = ''
found_oldrootvg = ''
Getting free physical volumes
Finally, the get_free_pvs
PVs
def get_free_pvs(module):
"""
Get the list of free PVs.
return: dictionary with free PVs information
"""
cmd = ['lspv']
ret, stdout, stderr = module.run_command(cmd)
if ret != 0:
results['stdout'] = stdout
results['stderr'] = stderr
results['msg'] = f'Command \'{ cmd }\' failed with return code { ret }.'
return None
# hdisk0 000018fa3b12f5cb rootvg active
free_pvs = {}
for line in stdout.split('\n'):
line = line.rstrip()
match_key = re.match(r"^(hdisk\S+)\s+(\S+)\s+(\S+)\s*(\S*)", line)
# Only match disks that have no volume groups
This is an auto-generated document by Swimm 🌊 and has not yet been verified by a human