Debian Codegraph @

ansible_collections/netapp/ontap/plugins/modules/na_ontap_rest_info.py

raw
1 #!/usr/bin/python
2
3 # (c) 2020-2026, NetApp, Inc
4 # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
5
6 """ NetApp ONTAP Info using REST APIs """
7
8 from __future__ import absolute_import, division, print_function
9
10 __metaclass__ = type
11
12 DOCUMENTATION = '''
13 module: na_ontap_rest_info
14 author: NetApp Ansible Team (@carchi8py) <[email protected]>
15 extends_documentation_fragment:
16 - netapp.ontap.netapp.na_ontap_rest
17 short_description: NetApp ONTAP information gatherer using REST APIs
18 description:
19 - This module allows you to gather various information about ONTAP configuration using REST APIs
20 version_added: 20.5.0
21 notes:
22 - I(security_login_role_config_info) there is no REST equivalent.
23 - I(security_login_role_info) there is no REST equivalent.
24 - I(security_key_manager_key_info) there is no REST equivalent.
25 - I(vserver_motd_info) there is no REST equivalent.
26 - I(vserver_login_banner_info) there is no REST equivalent.
27 - I(vscan_connection_extended_stats_info) there is no REST equivalent.
28 - I(env_sensors_info) there is no REST equivalent.
29 - I(fcp_adapter_info) there is no REST equivalent.
30 - I(net_dev_discovery_info) there is no REST equivalent.
31 - I(net_failover_group_info) there is no REST equivalent.
32 - I(net_firewall_info) there is no REST equivalent.
33 - I(ntfs_dacl_info) there is no REST equivalent.
34 - I(ntfs_sd_info) there is no REST equivalent.
35 - I(role_info) there is not REST equivalent.
36 - I(subsys_health_info) there is not REST equivalent.
37 - I(volume_move_target_aggr_info) there is not REST equivalent.
38 - Supports AWS Lambda proxy functionality. See README for example usage.
39
40 options:
41 state:
42 type: str
43 description:
44 - deprecated as of 21.1.0.
45 - this option was ignored and continues to be ignored.
46 gather_subset:
47 type: list
48 elements: str
49 description:
50 - When supplied, this argument will restrict the information collected to a given subset.
51 - Either the REST API or the ZAPI info name can be given. Possible values for this argument include
52 - application/applications or application_info
53 - application/consistency-groups
54 - application/consistency-groups/metrics B(Requires the owning_resource to be set)
55 - application/consistency-groups/snapshots B(Requires the owning_resource to be set)
56 - application/templates or application_template_info
57 - cloud/targets or cloud_targets_info
58 - cluster
59 - cluster/chassis or cluster_chassis_info
60 - cluster/counter/tables
61 - cluster/firmware/history
62 - cluster/jobs or cluster_jobs_info
63 - cluster/licensing/capacity-pools
64 - cluster/licensing/license-managers
65 - cluster/licensing/licenses or license_info
66 - cluster/mediators
67 - cluster/metrics or cluster_metrics_info
68 - cluster/metrocluster or metrocluster_info
69 - cluster/metrocluster/diagnostics or cluster_metrocluster_diagnostics or metrocluster_check_info
70 - cluster/metrocluster/dr-groups
71 - cluster/metrocluster/interconnects
72 - cluster/metrocluster/nodes or metrocluster-node-get-iter
73 - cluster/metrocluster/operations
74 - cluster/metrocluster/svms
75 - cluster/nodes or cluster_node_info or sysconfig_info
76 - cluster/ntp/keys
77 - cluster/ntp/servers or ntp_server_info
78 - cluster/peers or cluster_peer_info
79 - cluster/schedules or cluster_schedules or job_schedule_cron_info
80 - cluster/sensors
81 - cluster/software or ontap_system_version or cluster_image_info
82 - cluster/software/download or cluster_software_download
83 - cluster/software/history or cluster_software_history
84 - cluster/software/packages or cluster_software_packages
85 - cluster/web
86 - name-services/cache/group-membership/settings
87 - name-services/cache/host/settings
88 - name-services/cache/netgroup/settings
89 - name-services/cache/setting
90 - name-services/cache/unix-group/settings
91 - name-services/dns or svm_dns_config_info or net_dns_info
92 - name-services/ldap or svm_ldap_config_info or ldap_client or ldap_config
93 - name-services/ldap-schemas
94 - name-services/local-hosts
95 - name-services/name-mappings or svm_name_mapping_config_info
96 - name-services/nis or svm_nis_config_info
97 - name-services/unix-groups
98 - name-services/unix-users
99 - network/ethernet/broadcast-domains or broadcast_domains_info or net_port_broadcast_domain_info
100 - network/ethernet/ports or network_ports_info or net_port_info
101 - network/ethernet/switch/ports
102 - network/ethernet/switches or cluster_switch_info
103 - network/fc/fabrics
104 - network/fc/interfaces
105 - network/fc/logins or san_fc_logins_info
106 - network/fc/ports
107 - network/fc/wwpn-aliases or san_fc_wppn-aliases or fcp_alias_info
108 - network/http-proxy
109 - network/ip/bgp/peer-groups
110 - network/ip/interfaces or ip_interfaces_info or net_interface_info
111 - network/ip/routes or ip_routes_info or net_routes_info
112 - network/ip/service-policies or ip_service_policies or net_interface_service_policy_info
113 - network/ip/subnets
114 - network/ipspaces or network_ipspaces_info or net_ipspaces_info
115 - private/support/alerts or sys_cluster_alerts
116 - private/cli/vserver/security/file-directory or file_directory_security
117 - protocols/active-directory
118 - protocols/audit
119 - protocols/cifs/connections
120 - protocols/cifs/domains
121 - protocols/cifs/group-policies
122 - protocols/cifs/home-directory/search-paths or cifs_home_directory_info
123 - protocols/cifs/local-groups
124 - protocols/cifs/local-users
125 - protocols/cifs/netbios
126 - protocols/cifs/services or cifs_services_info or cifs_options_info
127 - protocols/cifs/session/files
128 - protocols/cifs/sessions
129 - protocols/cifs/shadow-copies
130 - protocols/cifs/shadowcopy-sets
131 - protocols/cifs/shares or cifs_share_info
132 - protocols/cifs/users-and-groups/privileges
133 - protocols/cifs/unix-symlink-mapping
134 - protocols/fpolicy
135 - protocols/locks
136 - protocols/ndmp
137 - protocols/ndmp/nodes
138 - protocols/ndmp/sessions
139 - protocols/ndmp/svms
140 - protocols/nfs/connected-clients
141 - protocols/nfs/connected-client-maps
142 - protocols/nfs/connected-client-settings
143 - protocols/nfs/export-policies or export_policy_info
144 - protocols/nfs/export-policies/rules B(Requires the owning_resource to be set)
145 - protocols/nfs/kerberos/interfaces
146 - protocols/nfs/kerberos/realms or kerberos_realm_info
147 - protocols/nfs/services or vserver_nfs_info or nfs_info
148 - protocols/nvme/interfaces or nvme_interface_info
149 - protocols/nvme/services or nvme_info
150 - protocols/nvme/subsystems or nvme_subsystem_info
151 - protocols/nvme/subsystem-controllers
152 - protocols/nvme/subsystem-maps
153 - protocols/s3/buckets
154 - protocols/s3/services
155 - protocols/san/fcp/services or san_fcp_services or fcp_service_info
156 - protocols/san/igroups or nitiator_groups_info or igroup_info
157 - protocols/san/iscsi/credentials or san_iscsi_credentials
158 - protocols/san/iscsi/services or san_iscsi_services or iscsi_service_info
159 - protocols/san/iscsi/sessions
160 - protocols/san/lun-maps or san_lun_maps or lun_map_info
161 - protocols/san/portsets
162 - protocols/san/vvol-bindings
163 - protocols/vscan or vscan_status_info or vscan_info
164 - protocols/vscan/on-access-policies B(Requires the owning_resource to be set)
165 - protocols/vscan/on-demand-policies B(Requires the owning_resource to be set)
166 - protocols/vscan/scanner-pools B(Requires the owning_resource to be set)
167 - protocols/vscan/server-status or vscan_connection_status_all_info
168 - security
169 - security/accounts or security_login_info or security_login_account_info
170 - security/anti-ransomware/suspects
171 - security/audit
172 - security/audit/destinations or cluster_log_forwarding_info
173 - security/audit/messages
174 - security/authentication/cluster/ad-proxy
175 - security/authentication/cluster/ldap
176 - security/authentication/cluster/nis
177 - security/authentication/cluster/saml-sp
178 - security/authentication/publickeys
179 - security/aws-kms
180 - security/azure-key-vaults
181 - security/certificates
182 - security/gcp-kms
183 - security/ipsec
184 - security/ipsec/ca-certificates
185 - security/ipsec/policies
186 - security/ipsec/security-associations
187 - security/key-manager-configs
188 - security/key-managers
189 - security/key-stores
190 - security/login/messages
191 - security/multi-admin-verify
192 - security/multi-admin-verify/approval-groups
193 - security/multi-admin-verify/requests
194 - security/multi-admin-verify/rules
195 - security/roles or security_login_rest_role_info
196 - security/ssh
197 - security/ssh/svms
198 - snapmirror/policies or snapmirror_policy_info
199 - snapmirror/relationships or snapmirror_info
200 - storage/aggregates or aggregate_info
201 - storage/bridges or storage_bridge_info
202 - storage/cluster
203 - storage/disks or disk_info
204 - storage/file/clone/split-loads
205 - storage/file/clone/split-status
206 - storage/file/clone/tokens
207 - storage/file/moves
208 - storage/flexcache/flexcaches or storage_flexcaches_info
209 - storage/flexcache/origins or storage_flexcaches_origin_info
210 - storage/luns or storage_luns_info or lun_info (if serial_number is present, serial_hex and naa_id are computed)
211 - storage/namespaces or storage_NVMe_namespaces or nvme_namespace_info
212 - storage/pools
213 - storage/ports or storage_ports_info
214 - storage/qos/policies or storage_qos_policies or qos_policy_info or qos_adaptive_policy_info
215 - storage/qos/workloads
216 - storage/qtrees or storage_qtrees_config or qtree_info
217 - storage/quota/reports or storage_quota_reports or quota_report_info
218 - storage/quota/rules or storage_quota_policy_rules
219 - storage/shelves or storage_shelves_config or shelf_info
220 - storage/snaplock/audit-logs
221 - storage/snaplock/compliance-clocks
222 - storage/snaplock/event-retention/operations
223 - storage/snaplock/event-retention/policies
224 - storage/snaplock/file-fingerprints
225 - storage/snaplock/litigations
226 - storage/snapshot-policies or storage_snapshot_policies or snapshot_policy_info
227 - storage/switches
228 - storage/tape-devices
229 - storage/volumes or volume_info
230 - storage/volumes/snapshots B(Requires the owning_resource to be set)
231 - storage/volume-efficiency-policies or sis_policy_info
232 - support/autosupport or autosupport_config_info
233 - support/autosupport/check or autosupport_check_info
234 - support/autosupport/messages or autosupport_messages_history
235 - support/auto-update
236 - support/auto-update/configurations
237 - support/auto-update/updates
238 - support/configuration-backup
239 - support/configuration-backup/backups
240 - support/coredump/coredumps
241 - support/ems or support_ems_config
242 - support/ems/destinations or event_notification_info or event_notification_destination_info
243 - support/ems/events or support_ems_events
244 - support/ems/filters or support_ems_filters
245 - support/ems/messages
246 - support/snmp
247 - support/snmp/traphosts
248 - support/snmp/users
249 - svm/migrations
250 - svm/peers or svm_peers_info or vserver_peer_info
251 - svm/peer-permissions or svm_peer-permissions_info
252 - svm/svms or vserver_info
253 - B(The following do not have direct Rest API equivalent)
254 - aggr_efficiency_info
255 - cifs_vserver_security_info
256 - clock_info
257 - cluster_identity_info
258 - net_vlan_info
259 - sis_info
260 - snapmirror_destination_info
261 - system_node_info
262 - volume_space_info
263 - Can specify a list of values to include a larger subset.
264 - REST APIs are supported with ONTAP 9.6 onwards.
265 default: "demo"
266 max_records:
267 type: int
268 description:
269 - Maximum number of records returned in a single call.
270 default: 1024
271 fields:
272 type: list
273 elements: str
274 description:
275 - Request specific fields from subset.
276 - Recommended - '<list of fields>' to return specified fields, only one subset will be allowed.
277 - Discouraged - '*' to return all the fields, one or more subsets are allowed. This option can be used for discovery, but is discouraged in production.
278 - Stongly discouraged - '**' to return all the fields, one or more subsets are allowed.
279 This option can put an extra load on the system and should not be used in production.
280 - Limited - '' to return default fields, generally the properties that uniquely identify the record (keys).
281 Other data is not returned by default and need to be explicitly called for using the field name or *.
282 - If the option is not present, return default fields for that API (see '' above).
283 version_added: '20.6.0'
284 parameters:
285 description:
286 - Allows for any rest option to be passed in
287 type: dict
288 version_added: '20.7.0'
289 use_python_keys:
290 description:
291 - If true, I(/) in the returned dictionary keys are translated to I(_).
292 - It makes it possible to use a . notation when processing the output.
293 - For instance I(ontap_info["svm/svms"]) can be accessed as I(ontap_info.svm_svms).
294 type: bool
295 default: false
296 version_added: '21.9.0'
297 owning_resource:
298 description:
299 - Some resources cannot be accessed directly. You need to select them based on the owner or parent. For instance, volume for a snapshot.
300 - The following subsets require an owning resource, and the following suboptions when uuid is not present.
301 - <application/consistency-groups/metrics> B(cg_name) is the consistency group name, B(svm_name) is the owning vserver name for the consistency group.
302 - <application/consistency-groups/snapshots> B(cg_name) is the consistency group name, B(svm_name) is the owning vserver name for the consistency group.
303 - <storage/volumes/snapshots> B(volume_name) is the volume name, B(svm_name) is the owning vserver name for the volume.
304 - <protocols/nfs/export-policies/rules> B(policy_name) is the name of the policy, B(svm_name) is the owning vserver name for the policy,
305 B(rule_index) is the rule index.
306 - <protocols/vscan/on-access-policies> B(svm_name) is the owning vserver name for the vscan.
307 - <protocols/vscan/on-demand-policies> B(svm_name) is the owning vserver name for the vscan.
308 - <protocols/vscan/scanner-pools> B(svm_name) is the owning vserver name for the vscan.
309 type: dict
310 version_added: '21.19.0'
311 ignore_api_errors:
312 description:
313 - List of substrings.
314 - If a substring is contained in an error message when fetching a subset, the module does not fail and the error is reported in the subset.
315 type: list
316 elements: str
317 version_added: '21.23.0'
318 hal_linking:
319 description:
320 - if false, HAL-encoded links are disabled in the REST calls.
321 default: true
322 type: bool
323 lambda_config:
324 description:
325 - Configuration parameters for AWS Lambda proxy functionality.
326 - These option and suboptions are only supported with REST.
327 type: dict
328 version_added: 23.5.0
329 suboptions:
330 function_name:
331 description:
332 - The name of the AWS Lambda function to invoke.
333 type: str
334 required: true
335 aws_region:
336 description:
337 - The name of the AWS region.
338 type: str
339 required: true
340 aws_profile:
341 description:
342 - The name of the AWS profile to use for authentication.
343 type: str
344 '''
345
346 EXAMPLES = '''
347 - name: Run ONTAP gather facts for vserver info
348 netapp.ontap.na_ontap_rest_info:
349 hostname: "{{ netapp_hostname }}"
350 username: "{{ netapp_username }}"
351 password: "{{ netapp_password }}"
352 validate_certs: false
353 gather_subset:
354 - svm/svms
355
356 - name: Run ONTAP gather facts for aggregate info and volume info
357 netapp.ontap.na_ontap_rest_info:
358 hostname: "{{ netapp_hostname }}"
359 username: "{{ netapp_username }}"
360 password: "{{ netapp_password }}"
361 validate_certs: false
362 gather_subset:
363 - storage/aggregates
364 - storage/volumes
365
366 - name: Run ONTAP gather facts for aggregate info and volume info with fields section
367 netapp.ontap.na_ontap_rest_info:
368 hostname: "{{ netapp_hostname }}"
369 username: "{{ netapp_username }}"
370 password: "{{ netapp_password }}"
371 fields:
372 - '*'
373 validate_certs: false
374 gather_subset:
375 - storage/aggregates
376 - storage/volumes
377
378 - name: Run ONTAP gather facts for aggregate info with specified fields
379 netapp.ontap.na_ontap_rest_info:
380 hostname: "{{ netapp_hostname }}"
381 username: "{{ netapp_username }}"
382 password: "{{ netapp_password }}"
383 fields:
384 - 'uuid'
385 - 'name'
386 - 'node'
387 validate_certs: false
388 gather_subset:
389 - storage/aggregates
390 parameters:
391 recommend:
392 true
393
394 - name: Get Snapshot info (owning_resource example)
395 netapp.ontap.na_ontap_rest_info:
396 hostname: "{{ netapp_hostname }}"
397 username: "{{ netapp_username }}"
398 password: "{{ netapp_password }}"
399 fields:
400 - '*'
401 validate_certs: false
402 gather_subset:
403 - storage/volumes/snapshots
404 owning_resource:
405 volume_name: volume_name
406 svm_name: svm_name
407
408 - name: Run ONTAP gather facts for volume info with query on name and state
409 netapp.ontap.na_ontap_rest_info:
410 hostname: "{{ netapp_hostname }}"
411 username: "{{ netapp_username }}"
412 password: "{{ netapp_password }}"
413 validate_certs: false
414 gather_subset:
415 - storage/volumes
416 parameters:
417 name: ansible*
418 state: online
419
420 - name: Run ONTAP gather fact to get DACLs
421 netapp.ontap.na_ontap_rest_info:
422 hostname: "{{ netapp_hostname }}"
423 username: "{{ netapp_username }}"
424 password: "{{ netapp_password }}"
425 validate_certs: false
426 gather_subset:
427 - file_directory_security
428 parameters:
429 vserver: svm1
430 path: /vol1/qtree1
431 use_python_keys: true
432
433 - name: Get ip network interface info
434 netapp.ontap.na_ontap_rest_info:
435 hostname: "{{ netapp_hostname }}"
436 username: "{{ netapp_username }}"
437 password: "{{ netapp_password }}"
438 validate_certs: false
439 gather_subset:
440 - ip_interfaces_info
441 parameters:
442 location.failover: home_node_only
443 location.node.name: ontap_cluster
444 service_policy.name: default-data-files
445
446 - name: Get aggregate info
447 netapp.ontap.na_ontap_rest_info:
448 hostname: "{{ netapp_hostname }}"
449 username: "{{ netapp_username }}"
450 password: "{{ netapp_password }}"
451 validate_certs: false
452 gather_subset:
453 - aggregate_info
454 parameters:
455 node.name: ontap_cluster
456 block_storage.primary.raid_type: raid_dp
457
458 # assuming module_defaults is used to set hostname, username, ...
459 - name: Run demo subset using custom vsadmin role
460 netapp.ontap.na_ontap_rest_info:
461 gather_subset:
462 - demo
463 force_ontap_version: 9.8
464 ignore_api_errors:
465 - 'not authorized for that command'
466
467 # reports: {"cluster/nodes": {"error": {"code": "6", "message": "not authorized for that command"}}
468 '''
469
470 import codecs
471 from ansible.module_utils.basic import AnsibleModule
472 from ansible.module_utils._text import to_text, to_bytes
473 import ansible_collections.netapp.ontap.plugins.module_utils.netapp as netapp_utils
474 from ansible_collections.netapp.ontap.plugins.module_utils.netapp_module import NetAppModule
475 from ansible_collections.netapp.ontap.plugins.module_utils.netapp import OntapRestAPI
476 from ansible_collections.netapp.ontap.plugins.module_utils import rest_owning_resource, rest_vserver
477
478
479 class NetAppONTAPGatherInfo(object):
480 '''Class with gather info methods'''
481
482 def __init__(self):
483 """
484 Parse arguments, setup state variables,
485 check parameters and ensure request module is installed
486 """
487 self.argument_spec = netapp_utils.na_ontap_rest_only_spec()
488 self.argument_spec.update(dict(
489 state=dict(type='str', required=False),
490 gather_subset=dict(default=['demo'], type='list', elements='str', required=False),
491 max_records=dict(type='int', default=1024, required=False),
492 fields=dict(type='list', elements='str', required=False),
493 parameters=dict(type='dict', required=False),
494 use_python_keys=dict(type='bool', default=False),
495 owning_resource=dict(type='dict', required=False),
496 ignore_api_errors=dict(type='list', elements='str', required=False),
497 hal_linking=dict(required=False, type='bool', default=True),
498 ))
499 self.argument_spec.update(netapp_utils.na_ontap_lambda_argument_spec())
500
501 self.module = AnsibleModule(
502 argument_spec=self.argument_spec,
503 required_if=[
504 ('use_lambda', True, ['lambda_config']),
505 ],
506 supports_check_mode=True
507 )
508
509 # set up variables
510 self.na_helper = NetAppModule()
511 self.parameters = self.na_helper.set_parameters(self.module.params)
512 self.fields = ''
513
514 self.rest_api = OntapRestAPI(self.module)
515 self.rest_api.fail_if_not_rest_minimum_version('na_ontap_rest_info', 9, 6, 0)
516
517 def get_subset_info(self, gather_subset_info, default_fields=None):
518 """
519 Gather ONTAP information for the given subset using REST APIs
520 Input for REST APIs call : (api, data)
521 return gathered_ontap_info
522 """
523
524 api = gather_subset_info['api_call']
525 if gather_subset_info.pop('post', False):
526 self.run_post(gather_subset_info)
527 if default_fields:
528 fields = default_fields + ',' + self.fields
529 elif 'fields' in gather_subset_info:
530 fields = gather_subset_info['fields']
531 else:
532 fields = self.fields
533
534 data = {'max_records': self.parameters['max_records'], 'fields': fields}
535
536 # Delete the fields record from data if it is a private/cli API call.
537 # The private_cli_fields method handles the fields for API calls using the private/cli endpoint.
538 if '/private/cli' in api:
539 del data['fields']
540
541 # allow for passing in any additional rest api fields
542 if self.parameters.get('parameters'):
543 for each in self.parameters['parameters']:
544 data[each] = self.parameters['parameters'][each]
545
546 accept_header = 'application/hal+json' if self.parameters.get('hal_linking') else 'application/json'
547 headers = self.rest_api.build_headers(accept=accept_header)
548 gathered_ontap_info, error = self.rest_api.get(api, data, headers=headers)
549
550 if error and "entry doesn't exist" in error.get('message', ''):
551 # If the API returns no records, return an empty set of records.
552 return {'records': [], 'num_records': 0}
553
554 if not error:
555 return gathered_ontap_info
556
557 if isinstance(error, dict):
558 # If the API doesn't exist (using an older system), we don't want to fail the task.
559 if int(error.get('code', 0)) == 3 or (
560 # if Aggr recommender can't make a recommendation, it will fail with the following error code, don't fail the task.
561 int(error.get('code', 0)) == 19726344 and "No recommendation can be made for this cluster" in error.get('message')):
562 return error.get('message')
563
564 # Do not fail on error
565 for error_pattern in self.parameters.get('ignore_api_errors', []):
566 if error_pattern in error.get('message'):
567 return {'error': error}
568 # Fail the module if error occurs from REST APIs call
569 if int(error.get('code', 0)) == 6:
570 error = "Error: %s user is not authorized to make %s api call" % (self.parameters.get('username'), api)
571 self.module.fail_json(msg=error)
572
573 @staticmethod
574 def strip_dacls(response):
575 # Use 'DACL - ACE' as a marker for the start of the list of DACLS in the descriptor.
576 if 'acls' not in response['records'][0]:
577 return None
578 if 'DACL - ACEs' not in response['records'][0]['acls']:
579 return None
580 index = response['records'][0]['acls'].index('DACL - ACEs')
581 dacls = response['records'][0]['acls'][(index + 1):]
582
583 dacl_list = []
584 if dacls:
585 for dacl in dacls:
586 # The '-' marker is the start of the DACL, the '-0x' marker is the end of the DACL.
587 start_hyphen = dacl.index('-') + 1
588 first_hyphen_removed = dacl[start_hyphen:]
589 end_hyphen = first_hyphen_removed.index('-0x')
590 dacl_dict = {'access_type': dacl[:start_hyphen - 1].strip()}
591 dacl_dict['user_or_group'] = first_hyphen_removed[:end_hyphen]
592 dacl_list.append(dacl_dict)
593 return dacl_list
594
595 def run_post(self, gather_subset_info):
596 api = gather_subset_info['api_call']
597 post_return, error = self.rest_api.post(api, None)
598 if error:
599 return None
600 dummy, error = self.rest_api.wait_on_job(post_return['job'], increment=5)
601 if error:
602 # TODO: Handle errors that are not errors
603 self.module.fail_json(msg="%s" % error)
604
605 def get_next_records(self, api):
606 """
607 Gather next set of ONTAP information for the specified api
608 Input for REST APIs call : (api, data)
609 return gather_subset_info
610 """
611
612 data = {}
613 gather_subset_info, error = self.rest_api.get(api, data)
614
615 if error:
616 self.module.fail_json(msg=error)
617
618 return gather_subset_info
619
620 def private_cli_fields(self, api):
621 '''
622 The private cli endpoint does not allow '*' to be an entered.
623 If fields='*' or fields are not included within the playbook, the API call will be populated to return all possible fields.
624 If fields is entered into the playbook the fields entered will be used when calling the API.
625 '''
626 if 'fields' not in self.parameters or '*' in self.parameters['fields'] or '**' in self.parameters['fields']:
627 if api == 'support/autosupport/check':
628 fields = 'node,corrective-action,status,error-detail,check-type,check-category'
629 elif api == 'private/cli/vserver/security/file-directory':
630 fields = 'acls'
631 else:
632 self.module.fail_json(msg='Internal error, no field for %s' % api)
633 else:
634 fields = ','.join(self.parameters['fields'])
635 return fields
636
637 def convert_subsets(self):
638 """
639 Convert an info to the REST API
640 """
641 info_to_rest_mapping = {
642 "aggregate_info": "storage/aggregates",
643 "aggr_efficiency_info": ['storage/aggregates', 'space.efficiency,name,node'],
644 "application_info": "application/applications",
645 "application_template_info": "application/templates",
646 "autosupport_check_info": "support/autosupport/check",
647 "autosupport_config_info": "support/autosupport",
648 "autosupport_messages_history": "support/autosupport/messages",
649 "broadcast_domains_info": "network/ethernet/broadcast-domains",
650 "cifs_home_directory_info": "protocols/cifs/home-directory/search-paths",
651 "cifs_options_info": "protocols/cifs/services",
652 "cifs_services_info": "protocols/cifs/services",
653 "cifs_share_info": "protocols/cifs/shares",
654 "cifs_vserver_security_info": ["protocols/cifs/services", "security.encrypt_dc_connection,"
655 "security.kdc_encryption,security.smb_signing,"
656 "security.smb_encryption,"
657 "security.lm_compatibility_level,svm.name"],
658 "clock_info": ["cluster/nodes", "date"],
659 "cloud_targets_info": "cloud/targets",
660 "cluster_chassis_info": "cluster/chassis",
661 "cluster_identity_info": ["cluster", "contact,location,name,uuid"],
662 "cluster_image_info": "cluster/software",
663 "cluster_jobs_info": "cluster/jobs",
664 "cluster_log_forwarding_info": "security/audit/destinations",
665 "cluster_metrocluster_diagnostics": "cluster/metrocluster/diagnostics",
666 "cluster_metrics_info": "cluster/metrics",
667 "cluster_node_info": "cluster/nodes",
668 "cluster_peer_info": "cluster/peers",
669 "cluster_schedules": "cluster/schedules",
670 "cluster_software_download": "cluster/software/download",
671 "cluster_software_history": "cluster/software/history",
672 "cluster_software_packages": "cluster/software/packages",
673 "cluster_switch_info": "network/ethernet/switches",
674 "disk_info": "storage/disks",
675 "event_notification_info": "support/ems/destinations",
676 "event_notification_destination_info": "support/ems/destinations",
677 "export_policy_info": "protocols/nfs/export-policies",
678 "fcp_alias_info": "network/fc/wwpn-aliases",
679 "fcp_service_info": "protocols/san/fcp/services",
680 "file_directory_security": "private/cli/vserver/security/file-directory",
681 "igroup_info": "protocols/san/igroups",
682 "initiator_groups_info": "protocols/san/igroups",
683 "ip_interfaces_info": "network/ip/interfaces",
684 "ip_routes_info": "network/ip/routes",
685 "ip_service_policies": "network/ip/service-policies",
686 "iscsi_service_info": "protocols/san/iscsi/services",
687 "job_schedule_cron_info": "cluster/schedules",
688 "kerberos_realm_info": "protocols/nfs/kerberos/realms",
689 "ldap_client": "name-services/ldap",
690 "ldap_config": "name-services/ldap",
691 "license_info": "cluster/licensing/licenses",
692 "lun_info": "storage/luns",
693 "lun_map_info": "protocols/san/lun-maps",
694 "net_dns_info": "name-services/dns",
695 "net_interface_info": "network/ip/interfaces",
696 "net_interface_service_policy_info": "network/ip/service-policies",
697 "net_port_broadcast_domain_info": "network/ethernet/broadcast-domains",
698 "net_port_info": "network/ethernet/ports",
699 "net_routes_info": "network/ip/routes",
700 "net_ipspaces_info": "network/ipspaces",
701 "net_vlan_info": ["network/ethernet/ports", "name,node.name,vlan.base_port,vlan.tag"],
702 "network_ipspaces_info": "network/ipspaces",
703 "network_ports_info": "network/ethernet/ports",
704 "nfs_info": "protocols/nfs/services",
705 "ntp_server_info": "cluster/ntp/servers",
706 "nvme_info": "protocols/nvme/services",
707 "nvme_interface_info": "protocols/nvme/interfaces",
708 "nvme_namespace_info": "storage/namespaces",
709 "nvme_subsystem_info": "protocols/nvme/subsystems",
710 "metrocluster_info": "cluster/metrocluster",
711 "metrocluster_node_info": "cluster/metrocluster/nodes",
712 "metrocluster_check_info": "cluster/metrocluster/diagnostics",
713 "ontap_system_version": "cluster/software",
714 "quota_report_info": "storage/quota/reports",
715 "qos_policy_info": "storage/qos/policies",
716 "qos_adaptive_policy_info": "storage/qos/policies",
717 "qtree_info": "storage/qtrees",
718 "san_fc_logins_info": "network/fc/logins",
719 "san_fc_wppn-aliases": "network/fc/wwpn-aliases",
720 "san_fcp_services": "protocols/san/fcp/services",
721 "san_iscsi_credentials": "protocols/san/iscsi/credentials",
722 "san_iscsi_services": "protocols/san/iscsi/services",
723 "san_lun_maps": "protocols/san/lun-maps",
724 "security_login_account_info": "security/accounts",
725 "security_login_info": "security/accounts",
726 "security_login_rest_role_info": "security/roles",
727 "shelf_info": "storage/shelves",
728 "sis_info": ["storage/volumes", "efficiency.compression,efficiency.cross_volume_dedupe,"
729 "efficiency.cross_volume_dedupe,efficiency.compaction,"
730 "efficiency.compression,efficiency.dedupe,efficiency.policy.name,"
731 "efficiency.schedule,svm.name"],
732 "sis_policy_info": "storage/volume-efficiency-policies",
733 "snapmirror_destination_info": ["snapmirror/relationships", "destination.path,destination.svm.name,"
734 "destination.svm.uuid,policy.type,uuid,state,"
735 "source.path,source.svm.name,source.svm.uuid,"
736 "transfer.bytes_transferred"],
737 "snapmirror_info": "snapmirror/relationships",
738 "snapmirror_policy_info": "snapmirror/policies",
739 "snapshot_policy_info": "storage/snapshot-policies",
740 "storage_bridge_info": "storage/bridges",
741 "storage_flexcaches_info": "storage/flexcache/flexcaches",
742 "storage_flexcaches_origin_info": "storage/flexcache/origins",
743 "storage_luns_info": "storage/luns",
744 "storage_NVMe_namespaces": "storage/namespaces",
745 "storage_ports_info": "storage/ports",
746 "storage_qos_policies": "storage/qos/policies",
747 "storage_qtrees_config": "storage/qtrees",
748 "storage_quota_reports": "storage/quota/reports",
749 "storage_quota_policy_rules": "storage/quota/rules",
750 "storage_shelves_config": "storage/shelves",
751 "storage_snapshot_policies": "storage/snapshot-policies",
752 "support_ems_config": "support/ems",
753 "support_ems_events": "support/ems/events",
754 "support_ems_filters": "support/ems/filters",
755 "svm_dns_config_info": "name-services/dns",
756 "svm_ldap_config_info": "name-services/ldap",
757 "svm_name_mapping_config_info": "name-services/name-mappings",
758 "svm_nis_config_info": "name-services/nis",
759 "svm_peers_info": "svm/peers",
760 "svm_peer-permissions_info": "svm/peer-permissions",
761 "sysconfig_info": "cluster/nodes",
762 "system_node_info": ["cluster/nodes", "controller.cpu.firmware_release,controller.failed_fan.count,"
763 "controller.failed_fan.message,"
764 "controller.failed_power_supply.count,"
765 "controller.failed_power_supply.message,"
766 "controller.over_temperature,is_all_flash_optimized,"
767 "is_all_flash_select_optimized,is_capacity_optimized,state,name,"
768 "location,model,nvram.id,owner,serial_number,storage_configuration,"
769 "system_id,uptime,uuid,vendor_serial_number,nvram.battery_state,"
770 "version,vm.provider_type"],
771 "sys_cluster_alerts": "private/support/alerts",
772 "vserver_info": "svm/svms",
773 "vserver_peer_info": "svm/peers",
774 "vserver_nfs_info": "protocols/nfs/services",
775 "volume_info": "storage/volumes",
776 "volume_space_info": ["storage/volumes", 'space.logical_space.available,space.logical_space.used,'
777 'space.logical_space.used_percent,space.snapshot.reserve_size,'
778 'space.snapshot.reserve_percent,space.used,name,svm.name'],
779 "vscan_connection_status_all_info": "protocols/vscan/server-status",
780 "vscan_info": "protocols/vscan",
781 "vscan_status_info": "protocols/vscan"
782 }
783 # Add rest API names as there info version, also make sure we don't add a duplicate
784 subsets = []
785 for subset in self.parameters['gather_subset']:
786 if subset in info_to_rest_mapping:
787 if info_to_rest_mapping[subset] not in subsets:
788 subsets.append(info_to_rest_mapping[subset])
789 elif subset not in subsets:
790 subsets.append(subset)
791 return subsets
792
793 def add_naa_id(self, info):
794 ''' https://kb.netapp.com/Advice_and_Troubleshooting/Data_Storage_Systems/FlexPod_with_Infrastructure_Automation/
795 How_to_match__LUNs_NAA_number_to_its_serial_number
796 '''
797 if info and 'records' in info:
798 for lun in info['records']:
799 if 'serial_number' in lun:
800 hexlify = codecs.getencoder('hex')
801 lun['serial_hex'] = to_text(hexlify(to_bytes(lun['serial_number']))[0])
802 lun['naa_id'] = 'naa.600a0980' + lun['serial_hex']
803
804 def augment_subset_info(self, subset, subset_info):
805 if subset == 'private/cli/vserver/security/file-directory':
806 # creates a new list of dicts
807 subset_info = self.strip_dacls(subset_info)
808 if subset == 'storage/luns':
809 # mutates the existing dicts
810 self.add_naa_id(subset_info)
811 return subset_info
812
813 def get_ontap_subset_info_all(self, subset, default_fields, get_ontap_subset_info):
814 """ Iteratively get all records for a subset """
815 try:
816 # Verify whether the supported subset passed
817 specified_subset = get_ontap_subset_info[subset]
818 except KeyError:
819 self.module.fail_json(msg="Specified subset %s is not found, supported subsets are %s" %
820 (subset, list(get_ontap_subset_info.keys())))
821 if 'api_call' not in specified_subset:
822 specified_subset['api_call'] = subset
823 subset_info = self.get_subset_info(specified_subset, default_fields)
824
825 if subset_info is not None and isinstance(subset_info, dict) and '_links' in subset_info:
826 while subset_info['_links'].get('next'):
827 # Get all the set of records if next link found in subset_info for the specified subset
828 next_api = subset_info['_links']['next']['href']
829 gathered_subset_info = self.get_next_records(next_api.replace('/api', ''))
830
831 # Update the subset info for the specified subset
832 subset_info['_links'] = gathered_subset_info['_links']
833 subset_info['records'].extend(gathered_subset_info['records'])
834
835 # metrocluster doesn't have a records field, so we need to skip this
836 if subset_info.get('records') is not None:
837 # Getting total number of records
838 subset_info['num_records'] = len(subset_info['records'])
839
840 return self.augment_subset_info(subset, subset_info)
841
842 def apply(self):
843 """
844 Perform pre-checks, call functions and exit
845 """
846
847 # Defining gather_subset and appropriate api_call
848 get_ontap_subset_info = {
849 'application/applications': {},
850 'application/consistency-groups': {'version': (9, 10, 1)},
851 'application/templates': {},
852 'cloud/targets': {},
853 'cluster': {},
854 'cluster/chassis': {},
855 'cluster/counter/tables': {'version': (9, 11, 1)},
856 'cluster/firmware/history': {'version': (9, 8)},
857 'cluster/jobs': {},
858 'cluster/licensing/capacity-pools': {'version': (9, 8)},
859 'cluster/licensing/license-managers': {'version': (9, 8)},
860 'cluster/licensing/licenses': {},
861 'cluster/mediators': {'version': (9, 8)},
862 'cluster/metrics': {},
863 'cluster/metrocluster': {'version': (9, 8)},
864 'cluster/metrocluster/diagnostics': {
865 'version': (9, 8),
866 'post': True
867 },
868 'cluster/metrocluster/dr-groups': {'version': (9, 8)},
869 'cluster/metrocluster/interconnects': {'version': (9, 8)},
870 'cluster/metrocluster/nodes': {'version': (9, 8)},
871 'cluster/metrocluster/operations': {'version': (9, 8)},
872 'cluster/metrocluster/svms': {'version': (9, 11, 1)},
873 'cluster/nodes': {},
874 'cluster/ntp/keys': {'version': (9, 7)},
875 'cluster/ntp/servers': {'version': (9, 7)},
876 'cluster/peers': {},
877 'cluster/schedules': {},
878 'cluster/sensors': {'version': (9, 11, 1)},
879 'cluster/software': {},
880 'cluster/software/download': {'version': (9, 7)},
881 'cluster/software/history': {},
882 'cluster/software/packages': {},
883 'cluster/web': {'version': (9, 10, 1)},
884 'name-services/cache/group-membership/settings': {'version': (9, 11, 1)},
885 'name-services/cache/host/settings': {'version': (9, 11, 1)},
886 'name-services/cache/netgroup/settings': {'version': (9, 11, 1)},
887 'name-services/cache/setting': {'version': (9, 11, 1)},
888 'name-services/cache/unix-group/settings': {'version': (9, 11, 1)},
889 'name-services/dns': {},
890 'name-services/ldap': {},
891 'name-services/ldap-schemas': {'version': (9, 11, 1)},
892 'name-services/local-hosts': {'version': (9, 10, 1)},
893 'name-services/name-mappings': {},
894 'name-services/nis': {},
895 'name-services/unix-groups': {'version': (9, 9)},
896 'name-services/unix-users': {'version': (9, 9)},
897 'network/ethernet/broadcast-domains': {},
898 'network/ethernet/ports': {},
899 'network/ethernet/switch/ports': {'version': (9, 8)},
900 'network/ethernet/switches': {'version': (9, 8)},
901 'network/fc/fabrics': {'version': (9, 11, 1)},
902 'network/fc/interfaces': {},
903 'network/fc/logins': {},
904 'network/fc/ports': {},
905 'network/fc/wwpn-aliases': {},
906 'network/http-proxy': {'version': (9, 7)},
907 'network/ip/bgp/peer-groups': {'version': (9, 7)},
908 'network/ip/interfaces': {},
909 'network/ip/routes': {},
910 'network/ip/service-policies': {},
911 'network/ip/subnets': {'version': (9, 11, 1)},
912 'network/ipspaces': {},
913 'private/support/alerts': {},
914 'protocols/active-directory': {'version': (9, 12, 1)},
915 'protocols/audit': {},
916 'protocols/cifs/connections': {'version': (9, 11, 1)},
917 'protocols/cifs/domains': {'version': (9, 10, 1)},
918 'protocols/cifs/group-policies': {'version': (9, 12, 1)},
919 'protocols/cifs/home-directory/search-paths': {},
920 'protocols/cifs/local-groups': {'version': (9, 9)},
921 'protocols/cifs/local-users': {'version': (9, 9)},
922 'protocols/cifs/netbios': {'version': (9, 11, 1)},
923 'protocols/cifs/services': {},
924 'protocols/cifs/session/files': {'version': (9, 11, 1)},
925 'protocols/cifs/sessions': {'version': (9, 8)},
926 'protocols/cifs/shadow-copies': {'version': (9, 11, 1)},
927 'protocols/cifs/shadowcopy-sets': {'version': (9, 11, 1)},
928 'protocols/cifs/shares': {},
929 'protocols/cifs/unix-symlink-mapping': {},
930 'protocols/cifs/users-and-groups/privileges': {'version': (9, 9)},
931 'protocols/fpolicy': {},
932 'protocols/locks': {'version': (9, 10, 1)},
933 'protocols/ndmp': {'version': (9, 7)},
934 'protocols/ndmp/nodes': {'version': (9, 7)},
935 'protocols/ndmp/sessions': {'version': (9, 7)},
936 'protocols/ndmp/svms': {'version': (9, 7)},
937 'protocols/nfs/connected-clients': {'version': (9, 7)},
938 'protocols/nfs/connected-client-maps': {'version': (9, 11, 1)},
939 'protocols/nfs/connected-client-settings': {'version': (9, 12, 1)},
940 'protocols/nfs/export-policies': {},
941 'protocols/nfs/kerberos/interfaces': {},
942 'protocols/nfs/kerberos/realms': {},
943 'protocols/nfs/services': {},
944 'protocols/nvme/interfaces': {},
945 'protocols/nvme/services': {},
946 'protocols/nvme/subsystem-controllers': {},
947 'protocols/nvme/subsystem-maps': {},
948 'protocols/nvme/subsystems': {},
949 'protocols/s3/buckets': {'version': (9, 7)},
950 'protocols/s3/services': {'version': (9, 7)},
951 'protocols/san/fcp/services': {},
952 'protocols/san/igroups': {},
953 'protocols/san/iscsi/credentials': {},
954 'protocols/san/iscsi/services': {},
955 'protocols/san/iscsi/sessions': {},
956 'protocols/san/lun-maps': {},
957 'protocols/san/portsets': {'version': (9, 9)},
958 'protocols/san/vvol-bindings': {'version': (9, 10, 1)},
959 'protocols/vscan/server-status': {},
960 'protocols/vscan': {},
961 'security': {'version': (9, 7)},
962 'security/accounts': {},
963 'security/anti-ransomware/suspects': {'version': (9, 10, 1)},
964 'security/audit': {},
965 'security/audit/destinations': {},
966 'security/audit/messages': {},
967 'security/authentication/cluster/ad-proxy': {'version': (9, 7)},
968 'security/authentication/cluster/ldap': {},
969 'security/authentication/cluster/nis': {},
970 'security/authentication/cluster/saml-sp': {},
971 'security/authentication/publickeys': {'version': (9, 7)},
972 'security/aws-kms': {'version': (9, 12, 1)},
973 'security/azure-key-vaults': {'version': (9, 8)},
974 'security/certificates': {},
975 'security/gcp-kms': {'version': (9, 9)},
976 'security/ipsec': {'version': (9, 8)},
977 'security/ipsec/ca-certificates': {'version': (9, 10, 1)},
978 'security/ipsec/policies': {'version': (9, 8)},
979 'security/ipsec/security-associations': {'version': (9, 8)},
980 'security/key-manager-configs': {'version': (9, 10, 1)},
981 'security/key-managers': {},
982 'security/key-stores': {'version': (9, 10, 1)},
983 'security/login/messages': {},
984 'security/multi-admin-verify': {'version': (9, 11, 1)},
985 'security/multi-admin-verify/approval-groups': {'version': (9, 11, 1)},
986 'security/multi-admin-verify/requests': {'version': (9, 11, 1)},
987 'security/multi-admin-verify/rules': {'version': (9, 11, 1)},
988 'security/roles': {},
989 'security/ssh': {'version': (9, 7)},
990 'security/ssh/svms': {'version': (9, 10, 1)},
991 'snapmirror/policies': {},
992 'snapmirror/relationships': {},
993 'storage/aggregates': {},
994 'storage/bridges': {'version': (9, 9)},
995 'storage/cluster': {},
996 'storage/disks': {},
997 'storage/file/clone/split-loads': {'version': (9, 10, 1)},
998 'storage/file/clone/split-status': {'version': (9, 10, 1)},
999 'storage/file/clone/tokens': {'version': (9, 10, 1)},
1000 'storage/file/moves': {'version': (9, 11, 1)},
1001 'storage/flexcache/flexcaches': {},
1002 'storage/flexcache/origins': {},
1003 'storage/luns': {},
1004 'storage/namespaces': {},
1005 'storage/pools': {'version': (9, 11, 1)},
1006 'storage/ports': {},
1007 'storage/qos/policies': {},
1008 'storage/qos/workloads': {'version': (9, 10, 1)},
1009 'storage/qtrees': {},
1010 'storage/quota/reports': {},
1011 'storage/quota/rules': {},
1012 'storage/shelves': {},
1013 'storage/snaplock/audit-logs': {'version': (9, 7)},
1014 'storage/snaplock/compliance-clocks': {'version': (9, 7)},
1015 'storage/snaplock/event-retention/operations': {'version': (9, 7)},
1016 'storage/snaplock/event-retention/policies': {'version': (9, 7)},
1017 'storage/snaplock/file-fingerprints': {'version': (9, 7)},
1018 'storage/snaplock/litigations': {'version': (9, 7)},
1019 'storage/snapshot-policies': {},
1020 'storage/switches': {'version': (9, 9)},
1021 'storage/tape-devices': {'version': (9, 9)},
1022 'storage/volumes': {},
1023 'storage/volume-efficiency-policies': {'version': (9, 8)},
1024 'support/autosupport': {},
1025 'support/autosupport/check': {
1026 'api_call': '/private/cli/system/node/autosupport/check/details',
1027 'fields': self.private_cli_fields('support/autosupport/check'),
1028 },
1029 'support/autosupport/messages': {},
1030 'support/auto-update': {'version': (9, 10, 1)},
1031 'support/auto-update/configurations': {'version': (9, 10, 1)},
1032 'support/auto-update/updates': {'version': (9, 10, 1)},
1033 'support/configuration-backup': {},
1034 'support/configuration-backup/backups': {'version': (9, 7)},
1035 'support/coredump/coredumps': {'version': (9, 10, 1)},
1036 'support/ems': {},
1037 'support/ems/destinations': {},
1038 'support/ems/events': {},
1039 'support/ems/filters': {},
1040 'support/ems/messages': {},
1041 'support/snmp': {'version': (9, 7)},
1042 'support/snmp/traphosts': {'version': (9, 7)},
1043 'support/snmp/users': {'version': (9, 7)},
1044 'svm/migrations': {'version': (9, 10, 1)},
1045 'svm/peers': {},
1046 'svm/peer-permissions': {},
1047 'svm/svms': {}
1048 }
1049 if 'gather_subset' in self.parameters and (
1050 'private/cli/vserver/security/file-directory' in self.parameters['gather_subset']
1051 or 'file_directory_security' in self.parameters['gather_subset']
1052 ):
1053 get_ontap_subset_info['private/cli/vserver/security/file-directory'] = {
1054 'api_call': 'private/cli/vserver/security/file-directory',
1055 'fields': self.private_cli_fields('private/cli/vserver/security/file-directory')
1056 }
1057 if 'all' in self.parameters['gather_subset']:
1058 # If all in subset list, get the information of all subsets
1059 self.parameters['gather_subset'] = sorted(get_ontap_subset_info.keys())
1060 if 'demo' in self.parameters['gather_subset']:
1061 self.parameters['gather_subset'] = ['cluster/software', 'svm/svms', 'cluster/nodes']
1062 get_ontap_subset_info = self.add_uuid_subsets(get_ontap_subset_info)
1063
1064 length_of_subsets = len(self.parameters['gather_subset'])
1065 unsupported_subsets = self.subset_version_warning(get_ontap_subset_info)
1066
1067 if self.parameters.get('fields'):
1068 if '**' in self.parameters.get('fields'):
1069 self.module.warn('Using ** can put an extra load on the system and should not be used in production')
1070 # If multiple fields specified to return, convert list to string
1071 self.fields = ','.join(self.parameters.get('fields'))
1072
1073 if self.fields not in ('*', '**') and length_of_subsets > 1:
1074 # Restrict gather subsets to one subset if fields section is list_of_fields
1075 self.module.fail_json(msg="Error: fields: %s, only one subset will be allowed." % self.parameters.get('fields'))
1076 converted_subsets = self.convert_subsets()
1077
1078 result_message = {}
1079 for subset in converted_subsets:
1080 subset, default_fields = subset if isinstance(subset, list) else (subset, None)
1081 result_message[subset] = self.get_ontap_subset_info_all(subset, default_fields, get_ontap_subset_info)
1082 for subset in unsupported_subsets:
1083 result_message[subset] = '%s requires ONTAP %s' % (subset, get_ontap_subset_info[subset]['version'])
1084
1085 results = {'changed': False}
1086 if self.parameters.get('state') is not None:
1087 results['state'] = self.parameters['state']
1088 results['warnings'] = "option 'state' is deprecated."
1089 if self.parameters['use_python_keys']:
1090 new_dict = dict((key.replace('/', '_'), value) for (key, value) in result_message.items())
1091 new_dict = dict((key.replace('-', '_'), value) for (key, value) in new_dict.items())
1092 result_message = new_dict
1093 self.module.exit_json(ontap_info=result_message, **results)
1094
1095 def subset_version_warning(self, get_ontap_subset_info):
1096 # If a user requests a subset that their version of ONTAP does not support give them a warning (but don't fail)
1097 unsupported_subset = []
1098 warn_message = ''
1099 user_version = self.rest_api.get_ontap_version()
1100 for subset in self.parameters['gather_subset']:
1101 if subset in get_ontap_subset_info and 'version' in get_ontap_subset_info[subset] and get_ontap_subset_info[subset]['version'] > user_version:
1102 warn_message += '%s requires %s, ' % (subset, get_ontap_subset_info[subset]['version'])
1103 # remove subset so info dosn't fail for a bad subset
1104 unsupported_subset.append(subset)
1105 self.parameters['gather_subset'].remove(subset)
1106 if warn_message != '':
1107 self.module.warn('The following subset have been removed from your query as they are not supported on your version of ONTAP %s' % warn_message)
1108 return unsupported_subset
1109
1110 def add_uuid_subsets(self, get_ontap_subset_info):
1111 params = self.parameters.get('owning_resource')
1112 owning_resource_supported_subsets = ['application/consistency-groups/metrics', 'application/consistency-groups/snapshots',
1113 'storage/volumes/snapshots', 'protocols/nfs/export-policies/rules',
1114 'protocols/vscan/on-access-policies', 'protocols/vscan/on-demand-policies',
1115 'protocols/vscan/scanner-pools']
1116 if 'gather_subset' in self.parameters:
1117 if 'application/consistency-groups/metrics' in self.parameters['gather_subset']:
1118 self.check_error_values('application/consistency-groups/metrics', params, ['cg_name', 'svm_name'])
1119 cg_uuid = rest_owning_resource.get_consistency_group_uuid(self.rest_api, self.parameters['owning_resource']['cg_name'],
1120 self.parameters['owning_resource']['svm_name'], self.module)
1121 if cg_uuid:
1122 get_ontap_subset_info['application/consistency-groups/metrics'] = {'api_call': 'application/consistency-groups/%s/metrics' % cg_uuid}
1123 if 'application/consistency-groups/snapshots' in self.parameters['gather_subset']:
1124 self.check_error_values('application/consistency-groups/snapshots', params, ['cg_name', 'svm_name'])
1125 cg_uuid = rest_owning_resource.get_consistency_group_uuid(self.rest_api, self.parameters['owning_resource']['cg_name'],
1126 self.parameters['owning_resource']['svm_name'], self.module)
1127 if cg_uuid:
1128 get_ontap_subset_info['application/consistency-groups/snapshots'] = {'api_call': 'application/consistency-groups/%s/snapshots' % cg_uuid}
1129 if 'storage/volumes/snapshots' in self.parameters['gather_subset']:
1130 self.check_error_values('storage/volumes/snapshots', params, ['volume_name', 'svm_name'])
1131 volume_uuid = rest_owning_resource.get_volume_uuid(self.rest_api, self.parameters['owning_resource']['volume_name'],
1132 self.parameters['owning_resource']['svm_name'], self.module)
1133 if volume_uuid:
1134 get_ontap_subset_info['storage/volumes/snapshots'] = {'api_call': 'storage/volumes/%s/snapshots' % volume_uuid}
1135 if 'protocols/nfs/export-policies/rules' in self.parameters['gather_subset']:
1136 self.check_error_values('protocols/nfs/export-policies/rules', params, ['policy_name', 'svm_name', 'rule_index'])
1137 policy_id = rest_owning_resource.get_export_policy_id(self.rest_api, self.parameters['owning_resource']['policy_name'],
1138 self.parameters['owning_resource']['svm_name'], self.module)
1139 if policy_id:
1140 get_ontap_subset_info['protocols/nfs/export-policies/rules'] = {
1141 'api_call': 'protocols/nfs/export-policies/%s/rules/%s' % (policy_id, self.parameters['owning_resource']['rule_index']),
1142 }
1143 if 'protocols/vscan/on-access-policies' in self.parameters['gather_subset']:
1144 self.add_vserver_owning_resource('protocols/vscan/on-access-policies', params, 'protocols/vscan/%s/on-access-policies', get_ontap_subset_info)
1145 if 'protocols/vscan/on-demand-policies' in self.parameters['gather_subset']:
1146 self.add_vserver_owning_resource('protocols/vscan/on-demand-policies', params, 'protocols/vscan/%s/on-demand-policies', get_ontap_subset_info)
1147 if 'protocols/vscan/scanner-pools' in self.parameters['gather_subset']:
1148 self.add_vserver_owning_resource('protocols/vscan/scanner-pools', params, 'protocols/vscan/%s/scanner-pools', get_ontap_subset_info)
1149 owning_resource_warning = any(subset not in owning_resource_supported_subsets for subset in self.parameters['gather_subset'])
1150 if owning_resource_warning and params is not None:
1151 self.module.warn("Kindly refer to Ansible documentation to check the subsets that support option 'owning_resource'.")
1152 return get_ontap_subset_info
1153
1154 def add_vserver_owning_resource(self, subset, params, api, get_ontap_subset_info):
1155 self.check_error_values(subset, params, ['svm_name'])
1156 svm_uuid, dummy = rest_vserver.get_vserver_uuid(self.rest_api, self.parameters['owning_resource']['svm_name'], self.module, True)
1157 if svm_uuid:
1158 get_ontap_subset_info[subset] = {'api_call': api % svm_uuid}
1159
1160 def check_error_values(self, api, params, items):
1161 error = not params or sorted(list(params.keys())) != sorted(items)
1162 if error:
1163 self.module.fail_json(msg="Error: %s are required for %s" % (', '.join(items), api))
1164
1165
1166 def main():
1167 """
1168 Main function
1169 """
1170 obj = NetAppONTAPGatherInfo()
1171 obj.apply()
1172
1173
1174 if __name__ == '__main__':
1175 main()