1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

Fix purefa_volume for QOS and erroneous delete (#53889)

This commit is contained in:
Simon Dodsley 2019-03-21 02:13:59 -04:00 committed by ansibot
parent 6401683e0b
commit 735f202e33

View file

@ -139,6 +139,9 @@ from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.pure import get_system, purefa_argument_spec from ansible.module_utils.pure import get_system, purefa_argument_spec
QOS_API_VERSION = "1.14"
def human_to_bytes(size): def human_to_bytes(size):
"""Given a human-readable byte string (e.g. 2G, 30M), """Given a human-readable byte string (e.g. 2G, 30M),
return the number of bytes. Will return 0 if the argument has return the number of bytes. Will return 0 if the argument has
@ -193,7 +196,8 @@ def get_target(module, array):
def create_volume(module, array): def create_volume(module, array):
"""Create Volume""" """Create Volume"""
changed = False changed = False
if module.params['qos']: 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: if 549755813888 >= int(human_to_bytes(module.params['qos'])) >= 1048576:
try: try:
volume = array.create_volume(module.params['name'], volume = array.create_volume(module.params['name'],
@ -244,7 +248,9 @@ def copy_from_volume(module, array):
def update_volume(module, array): def update_volume(module, array):
"""Update Volume size and/or QoS""" """Update Volume size and/or QoS"""
changed = False changed = False
api_version = array._list_available_rest_versions()
vol = array.get_volume(module.params['name']) vol = array.get_volume(module.params['name'])
if QOS_API_VERSION in api_version:
vol_qos = array.get_volume(module.params['name'], qos=True) vol_qos = array.get_volume(module.params['name'], qos=True)
if vol_qos['bandwidth_limit'] is None: if vol_qos['bandwidth_limit'] is None:
vol_qos['bandwidth_limit'] = 0 vol_qos['bandwidth_limit'] = 0
@ -256,7 +262,7 @@ def update_volume(module, array):
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']))
if module.params['qos']: if module.params['qos'] and QOS_API_VERSION in api_version:
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:
@ -280,7 +286,6 @@ def update_volume(module, array):
def delete_volume(module, array): def delete_volume(module, array):
""" Delete Volume""" """ Delete Volume"""
changed = False changed = False
if not module.check_mode:
try: try:
volume = array.destroy_volume(module.params['name']) volume = array.destroy_volume(module.params['name'])
if module.params['eradicate']: if module.params['eradicate']:
@ -297,6 +302,7 @@ def delete_volume(module, array):
def eradicate_volume(module, array): def eradicate_volume(module, array):
""" Eradicate Deleted Volume""" """ Eradicate Deleted Volume"""
changed = False changed = False
if module.params['eradicate']:
try: try:
volume = array.eradicate_volume(module.params['name']) volume = array.eradicate_volume(module.params['name'])
changed = True changed = True