Debian Codegraph @

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

raw symbols SCIP
1 #!/usr/bin/python
2 # -*- coding: utf-8 -*-
3
4 # (c) 2020, 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_smis
20 version_added: '1.0.0'
21 short_description: Enable or disable FlashArray SMI-S features
22 description:
23 - Enable or disable FlashArray SMI-S Provider and/or SLP
24 author:
25 - Pure Storage Ansible Team (@sdodsley) <[email protected]>
26 options:
27 slp:
28 description:
29 - Enable/Disable Service Locator Protocol
30 - Ports used are TCP 427 and UDP 427
31 type: bool
32 default: true
33 smis:
34 description:
35 - Enable/Disable SMI-S Provider
36 - Port used is TCP 5989
37 type: bool
38 default: true
39 extends_documentation_fragment:
40 - purestorage.flasharray.purestorage.fa
41 """
42
43 EXAMPLES = r"""
44 - name: Enable SMI-S and SLP
45 purestorage.flasharray.purefa_smis:
46 fa_url: 10.10.10.2
47 api_token: e31060a7-21fc-e277-6240-25983c6c4592
48
49 - name: Disable SMI-S and SLP
50 purestorage.flasharray.purefa_smis:
51 smis: false
52 slp: false
53 fa_url: 10.10.10.2
54 api_token: e31060a7-21fc-e277-6240-25983c6c4592
55 """
56
57 RETURN = r"""
58 """
59
60 HAS_PURESTORAGE = True
61 try:
62 from pypureclient import flasharray
63 except ImportError:
64 HAS_PURESTORAGE = False
65
66 from ansible.module_utils.basic import AnsibleModule
67 from ansible_collections.purestorage.flasharray.plugins.module_utils.purefa import (
68 get_array,
69 purefa_argument_spec,
70 )
71 from ansible_collections.purestorage.flasharray.plugins.module_utils.version import (
72 LooseVersion,
73 )
74
75 MIN_REQUIRED_API_VERSION = "2.2"
76
77
78 def update_smis(module, array):
79 """Update SMI-S features"""
80 changed = smis_changed = False
81 current = list(array.get_smi_s().items)[0]
82 slp_enabled = current.slp_enabled
83 wbem_enabled = current.wbem_https_enabled
84 if slp_enabled != module.params["slp"]:
85 slp_enabled = module.params["slp"]
86 smis_changed = True
87 if wbem_enabled != module.params["smis"]:
88 wbem_enabled = module.params["smis"]
89 smis_changed = True
90 if smis_changed:
91 smi_s = flasharray.Smis(
92 slp_enabled=slp_enabled, wbem_https_enabled=wbem_enabled
93 )
94 changed = True
95 if not module.check_mode:
96 res = array.patch_smi_s(smi_s=smi_s)
97 if res.status_code != 200:
98 module.fail_json(
99 msg="Failed to change SMI-S settings. Error: {0}".format(
100 res.errors[0].message
101 )
102 )
103 module.exit_json(changed=changed)
104
105
106 def main():
107 argument_spec = purefa_argument_spec()
108 argument_spec.update(
109 dict(
110 smis=dict(type="bool", default=True),
111 slp=dict(type="bool", default=True),
112 )
113 )
114
115 module = AnsibleModule(argument_spec, supports_check_mode=True)
116
117 if not HAS_PURESTORAGE:
118 module.fail_json(msg="py-pure-client sdk is required for this module")
119
120 array = get_array(module)
121 api_version = array.get_rest_version()
122
123 if LooseVersion(MIN_REQUIRED_API_VERSION) > LooseVersion(api_version):
124 module.fail_json(
125 msg="FlashArray REST version not supported. "
126 "Minimum version required: {0}".format(MIN_REQUIRED_API_VERSION)
127 )
128
129 update_smis(module, array)
130
131
132 if __name__ == "__main__":
133 main()