Coverage for plugins/modules/purefb_timeout.py: 93%
45 statements
« prev ^ index » next coverage.py v7.14.1, created at 2026-10-30 17:06 -0400
« prev ^ index » next coverage.py v7.14.1, created at 2026-10-30 17:06 -0400
1#!/usr/bin/python
2# -*- coding: utf-8 -*-
4# (c) 2021, Simon Dodsley (simon@everpuredata.com)
5# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
7from __future__ import absolute_import, division, print_function
9__metaclass__ = type
11ANSIBLE_METADATA = {
12 "metadata_version": "1.1",
13 "status": ["preview"],
14 "supported_by": "community",
15}
17DOCUMENTATION = r"""
18---
19module: purefb_timeout
20version_added: '1.6.0'
21short_description: Configure Everpure FlashBlade GUI idle timeout
22description:
23- Configure GUI idle timeout for Everpure FlashBlade.
24- This does not affect existing GUI sessions.
25author:
26- Everpure Ansible Team (@sdodsley) <pure-ansible-team@everpuredata.com>
27options:
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
39extends_documentation_fragment:
40- everpure.flashblade.everpure.fb
41"""
43EXAMPLES = r"""
44- name: Set GUI idle timeout to 25 minutes
45 everpure.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
51- name: Disable idle timeout
52 everpure.flashblade.purefb_timeout:
53 state: absent
54 fb_url: 10.10.10.2
55 api_token: T-68618f31-0c9e-4e57-aa44-5306a2cf10e3
56"""
58RETURN = r"""
59"""
61HAS_PYPURECLIENT = True
62try:
63 from pypureclient import flashblade
64except ImportError:
65 HAS_PYPURECLIENT = False
67from ansible.module_utils.basic import AnsibleModule
68from ansible_collections.everpure.flashblade.plugins.module_utils.purefb import (
69 get_system,
70 purefb_argument_spec,
71)
74def 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")
84 module.exit_json(changed=changed)
87def 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)
97def 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 )
106 module = AnsibleModule(argument_spec, supports_check_mode=True)
108 if not HAS_PYPURECLIENT:
109 module.fail_json(msg="py-pure-client sdk is required for this module")
111 blade = get_system(module)
113 state = module.params["state"]
114 if (
115 module.params["timeout"] < 5 or module.params["timeout"] > 180
116 ) and module.params["timeout"] != 0:
117 module.fail_json(msg="Timeout value must be between 5 and 180 minutes")
118 current_timeout = list(blade.get_arrays().items)[0].idle_timeout / 60000
119 if state == "present" and current_timeout != module.params["timeout"]:
120 set_timeout(module, blade)
121 elif state == "absent" and current_timeout != 0:
122 disable_timeout(module, blade)
124 module.exit_json(changed=False)
127if __name__ == "__main__":
128 main()