Debian Codegraph @

ansible_collections/purestorage/flasharray/plugins/modules/purefa_inventory.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_inventory
20 short_description: Collect information from Pure Storage FlashArray
21 version_added: '1.0.0'
22 description:
23 - Collect hardware inventory information from a Pure Storage Flasharray
24 author:
25 - Pure Storage ansible Team (@sdodsley) <[email protected]>
26 extends_documentation_fragment:
27 - purestorage.flasharray.purestorage.fa
28 """
29
30 EXAMPLES = r"""
31 - name: collect FlashArray inventory
32 purestorage.flasharray.purefa_inventory:
33 fa_url: 10.10.10.2
34 api_token: e31060a7-21fc-e277-6240-25983c6c4592
35 - name: show inventory information
36 debug:
37 msg: "{{ array_info['purefa_inv'] }}"
38 """
39
40 RETURN = r"""
41 purefa_inventory:
42 description: Returns the inventory information for the FlashArray
43 returned: always
44 type: dict
45 """
46
47
48 from ansible.module_utils.basic import AnsibleModule
49 from ansible_collections.purestorage.flasharray.plugins.module_utils.purefa import (
50 get_array,
51 purefa_argument_spec,
52 )
53 from ansible_collections.purestorage.flasharray.plugins.module_utils.version import (
54 LooseVersion,
55 )
56
57 SFP_API_VERSION = "2.16"
58
59
60 def generate_new_hardware_dict(array):
61 hw_info = {
62 "fans": {},
63 "controllers": {},
64 "drives": {},
65 "interfaces": {},
66 "power": {},
67 "chassis": {},
68 "temperature": {},
69 }
70 components = list(array.get_hardware().items)
71 for component in components:
72 component_name = component.name
73 if component.type == "chassis":
74 hw_info["chassis"][component_name] = {
75 "status": component.status,
76 "serial": component.serial,
77 "model": component.model,
78 "identify_enabled": component.identify_enabled,
79 }
80 if component.type == "controller":
81 hw_info["controllers"][component_name] = {
82 "status": component.status,
83 "serial": component.serial,
84 "model": component.model,
85 "identify_enabled": component.identify_enabled,
86 }
87 if component.type == "cooling":
88 hw_info["fans"][component_name] = {
89 "status": component.status,
90 }
91 if component.type == "temp_sensor":
92 hw_info["controllers"][component_name] = {
93 "status": component.status,
94 "temperature": component.temperature,
95 }
96 if component.type == "drive_bay":
97 hw_info["drives"][component_name] = {
98 "status": component.status,
99 "identify_enabled": component.identify_enabled,
100 "serial": getattr(component, "serial", None),
101 }
102 if component.type in [
103 "sas_port",
104 "fc_port",
105 "eth_port",
106 "ib_port",
107 ]:
108 hw_info["interfaces"][component_name] = {
109 "type": component.type,
110 "status": component.status,
111 "speed": component.speed,
112 "connector_type": None,
113 "rx_los": None,
114 "rx_power": None,
115 "static": {},
116 "temperature": None,
117 "tx_bias": None,
118 "tx_fault": None,
119 "tx_power": None,
120 "voltage": None,
121 }
122 if component.type == "power_supply":
123 hw_info["power"][component_name] = {
124 "status": component.status,
125 "voltage": getattr(component, "voltage", None),
126 "serial": getattr(component, "serial", None),
127 "model": getattr(component, "model", None),
128 }
129 drives = list(array.get_drives().items)
130 for drive in drives:
131 drive_name = drive.name
132 hw_info["drives"][drive_name] = {
133 "capacity": drive.capacity,
134 "capacity_installed": getattr(drive, "capacity_installed", drive.capacity),
135 "status": drive.status,
136 "protocol": getattr(drive, "protocol", None),
137 "details": getattr(drive, "details", None),
138 "type": drive.type,
139 }
140 api_version = array.get_rest_version()
141 if LooseVersion(SFP_API_VERSION) <= LooseVersion(api_version):
142 port_details = list(array.get_network_interfaces_port_details().items)
143 for port_detail in port_details:
144 port_name = port_detail.name
145 hw_info["interfaces"][port_name][
146 "interface_type"
147 ] = port_detail.interface_type
148 if not getattr(port_detail, "rx_los", None) is None:
149 hw_info["interfaces"][port_name]["rx_los"] = port_detail.rx_los[0].flag
150 if not getattr(port_detail, "rx_power", None) is None:
151 hw_info["interfaces"][port_name]["rx_power"] = port_detail.rx_power[
152 0
153 ].measurement
154 hw_info["interfaces"][port_name]["static"] = {
155 "connector_type": getattr(port_detail.static, "connector_type", None),
156 "vendor_name": getattr(port_detail.static, "vendor_name", None),
157 "vendor_oui": getattr(port_detail.static, "vendor_oui", None),
158 "vendor_serial_number": getattr(
159 port_detail.static, "vendor_serial_number", None
160 ),
161 "vendor_part_number": getattr(
162 port_detail.static, "vendor_part_number", None
163 ),
164 "vendor_date_code": getattr(
165 port_detail.static, "vendor_date_code", None
166 ),
167 "signaling_rate": getattr(port_detail.static, "signaling_rate", None),
168 "wavelength": getattr(port_detail.static, "wavelength", None),
169 "rate_identifier": getattr(port_detail.static, "rate_identifier", None),
170 "identifier": getattr(port_detail.static, "identifier", None),
171 "link_length": getattr(port_detail.static, "link_length", None),
172 "fc_speeds": getattr(port_detail.static, "fc_speeds", None),
173 "fc_technology": getattr(port_detail.static, "fc_technology", None),
174 "encoding": getattr(port_detail.static, "encoding", None),
175 "fc_link_lengths": getattr(port_detail.static, "fc_link_lengths", None),
176 "fc_transmission_media": getattr(
177 port_detail.static, "fc_transmission_media", None
178 ),
179 "extended_identifier": getattr(
180 port_detail.static, "extended_identifier", None
181 ),
182 }
183 if not getattr(port_detail.static, "voltage_thresholds", None) is None:
184 hw_info["interfaces"][port_name]["voltage_thresholds"] = {
185 "alarm_high": getattr(
186 port_detail.static.voltage_thresholds,
187 "alarm_high",
188 None,
189 ),
190 "alarm_low": getattr(
191 port_detail.static.voltage_thresholds,
192 "alarm_low",
193 None,
194 ),
195 "warn_high": getattr(
196 port_detail.static.voltage_thresholds,
197 "warn_high",
198 None,
199 ),
200 "warn_low": getattr(
201 port_detail.static.voltage_thresholds,
202 "warn_low",
203 None,
204 ),
205 }
206 if not getattr(port_detail.static, "tx_power_thresholds", None) is None:
207 hw_info["interfaces"][port_name]["tx_power_thresholds"] = {
208 "alarm_high": getattr(
209 port_detail.static.tx_power_thresholds,
210 "alarm_high",
211 None,
212 ),
213 "alarm_low": getattr(
214 port_detail.static.tx_power_thresholds,
215 "alarm_low",
216 None,
217 ),
218 "warn_high": getattr(
219 port_detail.static.tx_power_thresholds,
220 "warn_high",
221 None,
222 ),
223 "warn_low": getattr(
224 port_detail.static.tx_power_thresholds,
225 "warn_low",
226 None,
227 ),
228 }
229 if not getattr(port_detail.static, "rx_power_thresholds", None) is None:
230 hw_info["interfaces"][port_name]["rx_power_thresholds"] = {
231 "alarm_high": getattr(
232 port_detail.static.rx_power_thresholds,
233 "alarm_high",
234 None,
235 ),
236 "alarm_low": getattr(
237 port_detail.static.rx_power_thresholds,
238 "alarm_low",
239 None,
240 ),
241 "warn_high": getattr(
242 port_detail.static.rx_power_thresholds,
243 "warn_high",
244 None,
245 ),
246 "warn_low": getattr(
247 port_detail.static.rx_power_thresholds,
248 "warn_low",
249 None,
250 ),
251 }
252 if not getattr(port_detail.static, "tx_bias_thresholds", None) is None:
253 hw_info["interfaces"][port_name]["tx_bias_thresholds"] = {
254 "alarm_high": getattr(
255 port_detail.static.tx_bias_thresholds,
256 "alarm_high",
257 None,
258 ),
259 "alarm_low": getattr(
260 port_detail.static.tx_bias_thresholds,
261 "alarm_low",
262 None,
263 ),
264 "warn_high": getattr(
265 port_detail.static.tx_bias_thresholds,
266 "warn_high",
267 None,
268 ),
269 "warn_low": getattr(
270 port_detail.static.tx_bias_thresholds,
271 "warn_low",
272 None,
273 ),
274 }
275 if not getattr(port_detail.static, "temperature_thresholds", None) is None:
276 hw_info["interfaces"][port_name]["temperature_thresholds"] = {
277 "alarm_high": getattr(
278 port_detail.static.temperature_thresholds,
279 "alarm_high",
280 None,
281 ),
282 "alarm_low": getattr(
283 port_detail.static.temperature_thresholds,
284 "alarm_low",
285 None,
286 ),
287 "warn_high": getattr(
288 port_detail.static.temperature_thresholds,
289 "warn_high",
290 None,
291 ),
292 "warn_low": getattr(
293 port_detail.static.temperature_thresholds,
294 "warn_low",
295 None,
296 ),
297 }
298 if not getattr(port_detail, "temperature", None) is None:
299 hw_info["interfaces"][port_name]["temperature"] = getattr(
300 port_detail.temperature[0], "measurement", None
301 )
302 if not getattr(port_detail, "tx_bias", None) is None:
303 hw_info["interfaces"][port_name]["tx_bias"] = getattr(
304 port_detail.tx_bias[0], "measurement", None
305 )
306 if not getattr(port_detail, "tx_fault", None) is None:
307 hw_info["interfaces"][port_name]["tx_fault"] = getattr(
308 port_detail.tx_fault[0], "flag", None
309 )
310 if not getattr(port_detail, "tx_power", None) is None:
311 hw_info["interfaces"][port_name]["tx_power"] = getattr(
312 port_detail.tx_power[0], "measurement", None
313 )
314 if not getattr(port_detail, "voltage", None) is None:
315 hw_info["interfaces"][port_name]["voltage"] = getattr(
316 port_detail.voltage[0], "measurement", None
317 )
318 return hw_info
319
320
321 def main():
322 argument_spec = purefa_argument_spec()
323 inv_info = {}
324 module = AnsibleModule(argument_spec, supports_check_mode=True)
325 array = get_array(module)
326 inv_info = generate_new_hardware_dict(array)
327 module.exit_json(changed=False, purefa_inv=inv_info)
328
329
330 if __name__ == "__main__":
331 main()