Managing Logical Volumes Flow
In this document, we will explain the process of managing logical volumes. The process involves initializing the module, creating or modifying the logical volume, and executing the necessary commands.
The flow starts with initializing the Ansible module and setting up the required parameters. Depending on whether the logical volume should be present or absent, it either creates or removes the logical volume. If creating, it constructs the command with the specified attributes and executes it, checking the result for success or failure.
Flow drill down
Main Function
First, the main
def main():
"""
Main function
"""
global result
module = AnsibleModule(
argument_spec=dict(
state=dict(type='str', required=True, choices=['present', 'absent']),
lv=dict(type='str', required=True, aliases=['logical_volume']),
vg=dict(type='str'),
lv_type=dict(type='str', default='jfs2'),
strip_size=dict(type='str'),
extra_opts=dict(type='str', default=''),
copies=dict(type='int', default=1),
size=dict(type='str'),
pv_list=dict(type='list', elements='str'),
policy=dict(type='str', default='maximum', choices=['maximum', 'minimum']),
lv_new_name=dict(type='str'),
),
Creating Logical Volume
Next, the create_lv
def create_lv(module, name):
"""
Creates a logical volume with the attributes provided in the
lv_attributes field.
arguments:
module (dict): The Ansible module
name (str): Logical Volume Name
note:
Exits with fail_json in case of error
return:
none
"""
opts = ''
lv_type = module.params['lv_type']
strip_size = module.params['strip_size']
copies = module.params['copies']
policy = module.params['policy']
vg = module.params['vg']
num_log_part = module.params['size']
Running Logical Volume Command
Then, the lv_run_cmd
def lv_run_cmd(module, cmd, success_msg, fail_msg, init_props=None, fetch=False):
"""
Helper function for running commands to create/modify a
logical volume.
return: True - if any of the logical volume properties are modified
False - if nothing changed
"""
if success_msg is None:
success_msg = ""
rc, stdout, stderr = module.run_command(cmd)
result['cmd'] = cmd
result['rc'] = rc
result['stdout'] = stdout
result['stderr'] = stderr
if rc != 0:
result['msg'] += fail_msg
module.fail_json(**result)
else:
if (init_props is None) or (init_props != get_lv_props(module)):
This is an auto-generated document by Swimm 🌊 and has not yet been verified by a human