Debian Codegraph @

ansible_collections/netapp_eseries/santricity/plugins/modules/na_santricity_asup.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 ---
11 module: na_santricity_asup
12 short_description: NetApp E-Series manage auto-support settings
13 description:
14 - Allow the auto-support settings to be configured for an individual E-Series storage-system
15 author:
16 - Michael Price (@lmprice)
17 - Nathan Swartz (@swartzn)
18 - Vu Tran (@VuTran007)
19 extends_documentation_fragment:
20 - netapp_eseries.santricity.santricity.santricity_doc
21 options:
22 state:
23 description:
24 - Enable/disable the E-Series auto-support configuration or maintenance mode.
25 - When this option is enabled, configuration, logs, and other support-related information will be relayed
26 to NetApp to help better support your system. No personally identifiable information, passwords, etc, will
27 be collected.
28 - The maintenance state enables the maintenance window which allows maintenance activities to be performed on the storage array without
29 generating support cases.
30 - Maintenance mode cannot be enabled unless ASUP has previously been enabled.
31 type: str
32 default: enabled
33 choices:
34 - enabled
35 - disabled
36 - maintenance_enabled
37 - maintenance_disabled
38 active:
39 description:
40 - Enable active/proactive monitoring for ASUP. When a problem is detected by our monitoring systems, it's
41 possible that the bundle did not contain all of the required information at the time of the event.
42 Enabling this option allows NetApp support personnel to manually request transmission or re-transmission
43 of support data in order ot resolve the problem.
44 - Only applicable if I(state=enabled).
45 default: true
46 type: bool
47 start:
48 description:
49 - A start hour may be specified in a range from 0 to 23 hours.
50 - ASUP bundles will be sent daily between the provided start and end time (UTC).
51 - I(start) must be less than I(end).
52 type: int
53 default: 0
54 end:
55 description:
56 - An end hour may be specified in a range from 1 to 24 hours.
57 - ASUP bundles will be sent daily between the provided start and end time (UTC).
58 - I(start) must be less than I(end).
59 type: int
60 default: 24
61 days:
62 description:
63 - A list of days of the week that ASUP bundles will be sent. A larger, weekly bundle will be sent on one
64 of the provided days.
65 type: list
66 elements: str
67 choices:
68 - monday
69 - tuesday
70 - wednesday
71 - thursday
72 - friday
73 - saturday
74 - sunday
75 required: false
76 aliases:
77 - schedule_days
78 - days_of_week
79 method:
80 description:
81 - AutoSupport dispatch delivery method.
82 choices:
83 - https
84 - http
85 - email
86 type: str
87 required: false
88 default: https
89 routing_type:
90 description:
91 - AutoSupport routing
92 - Required when I(method==https or method==http).
93 choices:
94 - direct
95 - proxy
96 - script
97 type: str
98 default: direct
99 required: false
100 proxy:
101 description:
102 - Information particular to the proxy delivery method.
103 - Required when I((method==https or method==http) and routing_type==proxy).
104 type: dict
105 required: false
106 suboptions:
107 host:
108 description:
109 - Proxy host IP address or fully qualified domain name.
110 - Required when I(method==http or method==https) and I(routing_type==proxy).
111 type: str
112 required: false
113 port:
114 description:
115 - Proxy host port.
116 - Required when I(method==http or method==https) and I(routing_type==proxy).
117 type: int
118 required: false
119 script:
120 description:
121 - Path to the AutoSupport routing script file.
122 - Required when I(method==http or method==https) and I(routing_type==script).
123 type: str
124 required: false
125 username:
126 description:
127 - Username for the proxy.
128 type: str
129 required: false
130 password:
131 description:
132 - Password for the proxy.
133 type: str
134 required: false
135 email:
136 description:
137 - Information particular to the e-mail delivery method.
138 - Uses the SMTP protocol.
139 - Required when I(method==email).
140 type: dict
141 required: false
142 suboptions:
143 server:
144 description:
145 - Mail server's IP address or fully qualified domain name.
146 - Required when I(routing_type==email).
147 type: str
148 required: false
149 sender:
150 description:
151 - Sender's email account
152 - Required when I(routing_type==email).
153 type: str
154 required: false
155 test_recipient:
156 description:
157 - Test verification email
158 - Required when I(routing_type==email).
159 type: str
160 required: false
161 maintenance_duration:
162 description:
163 - The duration of time the ASUP maintenance mode will be active.
164 - Permittable range is between 1 and 72 hours.
165 - Required when I(state==maintenance_enabled).
166 type: int
167 default: 24
168 required: false
169 maintenance_emails:
170 description:
171 - List of email addresses for maintenance notifications.
172 - Required when I(state==maintenance_enabled).
173 type: list
174 elements: str
175 required: false
176 validate:
177 description:
178 - Validate ASUP configuration.
179 type: bool
180 default: false
181 required: false
182 notes:
183 - Check mode is supported.
184 - Enabling ASUP will allow our support teams to monitor the logs of the storage-system in order to proactively
185 respond to issues with the system. It is recommended that all ASUP-related options be enabled, but they may be
186 disabled if desired.
187 - This API is currently only supported with the Embedded Web Services API v2.0 and higher.
188 """
189
190 EXAMPLES = """
191 - name: Enable ASUP and allow pro-active retrieval of bundles
192 na_santricity_asup:
193 ssid: "1"
194 api_url: "https://192.168.1.100:8443/devmgr/v2"
195 api_username: "admin"
196 api_password: "adminpass"
197 validate_certs: true
198 state: enabled
199 active: true
200 days: ["saturday", "sunday"]
201 start: 17
202 end: 20
203 - name: Set the ASUP schedule to only send bundles from 12 AM CST to 3 AM CST.
204 na_santricity_asup:
205 ssid: "1"
206 api_url: "https://192.168.1.100:8443/devmgr/v2"
207 api_username: "admin"
208 api_password: "adminpass"
209 validate_certs: true
210 state: disabled
211 - name: Set the ASUP schedule to only send bundles from 12 AM CST to 3 AM CST.
212 na_santricity_asup:
213 ssid: "1"
214 api_url: "https://192.168.1.100:8443/devmgr/v2"
215 api_username: "admin"
216 api_password: "adminpass"
217 state: maintenance_enabled
218 maintenance_duration: 24
219 maintenance_emails:
220 - [email protected]
221 - name: Set the ASUP schedule to only send bundles from 12 AM CST to 3 AM CST.
222 na_santricity_asup:
223 ssid: "1"
224 api_url: "https://192.168.1.100:8443/devmgr/v2"
225 api_username: "admin"
226 api_password: "adminpass"
227 validate_certs: true
228 state: maintenance_disabled
229 """
230
231 RETURN = """
232 msg:
233 description: Success message
234 returned: on success
235 type: str
236 sample: The settings have been updated.
237 asup:
238 description:
239 - True if ASUP is enabled.
240 returned: on success
241 sample: true
242 type: bool
243 active:
244 description:
245 - True if the active option has been enabled.
246 returned: on success
247 sample: true
248 type: bool
249 cfg:
250 description:
251 - Provide the full ASUP configuration.
252 returned: on success
253 type: complex
254 contains:
255 asupEnabled:
256 description:
257 - True if ASUP has been enabled.
258 type: bool
259 onDemandEnabled:
260 description:
261 - True if ASUP active monitoring has been enabled.
262 type: bool
263 daysOfWeek:
264 description:
265 - The days of the week that ASUP bundles will be sent.
266 type: list
267 """
268 import time
269
270 from ansible_collections.netapp_eseries.santricity.plugins.module_utils.santricity import NetAppESeriesModule
271 from ansible.module_utils._text import to_native
272
273
274 class NetAppESeriesAsup(NetAppESeriesModule):
275 DAYS_OPTIONS = ["sunday", "monday", "tuesday", "wednesday", "thursday", "friday", "saturday"]
276
277 def __init__(self):
278
279 ansible_options = dict(
280 state=dict(type="str", required=False, default="enabled", choices=["enabled", "disabled", "maintenance_enabled", "maintenance_disabled"]),
281 active=dict(type="bool", required=False, default=True),
282 days=dict(type="list", elements="str", required=False, aliases=["schedule_days", "days_of_week"], choices=self.DAYS_OPTIONS),
283 start=dict(type="int", required=False, default=0),
284 end=dict(type="int", required=False, default=24),
285 method=dict(type="str", required=False, choices=["https", "http", "email"], default="https"),
286 routing_type=dict(type="str", required=False, choices=["direct", "proxy", "script"], default="direct"),
287 proxy=dict(type="dict", required=False, options=dict(host=dict(type="str", required=False),
288 port=dict(type="int", required=False),
289 script=dict(type="str", required=False),
290 username=dict(type="str", required=False),
291 password=dict(type="str", no_log=True, required=False))),
292 email=dict(type="dict", required=False, options=dict(server=dict(type="str", required=False),
293 sender=dict(type="str", required=False),
294 test_recipient=dict(type="str", required=False))),
295 maintenance_duration=dict(type="int", required=False, default=24),
296 maintenance_emails=dict(type="list", elements="str", required=False),
297 validate=dict(type="bool", required=False, default=False))
298
299 # # mutually_exclusive did not work with suboptions. Comment out this for now.
300 # mutually_exclusive = [["host", "script"],
301 # ["port", "script"]]
302 mutually_exclusive = None
303
304 required_if = [["method", "https", ["routing_type"]],
305 ["method", "http", ["routing_type"]],
306 ["method", "email", ["email"]],
307 ["state", "maintenance_enabled", ["maintenance_duration", "maintenance_emails"]]]
308
309 super(NetAppESeriesAsup, self).__init__(ansible_options=ansible_options,
310 web_services_version="02.00.0000.0000",
311 mutually_exclusive=mutually_exclusive,
312 required_if=required_if,
313 supports_check_mode=True)
314
315 args = self.module.params
316 self.state = args["state"]
317 self.active = args["active"]
318 self.days = args["days"]
319 self.start = args["start"]
320 self.end = args["end"]
321
322 self.method = args["method"]
323 self.routing_type = args["routing_type"] if args["routing_type"] else "none"
324 self.proxy = args["proxy"]
325 self.email = args["email"]
326 self.maintenance_duration = args["maintenance_duration"]
327 self.maintenance_emails = args["maintenance_emails"]
328 self.validate = args["validate"]
329
330 if self.validate and self.email and "test_recipient" not in self.email.keys():
331 self.module.fail_json(msg="test_recipient must be provided for validating email delivery method. Array [%s]" % self.ssid)
332
333 self.check_mode = self.module.check_mode
334
335 if self.start >= self.end:
336 self.module.fail_json(msg="The value provided for the start time is invalid."
337 " It must be less than the end time.")
338 if self.start < 0 or self.start > 23:
339 self.module.fail_json(msg="The value provided for the start time is invalid. It must be between 0 and 23.")
340 else:
341 self.start = self.start * 60
342 if self.end < 1 or self.end > 24:
343 self.module.fail_json(msg="The value provided for the end time is invalid. It must be between 1 and 24.")
344 else:
345 self.end = min(self.end * 60, 1439)
346
347 if self.maintenance_duration < 1 or self.maintenance_duration > 72:
348 self.module.fail_json(msg="The maintenance duration must be equal to or between 1 and 72 hours.")
349
350 if not self.days:
351 self.days = self.DAYS_OPTIONS
352
353 # Check whether request needs to be forwarded on to the controller web services rest api.
354 self.url_path_prefix = ""
355 if not self.is_embedded() and self.ssid != "0" and self.ssid.lower() != "proxy":
356 self.url_path_prefix = "storage-systems/%s/forward/devmgr/v2/" % self.ssid
357
358 def get_configuration(self):
359 try:
360 rc, result = self.request(self.url_path_prefix + "device-asup")
361
362 if not (result["asupCapable"] and result["onDemandCapable"]):
363 self.module.fail_json(msg="ASUP is not supported on this device. Array Id [%s]." % self.ssid)
364 return result
365
366 except Exception as err:
367 self.module.fail_json(msg="Failed to retrieve ASUP configuration! Array Id [%s]. Error [%s]." % (self.ssid, to_native(err)))
368
369 def in_maintenance_mode(self):
370 """Determine whether storage device is currently in maintenance mode."""
371 results = False
372 try:
373 rc, key_values = self.request(self.url_path_prefix + "key-values")
374
375 for key_value in key_values:
376 if key_value["key"] == "ansible_asup_maintenance_email_list":
377 if not self.maintenance_emails:
378 self.maintenance_emails = key_value["value"].split(",")
379 elif key_value["key"] == "ansible_asup_maintenance_stop_time":
380 if time.time() < float(key_value["value"]):
381 results = True
382
383 except Exception as error:
384 self.module.fail_json(msg="Failed to retrieve maintenance windows information! Array [%s]. Error [%s]." % (self.ssid, to_native(error)))
385
386 return results
387
388 def update_configuration(self):
389 config = self.get_configuration()
390 update = False
391 body = dict()
392
393 # Build request body
394 if self.state == "enabled":
395 body = dict(asupEnabled=True)
396 if not config["asupEnabled"]:
397 update = True
398
399 if (config["onDemandEnabled"] and config["remoteDiagsEnabled"]) != self.active:
400 update = True
401 body.update(dict(onDemandEnabled=self.active,
402 remoteDiagsEnabled=self.active))
403 self.days.sort()
404 config["schedule"]["daysOfWeek"].sort()
405
406 body["schedule"] = dict(daysOfWeek=self.days,
407 dailyMinTime=self.start,
408 dailyMaxTime=self.end,
409 weeklyMinTime=self.start,
410 weeklyMaxTime=self.end)
411
412 if self.days != config["schedule"]["daysOfWeek"]:
413 update = True
414 if self.start != config["schedule"]["dailyMinTime"] or self.start != config["schedule"]["weeklyMinTime"]:
415 update = True
416 elif self.end != config["schedule"]["dailyMaxTime"] or self.end != config["schedule"]["weeklyMaxTime"]:
417 update = True
418
419 if self.method in ["https", "http"]:
420 if self.routing_type == "direct":
421 body["delivery"] = dict(method=self.method,
422 routingType="direct")
423 elif self.routing_type == "proxy":
424 body["delivery"] = dict(method=self.method,
425 proxyHost=self.proxy["host"],
426 proxyPort=self.proxy["port"],
427 routingType="proxyServer")
428 if "username" in self.proxy.keys():
429 body["delivery"].update({"proxyUserName": self.proxy["username"]})
430 if "password" in self.proxy.keys():
431 body["delivery"].update({"proxyPassword": self.proxy["password"]})
432
433 elif self.routing_type == "script":
434 body["delivery"] = dict(method=self.method,
435 proxyScript=self.proxy["script"],
436 routingType="proxyScript")
437
438 else:
439 body["delivery"] = dict(method="smtp",
440 mailRelayServer=self.email["server"],
441 mailSenderAddress=self.email["sender"],
442 routingType="none")
443
444 # Check whether changes are required.
445 if config["delivery"]["method"] != body["delivery"]["method"]:
446 update = True
447 elif config["delivery"]["method"] in ["https", "http"]:
448 if config["delivery"]["routingType"] != body["delivery"]["routingType"]:
449 update = True
450 elif config["delivery"]["routingType"] == "proxyServer":
451 if (config["delivery"]["proxyHost"] != body["delivery"]["proxyHost"] or
452 config["delivery"]["proxyPort"] != body["delivery"]["proxyPort"] or
453 config["delivery"]["proxyUserName"] != body["delivery"]["proxyUserName"] or
454 config["delivery"]["proxyPassword"] != body["delivery"]["proxyPassword"]):
455 update = True
456 elif config["delivery"]["routingType"] == "proxyScript":
457 if config["delivery"]["proxyScript"] != body["delivery"]["proxyScript"]:
458 update = True
459 elif (config["delivery"]["method"] == "smtp" and
460 config["delivery"]["mailRelayServer"] != body["delivery"]["mailRelayServer"] and
461 config["delivery"]["mailSenderAddress"] != body["delivery"]["mailSenderAddress"]):
462 update = True
463
464 if self.in_maintenance_mode():
465 update = True
466
467 elif self.state == "disabled":
468 if config["asupEnabled"]: # Disable asupEnable is asup is disabled.
469 body = dict(asupEnabled=False)
470 update = True
471
472 else:
473 if not config["asupEnabled"]:
474 self.module.fail_json(msg="AutoSupport must be enabled before enabling or disabling maintenance mode. Array [%s]." % self.ssid)
475
476 if self.in_maintenance_mode() or self.state == "maintenance_enabled":
477 update = True
478
479 # Apply required changes.
480 if update and not self.check_mode:
481 if self.state == "maintenance_enabled":
482 try:
483 rc, response = self.request(self.url_path_prefix + "device-asup/maintenance-window", method="POST",
484 data=dict(maintenanceWindowEnabled=True,
485 duration=self.maintenance_duration,
486 emailAddresses=self.maintenance_emails))
487 except Exception as error:
488 self.module.fail_json(msg="Failed to enabled ASUP maintenance window. Array [%s]. Error [%s]." % (self.ssid, to_native(error)))
489
490 # Add maintenance information to the key-value store
491 try:
492 rc, response = self.request(self.url_path_prefix + "key-values/ansible_asup_maintenance_email_list", method="POST",
493 data=",".join(self.maintenance_emails))
494 rc, response = self.request(self.url_path_prefix + "key-values/ansible_asup_maintenance_stop_time", method="POST",
495 data=str(time.time() + 60 * 60 * self.maintenance_duration))
496 except Exception as error:
497 self.module.fail_json(msg="Failed to store maintenance information. Array [%s]. Error [%s]." % (self.ssid, to_native(error)))
498
499 elif self.state == "maintenance_disabled":
500 try:
501 rc, response = self.request(self.url_path_prefix + "device-asup/maintenance-window", method="POST",
502 data=dict(maintenanceWindowEnabled=False,
503 emailAddresses=self.maintenance_emails))
504 except Exception as error:
505 self.module.fail_json(msg="Failed to disable ASUP maintenance window. Array [%s]. Error [%s]." % (self.ssid, to_native(error)))
506
507 # Remove maintenance information to the key-value store
508 try:
509 rc, response = self.request(self.url_path_prefix + "key-values/ansible_asup_maintenance_email_list", method="DELETE")
510 rc, response = self.request(self.url_path_prefix + "key-values/ansible_asup_maintenance_stop_time", method="DELETE")
511 except Exception as error:
512 self.module.fail_json(msg="Failed to store maintenance information. Array [%s]. Error [%s]." % (self.ssid, to_native(error)))
513
514 else:
515 if body["asupEnabled"] and self.validate:
516 validate_body = dict(delivery=body["delivery"])
517 if self.email:
518 validate_body["mailReplyAddress"] = self.email["test_recipient"]
519
520 try:
521 rc, response = self.request(self.url_path_prefix + "device-asup/verify-config", timeout=600, method="POST", data=validate_body)
522 except Exception as err:
523 self.module.fail_json(msg="Failed to validate ASUP configuration! Array Id [%s]. Error [%s]." % (self.ssid, to_native(err)))
524
525 try:
526 rc, response = self.request(self.url_path_prefix + "device-asup", method="POST", data=body)
527 # This is going to catch cases like a connection failure
528 except Exception as err:
529 self.module.fail_json(msg="Failed to change ASUP configuration! Array Id [%s]. Error [%s]." % (self.ssid, to_native(err)))
530
531 return update
532
533 def apply(self):
534 update = self.update_configuration()
535 cfg = self.get_configuration()
536
537 if update:
538 self.module.exit_json(msg="The ASUP settings have been updated.", changed=update, asup=cfg["asupEnabled"], active=cfg["onDemandEnabled"], cfg=cfg)
539 else:
540 self.module.exit_json(msg="No ASUP changes required.", changed=update, asup=cfg["asupEnabled"], active=cfg["onDemandEnabled"], cfg=cfg)
541
542
543 def main():
544 asup = NetAppESeriesAsup()
545 asup.apply()
546
547
548 if __name__ == "__main__":
549 main()