mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-06-28 03:00:23 -07:00
added capture and return of information about changed volume (#53839)
This commit is contained in:
parent
96925a09b6
commit
ec0babe631
1 changed files with 44 additions and 20 deletions
|
@ -110,6 +110,29 @@ EXAMPLES = r'''
|
||||||
'''
|
'''
|
||||||
|
|
||||||
RETURN = r'''
|
RETURN = r'''
|
||||||
|
volume:
|
||||||
|
description: A dictionary describing the changed volume. Only some
|
||||||
|
attributes below will be returned with various actions.
|
||||||
|
type: dict
|
||||||
|
returned: success
|
||||||
|
contains:
|
||||||
|
source:
|
||||||
|
description: Volume name of source volume used for volume copy
|
||||||
|
type: str
|
||||||
|
serial:
|
||||||
|
description: Volume serial number
|
||||||
|
type: str
|
||||||
|
sample: '361019ECACE43D83000120A4'
|
||||||
|
created:
|
||||||
|
description: Volume creation time
|
||||||
|
type: str
|
||||||
|
sample: '2019-03-13T22:49:24Z'
|
||||||
|
name:
|
||||||
|
description: Volume name
|
||||||
|
type: str
|
||||||
|
size:
|
||||||
|
description: Volume size in bytes
|
||||||
|
type: int
|
||||||
'''
|
'''
|
||||||
|
|
||||||
from ansible.module_utils.basic import AnsibleModule
|
from ansible.module_utils.basic import AnsibleModule
|
||||||
|
@ -173,7 +196,8 @@ def create_volume(module, array):
|
||||||
if module.params['qos']:
|
if module.params['qos']:
|
||||||
if 549755813888 >= int(human_to_bytes(module.params['qos'])) >= 1048576:
|
if 549755813888 >= int(human_to_bytes(module.params['qos'])) >= 1048576:
|
||||||
try:
|
try:
|
||||||
array.create_volume(module.params['name'], module.params['size'],
|
volume = array.create_volume(module.params['name'],
|
||||||
|
module.params['size'],
|
||||||
bandwidth_limit=module.params['qos'])
|
bandwidth_limit=module.params['qos'])
|
||||||
changed = True
|
changed = True
|
||||||
except Exception:
|
except Exception:
|
||||||
|
@ -182,12 +206,12 @@ def create_volume(module, array):
|
||||||
module.fail_json(msg='QoS value {0} out of range.'.format(module.params['qos']))
|
module.fail_json(msg='QoS value {0} out of range.'.format(module.params['qos']))
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
array.create_volume(module.params['name'], module.params['size'])
|
volume = array.create_volume(module.params['name'], module.params['size'])
|
||||||
changed = True
|
changed = True
|
||||||
except Exception:
|
except Exception:
|
||||||
module.fail_json(msg='Volume {0} creation failed.'.format(module.params['name']))
|
module.fail_json(msg='Volume {0} creation failed.'.format(module.params['name']))
|
||||||
|
|
||||||
module.exit_json(changed=changed)
|
module.exit_json(changed=changed, volume=volume)
|
||||||
|
|
||||||
|
|
||||||
def copy_from_volume(module, array):
|
def copy_from_volume(module, array):
|
||||||
|
@ -198,7 +222,7 @@ def copy_from_volume(module, array):
|
||||||
|
|
||||||
if tgt is None:
|
if tgt is None:
|
||||||
try:
|
try:
|
||||||
array.copy_volume(module.params['name'],
|
volume = array.copy_volume(module.params['name'],
|
||||||
module.params['target'])
|
module.params['target'])
|
||||||
changed = True
|
changed = True
|
||||||
except Exception:
|
except Exception:
|
||||||
|
@ -206,7 +230,7 @@ def copy_from_volume(module, array):
|
||||||
module.params['target']))
|
module.params['target']))
|
||||||
elif tgt is not None and module.params['overwrite']:
|
elif tgt is not None and module.params['overwrite']:
|
||||||
try:
|
try:
|
||||||
array.copy_volume(module.params['name'],
|
volume = array.copy_volume(module.params['name'],
|
||||||
module.params['target'],
|
module.params['target'],
|
||||||
overwrite=module.params['overwrite'])
|
overwrite=module.params['overwrite'])
|
||||||
changed = True
|
changed = True
|
||||||
|
@ -214,7 +238,7 @@ def copy_from_volume(module, array):
|
||||||
module.fail_json(msg='Copy volume {0} to volume {1} failed.'.format(module.params['name'],
|
module.fail_json(msg='Copy volume {0} to volume {1} failed.'.format(module.params['name'],
|
||||||
module.params['target']))
|
module.params['target']))
|
||||||
|
|
||||||
module.exit_json(changed=changed)
|
module.exit_json(changed=changed, volume=volume)
|
||||||
|
|
||||||
|
|
||||||
def update_volume(module, array):
|
def update_volume(module, array):
|
||||||
|
@ -228,7 +252,7 @@ def update_volume(module, array):
|
||||||
if human_to_bytes(module.params['size']) != vol['size']:
|
if human_to_bytes(module.params['size']) != vol['size']:
|
||||||
if human_to_bytes(module.params['size']) > vol['size']:
|
if human_to_bytes(module.params['size']) > vol['size']:
|
||||||
try:
|
try:
|
||||||
array.extend_volume(module.params['name'], module.params['size'])
|
volume = array.extend_volume(module.params['name'], module.params['size'])
|
||||||
changed = True
|
changed = True
|
||||||
except Exception:
|
except Exception:
|
||||||
module.fail_json(msg='Volume {0} resize failed.'.format(module.params['name']))
|
module.fail_json(msg='Volume {0} resize failed.'.format(module.params['name']))
|
||||||
|
@ -236,13 +260,13 @@ def update_volume(module, array):
|
||||||
if human_to_bytes(module.params['qos']) != vol_qos['bandwidth_limit']:
|
if human_to_bytes(module.params['qos']) != vol_qos['bandwidth_limit']:
|
||||||
if module.params['qos'] == '0':
|
if module.params['qos'] == '0':
|
||||||
try:
|
try:
|
||||||
array.set_volume(module.params['name'], bandwidth_limit='')
|
volume = array.set_volume(module.params['name'], bandwidth_limit='')
|
||||||
changed = True
|
changed = True
|
||||||
except Exception:
|
except Exception:
|
||||||
module.fail_json(msg='Volume {0} QoS removal failed.'.format(module.params['name']))
|
module.fail_json(msg='Volume {0} QoS removal failed.'.format(module.params['name']))
|
||||||
elif 549755813888 >= int(human_to_bytes(module.params['qos'])) >= 1048576:
|
elif 549755813888 >= int(human_to_bytes(module.params['qos'])) >= 1048576:
|
||||||
try:
|
try:
|
||||||
array.set_volume(module.params['name'],
|
volume = array.set_volume(module.params['name'],
|
||||||
bandwidth_limit=module.params['qos'])
|
bandwidth_limit=module.params['qos'])
|
||||||
changed = True
|
changed = True
|
||||||
except Exception:
|
except Exception:
|
||||||
|
@ -250,7 +274,7 @@ def update_volume(module, array):
|
||||||
else:
|
else:
|
||||||
module.fail_json(msg='QoS value {0} out of range. Check documentation.'.format(module.params['qos']))
|
module.fail_json(msg='QoS value {0} out of range. Check documentation.'.format(module.params['qos']))
|
||||||
|
|
||||||
module.exit_json(changed=changed)
|
module.exit_json(changed=changed, volume=volume)
|
||||||
|
|
||||||
|
|
||||||
def delete_volume(module, array):
|
def delete_volume(module, array):
|
||||||
|
@ -258,27 +282,27 @@ def delete_volume(module, array):
|
||||||
changed = False
|
changed = False
|
||||||
if not module.check_mode:
|
if not module.check_mode:
|
||||||
try:
|
try:
|
||||||
array.destroy_volume(module.params['name'])
|
volume = array.destroy_volume(module.params['name'])
|
||||||
if module.params['eradicate']:
|
if module.params['eradicate']:
|
||||||
try:
|
try:
|
||||||
array.eradicate_volume(module.params['name'])
|
volume = array.eradicate_volume(module.params['name'])
|
||||||
except Exception:
|
except Exception:
|
||||||
module.fail_json(msg='Eradicate volume {0} failed.'.format(module.params['name']))
|
module.fail_json(msg='Eradicate volume {0} failed.'.format(module.params['name']))
|
||||||
changed = True
|
changed = True
|
||||||
except Exception:
|
except Exception:
|
||||||
module.fail_json(msg='Delete volume {0} failed.'.format(module.params['name']))
|
module.fail_json(msg='Delete volume {0} failed.'.format(module.params['name']))
|
||||||
module.exit_json(changed=changed)
|
module.exit_json(changed=changed, volume=volume)
|
||||||
|
|
||||||
|
|
||||||
def eradicate_volume(module, array):
|
def eradicate_volume(module, array):
|
||||||
""" Eradicate Deleted Volume"""
|
""" Eradicate Deleted Volume"""
|
||||||
changed = False
|
changed = False
|
||||||
try:
|
try:
|
||||||
array.eradicate_volume(module.params['name'])
|
volume = array.eradicate_volume(module.params['name'])
|
||||||
changed = True
|
changed = True
|
||||||
except Exception:
|
except Exception:
|
||||||
module.fail_json(msg='Eradication of volume {0} failed'.format(module.params['name']))
|
module.fail_json(msg='Eradication of volume {0} failed'.format(module.params['name']))
|
||||||
module.exit_json(changed=changed)
|
module.exit_json(changed=changed, volume=volume)
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue