Debian Codegraph @

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

raw
1 #!/usr/bin/python
2
3 # (c) 2018, NetApp, Inc
4 # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
5
6 from __future__ import absolute_import, division, print_function
7
8 __metaclass__ = type
9
10 ANSIBLE_METADATA = {'metadata_version': '1.1',
11 'status': ['deprecated'],
12 'supported_by': 'community'}
13
14 DOCUMENTATION = """
15 ---
16 module: netapp_e_mgmt_interface
17 short_description: NetApp E-Series management interface configuration
18 description:
19 - Configure the E-Series management interfaces
20 version_added: '2.7.0'
21 author:
22 - Michael Price (@lmprice)
23 - Nathan Swartz (@ndswartz)
24 extends_documentation_fragment:
25 - netapp_eseries.santricity.santricity.netapp.eseries
26 options:
27 state:
28 description:
29 - Enable or disable IPv4 network interface configuration.
30 - Either IPv4 or IPv6 must be enabled otherwise error will occur.
31 - Only required when enabling or disabling IPv4 network interface
32 choices:
33 - enable
34 - disable
35 required: no
36 type: str
37 aliases:
38 - enable_interface
39 controller:
40 description:
41 - The controller that owns the port you want to configure.
42 - Controller names are represented alphabetically, with the first controller as A,
43 the second as B, and so on.
44 - Current hardware models have either 1 or 2 available controllers, but that is not a guaranteed hard
45 limitation and could change in the future.
46 required: yes
47 type: str
48 choices:
49 - A
50 - B
51 name:
52 description:
53 - The port to modify the configuration for.
54 - The list of choices is not necessarily comprehensive. It depends on the number of ports
55 that are present in the system.
56 - The name represents the port number (typically from left to right on the controller),
57 beginning with a value of 1.
58 - Mutually exclusive with I(channel).
59 type: str
60 aliases:
61 - port
62 - iface
63 channel:
64 description:
65 - The port to modify the configuration for.
66 - The channel represents the port number (typically from left to right on the controller),
67 beginning with a value of 1.
68 - Mutually exclusive with I(name).
69 type: int
70 address:
71 description:
72 - The IPv4 address to assign to the interface.
73 - Should be specified in xx.xx.xx.xx form.
74 - Mutually exclusive with I(config_method=dhcp)
75 type: str
76 required: no
77 subnet_mask:
78 description:
79 - The subnet mask to utilize for the interface.
80 - Should be specified in xx.xx.xx.xx form.
81 - Mutually exclusive with I(config_method=dhcp)
82 type: str
83 required: no
84 gateway:
85 description:
86 - The IPv4 gateway address to utilize for the interface.
87 - Should be specified in xx.xx.xx.xx form.
88 - Mutually exclusive with I(config_method=dhcp)
89 type: str
90 required: no
91 config_method:
92 description:
93 - The configuration method type to use for network interface ports.
94 - dhcp is mutually exclusive with I(address), I(subnet_mask), and I(gateway).
95 choices:
96 - dhcp
97 - static
98 type: str
99 required: no
100 dns_config_method:
101 description:
102 - The configuration method type to use for DNS services.
103 - dhcp is mutually exclusive with I(dns_address), and I(dns_address_backup).
104 choices:
105 - dhcp
106 - static
107 type: str
108 required: no
109 dns_address:
110 description:
111 - Primary IPv4 DNS server address
112 type: str
113 required: no
114 dns_address_backup:
115 description:
116 - Backup IPv4 DNS server address
117 - Queried when primary DNS server fails
118 type: str
119 required: no
120 ntp_config_method:
121 description:
122 - The configuration method type to use for NTP services.
123 - disable is mutually exclusive with I(ntp_address) and I(ntp_address_backup).
124 - dhcp is mutually exclusive with I(ntp_address) and I(ntp_address_backup).
125 choices:
126 - disable
127 - dhcp
128 - static
129 type: str
130 required: no
131 ntp_address:
132 description:
133 - Primary IPv4 NTP server address
134 type: str
135 required: no
136 ntp_address_backup:
137 description:
138 - Backup IPv4 NTP server address
139 - Queried when primary NTP server fails
140 required: no
141 type: str
142 ssh:
143 type: bool
144 description:
145 - Enable ssh access to the controller for debug purposes.
146 - This is a controller-level setting.
147 - rlogin/telnet will be enabled for ancient equipment where ssh is not available.
148 required: no
149 log_path:
150 description:
151 - A local path to a file to be used for debug logging
152 type: str
153 required: no
154 notes:
155 - Check mode is supported.
156 - The interface settings are applied synchronously, but changes to the interface itself (receiving a new IP address
157 via dhcp, etc), can take seconds or minutes longer to take effect.
158 - "Known issue: Changes specifically to down ports will result in a failure. However, this may not be the case in up
159 coming NetApp E-Series firmware releases (released after firmware version 11.40.2)."
160 """
161
162 EXAMPLES = """
163 - name: Configure the first port on the A controller with a static IPv4 address
164 netapp_e_mgmt_interface:
165 channel: 1
166 controller: "A"
167 config_method: static
168 address: "192.168.1.100"
169 subnet_mask: "255.255.255.0"
170 gateway: "192.168.1.1"
171 ssid: "1"
172 api_url: "10.1.1.1:8443"
173 api_username: "admin"
174 api_password: "myPass"
175
176 - name: Disable ipv4 connectivity for the second port on the B controller
177 netapp_e_mgmt_interface:
178 channel: 2
179 controller: "B"
180 enable_interface: no
181 ssid: "{{ ssid }}"
182 api_url: "{{ netapp_api_url }}"
183 api_username: "{{ netapp_api_username }}"
184 api_password: "{{ netapp_api_password }}"
185
186 - name: Enable ssh access for ports one and two on controller A
187 netapp_e_mgmt_interface:
188 channel: "{{ item }}"
189 controller: "A"
190 ssh: yes
191 ssid: "{{ ssid }}"
192 api_url: "{{ netapp_api_url }}"
193 api_username: "{{ netapp_api_username }}"
194 api_password: "{{ netapp_api_password }}"
195 loop:
196 - 1
197 - 2
198
199 - name: Configure static DNS settings for the first port on controller A
200 netapp_e_mgmt_interface:
201 channel: 1
202 controller: "A"
203 dns_config_method: static
204 dns_address: "192.168.1.100"
205 dns_address_backup: "192.168.1.1"
206 ssid: "{{ ssid }}"
207 api_url: "{{ netapp_api_url }}"
208 api_username: "{{ netapp_api_username }}"
209 api_password: "{{ netapp_api_password }}"
210
211 - name: Configure static NTP settings for ports one and two on controller B
212 netapp_e_mgmt_interface:
213 channel: "{{ item }}"
214 controller: "B"
215 ntp_config_method: static
216 ntp_address: "129.100.1.100"
217 ntp_address_backup: "127.100.1.1"
218 ssid: "{{ ssid }}"
219 api_url: "{{ netapp_api_url }}"
220 api_username: "{{ netapp_api_username }}"
221 api_password: "{{ netapp_api_password }}"
222 loop:
223 - 1
224 - 2
225 """
226
227 RETURN = """
228 msg:
229 description: Success message
230 returned: on success
231 type: str
232 sample: The interface settings have been updated.
233 enabled:
234 description:
235 - Indicates whether IPv4 connectivity has been enabled or disabled.
236 - This does not necessarily indicate connectivity. If dhcp was enabled absent a dhcp server, for instance,
237 it is unlikely that the configuration will actually be valid.
238 returned: on success
239 sample: True
240 type: bool
241 """
242 import json
243 import logging
244 from pprint import pformat
245 import time
246 import socket
247
248 try:
249 import urlparse
250 except ImportError:
251 import urllib.parse as urlparse
252
253 from ansible.module_utils.basic import AnsibleModule
254 from ansible_collections.netapp_eseries.santricity.plugins.module_utils.netapp import request, eseries_host_argument_spec
255 from ansible.module_utils._text import to_native
256
257 HEADERS = {
258 "Content-Type": "application/json",
259 "Accept": "application/json",
260 }
261
262
263 class MgmtInterface(object):
264 MAX_RETRIES = 15
265
266 def __init__(self):
267 argument_spec = eseries_host_argument_spec()
268 argument_spec.update(dict(
269 state=dict(type="str", choices=["enable", "disable"],
270 aliases=["enable_interface"], required=False),
271 controller=dict(type="str", required=True, choices=["A", "B"]),
272 name=dict(type="str", aliases=["port", "iface"]),
273 channel=dict(type="int"),
274 address=dict(type="str", required=False),
275 subnet_mask=dict(type="str", required=False),
276 gateway=dict(type="str", required=False),
277 config_method=dict(type="str", required=False, choices=["dhcp", "static"]),
278 dns_config_method=dict(type="str", required=False, choices=["dhcp", "static"]),
279 dns_address=dict(type="str", required=False),
280 dns_address_backup=dict(type="str", required=False),
281 ntp_config_method=dict(type="str", required=False, choices=["disable", "dhcp", "static"]),
282 ntp_address=dict(type="str", required=False),
283 ntp_address_backup=dict(type="str", required=False),
284 ssh=dict(type="bool", required=False),
285 log_path=dict(type="str", required=False),
286 ))
287
288 required_if = [
289 ["state", "enable", ["config_method"]],
290 ["config_method", "static", ["address", "subnet_mask"]],
291 ["dns_config_method", "static", ["dns_address"]],
292 ["ntp_config_method", "static", ["ntp_address"]],
293 ]
294
295 mutually_exclusive = [
296 ["name", "channel"],
297 ]
298
299 self.module = AnsibleModule(argument_spec=argument_spec,
300 supports_check_mode=True,
301 required_if=required_if,
302 mutually_exclusive=mutually_exclusive)
303 args = self.module.params
304
305 self.controller = args["controller"]
306 self.name = args["name"]
307 self.channel = args["channel"]
308
309 self.config_method = args["config_method"]
310 self.address = args["address"]
311 self.subnet_mask = args["subnet_mask"]
312 self.gateway = args["gateway"]
313 self.enable_interface = None if args["state"] is None else args["state"] == "enable"
314
315 self.dns_config_method = args["dns_config_method"]
316 self.dns_address = args["dns_address"]
317 self.dns_address_backup = args["dns_address_backup"]
318
319 self.ntp_config_method = args["ntp_config_method"]
320 self.ntp_address = args["ntp_address"]
321 self.ntp_address_backup = args["ntp_address_backup"]
322
323 self.ssh = args["ssh"]
324
325 self.ssid = args["ssid"]
326 self.url = args["api_url"]
327 self.creds = dict(url_password=args["api_password"],
328 validate_certs=args["validate_certs"],
329 url_username=args["api_username"], )
330
331 self.retries = 0
332
333 self.check_mode = self.module.check_mode
334 self.post_body = dict()
335
336 log_path = args["log_path"]
337
338 # logging setup
339 self._logger = logging.getLogger(self.__class__.__name__)
340
341 if log_path:
342 logging.basicConfig(
343 level=logging.DEBUG, filename=log_path, filemode='w',
344 format='%(relativeCreated)dms %(levelname)s %(module)s.%(funcName)s:%(lineno)d\n %(message)s')
345
346 if not self.url.endswith('/'):
347 self.url += '/'
348
349 @property
350 def controllers(self):
351 """Retrieve a mapping of controller labels to their references
352 {
353 'A': '070000000000000000000001',
354 'B': '070000000000000000000002',
355 }
356 :return: the controllers defined on the system
357 """
358 try:
359 (rc, controllers) = request(self.url + 'storage-systems/%s/controllers'
360 % self.ssid, headers=HEADERS, **self.creds)
361 except Exception as err:
362 controllers = list()
363 self.module.fail_json(
364 msg="Failed to retrieve the controller settings. Array Id [%s]. Error [%s]."
365 % (self.ssid, to_native(err)))
366
367 controllers.sort(key=lambda c: c['physicalLocation']['slot'])
368
369 controllers_dict = dict()
370 i = ord('A')
371 for controller in controllers:
372 label = chr(i)
373 settings = dict(controllerSlot=controller['physicalLocation']['slot'],
374 controllerRef=controller['controllerRef'],
375 ssh=controller['networkSettings']['remoteAccessEnabled'])
376 controllers_dict[label] = settings
377 i += 1
378
379 return controllers_dict
380
381 @property
382 def interface(self):
383 net_interfaces = list()
384 try:
385 (rc, net_interfaces) = request(self.url + 'storage-systems/%s/configuration/ethernet-interfaces'
386 % self.ssid, headers=HEADERS, **self.creds)
387 except Exception as err:
388 self.module.fail_json(
389 msg="Failed to retrieve defined management interfaces. Array Id [%s]. Error [%s]."
390 % (self.ssid, to_native(err)))
391
392 controllers = self.controllers
393 controller = controllers[self.controller]
394
395 net_interfaces = [iface for iface in net_interfaces if iface["controllerRef"] == controller["controllerRef"]]
396
397 # Find the correct interface
398 iface = None
399 for net in net_interfaces:
400 if self.name:
401 if net["alias"] == self.name or net["interfaceName"] == self.name:
402 iface = net
403 break
404 elif self.channel:
405 if net["channel"] == self.channel:
406 iface = net
407 break
408
409 if iface is None:
410 identifier = self.name if self.name is not None else self.channel
411 self.module.fail_json(msg="We could not find an interface matching [%s] on Array=[%s]."
412 % (identifier, self.ssid))
413
414 return dict(alias=iface["alias"],
415 channel=iface["channel"],
416 link_status=iface["linkStatus"],
417 enabled=iface["ipv4Enabled"],
418 address=iface["ipv4Address"],
419 gateway=iface["ipv4GatewayAddress"],
420 subnet_mask=iface["ipv4SubnetMask"],
421 dns_config_method=iface["dnsProperties"]["acquisitionProperties"]["dnsAcquisitionType"],
422 dns_servers=iface["dnsProperties"]["acquisitionProperties"]["dnsServers"],
423 ntp_config_method=iface["ntpProperties"]["acquisitionProperties"]["ntpAcquisitionType"],
424 ntp_servers=iface["ntpProperties"]["acquisitionProperties"]["ntpServers"],
425 config_method=iface["ipv4AddressConfigMethod"],
426 controllerRef=iface["controllerRef"],
427 controllerSlot=iface["controllerSlot"],
428 ipv6Enabled=iface["ipv6Enabled"],
429 id=iface["interfaceRef"], )
430
431 def get_enable_interface_settings(self, iface, expected_iface, update, body):
432 """Enable or disable the IPv4 network interface."""
433 if self.enable_interface:
434 if not iface["enabled"]:
435 update = True
436 body["ipv4Enabled"] = True
437 else:
438 if iface["enabled"]:
439 update = True
440 body["ipv4Enabled"] = False
441
442 expected_iface["enabled"] = body["ipv4Enabled"]
443 return update, expected_iface, body
444
445 def get_interface_settings(self, iface, expected_iface, update, body):
446 """Update network interface settings."""
447
448 if self.config_method == "dhcp":
449 if iface["config_method"] != "configDhcp":
450 update = True
451 body["ipv4AddressConfigMethod"] = "configDhcp"
452
453 else:
454 if iface["config_method"] != "configStatic":
455 update = True
456 body["ipv4AddressConfigMethod"] = "configStatic"
457
458 if iface["address"] != self.address:
459 update = True
460 body["ipv4Address"] = self.address
461
462 if iface["subnet_mask"] != self.subnet_mask:
463 update = True
464 body["ipv4SubnetMask"] = self.subnet_mask
465
466 if self.gateway and iface["gateway"] != self.gateway:
467 update = True
468 body["ipv4GatewayAddress"] = self.gateway
469
470 expected_iface["address"] = body["ipv4Address"]
471 expected_iface["subnet_mask"] = body["ipv4SubnetMask"]
472 expected_iface["gateway"] = body["ipv4GatewayAddress"]
473
474 expected_iface["config_method"] = body["ipv4AddressConfigMethod"]
475
476 return update, expected_iface, body
477
478 def get_dns_server_settings(self, iface, expected_iface, update, body):
479 """Add DNS server information to the request body."""
480 if self.dns_config_method == "dhcp":
481 if iface["dns_config_method"] != "dhcp":
482 update = True
483 body["dnsAcquisitionDescriptor"] = dict(dnsAcquisitionType="dhcp")
484
485 elif self.dns_config_method == "static":
486 dns_servers = [dict(addressType="ipv4", ipv4Address=self.dns_address)]
487 if self.dns_address_backup:
488 dns_servers.append(dict(addressType="ipv4", ipv4Address=self.dns_address_backup))
489
490 body["dnsAcquisitionDescriptor"] = dict(dnsAcquisitionType="stat", dnsServers=dns_servers)
491
492 if (iface["dns_config_method"] != "stat" or
493 len(iface["dns_servers"]) != len(dns_servers) or
494 (len(iface["dns_servers"]) == 2 and
495 (iface["dns_servers"][0]["ipv4Address"] != self.dns_address or
496 iface["dns_servers"][1]["ipv4Address"] != self.dns_address_backup)) or
497 (len(iface["dns_servers"]) == 1 and
498 iface["dns_servers"][0]["ipv4Address"] != self.dns_address)):
499 update = True
500
501 expected_iface["dns_servers"] = dns_servers
502
503 expected_iface["dns_config_method"] = body["dnsAcquisitionDescriptor"]["dnsAcquisitionType"]
504 return update, expected_iface, body
505
506 def get_ntp_server_settings(self, iface, expected_iface, update, body):
507 """Add NTP server information to the request body."""
508 if self.ntp_config_method == "disable":
509 if iface["ntp_config_method"] != "disabled":
510 update = True
511 body["ntpAcquisitionDescriptor"] = dict(ntpAcquisitionType="disabled")
512
513 elif self.ntp_config_method == "dhcp":
514 if iface["ntp_config_method"] != "dhcp":
515 update = True
516 body["ntpAcquisitionDescriptor"] = dict(ntpAcquisitionType="dhcp")
517
518 elif self.ntp_config_method == "static":
519 ntp_servers = [dict(addrType="ipvx", ipvxAddress=dict(addressType="ipv4", ipv4Address=self.ntp_address))]
520 if self.ntp_address_backup:
521 ntp_servers.append(dict(addrType="ipvx",
522 ipvxAddress=dict(addressType="ipv4", ipv4Address=self.ntp_address_backup)))
523
524 body["ntpAcquisitionDescriptor"] = dict(ntpAcquisitionType="stat", ntpServers=ntp_servers)
525
526 if (iface["ntp_config_method"] != "stat" or
527 len(iface["ntp_servers"]) != len(ntp_servers) or
528 ((len(iface["ntp_servers"]) == 2 and
529 (iface["ntp_servers"][0]["ipvxAddress"]["ipv4Address"] != self.ntp_address or
530 iface["ntp_servers"][1]["ipvxAddress"]["ipv4Address"] != self.ntp_address_backup)) or
531 (len(iface["ntp_servers"]) == 1 and
532 iface["ntp_servers"][0]["ipvxAddress"]["ipv4Address"] != self.ntp_address))):
533 update = True
534
535 expected_iface["ntp_servers"] = ntp_servers
536
537 expected_iface["ntp_config_method"] = body["ntpAcquisitionDescriptor"]["ntpAcquisitionType"]
538 return update, expected_iface, body
539
540 def get_remote_ssh_settings(self, settings, update, body):
541 """Configure network interface ports for remote ssh access."""
542 if self.ssh != settings["ssh"]:
543 update = True
544
545 body["enableRemoteAccess"] = self.ssh
546 return update, body
547
548 def update_array(self, settings, iface):
549 """Update controller with new interface, dns service, ntp service and/or remote ssh access information.
550
551 :returns: whether information passed will modify the controller's current state
552 :rtype: bool
553 """
554 update = False
555 body = dict(controllerRef=settings['controllerRef'],
556 interfaceRef=iface['id'])
557 expected_iface = iface.copy()
558
559 # Check if api url is using the effected management interface to change itself
560 update_used_matching_address = False
561 if self.enable_interface and self.config_method:
562 netloc = list(urlparse.urlparse(self.url))[1]
563 address = netloc.split(":")[0]
564 address_info = socket.getaddrinfo(address, 8443)
565 url_address_info = socket.getaddrinfo(iface["address"], 8443)
566 update_used_matching_address = any(info in url_address_info for info in address_info)
567
568 self._logger.info("update_used_matching_address: %s", update_used_matching_address)
569
570 # Populate the body of the request and check for changes
571 if self.enable_interface is not None:
572 update, expected_iface, body = self.get_enable_interface_settings(iface, expected_iface, update, body)
573
574 if self.config_method is not None:
575 update, expected_iface, body = self.get_interface_settings(iface, expected_iface, update, body)
576
577 if self.dns_config_method is not None:
578 update, expected_iface, body = self.get_dns_server_settings(iface, expected_iface, update, body)
579
580 if self.ntp_config_method is not None:
581 update, expected_iface, body = self.get_ntp_server_settings(iface, expected_iface, update, body)
582
583 if self.ssh is not None:
584 update, body = self.get_remote_ssh_settings(settings, update, body)
585 iface["ssh"] = self.ssh
586 expected_iface["ssh"] = self.ssh
587
588 # debug information
589 self._logger.info(pformat(body))
590 self._logger.info(pformat(iface))
591 self._logger.info(pformat(expected_iface))
592
593 if self.check_mode:
594 return update
595
596 if update and not self.check_mode:
597 if not update_used_matching_address:
598 try:
599 (rc, data) = request(self.url + 'storage-systems/%s/configuration/ethernet-interfaces'
600 % self.ssid, method='POST', data=json.dumps(body), headers=HEADERS,
601 timeout=300, ignore_errors=True, **self.creds)
602 if rc == 422:
603 if data['retcode'] == "4" or data['retcode'] == "illegalParam":
604 if not (body['ipv4Enabled'] or iface['ipv6Enabled']):
605 self.module.fail_json(msg="This storage-system already has IPv6 connectivity disabled. "
606 "DHCP configuration for IPv4 is required at a minimum."
607 " Array Id [%s] Message [%s]."
608 % (self.ssid, data['errorMessage']))
609 else:
610 self.module.fail_json(msg="We failed to configure the management interface. Array Id "
611 "[%s] Message [%s]." % (self.ssid, data))
612 elif rc >= 300:
613 self.module.fail_json(
614 msg="We failed to configure the management interface. Array Id [%s] Message [%s]." %
615 (self.ssid, data))
616
617 # This is going to catch cases like a connection failure
618 except Exception as err:
619 self.module.fail_json(
620 msg="Connection failure: we failed to modify the network settings! Array Id [%s]. Error [%s]."
621 % (self.ssid, to_native(err)))
622 else:
623 self.update_api_address_interface_match(body)
624
625 return self.validate_changes(expected_iface) if update and iface["link_status"] != "up" else update
626
627 def update_api_address_interface_match(self, body):
628 """Change network interface address which matches the api_address"""
629 try:
630 try:
631 (rc, data) = request(self.url + 'storage-systems/%s/configuration/ethernet-interfaces' % self.ssid,
632 use_proxy=False, force=True, ignore_errors=True, method='POST',
633 data=json.dumps(body), headers=HEADERS, timeout=10, **self.creds)
634 except Exception:
635 url_parts = list(urlparse.urlparse(self.url))
636 domain = url_parts[1].split(":")
637 domain[0] = self.address
638 url_parts[1] = ":".join(domain)
639 expected_url = urlparse.urlunparse(url_parts)
640 self._logger.info(pformat(expected_url))
641
642 (rc, data) = request(expected_url + 'storage-systems/%s/configuration/ethernet-interfaces' % self.ssid,
643 headers=HEADERS, timeout=300, **self.creds)
644 return
645 except Exception as err:
646 self._logger.info(type(err))
647 self.module.fail_json(
648 msg="Connection failure: we failed to modify the network settings! Array Id [%s]. Error [%s]."
649 % (self.ssid, to_native(err)))
650
651 def validate_changes(self, expected_iface, retry=6):
652 """Validate interface changes were applied to the controller interface port. 30 second timeout"""
653 if self.interface != expected_iface:
654 time.sleep(5)
655 if retry:
656 return self.validate_changes(expected_iface, retry - 1)
657
658 self.module.fail_json(msg="Update failure: we failed to verify the necessary state change.")
659
660 return True
661
662 def check_health(self):
663 """It's possible, due to a previous operation, for the API to report a 424 (offline) status for the
664 storage-system. Therefore, we run a manual check with retries to attempt to contact the system before we
665 continue.
666 """
667 try:
668 (rc, data) = request(self.url + 'storage-systems/%s/controllers'
669 % self.ssid, headers=HEADERS,
670 ignore_errors=True, **self.creds)
671
672 # We've probably recently changed the interface settings and it's still coming back up: retry.
673 if rc == 424:
674 if self.retries < self.MAX_RETRIES:
675 self.retries += 1
676 self._logger.info("We hit a 424, retrying in 5s.")
677 time.sleep(5)
678 self.check_health()
679 else:
680 self.module.fail_json(
681 msg="We failed to pull storage-system information. Array Id [%s] Message [%s]." %
682 (self.ssid, data))
683 elif rc >= 300:
684 self.module.fail_json(
685 msg="We failed to pull storage-system information. Array Id [%s] Message [%s]." %
686 (self.ssid, data))
687 # This is going to catch cases like a connection failure
688 except Exception as err:
689 if self.retries < self.MAX_RETRIES:
690 self._logger.info("We hit a connection failure, retrying in 5s.")
691 self.retries += 1
692 time.sleep(5)
693 self.check_health()
694 else:
695 self.module.fail_json(
696 msg="Connection failure: we failed to modify the network settings! Array Id [%s]. Error [%s]."
697 % (self.ssid, to_native(err)))
698
699 def update(self):
700 """Update storage system with necessary changes."""
701 # Check if the storage array can be contacted
702 self.check_health()
703
704 # make the necessary changes to the storage system
705 settings = self.controllers[self.controller]
706 iface = self.interface
707 self._logger.info(pformat(settings))
708 self._logger.info(pformat(iface))
709 update = self.update_array(settings, iface)
710
711 self.module.exit_json(msg="The interface settings have been updated.", changed=update)
712
713 def __call__(self, *args, **kwargs):
714 self.update()
715
716
717 def main():
718 iface = MgmtInterface()
719 iface()
720
721
722 if __name__ == '__main__':
723 main()