Add hard_limit support to Pure Strage FlashBlade filesystem module (#43987)

This commit is contained in:
Simon Dodsley 2018-10-23 19:03:17 -04:00 committed by ansibot
commit 8a88d78285

View file

@ -78,6 +78,15 @@ options:
required: false required: false
type: bool type: bool
default: false default: false
hard_limit:
description:
- Define whether the capacity for a filesystem is a hard limit.
- CAUTION This will cause the filesystem to go Read-Only if the
capacity has already exceeded the logical size of the filesystem.
required: false
type: bool
default: false
version_added: 2.8
extends_documentation_fragment: extends_documentation_fragment:
- purestorage.fb - purestorage.fb
''' '''
@ -122,6 +131,7 @@ EXAMPLES = '''
nfs_rules: '*(ro)' nfs_rules: '*(ro)'
snapshot: true snapshot: true
fastremove: true fastremove: true
hard_limit: true
smb: true smb: true
state: present state: present
fb_url: 10.10.10.2 fb_url: 10.10.10.2
@ -140,6 +150,9 @@ from ansible.module_utils.basic import AnsibleModule, human_to_bytes
from ansible.module_utils.pure import get_blade, purefb_argument_spec from ansible.module_utils.pure import get_blade, purefb_argument_spec
HARD_LIMIT_API_VERSION = '1.4'
def get_fs(module, blade): def get_fs(module, blade):
"""Return Filesystem or None""" """Return Filesystem or None"""
fs = [] fs = []
@ -161,14 +174,26 @@ def create_fs(module, blade):
if not module.check_mode: if not module.check_mode:
try: try:
fs_obj = FileSystem(name=module.params['name'], api_version = blade.api_version.list_versions().versions
provisioned=size, if HARD_LIMIT_API_VERSION in api_version:
fast_remove_directory_enabled=module.params['fastremove'], fs_obj = FileSystem(name=module.params['name'],
snapshot_directory_enabled=module.params['snapshot'], provisioned=size,
nfs=NfsRule(enabled=module.params['nfs'], rules=module.params['nfs_rules']), fast_remove_directory_enabled=module.params['fastremove'],
smb=ProtocolRule(enabled=module.params['smb']), hard_limit_enabled=module.params['hard_limit'],
http=ProtocolRule(enabled=module.params['http']) snapshot_directory_enabled=module.params['snapshot'],
) nfs=NfsRule(enabled=module.params['nfs'], rules=module.params['nfs_rules']),
smb=ProtocolRule(enabled=module.params['smb']),
http=ProtocolRule(enabled=module.params['http'])
)
else:
fs_obj = FileSystem(name=module.params['name'],
provisioned=size,
fast_remove_directory_enabled=module.params['fastremove'],
snapshot_directory_enabled=module.params['snapshot'],
nfs=NfsRule(enabled=module.params['nfs'], rules=module.params['nfs_rules']),
smb=ProtocolRule(enabled=module.params['smb']),
http=ProtocolRule(enabled=module.params['http'])
)
blade.file_systems.create_file_systems(fs_obj) blade.file_systems.create_file_systems(fs_obj)
changed = True changed = True
except: except:
@ -223,6 +248,11 @@ def modify_fs(module, blade):
if not module.params['fastremove'] and fs.fast_remove_directory_enabled: if not module.params['fastremove'] and fs.fast_remove_directory_enabled:
attr['fast_remove_directory_enabled'] = module.params['fastremove'] attr['fast_remove_directory_enabled'] = module.params['fastremove']
changed = True changed = True
api_version = blade.api_version.list_versions().versions
if HARD_LIMIT_API_VERSION in api_version:
if not module.params['hard_limit'] and fs.hard_limit_enabled:
attr['hard_limit_enabled'] = module.params['hard_limit']
changed = True
if changed: if changed:
n_attr = FileSystem(**attr) n_attr = FileSystem(**attr)
try: try:
@ -277,6 +307,7 @@ def main():
http=dict(default='false', type='bool'), http=dict(default='false', type='bool'),
snapshot=dict(default='false', type='bool'), snapshot=dict(default='false', type='bool'),
fastremove=dict(default='false', type='bool'), fastremove=dict(default='false', type='bool'),
hard_limit=dict(default='false', type='bool'),
state=dict(default='present', choices=['present', 'absent']), state=dict(default='present', choices=['present', 'absent']),
size=dict() size=dict()
) )