Handling Backup Actions
In this document, we will explain the process of handling different actions in the backup module. The process involves retrieving parameters, creating backups, and managing volume group backups.
The flow starts with retrieving the action and type parameters to determine the operation and backup type. If the action is 'create', additional parameters are retrieved to customize the backup creation. For 'savevg' type, it checks for necessary parameters and sets error messages if conditions are not met. The savevg
check_vg
Flow drill down
Handling Different Actions
First, the main
action = module.params['action']
params['objtype'] = module.params['type']
params['flags'] = module.params['flags']
params['location'] = module.params['location']
Creating a Backup
Next, if the action is 'create', additional parameters like verbose, create_data_file
exclude_fs
exclude_files
extend_fs
if action == 'create':
params['verbose'] = module.params['verbose']
params['create_data_file'] = module.params['create_data_file']
params['exclude_fs'] = module.params['exclude_fs']
params['exclude_files'] = module.params['exclude_files']
params['extend_fs'] = module.params['extend_fs']
params['force'] = module.params['force']
Handling 'savevg' Type
Then, if the type is 'savevg', the function checks if the 'name' parameter is provided and if exclude_data
elif params['objtype'] == 'savevg':
params['name'] = module.params['name']
params['exclude_data'] = module.params['exclude_data']
if not params['name']:
results['msg'] = 'argument \'name\' is missing.'
module.fail_json(**results)
if params['exclude_data'] and params['name'] == 'rootvg':
results['msg'] = 'name cannot be \'rootvg\'.'
module.fail_json(**results)
Managing Volume Group Backups
Moving to the savevg
def savevg(module, params, vg):
"""
Run the savevg command to back up files of a volume group.
But first, checks the volume group is varied-on.
arguments:
module (dict): the module variable
params (dict): the command parameters
vg (str): the volume group to back up
return:
rc (int): the return code of the command
"""
module.log(f'Creating VG backup of { vg } with savevg.')
# Check if the backup image already exists
if not params['force']:
rc = restvg_view(module, params)
# check if there is an existing backup specified by 'location' parameter
# if there is not existing backup at 'location' then proceed to creation of backup
# 0512-054 listvgbackup: File /tmp/testvg_backup does not exist or is empty.
Checking Volume Group Status
Diving into the check_vg
def check_vg(module, vg):
"""
Check if the volume group is active (i.e. varied-on).
arguments:
module (dict): The Ansible module
vg (str): the volume group to back up
return:
True if the vg can be used
False otherwise
"""
module.log(f'Checking { vg } is active.')
# list active volume groups
cmd = ['/usr/sbin/lsvg', '-o']
rc, stdout, stderr = module.run_command(cmd)
if rc != 0:
results['msg'] = f'Cannot get active volume group. Command \'{ cmd }\' failed.'
results['stdout'] = stdout
results['stderr'] = stderr
This is an auto-generated document by Swimm 🌊 and has not yet been verified by a human