Fix bug in purefa_volume that errors on volume create (#55039)

pull/55039/merge
Simon Dodsley 6 years ago committed by ansibot
parent 377fba3d76
commit 42af1a58e0

@ -201,13 +201,14 @@ def get_target(module, array):
def create_volume(module, array):
"""Create Volume"""
changed = False
volfact = []
api_version = array._list_available_rest_versions()
if module.params['qos'] and QOS_API_VERSION in api_version:
if 549755813888 >= int(human_to_bytes(module.params['qos'])) >= 1048576:
try:
volume = array.create_volume(module.params['name'],
module.params['size'],
bandwidth_limit=module.params['qos'])
volfact = array.create_volume(module.params['name'],
module.params['size'],
bandwidth_limit=module.params['qos'])
changed = True
except Exception:
module.fail_json(msg='Volume {0} creation failed.'.format(module.params['name']))
@ -215,44 +216,45 @@ def create_volume(module, array):
module.fail_json(msg='QoS value {0} out of range.'.format(module.params['qos']))
else:
try:
volume = array.create_volume(module.params['name'], module.params['size'])
volfact = array.create_volume(module.params['name'], module.params['size'])
changed = True
except Exception:
module.fail_json(msg='Volume {0} creation failed.'.format(module.params['name']))
module.exit_json(changed=changed, volume=volume)
module.exit_json(changed=changed, volume=volfact)
def copy_from_volume(module, array):
"""Create Volume Clone"""
changed = False
volfact = []
tgt = get_target(module, array)
if tgt is None:
try:
volume = array.copy_volume(module.params['name'],
module.params['target'])
volfact = array.copy_volume(module.params['name'],
module.params['target'])
changed = True
except Exception:
module.fail_json(msg='Copy volume {0} to volume {1} failed.'.format(module.params['name'],
module.params['target']))
elif tgt is not None and module.params['overwrite']:
try:
volume = array.copy_volume(module.params['name'],
module.params['target'],
overwrite=module.params['overwrite'])
volfact = array.copy_volume(module.params['name'],
module.params['target'],
overwrite=module.params['overwrite'])
changed = True
except Exception:
module.fail_json(msg='Copy volume {0} to volume {1} failed.'.format(module.params['name'],
module.params['target']))
module.exit_json(changed=changed, volume=volume)
module.exit_json(changed=changed, volume=volfact)
def update_volume(module, array):
"""Update Volume size and/or QoS"""
changed = False
volfact = []
api_version = array._list_available_rest_versions()
vol = array.get_volume(module.params['name'])
if QOS_API_VERSION in api_version:
@ -263,7 +265,7 @@ def update_volume(module, array):
if human_to_bytes(module.params['size']) != vol['size']:
if human_to_bytes(module.params['size']) > vol['size']:
try:
volume = array.extend_volume(module.params['name'], module.params['size'])
volfact = array.extend_volume(module.params['name'], module.params['size'])
changed = True
except Exception:
module.fail_json(msg='Volume {0} resize failed.'.format(module.params['name']))
@ -271,49 +273,51 @@ def update_volume(module, array):
if human_to_bytes(module.params['qos']) != vol_qos['bandwidth_limit']:
if module.params['qos'] == '0':
try:
volume = array.set_volume(module.params['name'], bandwidth_limit='')
volfact = array.set_volume(module.params['name'], bandwidth_limit='')
changed = True
except Exception:
module.fail_json(msg='Volume {0} QoS removal failed.'.format(module.params['name']))
elif 549755813888 >= int(human_to_bytes(module.params['qos'])) >= 1048576:
try:
volume = array.set_volume(module.params['name'],
bandwidth_limit=module.params['qos'])
volfact = array.set_volume(module.params['name'],
bandwidth_limit=module.params['qos'])
changed = True
except Exception:
module.fail_json(msg='Volume {0} QoS change failed.'.format(module.params['name']))
else:
module.fail_json(msg='QoS value {0} out of range. Check documentation.'.format(module.params['qos']))
module.exit_json(changed=changed, volume=volume)
module.exit_json(changed=changed, volume=volfact)
def delete_volume(module, array):
""" Delete Volume"""
changed = False
volfact = []
try:
volume = array.destroy_volume(module.params['name'])
if module.params['eradicate']:
try:
volume = array.eradicate_volume(module.params['name'])
volfact = array.eradicate_volume(module.params['name'])
except Exception:
module.fail_json(msg='Eradicate volume {0} failed.'.format(module.params['name']))
changed = True
except Exception:
module.fail_json(msg='Delete volume {0} failed.'.format(module.params['name']))
module.exit_json(changed=changed, volume=volume)
module.exit_json(changed=changed, volume=volfact)
def eradicate_volume(module, array):
""" Eradicate Deleted Volume"""
changed = False
volfact = []
if module.params['eradicate']:
try:
volume = array.eradicate_volume(module.params['name'])
changed = True
except Exception:
module.fail_json(msg='Eradication of volume {0} failed'.format(module.params['name']))
module.exit_json(changed=changed, volume=volume)
module.exit_json(changed=changed, volume=volfact)
def main():

Loading…
Cancel
Save