Debian Codegraph @

ansible_collections/netapp_eseries/santricity/plugins/modules/na_santricity_facts.py

raw symbols SCIP
1 #!/usr/bin/python
2
3 # (c) 2024, NetApp, Inc
4 # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
5 from __future__ import absolute_import, division, print_function
6 __metaclass__ = type
7
8
9 DOCUMENTATION = '''
10 module: na_santricity_facts
11 short_description: NetApp E-Series retrieve facts about NetApp E-Series storage arrays
12 description:
13 - The na_santricity_facts module returns a collection of facts regarding NetApp E-Series storage arrays.
14 author:
15 - Kevin Hulquest (@hulquest)
16 - Nathan Swartz (@swartzn)
17 - Vu Tran (@VuTran007)
18 extends_documentation_fragment:
19 - netapp_eseries.santricity.santricity.santricity_doc
20 '''
21
22 EXAMPLES = """
23 ---
24 - name: Get array facts
25 na_santricity_facts:
26 ssid: "1"
27 api_url: "https://192.168.1.100:8443/devmgr/v2"
28 api_username: "admin"
29 api_password: "adminpass"
30 validate_certs: true
31 """
32
33 RETURN = """
34 msg:
35 description: Success message
36 returned: on success
37 type: str
38 sample:
39 - Gathered facts for storage array. Array ID [1].
40 - Gathered facts for web services proxy.
41 storage_array_facts:
42 description: provides details about the array, controllers, management interfaces, hostside interfaces,
43 driveside interfaces, disks, storage pools, volumes, snapshots, and features.
44 returned: on successful inquiry from from embedded web services rest api
45 type: complex
46 contains:
47 netapp_controllers:
48 description: storage array controller list that contains basic controller identification and status
49 type: list
50 sample:
51 - [{"name": "A", "serial": "021632007299", "status": "optimal"},
52 {"name": "B", "serial": "021632007300", "status": "failed"}]
53 netapp_disks:
54 description: drive list that contains identification, type, and status information for each drive
55 type: list
56 sample:
57 - [{"available": false,
58 "firmware_version": "MS02",
59 "id": "01000000500003960C8B67880000000000000000",
60 "media_type": "ssd",
61 "product_id": "PX02SMU080 ",
62 "serial_number": "15R0A08LT2BA",
63 "status": "optimal",
64 "tray_ref": "0E00000000000000000000000000000000000000",
65 "usable_bytes": "799629205504" }]
66 netapp_driveside_interfaces:
67 description: drive side interface list that contains identification, type, and speed for each interface
68 type: list
69 sample:
70 - [{ "controller": "A", "interface_speed": "12g", "interface_type": "sas" }]
71 - [{ "controller": "B", "interface_speed": "10g", "interface_type": "iscsi" }]
72 netapp_enabled_features:
73 description: specifies the enabled features on the storage array.
74 returned: on success
75 type: list
76 sample:
77 - [ "flashReadCache", "performanceTier", "protectionInformation", "secureVolume" ]
78 netapp_host_groups:
79 description: specifies the host groups on the storage arrays.
80 returned: on success
81 type: list
82 sample:
83 - [{ "id": "85000000600A098000A4B28D003610705C40B964", "name": "group1" }]
84 netapp_hosts:
85 description: specifies the hosts on the storage arrays.
86 returned: on success
87 type: list
88 sample:
89 - [{ "id": "8203800000000000000000000000000000000000",
90 "name": "host1",
91 "group_id": "85000000600A098000A4B28D003610705C40B964",
92 "host_type_index": 28,
93 "ports": [{ "type": "fc", "address": "1000FF7CFFFFFF01", "label": "FC_1" },
94 { "type": "fc", "address": "1000FF7CFFFFFF00", "label": "FC_2" }]}]
95 netapp_host_types:
96 description: lists the available host types on the storage array.
97 returned: on success
98 type: list
99 sample:
100 - [{ "index": 0, "type": "FactoryDefault" },
101 { "index": 1, "type": "W2KNETNCL"},
102 { "index": 2, "type": "SOL" },
103 { "index": 5, "type": "AVT_4M" },
104 { "index": 6, "type": "LNX" },
105 { "index": 7, "type": "LnxALUA" },
106 { "index": 8, "type": "W2KNETCL" },
107 { "index": 9, "type": "AIX MPIO" },
108 { "index": 10, "type": "VmwTPGSALUA" },
109 { "index": 15, "type": "HPXTPGS" },
110 { "index": 17, "type": "SolTPGSALUA" },
111 { "index": 18, "type": "SVC" },
112 { "index": 22, "type": "MacTPGSALUA" },
113 { "index": 23, "type": "WinTPGSALUA" },
114 { "index": 24, "type": "LnxTPGSALUA" },
115 { "index": 25, "type": "LnxTPGSALUA_PM" },
116 { "index": 26, "type": "ONTAP_ALUA" },
117 { "index": 27, "type": "LnxTPGSALUA_SF" },
118 { "index": 28, "type": "LnxDHALUA" },
119 { "index": 29, "type": "ATTOClusterAllOS" }]
120 netapp_hostside_interfaces:
121 description: host side interface list that contains identification, configuration, type, speed, and
122 status information for each interface
123 type: list
124 sample:
125 - [{"iscsi":
126 [{ "controller": "A",
127 "current_interface_speed": "10g",
128 "ipv4_address": "10.10.10.1",
129 "ipv4_enabled": true,
130 "ipv4_gateway": "10.10.10.1",
131 "ipv4_subnet_mask": "255.255.255.0",
132 "ipv6_enabled": false,
133 "iqn": "iqn.1996-03.com.netapp:2806.600a098000a81b6d0000000059d60c76",
134 "link_status": "up",
135 "mtu": 9000,
136 "supported_interface_speeds": [ "10g" ] }]}]
137 netapp_management_interfaces:
138 description: management interface list that contains identification, configuration, and status for
139 each interface
140 type: list
141 sample:
142 - [{"alias": "ict-2800-A",
143 "channel": 1,
144 "controller": "A",
145 "dns_config_method": "dhcp",
146 "dns_servers": [],
147 "ipv4_address": "10.1.1.1",
148 "ipv4_address_config_method": "static",
149 "ipv4_enabled": true,
150 "ipv4_gateway": "10.113.1.1",
151 "ipv4_subnet_mask": "255.255.255.0",
152 "ipv6_enabled": false,
153 "link_status": "up",
154 "mac_address": "00A098A81B5D",
155 "name": "wan0",
156 "ntp_config_method": "disabled",
157 "ntp_servers": [],
158 "remote_ssh_access": false }]
159 netapp_storage_array:
160 description: provides storage array identification, firmware version, and available capabilities
161 type: dict
162 sample:
163 - {"chassis_serial": "021540006043",
164 "firmware": "08.40.00.01",
165 "name": "ict-2800-11_40",
166 "wwn": "600A098000A81B5D0000000059D60C76",
167 "cacheBlockSizes": [4096,
168 8192,
169 16384,
170 32768],
171 "supportedSegSizes": [8192,
172 16384,
173 32768,
174 65536,
175 131072,
176 262144,
177 524288]}
178 netapp_storage_pools:
179 description: storage pool list that contains identification and capacity information for each pool
180 type: list
181 sample:
182 - [{"available_capacity": "3490353782784",
183 "id": "04000000600A098000A81B5D000002B45A953A61",
184 "name": "Raid6",
185 "total_capacity": "5399466745856",
186 "used_capacity": "1909112963072" }]
187 netapp_volumes:
188 description: storage volume list that contains identification and capacity information for each volume
189 type: list
190 sample:
191 - [{"capacity": "5368709120",
192 "id": "02000000600A098000AAC0C3000002C45A952BAA",
193 "is_thin_provisioned": false,
194 "name": "5G",
195 "parent_storage_pool_id": "04000000600A098000A81B5D000002B45A953A61" }]
196 netapp_workload_tags:
197 description: workload tag list
198 type: list
199 sample:
200 - [{"id": "87e19568-43fb-4d8d-99ea-2811daaa2b38",
201 "name": "ftp_server",
202 "workloadAttributes": [{"key": "use",
203 "value": "general"}]}]
204 netapp_volumes_by_initiators:
205 description: list of available volumes keyed by the mapped initiators.
206 type: dict
207 sample:
208 - {"beegfs_host": [{"id": "02000000600A098000A4B9D1000015FD5C8F7F9E",
209 "meta_data": {"filetype": "ext4", "public": true},
210 "name": "some_volume",
211 "workload_name": "beegfs_metadata",
212 "workload_metadata": {"filetype": "ext4", "public": true},
213 "volume_metadata": '{"format_type": "ext4",
214 "format_options": "-i 2048 -I 512 -J size=400 -Odir_index,filetype",
215 "mount_options": "noatime,nodiratime,nobarrier,_netdev",
216 "mount_directory": "/data/beegfs/"}',
217 "host_types": ["nvmeof"],
218 "eui": "0000139A3885FA4500A0980000EAA272V",
219 "wwn": "600A098000A4B9D1000015FD5C8F7F9E"}]}
220 snapshot_images:
221 description: snapshot image list that contains identification, capacity, and status information for each
222 snapshot image
223 type: list
224 sample:
225 - [{"active_cow": true,
226 "creation_method": "user",
227 "id": "34000000600A098000A81B5D00630A965B0535AC",
228 "pit_capacity": "5368709120",
229 "reposity_cap_utilization": "0",
230 "rollback_source": false,
231 "status": "optimal" }]
232 proxy_facts:
233 description: proxy storage system list
234 returned: on successful inquiry from from web services proxy's rest api
235 type: complex
236 contains:
237 ssid:
238 description: storage system id
239 type: str
240 sample: "ec8ed9d2-eba3-4cac-88fb-0954f327f1d4"
241 name:
242 description: storage system name
243 type: str
244 sample: "EF570-NVMe"
245 wwn:
246 description: storage system unique identifier
247 type: str
248 sample: "AC1100051E1E1E1E1E1E1E1E1E1E1E1E"
249 model:
250 description: NetApp E-Series model number
251 type: str
252 sample: "5700"
253 controller:
254 description: controller list that contains identification, ip addresses, and certificate information for
255 each controller
256 type: list
257 sample: [{"certificateStatus": "selfSigned",
258 "controllerId": "070000000000000000000001",
259 "ipAddresses": ["172.17.0.5", "3.3.3.3"]}]
260 drive_types:
261 description: all available storage system drive types
262 type: list
263 sample: ["sas", "fibre"]
264 unconfigured_space:
265 description: unconfigured storage system space in bytes
266 type: str
267 sample: "982259020595200"
268 array_status:
269 description: storage system status
270 type: str
271 sample: "optimal"
272 password_status:
273 description: storage system password status
274 type: str
275 sample: "invalid"
276 certificate_status:
277 description: storage system ssl certificate status
278 type: str
279 sample: "untrusted"
280 firmware_version:
281 description: storage system install firmware version
282 type: str
283 sample: "08.50.42.99"
284 chassis_serial:
285 description: storage system chassis serial number
286 type: str
287 sample: "SX0810032"
288 asup_enabled:
289 description: storage system auto-support status
290 type: bool
291 sample: True
292 """
293
294 from datetime import datetime
295 import re
296 from ansible_collections.netapp_eseries.santricity.plugins.module_utils.santricity import NetAppESeriesModule
297 try:
298 from ansible.module_utils.ansible_release import __version__ as ansible_version
299 except ImportError:
300 ansible_version = 'unknown'
301
302
303 class Facts(NetAppESeriesModule):
304 def __init__(self):
305 web_services_version = "02.00.0000.0000"
306 super(Facts, self).__init__(ansible_options={},
307 web_services_version=web_services_version,
308 supports_check_mode=True)
309
310 def get_controllers(self):
311 """Retrieve a mapping of controller references to their labels."""
312 controllers = list()
313 try:
314 rc, controllers = self.request('storage-systems/%s/graph/xpath-filter?query=/controller/id' % self.ssid)
315 except Exception as err:
316 self.module.fail_json(
317 msg="Failed to retrieve controller list! Array Id [%s]. Error [%s]."
318 % (self.ssid, str(err)))
319
320 controllers.sort()
321
322 controllers_dict = {}
323 i = ord('A')
324 for controller in controllers:
325 label = chr(i)
326 controllers_dict[controller] = label
327 i += 1
328
329 return controllers_dict
330
331 def get_array_facts(self):
332 """Extract particular facts from the storage array graph"""
333 facts = dict(facts_from_proxy=(not self.is_embedded()), ssid=self.ssid)
334 controller_reference_label = self.get_controllers()
335 array_facts = None
336 hardware_inventory_facts = None
337
338 # Get the storage array graph
339 try:
340 rc, array_facts = self.request("storage-systems/%s/graph" % self.ssid)
341 except Exception as error:
342 self.module.fail_json(msg="Failed to obtain facts from storage array with id [%s]. Error [%s]" % (self.ssid, str(error)))
343
344 # Get the storage array hardware inventory
345 try:
346 rc, hardware_inventory_facts = self.request("storage-systems/%s/hardware-inventory" % self.ssid)
347 except Exception as error:
348 self.module.fail_json(msg="Failed to obtain hardware inventory from storage array with id [%s]. Error [%s]" % (self.ssid, str(error)))
349
350 # Get storage system specific key-value pairs
351 key_value_url = "key-values"
352 key_values = []
353 if not self.is_embedded() and self.ssid.lower() not in ["0", "proxy"]:
354 key_value_url = "storage-systems/%s/forward/devmgr/v2/key-values" % self.ssid
355 try:
356 rc, key_values = self.request(key_value_url)
357 except Exception as error:
358 self.module.fail_json(msg="Failed to obtain embedded key-value database. Array [%s]. Error [%s]" % (self.ssid, str(error)))
359
360 facts['netapp_storage_array'] = dict(
361 name=array_facts['sa']['saData']['storageArrayLabel'],
362 chassis_serial=array_facts['sa']['saData']['chassisSerialNumber'],
363 firmware=array_facts['sa']['saData']['fwVersion'],
364 wwn=array_facts['sa']['saData']['saId']['worldWideName'],
365 segment_sizes=array_facts['sa']['featureParameters']['supportedSegSizes'],
366 cache_block_sizes=array_facts['sa']['featureParameters']['cacheBlockSizes'])
367
368 facts['netapp_controllers'] = [
369 dict(
370 name=controller_reference_label[controller['controllerRef']],
371 serial=controller['serialNumber'].strip(),
372 status=controller['status'],
373 ) for controller in array_facts['controller']]
374
375 facts['netapp_hosts'] = [
376 dict(
377 group_id=host['clusterRef'],
378 hosts_reference=host['hostRef'],
379 id=host['id'],
380 name=host['name'],
381 host_type_index=host['hostTypeIndex'],
382 ports=host['hostSidePorts']
383 ) for host in array_facts['storagePoolBundle']['host']]
384
385 facts['netapp_host_groups'] = [
386 dict(
387 id=group['id'],
388 name=group['name'],
389 hosts=[host['name'] for host in facts['netapp_hosts'] if host['group_id'] == group['id']]
390 ) for group in array_facts['storagePoolBundle']['cluster']]
391 facts['netapp_host_groups'].append(dict(
392 id='0000000000000000000000000000000000000000',
393 name='default_hostgroup',
394 hosts=[host["name"] for host in facts['netapp_hosts'] if host['group_id'] == '0000000000000000000000000000000000000000']))
395
396 facts['netapp_host_types'] = [
397 dict(
398 type=host_type['hostType'],
399 index=host_type['index']
400 ) for host_type in array_facts['sa']['hostSpecificVals']
401 if 'hostType' in host_type.keys() and host_type['hostType']
402 # This conditional ignores zero-length strings which indicates that the associated host-specific NVSRAM region has been cleared.
403 ]
404
405 facts['snapshot_images'] = [
406 dict(
407 id=snapshot['id'],
408 status=snapshot['status'],
409 pit_capacity=snapshot['pitCapacity'],
410 creation_method=snapshot['creationMethod'],
411 reposity_cap_utilization=snapshot['repositoryCapacityUtilization'],
412 active_cow=snapshot['activeCOW'],
413 rollback_source=snapshot['isRollbackSource']
414 ) for snapshot in array_facts['highLevelVolBundle']['pit']]
415
416 facts['netapp_disks'] = [
417 dict(
418 id=disk['id'],
419 available=disk['available'],
420 media_type=disk['driveMediaType'],
421 status=disk['status'],
422 usable_bytes=disk['usableCapacity'],
423 tray_ref=disk['physicalLocation']['trayRef'],
424 product_id=disk['productID'],
425 firmware_version=disk['firmwareVersion'],
426 serial_number=disk['serialNumber'].lstrip()
427 ) for disk in array_facts['drive']]
428
429 facts['netapp_management_interfaces'] = [
430 dict(controller=controller_reference_label[controller['controllerRef']],
431 name=iface['ethernet']['interfaceName'],
432 alias=iface['ethernet']['alias'],
433 channel=iface['ethernet']['channel'],
434 mac_address=iface['ethernet']['macAddr'],
435 remote_ssh_access=iface['ethernet']['rloginEnabled'],
436 link_status=iface['ethernet']['linkStatus'],
437 ipv4_enabled=iface['ethernet']['ipv4Enabled'],
438 ipv4_address_config_method=iface['ethernet']['ipv4AddressConfigMethod'].lower().replace("config", ""),
439 ipv4_address=iface['ethernet']['ipv4Address'],
440 ipv4_subnet_mask=iface['ethernet']['ipv4SubnetMask'],
441 ipv4_gateway=iface['ethernet']['ipv4GatewayAddress'],
442 ipv6_enabled=iface['ethernet']['ipv6Enabled'],
443 dns_config_method=iface['ethernet']['dnsProperties']['acquisitionProperties']['dnsAcquisitionType'],
444 dns_servers=(iface['ethernet']['dnsProperties']['acquisitionProperties']['dnsServers']
445 if iface['ethernet']['dnsProperties']['acquisitionProperties']['dnsServers'] else []),
446 ntp_config_method=iface['ethernet']['ntpProperties']['acquisitionProperties']['ntpAcquisitionType'],
447 ntp_servers=(iface['ethernet']['ntpProperties']['acquisitionProperties']['ntpServers']
448 if iface['ethernet']['ntpProperties']['acquisitionProperties']['ntpServers'] else [])
449 ) for controller in array_facts['controller'] for iface in controller['netInterfaces']]
450
451 facts['netapp_hostside_interfaces'] = [
452 dict(
453 fc=[dict(controller=controller_reference_label[controller['controllerRef']],
454 channel=iface['fibre']['channel'],
455 link_status=iface['fibre']['linkStatus'],
456 current_interface_speed=strip_interface_speed(iface['fibre']['currentInterfaceSpeed']),
457 maximum_interface_speed=strip_interface_speed(iface['fibre']['maximumInterfaceSpeed']))
458 for controller in array_facts['controller']
459 for iface in controller['hostInterfaces']
460 if iface['interfaceType'] == 'fc'],
461 ib=[dict(controller=controller_reference_label[controller['controllerRef']],
462 channel=iface['ib']['channel'],
463 link_status=iface['ib']['linkState'],
464 mtu=iface['ib']['maximumTransmissionUnit'],
465 current_interface_speed=strip_interface_speed(iface['ib']['currentSpeed']),
466 maximum_interface_speed=strip_interface_speed(iface['ib']['supportedSpeed']))
467 for controller in array_facts['controller']
468 for iface in controller['hostInterfaces']
469 if iface['interfaceType'] == 'ib'],
470 iscsi=[dict(controller=controller_reference_label[controller['controllerRef']],
471 iqn=iface['iscsi']['iqn'],
472 link_status=iface['iscsi']['interfaceData']['ethernetData']['linkStatus'],
473 ipv4_enabled=iface['iscsi']['ipv4Enabled'],
474 ipv4_address=iface['iscsi']['ipv4Data']['ipv4AddressData']['ipv4Address'],
475 ipv4_subnet_mask=iface['iscsi']['ipv4Data']['ipv4AddressData']['ipv4SubnetMask'],
476 ipv4_gateway=iface['iscsi']['ipv4Data']['ipv4AddressData']['ipv4GatewayAddress'],
477 ipv6_enabled=iface['iscsi']['ipv6Enabled'],
478 mtu=iface['iscsi']['interfaceData']['ethernetData']['maximumFramePayloadSize'],
479 current_interface_speed=strip_interface_speed(iface['iscsi']['interfaceData']
480 ['ethernetData']['currentInterfaceSpeed']),
481 supported_interface_speeds=strip_interface_speed(iface['iscsi']['interfaceData']
482 ['ethernetData']
483 ['supportedInterfaceSpeeds']))
484 for controller in array_facts['controller']
485 for iface in controller['hostInterfaces']
486 if iface['interfaceType'] == 'iscsi' and iface['iscsi']['interfaceData']['type'] == 'ethernet'],
487 sas=[dict(controller=controller_reference_label[controller['controllerRef']],
488 channel=iface['sas']['channel'],
489 current_interface_speed=strip_interface_speed(iface['sas']['currentInterfaceSpeed']),
490 maximum_interface_speed=strip_interface_speed(iface['sas']['maximumInterfaceSpeed']),
491 link_status=iface['sas']['iocPort']['state'])
492 for controller in array_facts['controller']
493 for iface in controller['hostInterfaces']
494 if iface['interfaceType'] == 'sas'])]
495
496 facts['netapp_driveside_interfaces'] = [
497 dict(
498 controller=controller_reference_label[controller['controllerRef']],
499 interface_type=interface['interfaceType'],
500 interface_speed=strip_interface_speed(
501 interface[interface['interfaceType']]['maximumInterfaceSpeed']
502 if (interface['interfaceType'] == 'sata' or
503 interface['interfaceType'] == 'sas' or
504 interface['interfaceType'] == 'fibre')
505 else (
506 interface[interface['interfaceType']]['currentSpeed']
507 if interface['interfaceType'] == 'ib'
508 else (
509 interface[interface['interfaceType']]['interfaceData']['maximumInterfaceSpeed']
510 if interface['interfaceType'] == 'iscsi' else 'unknown'
511 ))),
512 )
513 for controller in array_facts['controller']
514 for interface in controller['driveInterfaces']]
515
516 facts['netapp_storage_pools'] = [
517 dict(
518 id=storage_pool['id'],
519 name=storage_pool['name'],
520 available_capacity=storage_pool['freeSpace'],
521 total_capacity=storage_pool['totalRaidedSpace'],
522 used_capacity=storage_pool['usedSpace']
523 ) for storage_pool in array_facts['volumeGroup']]
524
525 all_volumes = list(array_facts['volume'] + array_facts['highLevelVolBundle']['thinVolume'])
526
527 facts['netapp_volumes'] = [
528 dict(
529 id=v['id'],
530 name=v['name'],
531 parent_storage_pool_id=v['volumeGroupRef'],
532 capacity=v['capacity'],
533 is_thin_provisioned=v['thinProvisioned'],
534 workload=v['metadata'],
535
536 ) for v in all_volumes]
537
538 # Add access volume information to volumes when enabled.
539 if array_facts['sa']['accessVolume']['enabled']:
540 facts['netapp_volumes'].append(dict(
541 id=array_facts['sa']['accessVolume']['id'],
542 name="access_volume",
543 parent_storage_pool_id="",
544 capacity=array_facts['sa']['accessVolume']['capacity'],
545 is_thin_provisioned=False,
546 workload=""))
547
548 facts['netapp_snapshot_consistency_groups'] = []
549 for group in array_facts["highLevelVolBundle"]["pitConsistencyGroup"]:
550 reserve_capacity_full_policy = "purge" if group["repFullPolicy"] == "purgepit" else "reject"
551 group_info = {"id": group["id"],
552 "name": group["name"],
553 "reserve_capacity_full_policy": reserve_capacity_full_policy,
554 "rollback_priority": group["rollbackPriority"],
555 "base_volumes": [],
556 "pit_images": [],
557 "pit_views": {}}
558
559 # Determine all consistency group base volumes.
560 volumes_by_id = {}
561 for pit_group in array_facts["highLevelVolBundle"]["pitGroup"]:
562 if pit_group["consistencyGroupRef"] == group["id"]:
563 for volume in array_facts["volume"]:
564 if volume["id"] == pit_group["baseVolume"]:
565 volumes_by_id.update({volume["id"]: volume["name"]})
566 group_info["base_volumes"].append({"id": volume["id"],
567 "name": volume["name"],
568 "reserve_capacity_volume_id": pit_group["repositoryVolume"]})
569 break
570
571 # Determine all consistency group pit snapshot images.
572 group_pit_key_values = {}
573 for entry in key_values:
574 if re.search("ansible\\|%s\\|" % group["name"], entry["key"]):
575 pit_name = entry["key"].replace("ansible|%s|" % group["name"], "")
576 pit_values = entry["value"].split("|")
577 if len(pit_values) == 3:
578 timestamp, image_id, description = pit_values
579 group_pit_key_values.update({timestamp: {"name": pit_name, "description": description}})
580
581 pit_by_id = {}
582 for pit in array_facts["highLevelVolBundle"]["pit"]:
583 if pit["consistencyGroupId"] == group["id"]:
584
585 if pit["pitTimestamp"] in group_pit_key_values.keys():
586 pit_image = {"name": group_pit_key_values[pit["pitTimestamp"]]["name"],
587 "description": group_pit_key_values[pit["pitTimestamp"]]["description"],
588 "timestamp": datetime.fromtimestamp(int(pit["pitTimestamp"])).strftime("%Y-%m-%d %H:%M:%S")}
589 else:
590 pit_image = {"name": "", "description": "",
591 "timestamp": datetime.fromtimestamp(int(pit["pitTimestamp"])).strftime("%Y-%m-%d %H:%M:%S")}
592 group_info["pit_images"].append(pit_image)
593 pit_by_id.update({pit["id"]: pit_image})
594
595 # Determine all consistency group pit views.
596 for view in array_facts["highLevelVolBundle"]["pitView"]:
597 if view["consistencyGroupId"] == group["id"]:
598 view_timestamp = datetime.fromtimestamp(int(view["viewTime"])).strftime("%Y-%m-%d %H:%M:%S")
599 reserve_capacity_pct = int(round(float(view["repositoryCapacity"]) / float(view["baseVolumeCapacity"]) * 100))
600 if view_timestamp in group_info["pit_views"].keys():
601 group_info["pit_views"][view_timestamp]["volumes"].append({"name": view["name"],
602 "base_volume": volumes_by_id[view["baseVol"]],
603 "writable": view["accessMode"] == "readWrite",
604 "reserve_capacity_pct": reserve_capacity_pct,
605 "status": view["status"]})
606 else:
607 group_info["pit_views"].update({view_timestamp: {"name": pit_by_id[view["basePIT"]]["name"],
608 "description": pit_by_id[view["basePIT"]]["description"],
609 "volumes": [{"name": view["name"],
610 "base_volume": volumes_by_id[view["baseVol"]],
611 "writable": view["accessMode"] == "readWrite",
612 "reserve_capacity_pct": reserve_capacity_pct,
613 "status": view["status"]}]}})
614
615 facts['netapp_snapshot_consistency_groups'].append(group_info)
616
617 lun_mappings = dict()
618 for host in facts['netapp_hosts']:
619 lun_mappings.update({host["name"]: []})
620 for host in facts['netapp_host_groups']:
621 lun_mappings.update({host["name"]: []})
622
623 facts['netapp_default_hostgroup_access_volume_lun'] = None
624 for lun in [a['lun'] for a in array_facts['storagePoolBundle']['lunMapping']
625 if a['type'] == 'all' and a['mapRef'] == '0000000000000000000000000000000000000000']:
626 facts['netapp_default_hostgroup_access_volume_lun'] = lun
627
628 # Get all host mappings
629 host_mappings = dict()
630 for host_mapping in [h for h in array_facts['storagePoolBundle']['lunMapping'] if h['type'] == 'host']:
631 for host_name in [h['name'] for h in facts['netapp_hosts'] if h['id'] == host_mapping['mapRef']]:
632 for volume in [v['name'] for v in facts['netapp_volumes'] if v['id'] == host_mapping['volumeRef']]:
633 if host_name in host_mappings.keys():
634 host_mappings[host_name].append((volume, host_mapping['lun']))
635 else:
636 host_mappings[host_name] = [(volume, host_mapping['lun'])]
637
638 # Get all host group mappings
639 group_mappings = dict()
640 for group_mapping in [h for h in array_facts['storagePoolBundle']['lunMapping'] if h['type'] == 'cluster']:
641 for group_name, group_hosts in [(g['name'], g['hosts']) for g in facts['netapp_host_groups'] if g['id'] == group_mapping['mapRef']]:
642 for volume in [v['name'] for v in facts['netapp_volumes'] if v['id'] == group_mapping['volumeRef']]:
643 if group_name in group_mappings.keys():
644 group_mappings[group_name].append((volume, group_mapping['lun']))
645 else:
646 group_mappings[group_name] = [(volume, group_mapping['lun'])]
647
648 for host_name in [h for h in group_hosts if h in host_mappings.keys()]:
649 if host_name in host_mappings.keys():
650 host_mappings[host_name].append((volume, group_mapping['lun']))
651 else:
652 host_mappings[host_name] = [(volume, group_mapping['lun'])]
653
654 facts['netapp_luns_by_target'] = lun_mappings
655 if host_mappings:
656 facts['netapp_luns_by_target'].update(host_mappings)
657 if group_mappings:
658 facts['netapp_luns_by_target'].update(group_mappings)
659
660 # Add all host mappings to respective groups mappings
661 for host_group in facts['netapp_host_groups']:
662 group_name = host_group['name']
663 for host in host_group['hosts']:
664 facts['netapp_luns_by_target'][group_name].extend(facts['netapp_luns_by_target'][host])
665
666 # Remove duplicate entries
667 for obj in facts['netapp_luns_by_target'].keys():
668 tmp = dict(facts['netapp_luns_by_target'][obj])
669 facts['netapp_luns_by_target'][obj] = [(k, tmp[k]) for k in tmp.keys()]
670
671 workload_tags = None
672 try:
673 rc, workload_tags = self.request("storage-systems/%s/workloads" % self.ssid)
674 except Exception as error:
675 self.module.fail_json(msg="Failed to retrieve workload tags. Array [%s]." % self.ssid)
676
677 facts['netapp_workload_tags'] = [
678 dict(
679 id=workload_tag['id'],
680 name=workload_tag['name'],
681 attributes=workload_tag['workloadAttributes']
682 ) for workload_tag in workload_tags]
683
684 targets = array_facts["storagePoolBundle"]["target"]
685
686 facts['netapp_hostside_io_interfaces'] = []
687 if "ioInterface" in array_facts:
688 for interface in array_facts["ioInterface"]:
689
690 # Select only the host side channels
691 if interface["channelType"] == "hostside":
692 interface_type = interface["ioInterfaceTypeData"]["interfaceType"]
693 if interface_type == "fibre":
694 interface_type = "fc"
695 elif interface_type == "nvmeCouplingDriver":
696 interface_type = "couplingDriverNvme"
697
698 interface_data = interface["ioInterfaceTypeData"][interface_type]
699 command_protocol_properties = interface["commandProtocolPropertiesList"]["commandProtocolProperties"]
700
701 # Build generic information for each interface entry
702 interface_info = {"protocol": "unknown",
703 "interface_reference": interface_data["interfaceRef"],
704 "controller_reference": interface["controllerRef"],
705 "channel_port_reference": interface_data["channelPortRef"] if "channelPortRef" in interface_data else "",
706 "controller": controller_reference_label[interface["controllerRef"]],
707 "channel": interface_data["channel"],
708 "part": "unknown",
709 "link_status": "unknown",
710 "speed": {"current": "unknown", "maximum": "unknown", "supported": []},
711 "mtu": None,
712 "guid": None,
713 "lid": None,
714 "nqn": None,
715 "iqn": None,
716 "wwnn": None,
717 "wwpn": None,
718 "ipv4": None, # enabled, config_method, address, subnet, gateway
719 "ipv6": None} # for expansion if needed
720
721 # Determine storage target identifiers
722 controller_iqn = "unknown"
723 controller_nqn = "unknown"
724 for target in targets:
725 if target["nodeName"]["ioInterfaceType"] == "nvmeof":
726 controller_nqn = target["nodeName"]["nvmeNodeName"]
727 if target["nodeName"]["ioInterfaceType"] == "iscsi":
728 controller_iqn = target["nodeName"]["iscsiNodeName"]
729
730 # iSCSI IO interface
731 if interface_type == "iscsi":
732 interface_info.update({"ipv4": {"enabled": interface_data["ipv4Enabled"],
733 "config_method": interface_data["ipv4Data"]["ipv4AddressConfigMethod"],
734 "address": interface_data["ipv4Data"]["ipv4AddressData"]["ipv4Address"],
735 "subnet": interface_data["ipv4Data"]["ipv4AddressData"]["ipv4SubnetMask"],
736 "gateway": interface_data["ipv4Data"]["ipv4AddressData"]["ipv4GatewayAddress"]}})
737
738 # InfiniBand (iSER) protocol
739 if interface_data["interfaceData"]["type"] == "infiniband" and interface_data["interfaceData"]["infinibandData"]["isIser"]:
740 interface_info.update({"protocol": "ib_iser",
741 "iqn": controller_iqn})
742
743 # Get more details from hardware-inventory
744 for ib_port in hardware_inventory_facts["ibPorts"]:
745 if ib_port["channelPortRef"] == interface_info["channel_port_reference"]:
746 interface_info.update({"link_status": ib_port["linkState"],
747 "guid": ib_port["globalIdentifier"],
748 "lid": ib_port["localIdentifier"],
749 "speed": {"current": strip_interface_speed(ib_port["currentSpeed"]),
750 "maximum": strip_interface_speed(ib_port["supportedSpeed"])[-1],
751 "supported": strip_interface_speed(ib_port["supportedSpeed"])}})
752
753 # iSCSI protocol
754 elif interface_data["interfaceData"]["type"] == "ethernet":
755 ethernet_data = interface_data["interfaceData"]["ethernetData"]
756 interface_info.update({"protocol": "iscsi",
757 "iqn": controller_iqn})
758 interface_info.update({"part": "%s,%s" % (ethernet_data["partData"]["vendorName"], ethernet_data["partData"]["partNumber"]),
759 "link_status": ethernet_data["linkStatus"],
760 "mtu": ethernet_data["maximumFramePayloadSize"],
761 "speed": {"current": strip_interface_speed(ethernet_data["currentInterfaceSpeed"]),
762 "maximum": strip_interface_speed(ethernet_data["maximumInterfaceSpeed"]),
763 "supported": strip_interface_speed(ethernet_data["supportedInterfaceSpeeds"])}})
764
765 # Fibre Channel IO interface
766 elif interface_type == "fc":
767 interface_info.update({"wwnn": interface_data["nodeName"],
768 "wwpn": interface_data["addressId"],
769 "part": interface_data["part"],
770 "link_status": interface_data["linkStatus"],
771 "speed": {"current": strip_interface_speed(interface_data["currentInterfaceSpeed"]),
772 "maximum": strip_interface_speed(interface_data["maximumInterfaceSpeed"]),
773 "supported": "unknown"}})
774
775 # NVMe over fibre channel protocol
776 if (command_protocol_properties and command_protocol_properties[0]["commandProtocol"] == "nvme" and
777 command_protocol_properties[0]["nvmeProperties"]["commandSet"] == "nvmeof" and
778 command_protocol_properties[0]["nvmeProperties"]["nvmeofProperties"]["fcProperties"]):
779 interface_info.update({"protocol": "nvme_fc",
780 "nqn": controller_nqn})
781
782 # Fibre channel protocol
783 else:
784 interface_info.update({"protocol": "fc"})
785
786 # SAS IO interface
787 elif interface_type == "sas":
788 interface_info.update({"protocol": "sas",
789 "wwpn": interface_data["addressId"],
790 "part": interface_data["part"],
791 "speed": {"current": strip_interface_speed(interface_data["currentInterfaceSpeed"]),
792 "maximum": strip_interface_speed(interface_data["maximumInterfaceSpeed"]),
793 "supported": "unknown"}})
794
795 # Infiniband IO interface
796 elif interface_type == "ib":
797 interface_info.update({"link_status": interface_data["linkState"],
798 "speed": {"current": strip_interface_speed(interface_data["currentSpeed"]),
799 "maximum": strip_interface_speed(interface_data["supportedSpeed"])[-1],
800 "supported": strip_interface_speed(interface_data["supportedSpeed"])},
801 "mtu": interface_data["maximumTransmissionUnit"],
802 "guid": interface_data["globalIdentifier"],
803 "lid": interface_data["localIdentifier"]})
804
805 # Determine protocol (NVMe over Infiniband, InfiniBand iSER, InfiniBand SRP)
806 if interface_data["isNVMeSupported"]:
807 interface_info.update({"protocol": "nvme_ib",
808 "nqn": controller_nqn})
809 elif interface_data["isISERSupported"]:
810 interface_info.update({"protocol": "ib_iser",
811 "iqn": controller_iqn})
812 elif interface_data["isSRPSupported"]:
813 interface_info.update({"protocol": "ib_srp"})
814
815 # Determine command protocol information
816 if command_protocol_properties:
817 for command_protocol_property in command_protocol_properties:
818 if command_protocol_property["commandProtocol"] == "nvme":
819 if command_protocol_property["nvmeProperties"]["commandSet"] == "nvmeof":
820 ip_address_data = command_protocol_property["nvmeProperties"]["nvmeofProperties"]["ibProperties"]["ipAddressData"]
821 if ip_address_data["addressType"] == "ipv4":
822 interface_info.update({"ipv4": {"enabled": True,
823 "config_method": "configStatic",
824 "address": ip_address_data["ipv4Data"]["ipv4Address"],
825 "subnet": ip_address_data["ipv4Data"]["ipv4SubnetMask"],
826 "gateway": ip_address_data["ipv4Data"]["ipv4GatewayAddress"]}})
827
828 elif command_protocol_property["commandProtocol"] == "scsi":
829 if command_protocol_property["scsiProperties"]["scsiProtocolType"] == "iser":
830 ipv4_data = command_protocol_property["scsiProperties"]["iserProperties"]["ipv4Data"]
831 interface_info.update({"ipv4": {"enabled": True,
832 "config_method": ipv4_data["ipv4AddressConfigMethod"],
833 "address": ipv4_data["ipv4AddressData"]["ipv4Address"],
834 "subnet": ipv4_data["ipv4AddressData"]["ipv4SubnetMask"],
835 "gateway": ipv4_data["ipv4AddressData"]["ipv4GatewayAddress"]}})
836
837 # Ethernet IO interface
838 elif interface_type == "ethernet":
839 ethernet_data = interface_data["interfaceData"]["ethernetData"]
840 interface_info.update({"part": "%s,%s" % (ethernet_data["partData"]["vendorName"], ethernet_data["partData"]["partNumber"]),
841 "link_status": ethernet_data["linkStatus"],
842 "mtu": ethernet_data["maximumFramePayloadSize"],
843 "speed": {"current": strip_interface_speed(ethernet_data["currentInterfaceSpeed"]),
844 "maximum": strip_interface_speed(ethernet_data["maximumInterfaceSpeed"]),
845 "supported": strip_interface_speed(ethernet_data["supportedInterfaceSpeeds"])}})
846
847 # Determine command protocol information
848 if command_protocol_properties:
849 for command_protocol_property in command_protocol_properties:
850 if command_protocol_property["commandProtocol"] == "nvme":
851 if command_protocol_property["nvmeProperties"]["commandSet"] == "nvmeof":
852
853 nvmeof_properties = command_protocol_property["nvmeProperties"]["nvmeofProperties"]
854 if nvmeof_properties["provider"] == "providerRocev2":
855 ipv4_data = nvmeof_properties["roceV2Properties"]["ipv4Data"]
856 interface_info.update({"protocol": "nvme_roce",
857 "nqn": controller_nqn})
858 interface_info.update({"ipv4": {"enabled": nvmeof_properties["roceV2Properties"]["ipv4Enabled"],
859 "config_method": ipv4_data["ipv4AddressConfigMethod"],
860 "address": ipv4_data["ipv4AddressData"]["ipv4Address"],
861 "subnet": ipv4_data["ipv4AddressData"]["ipv4SubnetMask"],
862 "gateway": ipv4_data["ipv4AddressData"]["ipv4GatewayAddress"]}})
863
864 facts['netapp_hostside_io_interfaces'].append(interface_info)
865
866 # Gather information from controller->hostInterfaces if available (This is a deprecated data structure. Prefer information from ioInterface.
867 for controller in array_facts['controller']:
868 if "hostInterfaces" in controller.keys():
869 for interface in controller['hostInterfaces']:
870
871 # Ignore any issue with this data structure since its a deprecated data structure.
872 try:
873 interface_type = interface["interfaceType"]
874 interface_data = interface["fibre" if interface_type == "fc" else interface_type]
875
876 # Build generic information for each interface entry
877 interface_info = {"protocol": "unknown",
878 "interface_reference": interface_data["interfaceRef"],
879 "controller_reference": controller["controllerRef"],
880 "channel_port_reference": interface_data["channelPortRef"] if "channelPortRef" in interface_data else "",
881 "controller": controller_reference_label[controller["controllerRef"]],
882 "channel": interface_data["channel"],
883 "part": "unknown",
884 "link_status": "unknown",
885 "speed": {"current": "unknown", "maximum": "unknown", "supported": []},
886 "mtu": None,
887 "guid": None,
888 "lid": None,
889 "nqn": None,
890 "iqn": None,
891 "wwnn": None,
892 "wwpn": None,
893 "ipv4": None, # enabled, config_method, address, subnet, gateway
894 "ipv6": None} # for expansion if needed
895
896 # Add target information
897 for target in targets:
898 if target["nodeName"]["ioInterfaceType"] == "nvmeof":
899 interface_info.update({"nqn": target["nodeName"]["nvmeNodeName"]})
900 if target["nodeName"]["ioInterfaceType"] == "iscsi":
901 interface_info.update({"iqn": target["nodeName"]["iscsiNodeName"]})
902
903 # iSCSI IO interface
904 if interface_type == "iscsi":
905 interface_info.update({"ipv4": {"enabled": interface_data["ipv4Enabled"],
906 "config_method": interface_data["ipv4Data"]["ipv4AddressConfigMethod"],
907 "address": interface_data["ipv4Data"]["ipv4AddressData"]["ipv4Address"],
908 "subnet": interface_data["ipv4Data"]["ipv4AddressData"]["ipv4SubnetMask"],
909 "gateway": interface_data["ipv4Data"]["ipv4AddressData"]["ipv4GatewayAddress"]}})
910 # InfiniBand (iSER) protocol
911 if interface_data["interfaceData"]["type"] == "infiniband" and interface_data["interfaceData"]["infinibandData"]["isIser"]:
912 interface_info.update({"protocol": "ib_iser"})
913
914 # Get more details from hardware-inventory
915 for ib_port in hardware_inventory_facts["ibPorts"]:
916 if ib_port["channelPortRef"] == interface_info["channel_port_reference"]:
917 interface_info.update({"link_status": ib_port["linkState"],
918 "guid": ib_port["globalIdentifier"],
919 "lid": ib_port["localIdentifier"],
920 "speed": {"current": strip_interface_speed(ib_port["currentSpeed"]),
921 "maximum": strip_interface_speed(ib_port["supportedSpeed"])[-1],
922 "supported": strip_interface_speed(ib_port["supportedSpeed"])}})
923 # iSCSI protocol
924 elif interface_data["interfaceData"]["type"] == "ethernet":
925 ethernet_data = interface_data["interfaceData"]["ethernetData"]
926 interface_info.update({"protocol": "iscsi"})
927 interface_info.update({"part": "%s,%s" % (ethernet_data["partData"]["vendorName"], ethernet_data["partData"]["partNumber"]),
928 "link_status": ethernet_data["linkStatus"],
929 "mtu": ethernet_data["maximumFramePayloadSize"],
930 "speed": {"current": strip_interface_speed(ethernet_data["currentInterfaceSpeed"]),
931 "maximum": strip_interface_speed(ethernet_data["maximumInterfaceSpeed"]),
932 "supported": strip_interface_speed(ethernet_data["supportedInterfaceSpeeds"])}})
933 # Fibre Channel IO interface
934 elif interface_type == "fc":
935 interface_info.update({"protocol": "fc",
936 "wwnn": interface_data["nodeName"],
937 "wwpn": interface_data["addressId"],
938 "link_status": interface_data["linkStatus"],
939 "speed": {"current": strip_interface_speed(interface_data["currentInterfaceSpeed"]),
940 "maximum": strip_interface_speed(interface_data["maximumInterfaceSpeed"]),
941 "supported": "unknown"}})
942 # SAS IO interface
943 elif interface_type == "sas":
944 interface_info.update({"protocol": "sas",
945 "wwpn": interface_data["iocPort"]["portTypeData"]["portIdentifier"],
946 "part": interface_data["part"],
947 "speed": {"current": strip_interface_speed(interface_data["currentInterfaceSpeed"]),
948 "maximum": strip_interface_speed(interface_data["maximumInterfaceSpeed"]),
949 "supported": "unknown"}})
950 # Infiniband IO interface
951 elif interface_type == "ib":
952 interface_info.update({"link_status": interface_data["linkState"],
953 "speed": {"current": strip_interface_speed(interface_data["currentSpeed"]),
954 "maximum": strip_interface_speed(interface_data["supportedSpeed"])[-1],
955 "supported": strip_interface_speed(interface_data["supportedSpeed"])},
956 "mtu": interface_data["maximumTransmissionUnit"],
957 "guid": interface_data["globalIdentifier"],
958 "lid": interface_data["localIdentifier"]})
959
960 # Determine protocol (NVMe over Infiniband, InfiniBand iSER, InfiniBand SRP)
961 if interface_data["isNVMeSupported"]:
962 interface_info.update({"protocol": "nvme_ib"})
963 elif interface_data["isISERSupported"]:
964 interface_info.update({"protocol": "ib_iser"})
965 elif interface_data["isSRPSupported"]:
966 interface_info.update({"protocol": "ib_srp"})
967
968 # Ethernet IO interface
969 elif interface_type == "ethernet":
970 ethernet_data = interface_data["interfaceData"]["ethernetData"]
971 interface_info.update({"part": "%s,%s" % (ethernet_data["partData"]["vendorName"], ethernet_data["partData"]["partNumber"]),
972 "link_status": ethernet_data["linkStatus"],
973 "mtu": ethernet_data["maximumFramePayloadSize"],
974 "speed": {"current": strip_interface_speed(ethernet_data["currentInterfaceSpeed"]),
975 "maximum": strip_interface_speed(ethernet_data["maximumInterfaceSpeed"]),
976 "supported": strip_interface_speed(ethernet_data["supportedInterfaceSpeeds"])}})
977
978 # Only add interface if not already added (i.e. was part of ioInterface structure)
979 for existing_hostside_io_interfaces in facts['netapp_hostside_io_interfaces']:
980 if existing_hostside_io_interfaces["interface_reference"] == interface_info["interface_reference"]:
981 break
982 else:
983 facts['netapp_hostside_io_interfaces'].append(interface_info)
984 except Exception as error:
985 pass
986
987 # Create a dictionary of volume lists keyed by host names
988 facts['netapp_volumes_by_initiators'] = dict()
989 for mapping in array_facts['storagePoolBundle']['lunMapping']:
990 for host in facts['netapp_hosts']:
991 if mapping['mapRef'] == host['hosts_reference'] or mapping['mapRef'] == host['group_id']:
992 if host['name'] not in facts['netapp_volumes_by_initiators'].keys():
993 facts['netapp_volumes_by_initiators'].update({host['name']: []})
994
995 # Determine host io interface protocols
996 host_types = [port['type'] for port in host['ports']]
997 hostside_io_interface_protocols = []
998 host_port_protocols = []
999 host_port_information = {}
1000 for interface in facts['netapp_hostside_io_interfaces']:
1001 hostside_io_interface_protocols.append(interface["protocol"])
1002 for host_type in host_types:
1003 if host_type == "iscsi" and interface["protocol"] in ["iscsi", "ib_iser"]:
1004 host_port_protocols.append(interface["protocol"])
1005 if interface["protocol"] in host_port_information:
1006 # Skip duplicate entries into host_port_information
1007 for host_port_info in host_port_information[interface["protocol"]]:
1008 if interface["interface_reference"] == host_port_info["interface_reference"]:
1009 break
1010 else:
1011 host_port_information[interface["protocol"]].append(interface)
1012 else:
1013 host_port_information.update({interface["protocol"]: [interface]})
1014
1015 elif host_type == "fc" and interface["protocol"] in ["fc"]:
1016 host_port_protocols.append(interface["protocol"])
1017 if interface["protocol"] in host_port_information:
1018 # Skip duplicate entries into host_port_information
1019 for host_port_info in host_port_information[interface["protocol"]]:
1020 if interface["interface_reference"] == host_port_info["interface_reference"]:
1021 break
1022 else:
1023 host_port_information[interface["protocol"]].append(interface)
1024 else:
1025 host_port_information.update({interface["protocol"]: [interface]})
1026
1027 elif host_type == "sas" and interface["protocol"] in ["sas"]:
1028 host_port_protocols.append(interface["protocol"])
1029 if interface["protocol"] in host_port_information:
1030 # Skip duplicate entries into host_port_information
1031 for host_port_info in host_port_information[interface["protocol"]]:
1032 if interface["interface_reference"] == host_port_info["interface_reference"]:
1033 break
1034 else:
1035 host_port_information[interface["protocol"]].append(interface)
1036 else:
1037 host_port_information.update({interface["protocol"]: [interface]})
1038
1039 elif host_type == "ib" and interface["protocol"] in ["ib_iser", "ib_srp"]:
1040 host_port_protocols.append(interface["protocol"])
1041 if interface["protocol"] in host_port_information:
1042 # Skip duplicate entries into host_port_information
1043 for host_port_info in host_port_information[interface["protocol"]]:
1044 if interface["interface_reference"] == host_port_info["interface_reference"]:
1045 break
1046 else:
1047 host_port_information[interface["protocol"]].append(interface)
1048 else:
1049 host_port_information.update({interface["protocol"]: [interface]})
1050
1051 elif host_type == "nvmeof" and interface["protocol"] in ["nvme_ib", "nvme_fc", "nvme_roce"]:
1052 host_port_protocols.append(interface["protocol"])
1053 if interface["protocol"] in host_port_information:
1054 # Skip duplicate entries into host_port_information
1055 for host_port_info in host_port_information[interface["protocol"]]:
1056 if interface["interface_reference"] == host_port_info["interface_reference"]:
1057 break
1058 else:
1059 host_port_information[interface["protocol"]].append(interface)
1060 else:
1061 host_port_information.update({interface["protocol"]: [interface]})
1062
1063 for volume in all_volumes:
1064 storage_pool = [pool["name"] for pool in facts['netapp_storage_pools'] if pool["id"] == volume["volumeGroupRef"]][0]
1065
1066 if mapping['id'] in [volume_mapping['id'] for volume_mapping in volume['listOfMappings']]:
1067
1068 # Determine workload name if there is one
1069 workload_name = ""
1070 metadata = dict()
1071 for volume_tag in volume['metadata']:
1072 if volume_tag['key'] == 'workloadId':
1073 for workload_tag in facts['netapp_workload_tags']:
1074 if volume_tag['value'] == workload_tag['id']:
1075 workload_name = workload_tag['name']
1076 metadata = dict((entry['key'], entry['value'])
1077 for entry in workload_tag['attributes']
1078 if entry['key'] != 'profileId')
1079
1080 # Get volume specific metadata tags
1081 volume_metadata_raw = dict()
1082 volume_metadata = dict()
1083 for entry in volume['metadata']:
1084 volume_metadata_raw.update({entry["key"]: entry["value"]})
1085
1086 for sorted_key in sorted(volume_metadata_raw.keys()):
1087 if re.match(".*~[0-9]$", sorted_key):
1088 key = re.sub("~[0-9]$", "", sorted_key)
1089 if key in volume_metadata:
1090 volume_metadata[key] = volume_metadata[key] + volume_metadata_raw[sorted_key]
1091 else:
1092 volume_metadata.update({key: volume_metadata_raw[sorted_key]})
1093 else:
1094 volume_metadata.update({sorted_key: volume_metadata_raw[sorted_key]})
1095
1096 # Determine drive count
1097 stripe_count = volume['dataDriveCount']
1098
1099 volume_info = {"type": volume['objectType'],
1100 "name": volume['name'],
1101 "storage_pool": storage_pool,
1102 "host_types": set(host_types),
1103 "host_port_information": host_port_information,
1104 "host_port_protocols": set(host_port_protocols),
1105 "hostside_io_interface_protocols": set(hostside_io_interface_protocols),
1106 "id": volume['id'],
1107 "wwn": volume['wwn'],
1108 "eui": volume['extendedUniqueIdentifier'],
1109 "workload_name": workload_name,
1110 "workload_metadata": metadata,
1111 "meta_data": metadata,
1112 "volume_metadata": volume_metadata,
1113 "raid_level": volume['raidLevel'],
1114 "segment_size_kb": int(volume['segmentSize'] / 1024),
1115 "stripe_count": stripe_count}
1116 facts['netapp_volumes_by_initiators'][host['name']].append(volume_info)
1117
1118 # Use the base volume to populate related details for snapshot volumes.
1119 for pit_view_volume in array_facts["highLevelVolBundle"]["pitView"]:
1120 if volume["id"] == pit_view_volume["baseVol"]:
1121 pit_view_volume_info = volume_info.copy()
1122 pit_view_volume_info.update({"type": pit_view_volume["objectType"],
1123 "name": pit_view_volume['name'],
1124 "id": pit_view_volume['id'],
1125 "wwn": pit_view_volume['wwn'],
1126 "eui": pit_view_volume['extendedUniqueIdentifier']})
1127 facts['netapp_volumes_by_initiators'][host['name']].append(pit_view_volume_info)
1128
1129 features = list(feature for feature in array_facts['sa']['capabilities'])
1130 features.extend([feature['capability'] for feature in array_facts['sa']['premiumFeatures']
1131 if feature['isEnabled']])
1132 features = list(set(features)) # ensure unique
1133 features.sort()
1134 facts['netapp_enabled_features'] = features
1135
1136 return facts
1137
1138 def get_facts(self):
1139 """Get the embedded or web services proxy information."""
1140 facts = self.get_array_facts()
1141
1142 facts_from_proxy = not self.is_embedded()
1143 facts.update({"facts_from_proxy": facts_from_proxy})
1144
1145 self.module.exit_json(msg="Gathered facts for storage array. Array ID: [%s]." % self.ssid,
1146 storage_array_facts=facts)
1147
1148
1149 def strip_interface_speed(speed):
1150 """Converts symbol interface speeds to a more common notation. Example: 'speed10gig' -> '10g'"""
1151 if isinstance(speed, list):
1152 result = [re.match(r"speed[0-9]{1,3}[gm]", sp) for sp in speed]
1153 result = [sp.group().replace("speed", "") if result else "unknown" for sp in result if sp]
1154 result = ["auto" if re.match(r"auto", sp) else sp for sp in result]
1155 else:
1156 result = re.match(r"speed[0-9]{1,3}[gm]", speed)
1157 result = result.group().replace("speed", "") if result else "unknown"
1158 result = "auto" if re.match(r"auto", result.lower()) else result
1159 return result
1160
1161
1162 def main():
1163 facts = Facts()
1164 facts.get_facts()
1165
1166
1167 if __name__ == "__main__":
1168 main()