Debian Codegraph @

ansible_collections/netapp_eseries/santricity/plugins/modules/na_santricity_firmware.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_firmware
12 short_description: NetApp E-Series manage firmware.
13 description:
14 - Ensure specific firmware versions are activated on E-Series storage system.
15 author:
16 - Nathan Swartz (@swartzn)
17 - Vu Tran (@VuTran007)
18 extends_documentation_fragment:
19 - netapp_eseries.santricity.santricity.santricity_doc
20 options:
21 nvsram:
22 description:
23 - Path to the NVSRAM file.
24 - NetApp recommends upgrading the NVSRAM when upgrading firmware.
25 - Due to concurrency issues, use M(netapp_eseries.santricity.na_santricity_proxy_firmware_upload) to upload
26 firmware and nvsram to SANtricity Web Services Proxy when upgrading multiple systems at the same time on
27 the same instance of the proxy.
28 type: str
29 required: false
30 firmware:
31 description:
32 - Path to the firmware file.
33 - Due to concurrency issues, use M(netapp_eseries.santricity.na_santricity_proxy_firmware_upload) to upload
34 firmware and nvsram to SANtricity Web Services Proxy when upgrading multiple systems at the same time on
35 the same instance of the proxy.
36 type: str
37 required: True
38 wait_for_completion:
39 description:
40 - This flag will cause module to wait for any upgrade actions to complete.
41 - When changes are required to both firmware and nvsram and task is executed against SANtricity Web Services Proxy,
42 the firmware will have to complete before nvsram can be installed.
43 type: bool
44 default: false
45 clear_mel_events:
46 description:
47 - This flag will force firmware to be activated in spite of the storage system mel-event issues.
48 - Warning! This will clear all storage system mel-events. Use at your own risk!
49 type: bool
50 default: false
51 """
52 EXAMPLES = """
53 - name: Ensure correct firmware versions
54 na_santricity_firmware:
55 ssid: "1"
56 api_url: "https://192.168.1.100:8443/devmgr/v2"
57 api_username: "admin"
58 api_password: "adminpass"
59 validate_certs: true
60 nvsram: "path/to/nvsram"
61 firmware: "path/to/bundle"
62 wait_for_completion: true
63 clear_mel_events: true
64 - name: Ensure correct firmware versions
65 na_santricity_firmware:
66 ssid: "1"
67 api_url: "https://192.168.1.100:8443/devmgr/v2"
68 api_username: "admin"
69 api_password: "adminpass"
70 validate_certs: true
71 nvsram: "path/to/nvsram"
72 firmware: "path/to/firmware"
73 """
74 RETURN = """
75 msg:
76 description: Status and version of firmware and NVSRAM.
77 type: str
78 returned: always
79 sample:
80 """
81 import os
82 import threading
83
84 from time import sleep
85 from ansible.module_utils import six
86 from ansible_collections.netapp_eseries.santricity.plugins.module_utils.santricity import NetAppESeriesModule, create_multipart_formdata
87 from ansible.module_utils._text import to_native
88
89
90 class NetAppESeriesFirmware(NetAppESeriesModule):
91 COMPATIBILITY_CHECK_TIMEOUT_SEC = 60
92 REBOOT_TIMEOUT_SEC = 30 * 60
93 MINIMUM_PROXY_VERSION = "04.10.00.0000"
94
95 def __init__(self):
96 ansible_options = dict(
97 nvsram=dict(type="str", required=False),
98 firmware=dict(type="str", required=True),
99 wait_for_completion=dict(type="bool", default=False),
100 clear_mel_events=dict(type="bool", default=False))
101
102 super(NetAppESeriesFirmware, self).__init__(ansible_options=ansible_options,
103 web_services_version="02.00.0000.0000",
104 supports_check_mode=True)
105
106 args = self.module.params
107 self.nvsram = args["nvsram"]
108 self.firmware = args["firmware"]
109 self.wait_for_completion = args["wait_for_completion"]
110 self.clear_mel_events = args["clear_mel_events"]
111
112 self.nvsram_name = None
113 self.firmware_name = None
114 self.is_bundle_cache = None
115 self.firmware_version_cache = None
116 self.nvsram_version_cache = None
117 self.upgrade_required = False
118 self.upgrade_in_progress = False
119 self.module_info = dict()
120
121 if self.nvsram:
122 self.nvsram_name = os.path.basename(self.nvsram)
123 if self.firmware:
124 self.firmware_name = os.path.basename(self.firmware)
125
126 self.last_known_event = -1
127 self.is_firmware_activation_started_mel_event_count = 1
128 self.is_nvsram_download_completed_mel_event_count = 1
129 self.proxy_wait_for_upgrade_mel_event_count = 1
130
131 def is_upgrade_in_progress(self):
132 """Determine whether an upgrade is already in progress."""
133 in_progress = False
134
135 if self.is_proxy():
136 try:
137 rc, status = self.request("storage-systems/%s/cfw-upgrade" % self.ssid)
138 in_progress = status["running"]
139 except Exception as error:
140 if "errorMessage" in to_native(error):
141 self.module.warn("Failed to retrieve upgrade status. Array [%s]. Error [%s]." % (self.ssid, error))
142 in_progress = False
143 else:
144 self.module.fail_json(msg="Failed to retrieve upgrade status. Array [%s]. Error [%s]." % (self.ssid, error))
145 else:
146 in_progress = False
147
148 return in_progress
149
150 def is_firmware_bundled(self):
151 """Determine whether supplied firmware is bundle."""
152 if self.is_bundle_cache is None:
153 with open(self.firmware, "rb") as fh:
154 signature = fh.read(16).lower()
155
156 if b"firmware" in signature:
157 self.is_bundle_cache = False
158 elif b"combined_content" in signature:
159 self.is_bundle_cache = True
160 else:
161 self.module.fail_json(msg="Firmware file is invalid. File [%s]. Array [%s]" % (self.firmware, self.ssid))
162
163 return self.is_bundle_cache
164
165 def firmware_version(self):
166 """Retrieve firmware version of the firmware file. Return: bytes string"""
167 if self.firmware_version_cache is None:
168
169 # Search firmware file for bundle or firmware version
170 with open(self.firmware, "rb") as fh:
171 line = fh.readline()
172 while line:
173 if self.is_firmware_bundled():
174 if b'displayableAttributeList=' in line:
175 for item in line[25:].split(b','):
176 key, value = item.split(b"|")
177 if key == b'VERSION':
178 self.firmware_version_cache = value.strip(b"\n")
179 break
180 elif b"Version:" in line:
181 self.firmware_version_cache = line.split()[-1].strip(b"\n")
182 break
183 line = fh.readline()
184 else:
185 self.module.fail_json(msg="Failed to determine firmware version. File [%s]. Array [%s]." % (self.firmware, self.ssid))
186 return self.firmware_version_cache
187
188 def nvsram_version(self):
189 """Retrieve NVSRAM version of the NVSRAM file. Return: byte string"""
190 if self.nvsram_version_cache is None:
191
192 with open(self.nvsram, "rb") as fh:
193 line = fh.readline()
194 while line:
195 if b".NVSRAM Configuration Number" in line:
196 self.nvsram_version_cache = line.split(b'"')[-2]
197 break
198 line = fh.readline()
199 else:
200 self.module.fail_json(msg="Failed to determine NVSRAM file version. File [%s]. Array [%s]." % (self.nvsram, self.ssid))
201 return self.nvsram_version_cache
202
203 def check_system_health(self):
204 """Ensure E-Series storage system is healthy. Works for both embedded and proxy web services."""
205 try:
206 rc, response = self.request("storage-systems/%s/health-check" % self.ssid, method="POST")
207 return response["successful"]
208 except Exception as error:
209 self.module.fail_json(msg="Health check failed! Array Id [%s]. Error[%s]." % (self.ssid, to_native(error)))
210
211 def embedded_check_compatibility(self):
212 """Verify files are compatible with E-Series storage system."""
213 if self.nvsram:
214 self.embedded_check_nvsram_compatibility()
215 if self.firmware:
216 self.embedded_check_bundle_compatibility()
217
218 def embedded_check_nvsram_compatibility(self):
219 """Verify the provided NVSRAM is compatible with E-Series storage system."""
220 files = [("nvsramimage", self.nvsram_name, self.nvsram)]
221 headers, data = create_multipart_formdata(files=files)
222 compatible = {}
223 try:
224 rc, compatible = self.request("firmware/embedded-firmware/%s/nvsram-compatibility-check" % self.ssid, method="POST", data=data, headers=headers)
225 except Exception as error:
226 self.module.fail_json(msg="Failed to retrieve NVSRAM compatibility results. Array Id [%s]. Error[%s]." % (self.ssid, to_native(error)))
227
228 if not compatible["signatureTestingPassed"]:
229 self.module.fail_json(msg="Invalid NVSRAM file. File [%s]." % self.nvsram)
230 if not compatible["fileCompatible"]:
231 self.module.fail_json(msg="Incompatible NVSRAM file. File [%s]." % self.nvsram)
232
233 # Determine whether nvsram upgrade is required
234 for module in compatible["versionContents"]:
235 if module["bundledVersion"] != module["onboardVersion"]:
236 self.upgrade_required = True
237
238 # Update bundle info
239 self.module_info.update({module["module"]: {"onboard_version": module["onboardVersion"], "bundled_version": module["bundledVersion"]}})
240
241 def embedded_check_bundle_compatibility(self):
242 """Verify the provided firmware bundle is compatible with E-Series storage system."""
243 files = [("files[]", "blob", self.firmware)]
244 headers, data = create_multipart_formdata(files=files, send_8kb=True)
245 compatible = {}
246 try:
247 rc, compatible = self.request("firmware/embedded-firmware/%s/bundle-compatibility-check" % self.ssid, method="POST", data=data, headers=headers)
248 except Exception as error:
249 self.module.fail_json(msg="Failed to retrieve bundle compatibility results. Array Id [%s]. Error[%s]." % (self.ssid, to_native(error)))
250
251 # Determine whether valid and compatible firmware
252 if not compatible["signatureTestingPassed"]:
253 self.module.fail_json(msg="Invalid firmware bundle file. File [%s]." % self.firmware)
254 if not compatible["fileCompatible"]:
255 self.module.fail_json(msg="Incompatible firmware bundle file. File [%s]." % self.firmware)
256
257 # Determine whether bundle upgrade is required
258 for module in compatible["versionContents"]:
259 bundle_module_version = module["bundledVersion"].split(".")
260 onboard_module_version = module["onboardVersion"].split(".")
261 version_minimum_length = min(len(bundle_module_version), len(onboard_module_version))
262
263 if bundle_module_version[:version_minimum_length] != onboard_module_version[:version_minimum_length]:
264 self.upgrade_required = True
265
266 # Build the modules information for logging purposes
267 self.module_info.update({module["module"]: {"onboard_version": module["onboardVersion"], "bundled_version": module["bundledVersion"]}})
268
269 def embedded_firmware_activate(self):
270 """Activate firmware."""
271 rc, response = self.request("firmware/embedded-firmware/activate", method="POST", ignore_errors=True, timeout=10)
272 if rc == "422":
273 self.module.fail_json(msg="Failed to activate the staged firmware. Array Id [%s]. Error [%s]" % (self.ssid, response))
274
275 def embedded_firmware_download(self):
276 """Execute the firmware download."""
277 if self.nvsram:
278 firmware_url = "firmware/embedded-firmware?nvsram=true&staged=true"
279 headers, data = create_multipart_formdata(files=[("nvsramfile", self.nvsram_name, self.nvsram),
280 ("dlpfile", self.firmware_name, self.firmware)])
281 else:
282 firmware_url = "firmware/embedded-firmware?nvsram=false&staged=true"
283 headers, data = create_multipart_formdata(files=[("dlpfile", self.firmware_name, self.firmware)])
284
285 # Stage firmware and nvsram
286 try:
287
288 rc, response = self.request(firmware_url, method="POST", data=data, headers=headers, timeout=(30 * 60))
289 except Exception as error:
290 self.module.fail_json(msg="Failed to stage firmware. Array Id [%s]. Error[%s]." % (self.ssid, to_native(error)))
291
292 # Activate firmware
293 activate_thread = threading.Thread(target=self.embedded_firmware_activate)
294 activate_thread.start()
295 self.wait_for_reboot()
296
297 def wait_for_reboot(self):
298 """Wait for controller A to fully reboot and web services running"""
299 reboot_started = False
300 reboot_completed = False
301 self.module.log("Controller firmware: Reboot commencing. Array Id [%s]." % self.ssid)
302 while self.wait_for_completion and not (reboot_started and reboot_completed):
303 try:
304 rc, response = self.request("storage-systems/%s/symbol/pingController?controller=a&verboseErrorResponse=true"
305 % self.ssid, method="POST", timeout=10, log_request=False)
306
307 if reboot_started and response == "ok":
308 self.module.log("Controller firmware: Reboot completed. Array Id [%s]." % self.ssid)
309 reboot_completed = True
310 sleep(2)
311 except Exception as error:
312 if not reboot_started:
313 self.module.log("Controller firmware: Reboot started. Array Id [%s]." % self.ssid)
314 reboot_started = True
315 continue
316
317 def firmware_event_logger(self):
318 """Determine if firmware activation has started."""
319 # Determine the last known event
320 try:
321 rc, events = self.request("storage-systems/%s/events" % self.ssid)
322 for event in events:
323 if int(event["eventNumber"]) > int(self.last_known_event):
324 self.last_known_event = event["eventNumber"]
325 except Exception as error:
326 self.module.fail_json(msg="Failed to determine last known event. Array Id [%s]. Error[%s]." % (self.ssid, to_native(error)))
327
328 while True:
329 try:
330 rc, events = self.request("storage-systems/%s/events?lastKnown=%s&wait=1" % (self.ssid, self.last_known_event), log_request=False)
331 for event in events:
332 if int(event["eventNumber"]) > int(self.last_known_event):
333 self.last_known_event = event["eventNumber"]
334
335 # Log firmware events
336 if event["eventType"] == "firmwareDownloadEvent":
337 self.module.log("%s" % event["status"])
338 if event["status"] == "informational" and event["statusMessage"]:
339 self.module.log("Controller firmware: %s Array Id [%s]." % (event["statusMessage"], self.ssid))
340
341 # When activation is successful, finish thread
342 if event["status"] == "activate_success":
343 self.module.log("Controller firmware activated. Array Id [%s]." % self.ssid)
344 return
345 except Exception as error:
346 pass
347
348 def wait_for_web_services(self):
349 """Wait for web services to report firmware and nvsram upgrade."""
350 # Wait for system to reflect changes
351 for count in range(int(self.REBOOT_TIMEOUT_SEC / 5)):
352 try:
353 if self.is_firmware_bundled():
354 firmware_rc, firmware_version = self.request("storage-systems/%s/graph/xpath-filter?query=/controller/"
355 "codeVersions[codeModule='bundleDisplay']" % self.ssid, log_request=False)
356 current_firmware_version = six.b(firmware_version[0]["versionString"])
357 else:
358 firmware_rc, firmware_version = self.request("storage-systems/%s/graph/xpath-filter?query=/sa/saData/fwVersion"
359 % self.ssid, log_request=False)
360 current_firmware_version = six.b(firmware_version[0])
361
362 nvsram_rc, nvsram_version = self.request("storage-systems/%s/graph/xpath-filter?query=/sa/saData/nvsramVersion" % self.ssid, log_request=False)
363 current_nvsram_version = six.b(nvsram_version[0])
364
365 if current_firmware_version == self.firmware_version() and (not self.nvsram or current_nvsram_version == self.nvsram_version()):
366 break
367 except Exception as error:
368 pass
369 sleep(5)
370 else:
371 self.module.fail_json(msg="Timeout waiting for Santricity Web Services. Array [%s]" % self.ssid)
372
373 # Wait for system to be optimal
374 for count in range(int(self.REBOOT_TIMEOUT_SEC / 5)):
375 try:
376 rc, response = self.request("storage-systems/%s" % self.ssid, log_request=False)
377
378 if response["status"] == "optimal":
379 self.upgrade_in_progress = False
380 break
381 except Exception as error:
382 pass
383 sleep(5)
384 else:
385 self.module.fail_json(msg="Timeout waiting for storage system to return to optimal status. Array [%s]" % self.ssid)
386
387 def embedded_upgrade(self):
388 """Upload and activate both firmware and NVSRAM."""
389 download_thread = threading.Thread(target=self.embedded_firmware_download)
390 event_thread = threading.Thread(target=self.firmware_event_logger)
391 download_thread.start()
392 event_thread.start()
393 download_thread.join()
394 event_thread.join()
395
396 def proxy_check_nvsram_compatibility(self, retries=10):
397 """Verify nvsram is compatible with E-Series storage system."""
398 self.module.log("Checking nvsram compatibility...")
399 data = {"storageDeviceIds": [self.ssid]}
400 try:
401 rc, check = self.request("firmware/compatibility-check", method="POST", data=data)
402 except Exception as error:
403 if retries:
404 sleep(1)
405 self.proxy_check_nvsram_compatibility(retries - 1)
406 else:
407 self.module.fail_json(msg="Failed to receive NVSRAM compatibility information. Array [%s]. Error [%s]." % (self.ssid, to_native(error)))
408
409 for count in range(int(self.COMPATIBILITY_CHECK_TIMEOUT_SEC / 5)):
410 try:
411 rc, response = self.request("firmware/compatibility-check?requestId=%s" % check["requestId"])
412 except Exception as error:
413 continue
414
415 if not response["checkRunning"]:
416 for result in response["results"][0]["nvsramFiles"]:
417 if result["filename"] == self.nvsram_name:
418 return
419 self.module.fail_json(msg="NVSRAM is not compatible. NVSRAM [%s]. Array [%s]." % (self.nvsram_name, self.ssid))
420 sleep(5)
421
422 self.module.fail_json(msg="Failed to retrieve NVSRAM status update from proxy. Array [%s]." % self.ssid)
423
424 def proxy_check_firmware_compatibility(self, retries=10):
425 """Verify firmware is compatible with E-Series storage system."""
426 check = {}
427 try:
428 rc, check = self.request("firmware/compatibility-check", method="POST", data={"storageDeviceIds": [self.ssid]})
429 except Exception as error:
430 if retries:
431 sleep(1)
432 self.proxy_check_firmware_compatibility(retries - 1)
433 else:
434 self.module.fail_json(msg="Failed to receive firmware compatibility information. Array [%s]. Error [%s]." % (self.ssid, to_native(error)))
435
436 for count in range(int(self.COMPATIBILITY_CHECK_TIMEOUT_SEC / 5)):
437 try:
438 rc, response = self.request("firmware/compatibility-check?requestId=%s" % check["requestId"])
439 except Exception as error:
440 continue
441
442 if not response["checkRunning"]:
443 for result in response["results"][0]["cfwFiles"]:
444 if result["filename"] == self.firmware_name:
445 return
446 self.module.fail_json(msg="Firmware bundle is not compatible. firmware [%s]. Array [%s]." % (self.firmware_name, self.ssid))
447 sleep(5)
448
449 self.module.fail_json(msg="Failed to retrieve firmware status update from proxy. Array [%s]." % self.ssid)
450
451 def proxy_upload_and_check_compatibility(self):
452 """Ensure firmware/nvsram file is uploaded and verify compatibility."""
453 uploaded_files = []
454 try:
455 rc, uploaded_files = self.request("firmware/cfw-files")
456 except Exception as error:
457 self.module.fail_json(msg="Failed to retrieve uploaded firmware and nvsram files. Error [%s]" % to_native(error))
458
459 if self.firmware:
460 for uploaded_file in uploaded_files:
461 if uploaded_file["filename"] == self.firmware_name:
462 break
463 else:
464 fields = [("validate", "true")]
465 files = [("firmwareFile", self.firmware_name, self.firmware)]
466 headers, data = create_multipart_formdata(files=files, fields=fields)
467 try:
468 rc, response = self.request("firmware/upload", method="POST", data=data, headers=headers)
469 except Exception as error:
470 self.module.fail_json(msg="Failed to upload firmware bundle file. File [%s]. Array [%s]. Error [%s]."
471 % (self.firmware_name, self.ssid, to_native(error)))
472 self.proxy_check_firmware_compatibility()
473
474 if self.nvsram:
475 for uploaded_file in uploaded_files:
476 if uploaded_file["filename"] == self.nvsram_name:
477 break
478 else:
479 fields = [("validate", "true")]
480 files = [("firmwareFile", self.nvsram_name, self.nvsram)]
481 headers, data = create_multipart_formdata(files=files, fields=fields)
482 try:
483 rc, response = self.request("firmware/upload", method="POST", data=data, headers=headers)
484 except Exception as error:
485 self.module.fail_json(msg="Failed to upload NVSRAM file. File [%s]. Array [%s]. Error [%s]."
486 % (self.nvsram_name, self.ssid, to_native(error)))
487 self.proxy_check_nvsram_compatibility()
488
489 def proxy_check_upgrade_required(self):
490 """Determine whether the onboard firmware/nvsram version is the same as the file"""
491 # Verify controller consistency and get firmware versions
492 if self.firmware:
493 current_firmware_version = b""
494 try:
495 # Retrieve current bundle version
496 if self.is_firmware_bundled():
497 rc, response = self.request("storage-systems/%s/graph/xpath-filter?query=/controller/codeVersions[codeModule='bundleDisplay']" % self.ssid)
498 current_firmware_version = six.b(response[0]["versionString"])
499 else:
500 rc, response = self.request("storage-systems/%s/graph/xpath-filter?query=/sa/saData/fwVersion" % self.ssid)
501 current_firmware_version = six.b(response[0])
502 except Exception as error:
503 self.module.fail_json(msg="Failed to retrieve controller firmware information. Array [%s]. Error [%s]" % (self.ssid, to_native(error)))
504
505 # Determine whether the current firmware version is the same as the file
506 new_firmware_version = self.firmware_version()
507 if current_firmware_version != new_firmware_version:
508 self.upgrade_required = True
509
510 # Build the modules information for logging purposes
511 self.module_info.update({"bundleDisplay": {"onboard_version": current_firmware_version, "bundled_version": new_firmware_version}})
512
513 # Determine current NVSRAM version and whether change is required
514 if self.nvsram:
515 try:
516 rc, response = self.request("storage-systems/%s/graph/xpath-filter?query=/sa/saData/nvsramVersion" % self.ssid)
517
518 if six.b(response[0]) != self.nvsram_version():
519 self.upgrade_required = True
520 except Exception as error:
521 self.module.fail_json(msg="Failed to retrieve storage system's NVSRAM version. Array [%s]. Error [%s]" % (self.ssid, to_native(error)))
522
523 def proxy_wait_for_upgrade(self):
524 """Wait for SANtricity Web Services Proxy to report upgrade complete"""
525 self.module.log("(Proxy) Waiting for upgrade to complete...")
526
527 status = {}
528 while True:
529 try:
530 rc, status = self.request("storage-systems/%s/cfw-upgrade" % self.ssid, log_request=False, ignore_errors=True)
531 except Exception as error:
532 self.module.fail_json(msg="Failed to retrieve firmware upgrade status! Array [%s]. Error[%s]." % (self.ssid, to_native(error)))
533
534 if "errorMessage" in status:
535 self.module.warn("Proxy reported an error. Checking whether upgrade completed. Array [%s]. Error [%s]." % (self.ssid, status["errorMessage"]))
536 self.wait_for_web_services()
537 break
538
539 if not status["running"]:
540 if status["activationCompletionTime"]:
541 self.upgrade_in_progress = False
542 break
543 else:
544 self.module.fail_json(msg="Failed to complete upgrade. Array [%s]." % self.ssid)
545 sleep(5)
546
547 def delete_mel_events(self):
548 """Clear all mel-events."""
549 try:
550 rc, response = self.request("storage-systems/%s/mel-events?clearCache=true&resetMel=true" % self.ssid, method="DELETE")
551 except Exception as error:
552 self.module.fail_json(msg="Failed to clear mel-events. Array [%s]. Error [%s]." % (self.ssid, to_native(error)))
553
554 def proxy_upgrade(self):
555 """Activate previously uploaded firmware related files."""
556 self.module.log("(Proxy) Firmware upgrade commencing...")
557 body = {"stageFirmware": False, "skipMelCheck": self.clear_mel_events, "cfwFile": self.firmware_name}
558 if self.nvsram:
559 body.update({"nvsramFile": self.nvsram_name})
560
561 try:
562 rc, response = self.request("storage-systems/%s/cfw-upgrade" % self.ssid, method="POST", data=body)
563 except Exception as error:
564 self.module.fail_json(msg="Failed to initiate firmware upgrade. Array [%s]. Error [%s]." % (self.ssid, to_native(error)))
565
566 self.upgrade_in_progress = True
567 if self.wait_for_completion:
568 self.proxy_wait_for_upgrade()
569
570 def apply(self):
571 """Upgrade controller firmware."""
572 if self.is_upgrade_in_progress():
573 self.module.fail_json(msg="Upgrade is already is progress. Array [%s]." % self.ssid)
574
575 if self.is_embedded():
576 self.embedded_check_compatibility()
577 else:
578 if not self.is_web_services_version_met(self.MINIMUM_PROXY_VERSION):
579 self.module.fail_json(msg="Minimum proxy version %s required!")
580 self.proxy_check_upgrade_required()
581
582 # This will upload the firmware files to the web services proxy but not to the controller
583 if self.upgrade_required:
584 self.proxy_upload_and_check_compatibility()
585
586 # Perform upgrade
587 if self.upgrade_required and not self.module.check_mode:
588
589 if self.clear_mel_events:
590 self.delete_mel_events()
591
592 if self.is_embedded():
593 self.embedded_upgrade()
594 else:
595 self.proxy_upgrade()
596
597 self.module.exit_json(changed=self.upgrade_required, upgrade_in_process=self.upgrade_in_progress, modules_info=self.module_info)
598
599
600 def main():
601 firmware = NetAppESeriesFirmware()
602 firmware.apply()
603
604
605 if __name__ == "__main__":
606 main()