Fix major bug in the last update of this module. (#60223)

pull/60341/head
Simon Dodsley 6 years ago committed by ansibot
parent 8b68feb67e
commit 1b45abc4f3

@ -200,20 +200,25 @@ def get_fs(module, blade):
def create_fs(module, blade):
"""Create Filesystem"""
changed = True
if not module.check_mode:
try:
if not module.params['size']:
module.params['size'] = '32G'
if not module.params['size']:
module.params['size'] = '32G'
size = human_to_bytes(module.params['size'])
nfsv3 = module.params['nfs'] if module.params['nfsv3'] is None else module.params['nfsv3']
size = human_to_bytes(module.params['size'])
nfsv3 = module.params['nfs'] if module.params['nfsv3'] is None else module.params['nfsv3']
if module.params['user_quota']:
user_quota = human_to_bytes(module.params['user_quota'])
if module.params['group_quota']:
group_quota = human_to_bytes(module.params['group_quota'])
if module.params['user_quota']:
user_quota = human_to_bytes(module.params['user_quota'])
else:
user_quota = None
if module.params['group_quota']:
group_quota = human_to_bytes(module.params['group_quota'])
else:
group_quota = None
if not module.check_mode:
try:
api_version = blade.api_version.list_versions().versions
if HARD_LIMIT_API_VERSION in api_version:
if NFSV4_API_VERSION in api_version:
@ -250,133 +255,148 @@ def create_fs(module, blade):
http=ProtocolRule(enabled=module.params['http'])
)
blade.file_systems.create_file_systems(fs_obj)
changed = True
except Exception:
changed = False
module.fail_json(msg="Failed to create filesystem {0}.".format(module.params['name']))
module.exit_json(changed=changed)
def modify_fs(module, blade):
"""Modify Filesystem"""
changed = False
nfsv3 = module.params['nfs'] if module.params['nfsv3'] is None else module.params['nfsv3']
attr = {}
if module.params['user_quota']:
user_quota = human_to_bytes(module.params['user_quota'])
if module.params['group_quota']:
group_quota = human_to_bytes(module.params['group_quota'])
changed = True
if not module.check_mode:
api_version = blade.api_version.list_versions().versions
mod_fs = False
nfsv3 = module.params['nfs'] if module.params['nfsv3'] is None else module.params['nfsv3']
attr = {}
if module.params['user_quota']:
user_quota = human_to_bytes(module.params['user_quota'])
if module.params['group_quota']:
group_quota = human_to_bytes(module.params['group_quota'])
fsys = get_fs(module, blade)
if fsys.destroyed:
attr['destroyed'] = False
changed = True
mod_fs = True
if module.params['size']:
if human_to_bytes(module.params['size']) > fsys.provisioned:
if human_to_bytes(module.params['size']) != fsys.provisioned:
attr['provisioned'] = human_to_bytes(module.params['size'])
changed = True
mod_fs = True
api_version = blade.api_version.list_versions().versions
if NFSV4_API_VERSION in api_version:
if nfsv3 and not fsys.nfs.v3_enabled:
attr['nfs'] = NfsRule(v3_enabled=nfsv3)
changed = True
mod_fs = True
if not nfsv3 and fsys.nfs.v3_enabled:
attr['nfs'] = NfsRule(v3_enabled=nfsv3)
changed = True
mod_fs = True
if module.params['nfsv4'] and not fsys.nfs.v4_1_enabled:
attr['nfs'] = NfsRule(v4_1_enabled=module.params['nfsv4'])
changed = True
mod_fs = True
if not module.params['nfsv4'] and fsys.nfs.v4_1_enabled:
attr['nfs'] = NfsRule(v4_1_enabled=module.params['nfsv4'])
changed = True
mod_fs = True
if nfsv3 or module.params['nfsv4'] and fsys.nfs.v3_enabled or fsys.nfs.v4_1_enabled:
if fsys.nfs.rules != module.params['nfs_rules']:
attr['nfs'] = NfsRule(rules=module.params['nfs_rules'])
changed = True
mod_fs = True
if module.params['user_quota'] and user_quota != fsys.default_user_quota:
attr['default_user_quota'] = user_quota
changed = True
mod_fs = True
if module.params['group_quota'] and group_quota != fsys.default_group_quota:
attr['default_group_quota'] = group_quota
changed = True
mod_fs = True
else:
if nfsv3 and not fsys.nfs.enabled:
attr['nfs'] = NfsRule(enabled=nfsv3)
changed = True
mod_fs = True
if not nfsv3 and fsys.nfs.enabled:
attr['nfs'] = NfsRule(enabled=nfsv3)
changed = True
mod_fs = True
if nfsv3 and fsys.nfs.enabled:
if fsys.nfs.rules != module.params['nfs_rules']:
attr['nfs'] = NfsRule(rules=module.params['nfs_rules'])
changed = True
mod_fs = True
if module.params['smb'] and not fsys.smb.enabled:
attr['smb'] = ProtocolRule(enabled=module.params['smb'])
changed = True
mod_fs = True
if not module.params['smb'] and fsys.smb.enabled:
attr['smb'] = ProtocolRule(enabled=module.params['smb'])
changed = True
mod_fs = True
if module.params['http'] and not fsys.http.enabled:
attr['http'] = ProtocolRule(enabled=module.params['http'])
changed = True
mod_fs = True
if not module.params['http'] and fsys.http.enabled:
attr['http'] = ProtocolRule(enabled=module.params['http'])
changed = True
mod_fs = True
if module.params['snapshot'] and not fsys.snapshot_directory_enabled:
attr['snapshot_directory_enabled'] = module.params['snapshot']
changed = True
mod_fs = True
if not module.params['snapshot'] and fsys.snapshot_directory_enabled:
attr['snapshot_directory_enabled'] = module.params['snapshot']
changed = True
mod_fs = True
if module.params['fastremove'] and not fsys.fast_remove_directory_enabled:
attr['fast_remove_directory_enabled'] = module.params['fastremove']
changed = True
mod_fs = True
if not module.params['fastremove'] and fsys.fast_remove_directory_enabled:
attr['fast_remove_directory_enabled'] = module.params['fastremove']
changed = True
mod_fs = True
api_version = blade.api_version.list_versions().versions
if HARD_LIMIT_API_VERSION in api_version:
if not module.params['hard_limit'] and fsys.hard_limit_enabled:
attr['hard_limit_enabled'] = module.params['hard_limit']
changed = True
if changed:
mod_fs = True
if module.params['hard_limit'] and not fsys.hard_limit_enabled:
attr['hard_limit_enabled'] = module.params['hard_limit']
mod_fs = True
if mod_fs:
n_attr = FileSystem(**attr)
try:
blade.file_systems.update_file_systems(name=module.params['name'], attributes=n_attr)
except Exception:
changed = False
module.fail_json(msg="Failed to update filesystem {0}.".format(module.params['name']))
else:
changed = False
module.exit_json(changed=changed)
def delete_fs(module, blade):
""" Delete Filesystem"""
changed = True
if not module.check_mode:
try:
blade.file_systems.update_file_systems(name=module.params['name'],
attributes=FileSystem(nfs=NfsRule(enabled=False),
smb=ProtocolRule(enabled=False),
http=ProtocolRule(enabled=False),
destroyed=True)
)
changed = True
api_version = blade.api_version.list_versions().versions
if NFSV4_API_VERSION in api_version:
blade.file_systems.update_file_systems(name=module.params['name'],
attributes=FileSystem(nfs=NfsRule(v3_enabled=False,
v4_1_enabled=False),
smb=ProtocolRule(enabled=False),
http=ProtocolRule(enabled=False),
destroyed=True)
)
else:
blade.file_systems.update_file_systems(name=module.params['name'],
attributes=FileSystem(nfs=NfsRule(enabled=False),
smb=ProtocolRule(enabled=False),
http=ProtocolRule(enabled=False),
destroyed=True)
)
if module.params['eradicate']:
try:
blade.file_systems.delete_file_systems(module.params['name'])
changed = True
except Exception:
changed = False
module.fail_json(msg="Failed to delete filesystem {0}.".format(module.params['name']))
except Exception:
changed = False
module.fail_json(msg="Failed to update filesystem {0} prior to deletion.".format(module.params['name']))
module.exit_json(changed=changed)
def eradicate_fs(module, blade):
""" Eradicate Filesystem"""
changed = True
if not module.check_mode:
try:
blade.file_systems.delete_file_systems(module.params['name'])
changed = True
except Exception:
changed = False
module.fail_json(msg="Failed to eradicate filesystem {0}.".format(module.params['name']))
module.exit_json(changed=changed)

Loading…
Cancel
Save