| 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 |
|
| 7 |
__metaclass__ = type |
| 8 |
|
| 9 |
DOCUMENTATION = """ |
| 10 |
--- |
| 11 |
module: na_santricity_mgmt_interface |
| 12 |
short_description: NetApp E-Series manage management interface configuration |
| 13 |
description: |
| 14 |
- Configure the E-Series management interfaces |
| 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 or disable IPv4 network interface configuration. |
| 25 |
- Either IPv4 or IPv6 must be enabled otherwise error will occur. |
| 26 |
- Assumed to be I(state==enabled) when I(config_method) is specified unless defined. |
| 27 |
choices: |
| 28 |
- enabled |
| 29 |
- disabled |
| 30 |
type: str |
| 31 |
required: false |
| 32 |
controller: |
| 33 |
description: |
| 34 |
- The controller that owns the port you want to configure. |
| 35 |
- Controller names are represented alphabetically, with the first controller as A, |
| 36 |
the second as B, and so on. |
| 37 |
- Current hardware models have either 1 or 2 available controllers, but that is not a guaranteed hard |
| 38 |
limitation and could change in the future. |
| 39 |
choices: |
| 40 |
- A |
| 41 |
- B |
| 42 |
type: str |
| 43 |
required: true |
| 44 |
port: |
| 45 |
description: |
| 46 |
- The ethernet port configuration to modify. |
| 47 |
- The channel represents the port number left to right on the controller, beginning with 1. |
| 48 |
- Required when I(config_method) is specified. |
| 49 |
type: int |
| 50 |
required: false |
| 51 |
address: |
| 52 |
description: |
| 53 |
- The IPv4 address to assign to the interface. |
| 54 |
- Should be specified in xx.xx.xx.xx form. |
| 55 |
- Mutually exclusive with I(config_method=dhcp) |
| 56 |
type: str |
| 57 |
required: false |
| 58 |
subnet_mask: |
| 59 |
description: |
| 60 |
- The subnet mask to utilize for the interface. |
| 61 |
- Should be specified in xx.xx.xx.xx form. |
| 62 |
- Mutually exclusive with I(config_method=dhcp) |
| 63 |
type: str |
| 64 |
required: false |
| 65 |
gateway: |
| 66 |
description: |
| 67 |
- The IPv4 gateway address to utilize for the interface. |
| 68 |
- Should be specified in xx.xx.xx.xx form. |
| 69 |
- Mutually exclusive with I(config_method=dhcp) |
| 70 |
type: str |
| 71 |
required: false |
| 72 |
config_method: |
| 73 |
description: |
| 74 |
- The configuration method type to use for network interface ports. |
| 75 |
- dhcp is mutually exclusive with I(address), I(subnet_mask), and I(gateway). |
| 76 |
choices: |
| 77 |
- dhcp |
| 78 |
- static |
| 79 |
type: str |
| 80 |
required: false |
| 81 |
dns_config_method: |
| 82 |
description: |
| 83 |
- The configuration method type to use for DNS services. |
| 84 |
- dhcp is mutually exclusive with I(dns_address), and I(dns_address_backup). |
| 85 |
choices: |
| 86 |
- dhcp |
| 87 |
- static |
| 88 |
type: str |
| 89 |
required: false |
| 90 |
dns_address: |
| 91 |
description: |
| 92 |
- Primary IPv4 or IPv6 DNS server address |
| 93 |
type: str |
| 94 |
required: false |
| 95 |
dns_address_backup: |
| 96 |
description: |
| 97 |
- Secondary IPv4 or IPv6 DNS server address |
| 98 |
type: str |
| 99 |
required: false |
| 100 |
ntp_config_method: |
| 101 |
description: |
| 102 |
- The configuration method type to use for NTP services. |
| 103 |
- disable is mutually exclusive with I(ntp_address) and I(ntp_address_backup). |
| 104 |
- dhcp is mutually exclusive with I(ntp_address) and I(ntp_address_backup). |
| 105 |
choices: |
| 106 |
- disabled |
| 107 |
- dhcp |
| 108 |
- static |
| 109 |
type: str |
| 110 |
required: false |
| 111 |
ntp_address: |
| 112 |
description: |
| 113 |
- Primary IPv4, IPv6, or FQDN NTP server address |
| 114 |
type: str |
| 115 |
required: false |
| 116 |
ntp_address_backup: |
| 117 |
description: |
| 118 |
- Secondary IPv4, IPv6, or FQDN NTP server address |
| 119 |
type: str |
| 120 |
required: false |
| 121 |
ssh: |
| 122 |
description: |
| 123 |
- Enable ssh access to the controller for debug purposes. |
| 124 |
- This is a controller-level setting. |
| 125 |
- rlogin/telnet will be enabled for ancient equipment where ssh is not available. |
| 126 |
type: bool |
| 127 |
required: false |
| 128 |
notes: |
| 129 |
- Check mode is supported. |
| 130 |
- It is highly recommended to have a minimum of one up management port on each controller. |
| 131 |
- When using SANtricity Web Services Proxy, use M(netapp_eseries.santricity.na_santricity_storage_system) to update |
| 132 |
management paths. This is required because of a known issue and will be addressed in the proxy version 4.1. After |
| 133 |
the resolution the management ports should automatically be updated. |
| 134 |
- The interface settings are applied synchronously, but changes to the interface itself (receiving a new IP address |
| 135 |
via dhcp, etc), can take seconds or minutes longer to take effect. |
| 136 |
""" |
| 137 |
|
| 138 |
EXAMPLES = """ |
| 139 |
- name: Configure the first port on the A controller with a static IPv4 address |
| 140 |
na_santricity_mgmt_interface: |
| 141 |
ssid: "1" |
| 142 |
api_url: "https://192.168.1.100:8443/devmgr/v2" |
| 143 |
api_username: "admin" |
| 144 |
api_password: "adminpass" |
| 145 |
validate_certs: true |
| 146 |
port: "1" |
| 147 |
controller: "A" |
| 148 |
config_method: static |
| 149 |
address: "192.168.1.100" |
| 150 |
subnet_mask: "255.255.255.0" |
| 151 |
gateway: "192.168.1.1" |
| 152 |
|
| 153 |
- name: Disable ipv4 connectivity for the second port on the B controller |
| 154 |
na_santricity_mgmt_interface: |
| 155 |
ssid: "1" |
| 156 |
api_url: "https://192.168.1.100:8443/devmgr/v2" |
| 157 |
api_username: "admin" |
| 158 |
api_password: "adminpass" |
| 159 |
validate_certs: true |
| 160 |
port: "2" |
| 161 |
controller: "B" |
| 162 |
enable_interface: no |
| 163 |
|
| 164 |
- name: Enable ssh access for ports one and two on controller A |
| 165 |
na_santricity_mgmt_interface: |
| 166 |
ssid: "1" |
| 167 |
api_url: "https://192.168.1.100:8443/devmgr/v2" |
| 168 |
api_username: "admin" |
| 169 |
api_password: "adminpass" |
| 170 |
validate_certs: true |
| 171 |
port: "1" |
| 172 |
controller: "A" |
| 173 |
ssh: yes |
| 174 |
|
| 175 |
- name: Configure static DNS settings for the first port on controller A |
| 176 |
na_santricity_mgmt_interface: |
| 177 |
ssid: "1" |
| 178 |
api_url: "https://192.168.1.100:8443/devmgr/v2" |
| 179 |
api_username: "admin" |
| 180 |
api_password: "adminpass" |
| 181 |
validate_certs: true |
| 182 |
port: "1" |
| 183 |
controller: "A" |
| 184 |
dns_config_method: static |
| 185 |
dns_address: "192.168.1.100" |
| 186 |
dns_address_backup: "192.168.1.1" |
| 187 |
|
| 188 |
""" |
| 189 |
|
| 190 |
RETURN = """ |
| 191 |
msg: |
| 192 |
description: Success message |
| 193 |
returned: on success |
| 194 |
type: str |
| 195 |
sample: The interface settings have been updated. |
| 196 |
available_embedded_api_urls: |
| 197 |
description: List containing available web services embedded REST API urls |
| 198 |
returned: on success |
| 199 |
type: list |
| 200 |
sample: |
| 201 |
""" |
| 202 |
from time import sleep |
| 203 |
|
| 204 |
from ansible_collections.netapp_eseries.santricity.plugins.module_utils.santricity import NetAppESeriesModule |
| 205 |
from ansible.module_utils._text import to_native |
| 206 |
from ansible.module_utils import six |
| 207 |
|
| 208 |
try: |
| 209 |
import urlparse |
| 210 |
except ImportError: |
| 211 |
import urllib.parse as urlparse |
| 212 |
|
| 213 |
try: |
| 214 |
import ipaddress |
| 215 |
except ImportError: |
| 216 |
HAS_IPADDRESS = False |
| 217 |
else: |
| 218 |
HAS_IPADDRESS = True |
| 219 |
|
| 220 |
|
| 221 |
def is_ipv4(address): |
| 222 |
"""Determine whether address is IPv4.""" |
| 223 |
try: |
| 224 |
if six.PY2: |
| 225 |
address = six.u(address) |
| 226 |
ipaddress.IPv4Address(address) |
| 227 |
return True |
| 228 |
except Exception as error: |
| 229 |
return False |
| 230 |
|
| 231 |
|
| 232 |
def is_ipv6(address): |
| 233 |
"""Determine whether address is IPv6.""" |
| 234 |
try: |
| 235 |
if six.PY2: |
| 236 |
address = six.u(address) |
| 237 |
ipaddress.IPv6Address(address) |
| 238 |
return True |
| 239 |
except Exception as error: |
| 240 |
return False |
| 241 |
|
| 242 |
|
| 243 |
class NetAppESeriesMgmtInterface(NetAppESeriesModule): |
| 244 |
MAXIMUM_VERIFICATION_TIMEOUT = 120 |
| 245 |
|
| 246 |
def __init__(self): |
| 247 |
ansible_options = dict(state=dict(type="str", choices=["enabled", "disabled"], required=False), |
| 248 |
controller=dict(type="str", required=True, choices=["A", "B"]), |
| 249 |
port=dict(type="int"), |
| 250 |
address=dict(type="str", required=False), |
| 251 |
subnet_mask=dict(type="str", required=False), |
| 252 |
gateway=dict(type="str", required=False), |
| 253 |
config_method=dict(type="str", required=False, choices=["dhcp", "static"]), |
| 254 |
dns_config_method=dict(type="str", required=False, choices=["dhcp", "static"]), |
| 255 |
dns_address=dict(type="str", required=False), |
| 256 |
dns_address_backup=dict(type="str", required=False), |
| 257 |
ntp_config_method=dict(type="str", required=False, choices=["disabled", "dhcp", "static"]), |
| 258 |
ntp_address=dict(type="str", required=False), |
| 259 |
ntp_address_backup=dict(type="str", required=False), |
| 260 |
ssh=dict(type="bool", required=False)) |
| 261 |
|
| 262 |
required_if = [["config_method", "static", ["port", "address", "subnet_mask"]], |
| 263 |
["dns_config_method", "static", ["dns_address"]], |
| 264 |
["ntp_config_method", "static", ["ntp_address"]]] |
| 265 |
|
| 266 |
super(NetAppESeriesMgmtInterface, self).__init__(ansible_options=ansible_options, |
| 267 |
web_services_version="02.00.0000.0000", |
| 268 |
required_if=required_if, |
| 269 |
supports_check_mode=True) |
| 270 |
|
| 271 |
args = self.module.params |
| 272 |
if args["state"] is None: |
| 273 |
if args["config_method"] is not None: |
| 274 |
self.enable_interface = True |
| 275 |
else: |
| 276 |
self.enable_interface = None |
| 277 |
else: |
| 278 |
self.enable_interface = args["state"] == "enabled" |
| 279 |
|
| 280 |
self.controller = args["controller"] |
| 281 |
self.channel = args["port"] |
| 282 |
|
| 283 |
self.config_method = args["config_method"] |
| 284 |
self.address = args["address"] |
| 285 |
self.subnet_mask = args["subnet_mask"] |
| 286 |
self.gateway = args["gateway"] |
| 287 |
|
| 288 |
self.dns_config_method = args["dns_config_method"] |
| 289 |
self.dns_address = args["dns_address"] |
| 290 |
self.dns_address_backup = args["dns_address_backup"] |
| 291 |
|
| 292 |
self.ntp_config_method = args["ntp_config_method"] |
| 293 |
self.ntp_address = args["ntp_address"] |
| 294 |
self.ntp_address_backup = args["ntp_address_backup"] |
| 295 |
|
| 296 |
self.ssh = args["ssh"] |
| 297 |
|
| 298 |
self.body = {} |
| 299 |
self.interface_info = {} |
| 300 |
self.alt_interface_addresses = [] |
| 301 |
self.all_interface_addresses = [] |
| 302 |
self.use_alternate_address = False |
| 303 |
self.alt_url_path = None |
| 304 |
|
| 305 |
self.available_embedded_api_urls = [] |
| 306 |
|
| 307 |
def get_controllers(self): |
| 308 |
"""Retrieve a mapping of controller labels to their references |
| 309 |
:return: controllers defined on the system. Example: {'A': '070000000000000000000001', 'B': '070000000000000000000002'} |
| 310 |
""" |
| 311 |
try: |
| 312 |
rc, controllers = self.request("storage-systems/%s/controllers" % self.ssid) |
| 313 |
except Exception as err: |
| 314 |
controllers = list() |
| 315 |
self.module.fail_json(msg="Failed to retrieve the controller settings. Array Id [%s]. Error [%s]." % (self.ssid, to_native(err))) |
| 316 |
|
| 317 |
controllers.sort(key=lambda c: c['physicalLocation']['slot']) |
| 318 |
controllers_dict = dict() |
| 319 |
i = ord('A') |
| 320 |
for controller in controllers: |
| 321 |
label = chr(i) |
| 322 |
settings = dict(controllerSlot=controller['physicalLocation']['slot'], |
| 323 |
controllerRef=controller['controllerRef'], |
| 324 |
ssh=controller['networkSettings']['remoteAccessEnabled']) |
| 325 |
controllers_dict[label] = settings |
| 326 |
i += 1 |
| 327 |
return controllers_dict |
| 328 |
|
| 329 |
def update_target_interface_info(self, retries=60): |
| 330 |
"""Discover and update cached interface info.""" |
| 331 |
net_interfaces = list() |
| 332 |
try: |
| 333 |
rc, net_interfaces = self.request("storage-systems/%s/configuration/ethernet-interfaces" % self.ssid) |
| 334 |
except Exception as error: |
| 335 |
if retries > 0: |
| 336 |
self.update_target_interface_info(retries=retries - 1) |
| 337 |
return |
| 338 |
else: |
| 339 |
self.module.fail_json(msg="Failed to retrieve defined management interfaces. Array Id [%s]. Error [%s]." % (self.ssid, to_native(error))) |
| 340 |
|
| 341 |
iface = None |
| 342 |
channels = {} |
| 343 |
controller_info = self.get_controllers()[self.controller] |
| 344 |
controller_ref = controller_info["controllerRef"] |
| 345 |
controller_ssh = controller_info["ssh"] |
| 346 |
controller_dns = None |
| 347 |
controller_ntp = None |
| 348 |
dummy_interface_id = None # Needed for when a specific interface is not required (ie dns/ntp/ssh changes only) |
| 349 |
for net in net_interfaces: |
| 350 |
if net["controllerRef"] == controller_ref: |
| 351 |
channels.update({net["channel"]: net["linkStatus"]}) |
| 352 |
if dummy_interface_id is None: |
| 353 |
dummy_interface_id = net["interfaceRef"] |
| 354 |
if controller_dns is None: |
| 355 |
controller_dns = net["dnsProperties"] |
| 356 |
if controller_ntp is None: |
| 357 |
controller_ntp = net["ntpProperties"] |
| 358 |
|
| 359 |
if net["ipv4Enabled"] and net["linkStatus"] == "up": |
| 360 |
self.all_interface_addresses.append(net["ipv4Address"]) |
| 361 |
if net["controllerRef"] == controller_ref and net["channel"] == self.channel: |
| 362 |
iface = net |
| 363 |
elif net["ipv4Enabled"] and net["linkStatus"] == "up": |
| 364 |
self.alt_interface_addresses.append(net["ipv4Address"]) |
| 365 |
|
| 366 |
# Add controller specific information (ssh, dns and ntp) |
| 367 |
self.interface_info.update({ |
| 368 |
"id": dummy_interface_id, |
| 369 |
"controllerRef": controller_ref, |
| 370 |
"ssh": controller_ssh, |
| 371 |
"dns_config_method": controller_dns["acquisitionProperties"]["dnsAcquisitionType"], |
| 372 |
"dns_servers": controller_dns["acquisitionProperties"]["dnsServers"], |
| 373 |
"ntp_config_method": controller_ntp["acquisitionProperties"]["ntpAcquisitionType"], |
| 374 |
"ntp_servers": controller_ntp["acquisitionProperties"]["ntpServers"], |
| 375 |
}) |
| 376 |
|
| 377 |
# Add interface specific information when configuring IP address. |
| 378 |
if self.config_method is not None: |
| 379 |
if iface is None: |
| 380 |
available_controllers = ["%s (%s)" % (channel, status) for channel, status in channels.items()] |
| 381 |
self.module.fail_json( |
| 382 |
msg="Invalid port number! Controller %s ports: [%s]. Array [%s]" % ( |
| 383 |
self.controller, ",".join(available_controllers), self.ssid |
| 384 |
) |
| 385 |
) |
| 386 |
else: |
| 387 |
self.interface_info.update({ |
| 388 |
"id": iface["interfaceRef"], |
| 389 |
"controllerSlot": iface["controllerSlot"], |
| 390 |
"channel": iface["channel"], |
| 391 |
"link_status": iface["linkStatus"], |
| 392 |
"enabled": iface["ipv4Enabled"], |
| 393 |
"config_method": iface["ipv4AddressConfigMethod"], |
| 394 |
"address": iface["ipv4Address"], |
| 395 |
"subnet_mask": iface["ipv4SubnetMask"], |
| 396 |
"gateway": iface["ipv4GatewayAddress"], |
| 397 |
"ipv6_enabled": iface["ipv6Enabled"], |
| 398 |
}) |
| 399 |
|
| 400 |
def update_body_enable_interface_setting(self): |
| 401 |
"""Enable or disable the IPv4 network interface.""" |
| 402 |
change_required = False |
| 403 |
if not self.enable_interface and not self.interface_info["ipv6_enabled"]: |
| 404 |
self.module.fail_json(msg="Either IPv4 or IPv6 must be enabled. Array [%s]." % self.ssid) |
| 405 |
|
| 406 |
if self.enable_interface != self.interface_info["enabled"]: |
| 407 |
change_required = True |
| 408 |
self.body.update({"ipv4Enabled": self.enable_interface}) |
| 409 |
return change_required |
| 410 |
|
| 411 |
def update_body_interface_settings(self): |
| 412 |
"""Update network interface settings.""" |
| 413 |
change_required = False |
| 414 |
if self.config_method == "dhcp": |
| 415 |
if self.interface_info["config_method"] != "configDhcp": |
| 416 |
if self.interface_info["address"] in self.url: |
| 417 |
self.use_alternate_address = True |
| 418 |
change_required = True |
| 419 |
self.body.update({"ipv4AddressConfigMethod": "configDhcp"}) |
| 420 |
else: |
| 421 |
self.body.update({"ipv4AddressConfigMethod": "configStatic", "ipv4Address": self.address, "ipv4SubnetMask": self.subnet_mask}) |
| 422 |
if self.interface_info["config_method"] != "configStatic": |
| 423 |
change_required = True |
| 424 |
if self.address and self.interface_info["address"] != self.address: |
| 425 |
if self.interface_info["address"] in self.url: |
| 426 |
self.use_alternate_address = True |
| 427 |
change_required = True |
| 428 |
if self.subnet_mask and self.interface_info["subnet_mask"] != self.subnet_mask: |
| 429 |
change_required = True |
| 430 |
if self.gateway and self.interface_info["gateway"] != self.gateway: |
| 431 |
self.body.update({"ipv4GatewayAddress": self.gateway}) |
| 432 |
change_required = True |
| 433 |
|
| 434 |
return change_required |
| 435 |
|
| 436 |
def update_body_dns_server_settings(self): |
| 437 |
"""Add DNS server information to the request body.""" |
| 438 |
change_required = False |
| 439 |
if self.dns_config_method == "dhcp": |
| 440 |
if self.interface_info["dns_config_method"] != "dhcp": |
| 441 |
change_required = True |
| 442 |
self.body.update({"dnsAcquisitionDescriptor": {"dnsAcquisitionType": "dhcp"}}) |
| 443 |
|
| 444 |
elif self.dns_config_method == "static": |
| 445 |
dns_servers = [] |
| 446 |
if ((self.dns_address and self.dns_address_backup and (not self.interface_info["dns_servers"] or |
| 447 |
len(self.interface_info["dns_servers"]) != 2)) or |
| 448 |
(self.dns_address and not self.dns_address_backup and (not self.interface_info["dns_servers"] or |
| 449 |
len(self.interface_info["dns_servers"]) != 1))): |
| 450 |
change_required = True |
| 451 |
|
| 452 |
# Check primary DNS address |
| 453 |
if self.dns_address: |
| 454 |
if is_ipv4(self.dns_address): |
| 455 |
dns_servers.append({"addressType": "ipv4", "ipv4Address": self.dns_address}) |
| 456 |
if (not self.interface_info["dns_servers"] or len(self.interface_info["dns_servers"]) < 1 or |
| 457 |
self.interface_info["dns_servers"][0]["addressType"] != "ipv4" or |
| 458 |
self.interface_info["dns_servers"][0]["ipv4Address"] != self.dns_address): |
| 459 |
change_required = True |
| 460 |
elif is_ipv6(self.dns_address): |
| 461 |
dns_servers.append({"addressType": "ipv6", "ipv6Address": self.dns_address}) |
| 462 |
if (not self.interface_info["dns_servers"] or len(self.interface_info["dns_servers"]) < 1 or |
| 463 |
self.interface_info["dns_servers"][0]["addressType"] != "ipv6" or |
| 464 |
self.interface_info["dns_servers"][0]["ipv6Address"].replace(":", "").lower() != self.dns_address.replace(":", "").lower()): |
| 465 |
change_required = True |
| 466 |
else: |
| 467 |
self.module.fail_json(msg="Invalid IP address! DNS address must be either IPv4 or IPv6. Address [%s]." |
| 468 |
" Array [%s]." % (self.dns_address, self.ssid)) |
| 469 |
|
| 470 |
# Check secondary DNS address |
| 471 |
if self.dns_address_backup: |
| 472 |
if is_ipv4(self.dns_address_backup): |
| 473 |
dns_servers.append({"addressType": "ipv4", "ipv4Address": self.dns_address_backup}) |
| 474 |
if (not self.interface_info["dns_servers"] or len(self.interface_info["dns_servers"]) < 2 or |
| 475 |
self.interface_info["dns_servers"][1]["addressType"] != "ipv4" or |
| 476 |
self.interface_info["dns_servers"][1]["ipv4Address"] != self.dns_address_backup): |
| 477 |
change_required = True |
| 478 |
elif is_ipv6(self.dns_address_backup): |
| 479 |
dns_servers.append({"addressType": "ipv6", "ipv6Address": self.dns_address_backup}) |
| 480 |
if (not self.interface_info["dns_servers"] or len(self.interface_info["dns_servers"]) < 2 or |
| 481 |
self.interface_info["dns_servers"][1]["addressType"] != "ipv6" or |
| 482 |
self.interface_info["dns_servers"][1]["ipv6Address"].replace(":", "").lower() != self.dns_address_backup.replace(":", "").lower()): |
| 483 |
change_required = True |
| 484 |
else: |
| 485 |
self.module.fail_json(msg="Invalid IP address! DNS address must be either IPv4 or IPv6. Address [%s]." |
| 486 |
" Array [%s]." % (self.dns_address, self.ssid)) |
| 487 |
|
| 488 |
self.body.update({"dnsAcquisitionDescriptor": {"dnsAcquisitionType": "stat", "dnsServers": dns_servers}}) |
| 489 |
|
| 490 |
return change_required |
| 491 |
|
| 492 |
def update_body_ntp_server_settings(self): |
| 493 |
"""Add NTP server information to the request body.""" |
| 494 |
change_required = False |
| 495 |
if self.ntp_config_method == "disabled": |
| 496 |
if self.interface_info["ntp_config_method"] != "disabled": |
| 497 |
change_required = True |
| 498 |
self.body.update({"ntpAcquisitionDescriptor": {"ntpAcquisitionType": "disabled"}}) |
| 499 |
|
| 500 |
elif self.ntp_config_method == "dhcp": |
| 501 |
if self.interface_info["ntp_config_method"] != "dhcp": |
| 502 |
change_required = True |
| 503 |
self.body.update({"ntpAcquisitionDescriptor": {"ntpAcquisitionType": "dhcp"}}) |
| 504 |
|
| 505 |
elif self.ntp_config_method == "static": |
| 506 |
ntp_servers = [] |
| 507 |
if ((self.ntp_address and self.ntp_address_backup and (not self.interface_info["ntp_servers"] or |
| 508 |
len(self.interface_info["ntp_servers"]) != 2)) or |
| 509 |
(self.ntp_address and not self.ntp_address_backup and (not self.interface_info["ntp_servers"] or |
| 510 |
len(self.interface_info["ntp_servers"]) != 1))): |
| 511 |
change_required = True |
| 512 |
|
| 513 |
# Check primary NTP address |
| 514 |
if self.ntp_address: |
| 515 |
if is_ipv4(self.ntp_address): |
| 516 |
ntp_servers.append({"addrType": "ipvx", "ipvxAddress": {"addressType": "ipv4", "ipv4Address": self.ntp_address}}) |
| 517 |
if (not self.interface_info["ntp_servers"] or len(self.interface_info["ntp_servers"]) < 1 or |
| 518 |
self.interface_info["ntp_servers"][0]["addrType"] != "ipvx" or |
| 519 |
self.interface_info["ntp_servers"][0]["ipvxAddress"]["addressType"] != "ipv4" or |
| 520 |
self.interface_info["ntp_servers"][0]["ipvxAddress"]["ipv4Address"] != self.ntp_address): |
| 521 |
change_required = True |
| 522 |
elif is_ipv6(self.ntp_address): |
| 523 |
ntp_servers.append({"addrType": "ipvx", "ipvxAddress": {"addressType": "ipv6", "ipv6Address": self.ntp_address}}) |
| 524 |
if (not self.interface_info["ntp_servers"] or len(self.interface_info["ntp_servers"]) < 1 or |
| 525 |
self.interface_info["ntp_servers"][0]["addrType"] != "ipvx" or |
| 526 |
self.interface_info["ntp_servers"][0]["ipvxAddress"]["addressType"] != "ipv6" or |
| 527 |
self.interface_info["ntp_servers"][0]["ipvxAddress"][ |
| 528 |
"ipv6Address"].replace(":", "").lower() != self.ntp_address.replace(":", "").lower()): |
| 529 |
change_required = True |
| 530 |
else: |
| 531 |
ntp_servers.append({"addrType": "domainName", "domainName": self.ntp_address}) |
| 532 |
if (not self.interface_info["ntp_servers"] or len(self.interface_info["ntp_servers"]) < 1 or |
| 533 |
self.interface_info["ntp_servers"][0]["addrType"] != "domainName" or |
| 534 |
self.interface_info["ntp_servers"][0]["domainName"] != self.ntp_address): |
| 535 |
change_required = True |
| 536 |
|
| 537 |
# Check secondary NTP address |
| 538 |
if self.ntp_address_backup: |
| 539 |
if is_ipv4(self.ntp_address_backup): |
| 540 |
ntp_servers.append({"addrType": "ipvx", "ipvxAddress": {"addressType": "ipv4", "ipv4Address": self.ntp_address_backup}}) |
| 541 |
if (not self.interface_info["ntp_servers"] or len(self.interface_info["ntp_servers"]) < 2 or |
| 542 |
self.interface_info["ntp_servers"][1]["addrType"] != "ipvx" or |
| 543 |
self.interface_info["ntp_servers"][1]["ipvxAddress"]["addressType"] != "ipv4" or |
| 544 |
self.interface_info["ntp_servers"][1]["ipvxAddress"]["ipv4Address"] != self.ntp_address_backup): |
| 545 |
change_required = True |
| 546 |
elif is_ipv6(self.ntp_address_backup): |
| 547 |
ntp_servers.append({"addrType": "ipvx", "ipvxAddress": {"addressType": "ipv6", "ipv6Address": self.ntp_address_backup}}) |
| 548 |
if (not self.interface_info["ntp_servers"] or len(self.interface_info["ntp_servers"]) < 2 or |
| 549 |
self.interface_info["ntp_servers"][1]["addrType"] != "ipvx" or |
| 550 |
self.interface_info["ntp_servers"][1]["ipvxAddress"]["addressType"] != "ipv6" or |
| 551 |
self.interface_info["ntp_servers"][1]["ipvxAddress"][ |
| 552 |
"ipv6Address"].replace(":", "").lower() != self.ntp_address_backup.replace(":", "").lower()): |
| 553 |
change_required = True |
| 554 |
else: |
| 555 |
ntp_servers.append({"addrType": "domainName", "domainName": self.ntp_address_backup}) |
| 556 |
if (not self.interface_info["ntp_servers"] or len(self.interface_info["ntp_servers"]) < 2 or |
| 557 |
self.interface_info["ntp_servers"][1]["addrType"] != "domainName" or |
| 558 |
self.interface_info["ntp_servers"][1]["domainName"].lower() != self.ntp_address_backup.lower()): |
| 559 |
change_required = True |
| 560 |
|
| 561 |
self.body.update({"ntpAcquisitionDescriptor": {"ntpAcquisitionType": "stat", "ntpServers": ntp_servers}}) |
| 562 |
|
| 563 |
return change_required |
| 564 |
|
| 565 |
def update_body_ssh_setting(self): |
| 566 |
"""Configure network interface ports for remote ssh access.""" |
| 567 |
change_required = False |
| 568 |
if self.interface_info["ssh"] != self.ssh: |
| 569 |
change_required = True |
| 570 |
self.body.update({"enableRemoteAccess": self.ssh}) |
| 571 |
return change_required |
| 572 |
|
| 573 |
def update_request_body(self): |
| 574 |
"""Verify all required changes have been made.""" |
| 575 |
self.update_target_interface_info() |
| 576 |
self.body = {"controllerRef": self.get_controllers()[self.controller]["controllerRef"], "interfaceRef": self.interface_info["id"]} |
| 577 |
|
| 578 |
change_required = False |
| 579 |
if self.enable_interface is not None: |
| 580 |
change_required = self.update_body_enable_interface_setting() |
| 581 |
if self.config_method is not None: |
| 582 |
change_required = self.update_body_interface_settings() or change_required |
| 583 |
if self.dns_config_method is not None: |
| 584 |
change_required = self.update_body_dns_server_settings() or change_required |
| 585 |
if self.ntp_config_method is not None: |
| 586 |
change_required = self.update_body_ntp_server_settings() or change_required |
| 587 |
if self.ssh is not None: |
| 588 |
change_required = self.update_body_ssh_setting() or change_required |
| 589 |
|
| 590 |
self.module.log("update_request_body change_required: %s" % change_required) |
| 591 |
return change_required |
| 592 |
|
| 593 |
def update_url(self, retries=60): |
| 594 |
"""Update eseries base class url if on is available.""" |
| 595 |
for address in self.alt_interface_addresses: |
| 596 |
if address not in self.url and address != "0.0.0.0": |
| 597 |
parsed_url = urlparse.urlparse(self.url) |
| 598 |
location = parsed_url.netloc.split(":") |
| 599 |
location[0] = address |
| 600 |
self.url = "%s://%s/" % (parsed_url.scheme, ":".join(location)) |
| 601 |
self.available_embedded_api_urls = ["%s://%s/%s" % (parsed_url.scheme, ":".join(location), self.DEFAULT_REST_API_PATH)] |
| 602 |
self.module.warn("Using alternate address [%s]" % self.available_embedded_api_urls[0]) |
| 603 |
break |
| 604 |
else: |
| 605 |
if retries > 0: |
| 606 |
sleep(1) |
| 607 |
self.update_target_interface_info() |
| 608 |
self.update_url(retries=retries - 1) |
| 609 |
else: |
| 610 |
self.module.warn("Unable to obtain an alternate url!") |
| 611 |
|
| 612 |
def update(self): |
| 613 |
"""Update controller with new interface, dns service, ntp service and/or remote ssh access information.""" |
| 614 |
change_required = self.update_request_body() |
| 615 |
|
| 616 |
# Build list of available web services rest api urls |
| 617 |
self.available_embedded_api_urls = [] |
| 618 |
parsed_url = urlparse.urlparse(self.url) |
| 619 |
location = parsed_url.netloc.split(":") |
| 620 |
for address in self.all_interface_addresses: |
| 621 |
location[0] = address |
| 622 |
self.available_embedded_api_urls = ["%s://%s/%s" % (parsed_url.scheme, ":".join(location), self.DEFAULT_REST_API_PATH)] |
| 623 |
|
| 624 |
if change_required and not self.module.check_mode: |
| 625 |
|
| 626 |
# Update url if currently used interface will be modified |
| 627 |
if self.is_embedded(): |
| 628 |
if self.use_alternate_address: |
| 629 |
self.update_url() |
| 630 |
if self.address: |
| 631 |
parsed_url = urlparse.urlparse(self.url) |
| 632 |
location = parsed_url.netloc.split(":") |
| 633 |
location[0] = self.address |
| 634 |
self.available_embedded_api_urls.append("%s://%s/%s" % (parsed_url.scheme, ":".join(location), self.DEFAULT_REST_API_PATH)) |
| 635 |
else: |
| 636 |
self.available_embedded_api_urls = ["%s/%s" % (self.url, self.DEFAULT_REST_API_PATH)] |
| 637 |
|
| 638 |
# Update management interface |
| 639 |
try: |
| 640 |
rc, response = self.request("storage-systems/%s/configuration/ethernet-interfaces" % self.ssid, method="POST", data=self.body) |
| 641 |
except Exception as error: |
| 642 |
pass |
| 643 |
|
| 644 |
# Validate all changes have been made |
| 645 |
for retries in range(self.MAXIMUM_VERIFICATION_TIMEOUT): |
| 646 |
if not self.update_request_body(): |
| 647 |
break |
| 648 |
sleep(1) |
| 649 |
else: |
| 650 |
self.module.warn("Changes failed to complete! Timeout waiting for management interface to update. Array [%s]." % self.ssid) |
| 651 |
self.module.exit_json(msg="The interface settings have been updated.", changed=change_required, |
| 652 |
available_embedded_api_urls=self.available_embedded_api_urls) |
| 653 |
self.module.exit_json(msg="No changes are required.", changed=change_required, |
| 654 |
available_embedded_api_urls=self.available_embedded_api_urls if self.is_embedded() else []) |
| 655 |
|
| 656 |
|
| 657 |
def main(): |
| 658 |
interface = NetAppESeriesMgmtInterface() |
| 659 |
interface.update() |
| 660 |
|
| 661 |
|
| 662 |
if __name__ == "__main__": |
| 663 |
main() |