Debian Codegraph @

ansible_collections/purestorage/flasharray/plugins/modules/purefa_hardware.py

raw symbols SCIP
1 #!/usr/bin/python
2 # -*- coding: utf-8 -*-
3
4 # (c) 2021, Simon Dodsley ([email protected])
5 # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
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: purefa_hardware
20 version_added: '1.24.0'
21 short_description: Manage FlashArray Hardware Identification
22 description:
23 - Enable or disable FlashArray visual identification lights
24 author:
25 - Pure Storage Ansible Team (@sdodsley) <[email protected]>
26 options:
27 name:
28 description:
29 - Name of hardware component
30 type: str
31 required: true
32 enabled:
33 description:
34 - State of the component identification LED
35 type: bool
36 extends_documentation_fragment:
37 - purestorage.flasharray.purestorage.fa
38 """
39
40 EXAMPLES = r"""
41 - name: Enable identification LED
42 purestorage.flasharray.purefa_hardware:
43 name: "CH1.FB1"
44 enabled: true
45 fa_url: 10.10.10.2
46 api_token: T-68618f31-0c9e-4e57-aa44-5306a2cf10e3
47
48 - name: Disable identification LED
49 purestorage.flasharray.purefa_hardware:
50 name: "CH1.FB1"
51 enabled: false
52 fa_url: 10.10.10.2
53 api_token: T-68618f31-0c9e-4e57-aa44-5306a2cf10e3
54 """
55
56 RETURN = r"""
57 """
58
59 HAS_PURESTORAGE = True
60 try:
61 from pypureclient import flasharray
62 except ImportError:
63 HAS_PURESTORAGE = False
64
65 from ansible.module_utils.basic import AnsibleModule
66 from ansible_collections.purestorage.flasharray.plugins.module_utils.purefa import (
67 get_array,
68 purefa_argument_spec,
69 )
70
71
72 def main():
73 argument_spec = purefa_argument_spec()
74 argument_spec.update(
75 dict(
76 enabled=dict(type="bool"),
77 name=dict(type="str", required=True),
78 )
79 )
80
81 module = AnsibleModule(argument_spec, supports_check_mode=True)
82 if not HAS_PURESTORAGE:
83 module.fail_json(msg="py-pure-client sdk is required for this module")
84
85 array = get_array(module)
86 changed = False
87 res = array.get_hardware(names=[module.params["name"]])
88 if res.status_code == 200:
89 id_state = getattr(list(res.items)[0], "identify_enabled", None)
90 if id_state is not None and id_state != module.params["enabled"]:
91 changed = True
92 if not module.check_mode:
93 res = array.patch_hardware(
94 names=[module.params["name"]],
95 hardware=flasharray.Hardware(
96 identify_enabled=module.params["enabled"]
97 ),
98 )
99 if res.status_code != 200:
100 module.fail_json(
101 msg="Failed to set identification LED for {0}. Error: {1}".format(
102 module.params["name"], res.errors[0].message
103 )
104 )
105
106 module.exit_json(changed=changed)
107
108
109 if __name__ == "__main__":
110 main()