| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
from __future__ import absolute_import, division, print_function |
| 8 |
|
| 9 |
__metaclass__ = type |
| 10 |
|
| 11 |
ANSIBLE_METADATA = { |
| 12 |
"metadata_version": "1.1", |
| 13 |
"status": ["preview"], |
| 14 |
"supported_by": "community", |
| 15 |
} |
| 16 |
|
| 17 |
DOCUMENTATION = r""" |
| 18 |
--- |
| 19 |
module: purefb_timeout |
| 20 |
version_added: '1.6.0' |
| 21 |
short_description: Configure Pure Storage FlashBlade GUI idle timeout |
| 22 |
description: |
| 23 |
- Configure GUI idle timeout for Pure Storage FlashBlade. |
| 24 |
- This does not affect existing GUI sessions. |
| 25 |
author: |
| 26 |
- Pure Storage Ansible Team (@sdodsley) <[email protected]> |
| 27 |
options: |
| 28 |
state: |
| 29 |
description: |
| 30 |
- Set or disable the GUI idle timeout |
| 31 |
default: present |
| 32 |
type: str |
| 33 |
choices: [ present, absent ] |
| 34 |
timeout: |
| 35 |
description: |
| 36 |
- Minutes for idle timeout. |
| 37 |
type: int |
| 38 |
default: 30 |
| 39 |
extends_documentation_fragment: |
| 40 |
- purestorage.flashblade.purestorage.fb |
| 41 |
""" |
| 42 |
|
| 43 |
EXAMPLES = r""" |
| 44 |
- name: Set GUI idle timeout to 25 minutes |
| 45 |
purestorage.flashblade.purefb_timeout: |
| 46 |
timeout: 25 |
| 47 |
state: present |
| 48 |
fb_url: 10.10.10.2 |
| 49 |
api_token: T-68618f31-0c9e-4e57-aa44-5306a2cf10e3 |
| 50 |
|
| 51 |
- name: Disable idle timeout |
| 52 |
purestorage.flashblade.purefb_timeout: |
| 53 |
state: absent |
| 54 |
fb_url: 10.10.10.2 |
| 55 |
api_token: T-68618f31-0c9e-4e57-aa44-5306a2cf10e3 |
| 56 |
""" |
| 57 |
|
| 58 |
RETURN = r""" |
| 59 |
""" |
| 60 |
|
| 61 |
HAS_PURESTORAGE = True |
| 62 |
try: |
| 63 |
from pypureclient import flashblade |
| 64 |
except ImportError: |
| 65 |
HAS_PURESTORAGE = False |
| 66 |
|
| 67 |
from ansible.module_utils.basic import AnsibleModule |
| 68 |
from ansible_collections.purestorage.flashblade.plugins.module_utils.purefb import ( |
| 69 |
get_system, |
| 70 |
purefb_argument_spec, |
| 71 |
) |
| 72 |
|
| 73 |
|
| 74 |
def set_timeout(module, blade): |
| 75 |
"""Set GUI idle timeout""" |
| 76 |
changed = True |
| 77 |
if not module.check_mode: |
| 78 |
res = blade.patch_arrays( |
| 79 |
flashblade.Array(idle_timeout=module.params["timeout"] * 60000) |
| 80 |
) |
| 81 |
if res.status_code != 200: |
| 82 |
module.fail_json(msg="Failed to set GUI idle timeout") |
| 83 |
|
| 84 |
module.exit_json(changed=changed) |
| 85 |
|
| 86 |
|
| 87 |
def disable_timeout(module, blade): |
| 88 |
"""Disable idle timeout""" |
| 89 |
changed = True |
| 90 |
if not module.check_mode: |
| 91 |
res = blade.patch_arrays(flashblade.Array(idle_timeout=0)) |
| 92 |
if res.status_code != 200: |
| 93 |
module.fail_json(msg="Failed to disable GUI idle timeout") |
| 94 |
module.exit_json(changed=changed) |
| 95 |
|
| 96 |
|
| 97 |
def main(): |
| 98 |
argument_spec = purefb_argument_spec() |
| 99 |
argument_spec.update( |
| 100 |
dict( |
| 101 |
timeout=dict(type="int", default=30), |
| 102 |
state=dict(type="str", default="present", choices=["present", "absent"]), |
| 103 |
) |
| 104 |
) |
| 105 |
|
| 106 |
module = AnsibleModule(argument_spec, supports_check_mode=True) |
| 107 |
|
| 108 |
if not HAS_PURESTORAGE: |
| 109 |
module.fail_json(msg="py-pure-client sdk is required for this module") |
| 110 |
|
| 111 |
blade = get_system(module) |
| 112 |
|
| 113 |
state = module.params["state"] |
| 114 |
if 5 < module.params["timeout"] > 180 and module.params["timeout"] != 0: |
| 115 |
module.fail_json(msg="Timeout value must be between 5 and 180 minutes") |
| 116 |
blade = get_system(module) |
| 117 |
current_timeout = list(blade.get_arrays().items)[0].idle_timeout / 60000 |
| 118 |
if state == "present" and current_timeout != module.params["timeout"]: |
| 119 |
set_timeout(module, blade) |
| 120 |
elif state == "absent" and current_timeout != 0: |
| 121 |
disable_timeout(module, blade) |
| 122 |
|
| 123 |
module.exit_json(changed=False) |
| 124 |
|
| 125 |
|
| 126 |
if __name__ == "__main__": |
| 127 |
main() |