| 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 |
|
| 6 |
from __future__ import absolute_import, division, print_function |
| 7 |
__metaclass__ = type |
| 8 |
|
| 9 |
|
| 10 |
ANSIBLE_METADATA = {'metadata_version': '1.1', |
| 11 |
'status': ['deprecated'], |
| 12 |
'supported_by': 'community'} |
| 13 |
|
| 14 |
DOCUMENTATION = ''' |
| 15 |
module: netapp_e_facts |
| 16 |
short_description: NetApp E-Series retrieve facts about NetApp E-Series storage arrays |
| 17 |
description: |
| 18 |
- The netapp_e_facts module returns a collection of facts regarding NetApp E-Series storage arrays. |
| 19 |
version_added: '2.2.0' |
| 20 |
author: |
| 21 |
- Kevin Hulquest (@hulquest) |
| 22 |
- Nathan Swartz (@swartzn) |
| 23 |
- Vu Tran (@VuTran007) |
| 24 |
extends_documentation_fragment: |
| 25 |
- netapp_eseries.santricity.santricity.netapp.eseries |
| 26 |
''' |
| 27 |
|
| 28 |
EXAMPLES = """ |
| 29 |
--- |
| 30 |
- name: Get array facts |
| 31 |
netapp_e_facts: |
| 32 |
ssid: "1" |
| 33 |
api_url: "https://192.168.1.100:8443/devmgr/v2" |
| 34 |
api_username: "admin" |
| 35 |
api_password: "adminpass" |
| 36 |
validate_certs: true |
| 37 |
""" |
| 38 |
|
| 39 |
RETURN = """ |
| 40 |
msg: |
| 41 |
description: Success message |
| 42 |
returned: on success |
| 43 |
type: str |
| 44 |
sample: |
| 45 |
- Gathered facts for storage array. Array ID [1]. |
| 46 |
- Gathered facts for web services proxy. |
| 47 |
storage_array_facts: |
| 48 |
description: provides details about the array, controllers, management interfaces, hostside interfaces, |
| 49 |
driveside interfaces, disks, storage pools, volumes, snapshots, and features. |
| 50 |
returned: on successful inquiry from from embedded web services rest api |
| 51 |
type: complex |
| 52 |
contains: |
| 53 |
netapp_controllers: |
| 54 |
description: storage array controller list that contains basic controller identification and status |
| 55 |
type: list |
| 56 |
sample: |
| 57 |
- [{"name": "A", "serial": "021632007299", "status": "optimal"}, |
| 58 |
{"name": "B", "serial": "021632007300", "status": "failed"}] |
| 59 |
netapp_disks: |
| 60 |
description: drive list that contains identification, type, and status information for each drive |
| 61 |
type: list |
| 62 |
sample: |
| 63 |
- [{"available": false, |
| 64 |
"firmware_version": "MS02", |
| 65 |
"id": "01000000500003960C8B67880000000000000000", |
| 66 |
"media_type": "ssd", |
| 67 |
"product_id": "PX02SMU080 ", |
| 68 |
"serial_number": "15R0A08LT2BA", |
| 69 |
"status": "optimal", |
| 70 |
"tray_ref": "0E00000000000000000000000000000000000000", |
| 71 |
"usable_bytes": "799629205504" }] |
| 72 |
netapp_driveside_interfaces: |
| 73 |
description: drive side interface list that contains identification, type, and speed for each interface |
| 74 |
type: list |
| 75 |
sample: |
| 76 |
- [{ "controller": "A", "interface_speed": "12g", "interface_type": "sas" }] |
| 77 |
- [{ "controller": "B", "interface_speed": "10g", "interface_type": "iscsi" }] |
| 78 |
netapp_enabled_features: |
| 79 |
description: specifies the enabled features on the storage array. |
| 80 |
returned: on success |
| 81 |
type: list |
| 82 |
sample: |
| 83 |
- [ "flashReadCache", "performanceTier", "protectionInformation", "secureVolume" ] |
| 84 |
netapp_host_groups: |
| 85 |
description: specifies the host groups on the storage arrays. |
| 86 |
returned: on success |
| 87 |
type: list |
| 88 |
sample: |
| 89 |
- [{ "id": "85000000600A098000A4B28D003610705C40B964", "name": "group1" }] |
| 90 |
netapp_hosts: |
| 91 |
description: specifies the hosts on the storage arrays. |
| 92 |
returned: on success |
| 93 |
type: list |
| 94 |
sample: |
| 95 |
- [{ "id": "8203800000000000000000000000000000000000", |
| 96 |
"name": "host1", |
| 97 |
"group_id": "85000000600A098000A4B28D003610705C40B964", |
| 98 |
"host_type_index": 28, |
| 99 |
"ports": [{ "type": "fc", "address": "1000FF7CFFFFFF01", "label": "FC_1" }, |
| 100 |
{ "type": "fc", "address": "1000FF7CFFFFFF00", "label": "FC_2" }]}] |
| 101 |
netapp_host_types: |
| 102 |
description: lists the available host types on the storage array. |
| 103 |
returned: on success |
| 104 |
type: list |
| 105 |
sample: |
| 106 |
- [{ "index": 0, "type": "FactoryDefault" }, |
| 107 |
{ "index": 1, "type": "W2KNETNCL"}, |
| 108 |
{ "index": 2, "type": "SOL" }, |
| 109 |
{ "index": 5, "type": "AVT_4M" }, |
| 110 |
{ "index": 6, "type": "LNX" }, |
| 111 |
{ "index": 7, "type": "LnxALUA" }, |
| 112 |
{ "index": 8, "type": "W2KNETCL" }, |
| 113 |
{ "index": 9, "type": "AIX MPIO" }, |
| 114 |
{ "index": 10, "type": "VmwTPGSALUA" }, |
| 115 |
{ "index": 15, "type": "HPXTPGS" }, |
| 116 |
{ "index": 17, "type": "SolTPGSALUA" }, |
| 117 |
{ "index": 18, "type": "SVC" }, |
| 118 |
{ "index": 22, "type": "MacTPGSALUA" }, |
| 119 |
{ "index": 23, "type": "WinTPGSALUA" }, |
| 120 |
{ "index": 24, "type": "LnxTPGSALUA" }, |
| 121 |
{ "index": 25, "type": "LnxTPGSALUA_PM" }, |
| 122 |
{ "index": 26, "type": "ONTAP_ALUA" }, |
| 123 |
{ "index": 27, "type": "LnxTPGSALUA_SF" }, |
| 124 |
{ "index": 28, "type": "LnxDHALUA" }, |
| 125 |
{ "index": 29, "type": "ATTOClusterAllOS" }] |
| 126 |
netapp_hostside_interfaces: |
| 127 |
description: host side interface list that contains identification, configuration, type, speed, and |
| 128 |
status information for each interface |
| 129 |
type: list |
| 130 |
sample: |
| 131 |
- [{"iscsi": |
| 132 |
[{ "controller": "A", |
| 133 |
"current_interface_speed": "10g", |
| 134 |
"ipv4_address": "10.10.10.1", |
| 135 |
"ipv4_enabled": true, |
| 136 |
"ipv4_gateway": "10.10.10.1", |
| 137 |
"ipv4_subnet_mask": "255.255.255.0", |
| 138 |
"ipv6_enabled": false, |
| 139 |
"iqn": "iqn.1996-03.com.netapp:2806.600a098000a81b6d0000000059d60c76", |
| 140 |
"link_status": "up", |
| 141 |
"mtu": 9000, |
| 142 |
"supported_interface_speeds": [ "10g" ] }]}] |
| 143 |
netapp_management_interfaces: |
| 144 |
description: management interface list that contains identification, configuration, and status for |
| 145 |
each interface |
| 146 |
type: list |
| 147 |
sample: |
| 148 |
- [{"alias": "ict-2800-A", |
| 149 |
"channel": 1, |
| 150 |
"controller": "A", |
| 151 |
"dns_config_method": "dhcp", |
| 152 |
"dns_servers": [], |
| 153 |
"ipv4_address": "10.1.1.1", |
| 154 |
"ipv4_address_config_method": "static", |
| 155 |
"ipv4_enabled": true, |
| 156 |
"ipv4_gateway": "10.113.1.1", |
| 157 |
"ipv4_subnet_mask": "255.255.255.0", |
| 158 |
"ipv6_enabled": false, |
| 159 |
"link_status": "up", |
| 160 |
"mac_address": "00A098A81B5D", |
| 161 |
"name": "wan0", |
| 162 |
"ntp_config_method": "disabled", |
| 163 |
"ntp_servers": [], |
| 164 |
"remote_ssh_access": false }] |
| 165 |
netapp_storage_array: |
| 166 |
description: provides storage array identification, firmware version, and available capabilities |
| 167 |
type: dict |
| 168 |
sample: |
| 169 |
- {"chassis_serial": "021540006043", |
| 170 |
"firmware": "08.40.00.01", |
| 171 |
"name": "ict-2800-11_40", |
| 172 |
"wwn": "600A098000A81B5D0000000059D60C76", |
| 173 |
"cacheBlockSizes": [4096, |
| 174 |
8192, |
| 175 |
16384, |
| 176 |
32768], |
| 177 |
"supportedSegSizes": [8192, |
| 178 |
16384, |
| 179 |
32768, |
| 180 |
65536, |
| 181 |
131072, |
| 182 |
262144, |
| 183 |
524288]} |
| 184 |
netapp_storage_pools: |
| 185 |
description: storage pool list that contains identification and capacity information for each pool |
| 186 |
type: list |
| 187 |
sample: |
| 188 |
- [{"available_capacity": "3490353782784", |
| 189 |
"id": "04000000600A098000A81B5D000002B45A953A61", |
| 190 |
"name": "Raid6", |
| 191 |
"total_capacity": "5399466745856", |
| 192 |
"used_capacity": "1909112963072" }] |
| 193 |
netapp_volumes: |
| 194 |
description: storage volume list that contains identification and capacity information for each volume |
| 195 |
type: list |
| 196 |
sample: |
| 197 |
- [{"capacity": "5368709120", |
| 198 |
"id": "02000000600A098000AAC0C3000002C45A952BAA", |
| 199 |
"is_thin_provisioned": false, |
| 200 |
"name": "5G", |
| 201 |
"parent_storage_pool_id": "04000000600A098000A81B5D000002B45A953A61" }] |
| 202 |
netapp_workload_tags: |
| 203 |
description: workload tag list |
| 204 |
type: list |
| 205 |
sample: |
| 206 |
- [{"id": "87e19568-43fb-4d8d-99ea-2811daaa2b38", |
| 207 |
"name": "ftp_server", |
| 208 |
"workloadAttributes": [{"key": "use", |
| 209 |
"value": "general"}]}] |
| 210 |
netapp_volumes_by_initiators: |
| 211 |
description: list of available volumes keyed by the mapped initiators. |
| 212 |
type: dict |
| 213 |
sample: |
| 214 |
- {"192_168_1_1": [{"id": "02000000600A098000A4B9D1000015FD5C8F7F9E", |
| 215 |
"meta_data": {"filetype": "xfs", "public": true}, |
| 216 |
"name": "some_volume", |
| 217 |
"workload_name": "test2_volumes", |
| 218 |
"wwn": "600A098000A4B9D1000015FD5C8F7F9E"}]} |
| 219 |
snapshot_images: |
| 220 |
description: snapshot image list that contains identification, capacity, and status information for each |
| 221 |
snapshot image |
| 222 |
type: list |
| 223 |
sample: |
| 224 |
- [{"active_cow": true, |
| 225 |
"creation_method": "user", |
| 226 |
"id": "34000000600A098000A81B5D00630A965B0535AC", |
| 227 |
"pit_capacity": "5368709120", |
| 228 |
"reposity_cap_utilization": "0", |
| 229 |
"rollback_source": false, |
| 230 |
"status": "optimal" }] |
| 231 |
""" |
| 232 |
|
| 233 |
from re import match |
| 234 |
from pprint import pformat |
| 235 |
from ansible_collections.netapp_eseries.santricity.plugins.module_utils.netapp import NetAppESeriesModule |
| 236 |
|
| 237 |
|
| 238 |
class Facts(NetAppESeriesModule): |
| 239 |
def __init__(self): |
| 240 |
web_services_version = "02.00.0000.0000" |
| 241 |
super(Facts, self).__init__(ansible_options={}, |
| 242 |
web_services_version=web_services_version, |
| 243 |
supports_check_mode=True) |
| 244 |
|
| 245 |
def get_controllers(self): |
| 246 |
"""Retrieve a mapping of controller references to their labels.""" |
| 247 |
controllers = list() |
| 248 |
try: |
| 249 |
rc, controllers = self.request('storage-systems/%s/graph/xpath-filter?query=/controller/id' % self.ssid) |
| 250 |
except Exception as err: |
| 251 |
self.module.fail_json( |
| 252 |
msg="Failed to retrieve controller list! Array Id [%s]. Error [%s]." |
| 253 |
% (self.ssid, str(err))) |
| 254 |
|
| 255 |
controllers.sort() |
| 256 |
|
| 257 |
controllers_dict = {} |
| 258 |
i = ord('A') |
| 259 |
for controller in controllers: |
| 260 |
label = chr(i) |
| 261 |
controllers_dict[controller] = label |
| 262 |
i += 1 |
| 263 |
|
| 264 |
return controllers_dict |
| 265 |
|
| 266 |
def get_array_facts(self): |
| 267 |
"""Extract particular facts from the storage array graph""" |
| 268 |
facts = dict(facts_from_proxy=(not self.is_embedded()), ssid=self.ssid) |
| 269 |
controller_reference_label = self.get_controllers() |
| 270 |
array_facts = None |
| 271 |
|
| 272 |
# Get the storage array graph |
| 273 |
try: |
| 274 |
rc, array_facts = self.request("storage-systems/%s/graph" % self.ssid) |
| 275 |
except Exception as error: |
| 276 |
self.module.fail_json(msg="Failed to obtain facts from storage array with id [%s]. Error [%s]" % (self.ssid, str(error))) |
| 277 |
|
| 278 |
facts['netapp_storage_array'] = dict( |
| 279 |
name=array_facts['sa']['saData']['storageArrayLabel'], |
| 280 |
chassis_serial=array_facts['sa']['saData']['chassisSerialNumber'], |
| 281 |
firmware=array_facts['sa']['saData']['fwVersion'], |
| 282 |
wwn=array_facts['sa']['saData']['saId']['worldWideName'], |
| 283 |
segment_sizes=array_facts['sa']['featureParameters']['supportedSegSizes'], |
| 284 |
cache_block_sizes=array_facts['sa']['featureParameters']['cacheBlockSizes']) |
| 285 |
|
| 286 |
facts['netapp_controllers'] = [ |
| 287 |
dict( |
| 288 |
name=controller_reference_label[controller['controllerRef']], |
| 289 |
serial=controller['serialNumber'].strip(), |
| 290 |
status=controller['status'], |
| 291 |
) for controller in array_facts['controller']] |
| 292 |
|
| 293 |
facts['netapp_host_groups'] = [ |
| 294 |
dict( |
| 295 |
id=group['id'], |
| 296 |
name=group['name'] |
| 297 |
) for group in array_facts['storagePoolBundle']['cluster']] |
| 298 |
|
| 299 |
facts['netapp_hosts'] = [ |
| 300 |
dict( |
| 301 |
group_id=host['clusterRef'], |
| 302 |
hosts_reference=host['hostRef'], |
| 303 |
id=host['id'], |
| 304 |
name=host['name'], |
| 305 |
host_type_index=host['hostTypeIndex'], |
| 306 |
posts=host['hostSidePorts'] |
| 307 |
) for host in array_facts['storagePoolBundle']['host']] |
| 308 |
|
| 309 |
facts['netapp_host_types'] = [ |
| 310 |
dict( |
| 311 |
type=host_type['hostType'], |
| 312 |
index=host_type['index'] |
| 313 |
) for host_type in array_facts['sa']['hostSpecificVals'] |
| 314 |
if 'hostType' in host_type.keys() and host_type['hostType'] |
| 315 |
# This conditional ignores zero-length strings which indicates that the associated host-specific NVSRAM region has been cleared. |
| 316 |
] |
| 317 |
facts['snapshot_images'] = [ |
| 318 |
dict( |
| 319 |
id=snapshot['id'], |
| 320 |
status=snapshot['status'], |
| 321 |
pit_capacity=snapshot['pitCapacity'], |
| 322 |
creation_method=snapshot['creationMethod'], |
| 323 |
reposity_cap_utilization=snapshot['repositoryCapacityUtilization'], |
| 324 |
active_cow=snapshot['activeCOW'], |
| 325 |
rollback_source=snapshot['isRollbackSource'] |
| 326 |
) for snapshot in array_facts['highLevelVolBundle']['pit']] |
| 327 |
|
| 328 |
facts['netapp_disks'] = [ |
| 329 |
dict( |
| 330 |
id=disk['id'], |
| 331 |
available=disk['available'], |
| 332 |
media_type=disk['driveMediaType'], |
| 333 |
status=disk['status'], |
| 334 |
usable_bytes=disk['usableCapacity'], |
| 335 |
tray_ref=disk['physicalLocation']['trayRef'], |
| 336 |
product_id=disk['productID'], |
| 337 |
firmware_version=disk['firmwareVersion'], |
| 338 |
serial_number=disk['serialNumber'].lstrip() |
| 339 |
) for disk in array_facts['drive']] |
| 340 |
|
| 341 |
facts['netapp_management_interfaces'] = [ |
| 342 |
dict(controller=controller_reference_label[controller['controllerRef']], |
| 343 |
name=iface['ethernet']['interfaceName'], |
| 344 |
alias=iface['ethernet']['alias'], |
| 345 |
channel=iface['ethernet']['channel'], |
| 346 |
mac_address=iface['ethernet']['macAddr'], |
| 347 |
remote_ssh_access=iface['ethernet']['rloginEnabled'], |
| 348 |
link_status=iface['ethernet']['linkStatus'], |
| 349 |
ipv4_enabled=iface['ethernet']['ipv4Enabled'], |
| 350 |
ipv4_address_config_method=iface['ethernet']['ipv4AddressConfigMethod'].lower().replace("config", ""), |
| 351 |
ipv4_address=iface['ethernet']['ipv4Address'], |
| 352 |
ipv4_subnet_mask=iface['ethernet']['ipv4SubnetMask'], |
| 353 |
ipv4_gateway=iface['ethernet']['ipv4GatewayAddress'], |
| 354 |
ipv6_enabled=iface['ethernet']['ipv6Enabled'], |
| 355 |
dns_config_method=iface['ethernet']['dnsProperties']['acquisitionProperties']['dnsAcquisitionType'], |
| 356 |
dns_servers=(iface['ethernet']['dnsProperties']['acquisitionProperties']['dnsServers'] |
| 357 |
if iface['ethernet']['dnsProperties']['acquisitionProperties']['dnsServers'] else []), |
| 358 |
ntp_config_method=iface['ethernet']['ntpProperties']['acquisitionProperties']['ntpAcquisitionType'], |
| 359 |
ntp_servers=(iface['ethernet']['ntpProperties']['acquisitionProperties']['ntpServers'] |
| 360 |
if iface['ethernet']['ntpProperties']['acquisitionProperties']['ntpServers'] else []) |
| 361 |
) for controller in array_facts['controller'] for iface in controller['netInterfaces']] |
| 362 |
|
| 363 |
facts['netapp_hostside_interfaces'] = [ |
| 364 |
dict( |
| 365 |
fc=[dict(controller=controller_reference_label[controller['controllerRef']], |
| 366 |
channel=iface['fibre']['channel'], |
| 367 |
link_status=iface['fibre']['linkStatus'], |
| 368 |
current_interface_speed=strip_interface_speed(iface['fibre']['currentInterfaceSpeed']), |
| 369 |
maximum_interface_speed=strip_interface_speed(iface['fibre']['maximumInterfaceSpeed'])) |
| 370 |
for controller in array_facts['controller'] |
| 371 |
for iface in controller['hostInterfaces'] |
| 372 |
if iface['interfaceType'] == 'fc'], |
| 373 |
ib=[dict(controller=controller_reference_label[controller['controllerRef']], |
| 374 |
channel=iface['ib']['channel'], |
| 375 |
link_status=iface['ib']['linkState'], |
| 376 |
mtu=iface['ib']['maximumTransmissionUnit'], |
| 377 |
current_interface_speed=strip_interface_speed(iface['ib']['currentSpeed']), |
| 378 |
maximum_interface_speed=strip_interface_speed(iface['ib']['supportedSpeed'])) |
| 379 |
for controller in array_facts['controller'] |
| 380 |
for iface in controller['hostInterfaces'] |
| 381 |
if iface['interfaceType'] == 'ib'], |
| 382 |
iscsi=[dict(controller=controller_reference_label[controller['controllerRef']], |
| 383 |
iqn=iface['iscsi']['iqn'], |
| 384 |
link_status=iface['iscsi']['interfaceData']['ethernetData']['linkStatus'], |
| 385 |
ipv4_enabled=iface['iscsi']['ipv4Enabled'], |
| 386 |
ipv4_address=iface['iscsi']['ipv4Data']['ipv4AddressData']['ipv4Address'], |
| 387 |
ipv4_subnet_mask=iface['iscsi']['ipv4Data']['ipv4AddressData']['ipv4SubnetMask'], |
| 388 |
ipv4_gateway=iface['iscsi']['ipv4Data']['ipv4AddressData']['ipv4GatewayAddress'], |
| 389 |
ipv6_enabled=iface['iscsi']['ipv6Enabled'], |
| 390 |
mtu=iface['iscsi']['interfaceData']['ethernetData']['maximumFramePayloadSize'], |
| 391 |
current_interface_speed=strip_interface_speed(iface['iscsi']['interfaceData'] |
| 392 |
['ethernetData']['currentInterfaceSpeed']), |
| 393 |
supported_interface_speeds=strip_interface_speed(iface['iscsi']['interfaceData'] |
| 394 |
['ethernetData'] |
| 395 |
['supportedInterfaceSpeeds'])) |
| 396 |
for controller in array_facts['controller'] |
| 397 |
for iface in controller['hostInterfaces'] |
| 398 |
if iface['interfaceType'] == 'iscsi'], |
| 399 |
sas=[dict(controller=controller_reference_label[controller['controllerRef']], |
| 400 |
channel=iface['sas']['channel'], |
| 401 |
current_interface_speed=strip_interface_speed(iface['sas']['currentInterfaceSpeed']), |
| 402 |
maximum_interface_speed=strip_interface_speed(iface['sas']['maximumInterfaceSpeed']), |
| 403 |
link_status=iface['sas']['iocPort']['state']) |
| 404 |
for controller in array_facts['controller'] |
| 405 |
for iface in controller['hostInterfaces'] |
| 406 |
if iface['interfaceType'] == 'sas'])] |
| 407 |
|
| 408 |
facts['netapp_driveside_interfaces'] = [ |
| 409 |
dict( |
| 410 |
controller=controller_reference_label[controller['controllerRef']], |
| 411 |
interface_type=interface['interfaceType'], |
| 412 |
interface_speed=strip_interface_speed( |
| 413 |
interface[interface['interfaceType']]['maximumInterfaceSpeed'] |
| 414 |
if (interface['interfaceType'] == 'sata' or |
| 415 |
interface['interfaceType'] == 'sas' or |
| 416 |
interface['interfaceType'] == 'fibre') |
| 417 |
else ( |
| 418 |
interface[interface['interfaceType']]['currentSpeed'] |
| 419 |
if interface['interfaceType'] == 'ib' |
| 420 |
else ( |
| 421 |
interface[interface['interfaceType']]['interfaceData']['maximumInterfaceSpeed'] |
| 422 |
if interface['interfaceType'] == 'iscsi' else 'unknown' |
| 423 |
))), |
| 424 |
) |
| 425 |
for controller in array_facts['controller'] |
| 426 |
for interface in controller['driveInterfaces']] |
| 427 |
|
| 428 |
facts['netapp_storage_pools'] = [ |
| 429 |
dict( |
| 430 |
id=storage_pool['id'], |
| 431 |
name=storage_pool['name'], |
| 432 |
available_capacity=storage_pool['freeSpace'], |
| 433 |
total_capacity=storage_pool['totalRaidedSpace'], |
| 434 |
used_capacity=storage_pool['usedSpace'] |
| 435 |
) for storage_pool in array_facts['volumeGroup']] |
| 436 |
|
| 437 |
all_volumes = list(array_facts['volume']) |
| 438 |
|
| 439 |
facts['netapp_volumes'] = [ |
| 440 |
dict( |
| 441 |
id=v['id'], |
| 442 |
name=v['name'], |
| 443 |
parent_storage_pool_id=v['volumeGroupRef'], |
| 444 |
capacity=v['capacity'], |
| 445 |
is_thin_provisioned=v['thinProvisioned'], |
| 446 |
workload=v['metadata'], |
| 447 |
) for v in all_volumes] |
| 448 |
|
| 449 |
workload_tags = None |
| 450 |
try: |
| 451 |
rc, workload_tags = self.request("storage-systems/%s/workloads" % self.ssid) |
| 452 |
except Exception as error: |
| 453 |
self.module.fail_json(msg="Failed to retrieve workload tags. Array [%s]." % self.ssid) |
| 454 |
|
| 455 |
facts['netapp_workload_tags'] = [ |
| 456 |
dict( |
| 457 |
id=workload_tag['id'], |
| 458 |
name=workload_tag['name'], |
| 459 |
attributes=workload_tag['workloadAttributes'] |
| 460 |
) for workload_tag in workload_tags] |
| 461 |
|
| 462 |
# Create a dictionary of volume lists keyed by host names |
| 463 |
facts['netapp_volumes_by_initiators'] = dict() |
| 464 |
for mapping in array_facts['storagePoolBundle']['lunMapping']: |
| 465 |
for host in facts['netapp_hosts']: |
| 466 |
if mapping['mapRef'] == host['hosts_reference'] or mapping['mapRef'] == host['group_id']: |
| 467 |
if host['name'] not in facts['netapp_volumes_by_initiators'].keys(): |
| 468 |
facts['netapp_volumes_by_initiators'].update({host['name']: []}) |
| 469 |
|
| 470 |
for volume in all_volumes: |
| 471 |
if mapping['id'] in [volume_mapping['id'] for volume_mapping in volume['listOfMappings']]: |
| 472 |
|
| 473 |
# Determine workload name if there is one |
| 474 |
workload_name = "" |
| 475 |
metadata = dict() |
| 476 |
for volume_tag in volume['metadata']: |
| 477 |
if volume_tag['key'] == 'workloadId': |
| 478 |
for workload_tag in facts['netapp_workload_tags']: |
| 479 |
if volume_tag['value'] == workload_tag['id']: |
| 480 |
workload_name = workload_tag['name'] |
| 481 |
metadata = dict((entry['key'], entry['value']) |
| 482 |
for entry in workload_tag['attributes'] |
| 483 |
if entry['key'] != 'profileId') |
| 484 |
|
| 485 |
facts['netapp_volumes_by_initiators'][host['name']].append( |
| 486 |
dict(name=volume['name'], |
| 487 |
id=volume['id'], |
| 488 |
wwn=volume['wwn'], |
| 489 |
workload_name=workload_name, |
| 490 |
meta_data=metadata)) |
| 491 |
|
| 492 |
features = list(feature for feature in array_facts['sa']['capabilities']) |
| 493 |
features.extend(feature['capability'] for feature in array_facts['sa']['premiumFeatures'] |
| 494 |
if feature['isEnabled']) |
| 495 |
features = list(set(features)) # ensure unique |
| 496 |
features.sort() |
| 497 |
facts['netapp_enabled_features'] = features |
| 498 |
|
| 499 |
return facts |
| 500 |
|
| 501 |
def get_facts(self): |
| 502 |
"""Get the embedded or web services proxy information.""" |
| 503 |
facts = self.get_array_facts() |
| 504 |
|
| 505 |
self.module.log("isEmbedded: %s" % self.is_embedded()) |
| 506 |
self.module.log(pformat(facts)) |
| 507 |
|
| 508 |
self.module.exit_json(msg="Gathered facts for storage array. Array ID: [%s]." % self.ssid, |
| 509 |
storage_array_facts=facts) |
| 510 |
|
| 511 |
|
| 512 |
def strip_interface_speed(speed): |
| 513 |
"""Converts symbol interface speeds to a more common notation. Example: 'speed10gig' -> '10g'""" |
| 514 |
if isinstance(speed, list): |
| 515 |
result = [match(r"speed[0-9]{1,3}[gm]", sp) for sp in speed] |
| 516 |
result = [sp.group().replace("speed", "") if result else "unknown" for sp in result if sp] |
| 517 |
result = ["auto" if match(r"auto", sp) else sp for sp in result] |
| 518 |
else: |
| 519 |
result = match(r"speed[0-9]{1,3}[gm]", speed) |
| 520 |
result = result.group().replace("speed", "") if result else "unknown" |
| 521 |
result = "auto" if match(r"auto", result.lower()) else result |
| 522 |
return result |
| 523 |
|
| 524 |
|
| 525 |
def main(): |
| 526 |
facts = Facts() |
| 527 |
facts.get_facts() |
| 528 |
|
| 529 |
|
| 530 |
if __name__ == "__main__": |
| 531 |
main() |