| 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_ib_iser_interface |
| 12 |
short_description: NetApp E-Series manage InfiniBand iSER interface configuration |
| 13 |
description: |
| 14 |
- Configure settings of an E-Series InfiniBand iSER interface IPv4 address configuration. |
| 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 |
controller: |
| 23 |
description: |
| 24 |
- The controller that owns the port you want to configure. |
| 25 |
- Controller names are presented alphabetically, with the first controller as A, the second as B, and so on. |
| 26 |
- Current hardware models have either 1 or 2 available controllers, but that is not a guaranteed hard limitation and could change in the future. |
| 27 |
type: str |
| 28 |
required: true |
| 29 |
choices: |
| 30 |
- A |
| 31 |
- B |
| 32 |
channel: |
| 33 |
description: |
| 34 |
- The InfiniBand HCA port you wish to modify. |
| 35 |
- Ports start left to right and start with 1. |
| 36 |
type: int |
| 37 |
required: true |
| 38 |
address: |
| 39 |
description: |
| 40 |
- The IPv4 address to assign to the interface. |
| 41 |
- Should be specified in xx.xx.xx.xx form. |
| 42 |
type: str |
| 43 |
required: true |
| 44 |
notes: |
| 45 |
- Check mode is supported. |
| 46 |
""" |
| 47 |
|
| 48 |
EXAMPLES = """ |
| 49 |
- name: Configure the first port on the A controller with a static IPv4 address |
| 50 |
na_santricity_ib_iser_interface: |
| 51 |
ssid: "1" |
| 52 |
api_url: "https://192.168.1.100:8443/devmgr/v2" |
| 53 |
api_username: "admin" |
| 54 |
api_password: "adminpass" |
| 55 |
validate_certs: true |
| 56 |
controller: "A" |
| 57 |
channel: "1" |
| 58 |
address: "192.168.1.100" |
| 59 |
""" |
| 60 |
|
| 61 |
RETURN = """ |
| 62 |
msg: |
| 63 |
description: Success message |
| 64 |
returned: on success |
| 65 |
type: str |
| 66 |
sample: The interface settings have been updated. |
| 67 |
enabled: |
| 68 |
description: |
| 69 |
- Indicates whether IPv4 connectivity has been enabled or disabled. |
| 70 |
- This does not necessarily indicate connectivity. If dhcp was enabled without a dhcp server, for instance, |
| 71 |
it is unlikely that the configuration will actually be valid. |
| 72 |
returned: on success |
| 73 |
sample: True |
| 74 |
type: bool |
| 75 |
""" |
| 76 |
import re |
| 77 |
|
| 78 |
from ansible_collections.netapp_eseries.santricity.plugins.module_utils.santricity import NetAppESeriesModule |
| 79 |
from ansible.module_utils._text import to_native |
| 80 |
|
| 81 |
|
| 82 |
class NetAppESeriesIbIserInterface(NetAppESeriesModule): |
| 83 |
def __init__(self): |
| 84 |
ansible_options = dict(controller=dict(type="str", required=True, choices=["A", "B"]), |
| 85 |
channel=dict(type="int", required=True), |
| 86 |
address=dict(type="str", required=True)) |
| 87 |
|
| 88 |
super(NetAppESeriesIbIserInterface, self).__init__(ansible_options=ansible_options, |
| 89 |
web_services_version="02.00.0000.0000", |
| 90 |
supports_check_mode=True) |
| 91 |
|
| 92 |
args = self.module.params |
| 93 |
self.controller = args["controller"] |
| 94 |
self.channel = args["channel"] |
| 95 |
self.address = args["address"] |
| 96 |
self.check_mode = self.module.check_mode |
| 97 |
|
| 98 |
self.get_target_interface_cache = None |
| 99 |
|
| 100 |
# A relatively primitive regex to validate that the input is formatted like a valid ip address |
| 101 |
address_regex = re.compile(r"^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$") |
| 102 |
if self.address and not address_regex.match(self.address): |
| 103 |
self.module.fail_json(msg="An invalid ip address was provided for address.") |
| 104 |
|
| 105 |
def get_interfaces(self): |
| 106 |
"""Retrieve and filter all hostside interfaces for IB iSER.""" |
| 107 |
ifaces = [] |
| 108 |
try: |
| 109 |
rc, ifaces = self.request("storage-systems/%s/interfaces?channelType=hostside" % self.ssid) |
| 110 |
except Exception as err: |
| 111 |
self.module.fail_json(msg="Failed to retrieve defined host interfaces. Array Id [%s]. Error [%s]." % (self.ssid, to_native(err))) |
| 112 |
|
| 113 |
# Filter out non-ib-iser interfaces |
| 114 |
ib_iser_ifaces = [] |
| 115 |
for iface in ifaces: |
| 116 |
if ((iface["ioInterfaceTypeData"]["interfaceType"] == "iscsi" and |
| 117 |
iface["ioInterfaceTypeData"]["iscsi"]["interfaceData"]["type"] == "infiniband" and |
| 118 |
iface["ioInterfaceTypeData"]["iscsi"]["interfaceData"]["infinibandData"]["isIser"]) or |
| 119 |
(iface["ioInterfaceTypeData"]["interfaceType"] == "ib" and |
| 120 |
iface["ioInterfaceTypeData"]["ib"]["isISERSupported"])): |
| 121 |
ib_iser_ifaces.append(iface) |
| 122 |
|
| 123 |
if not ib_iser_ifaces: |
| 124 |
self.module.fail_json(msg="Failed to detect any InfiniBand iSER interfaces! Array [%s] - %s." % self.ssid) |
| 125 |
|
| 126 |
return ib_iser_ifaces |
| 127 |
|
| 128 |
def get_controllers(self): |
| 129 |
"""Retrieve a mapping of controller labels to their references |
| 130 |
{ |
| 131 |
'A': '070000000000000000000001', |
| 132 |
'B': '070000000000000000000002', |
| 133 |
} |
| 134 |
:return: the controllers defined on the system |
| 135 |
""" |
| 136 |
controllers = list() |
| 137 |
try: |
| 138 |
rc, controllers = self.request("storage-systems/%s/graph/xpath-filter?query=/controller/id" % self.ssid) |
| 139 |
except Exception as err: |
| 140 |
self.module.fail_json(msg="Failed to retrieve controller list! Array Id [%s]. Error [%s]." |
| 141 |
% (self.ssid, to_native(err))) |
| 142 |
|
| 143 |
controllers.sort() |
| 144 |
|
| 145 |
controllers_dict = {} |
| 146 |
i = ord('A') |
| 147 |
for controller in controllers: |
| 148 |
label = chr(i) |
| 149 |
controllers_dict[label] = controller |
| 150 |
i += 1 |
| 151 |
|
| 152 |
return controllers_dict |
| 153 |
|
| 154 |
def get_ib_link_status(self): |
| 155 |
"""Determine the infiniband link status. Returns dictionary keyed by interface reference number.""" |
| 156 |
link_statuses = {} |
| 157 |
try: |
| 158 |
rc, result = self.request("storage-systems/%s/hardware-inventory" % self.ssid) |
| 159 |
for link in result["ibPorts"]: |
| 160 |
link_statuses.update({link["channelPortRef"]: link["linkState"]}) |
| 161 |
except Exception as error: |
| 162 |
self.module.fail_json(msg="Failed to retrieve ib link status information! Array Id [%s]. Error [%s]." |
| 163 |
% (self.ssid, to_native(error))) |
| 164 |
|
| 165 |
return link_statuses |
| 166 |
|
| 167 |
def get_target_interface(self): |
| 168 |
"""Search for the selected IB iSER interface""" |
| 169 |
if self.get_target_interface_cache is None: |
| 170 |
ifaces = self.get_interfaces() |
| 171 |
ifaces_status = self.get_ib_link_status() |
| 172 |
controller_id = self.get_controllers()[self.controller] |
| 173 |
|
| 174 |
controller_ifaces = [] |
| 175 |
for iface in ifaces: |
| 176 |
if iface["ioInterfaceTypeData"]["interfaceType"] == "iscsi" and iface["controllerRef"] == controller_id: |
| 177 |
controller_ifaces.append([iface["ioInterfaceTypeData"]["iscsi"]["channel"], iface, |
| 178 |
ifaces_status[iface["ioInterfaceTypeData"]["iscsi"]["channelPortRef"]]]) |
| 179 |
elif iface["ioInterfaceTypeData"]["interfaceType"] == "ib" and iface["controllerRef"] == controller_id: |
| 180 |
controller_ifaces.append([iface["ioInterfaceTypeData"]["ib"]["channel"], iface, |
| 181 |
iface["ioInterfaceTypeData"]["ib"]["linkState"]]) |
| 182 |
|
| 183 |
sorted_controller_ifaces = sorted(controller_ifaces) |
| 184 |
if self.channel < 1 or self.channel > len(controller_ifaces): |
| 185 |
status_msg = ", ".join(["%s (link %s)" % (index + 1, values[2]) |
| 186 |
for index, values in enumerate(sorted_controller_ifaces)]) |
| 187 |
self.module.fail_json(msg="Invalid controller %s HCA channel. Available channels: %s, Array Id [%s]." |
| 188 |
% (self.controller, status_msg, self.ssid)) |
| 189 |
|
| 190 |
self.get_target_interface_cache = sorted_controller_ifaces[self.channel - 1][1] |
| 191 |
return self.get_target_interface_cache |
| 192 |
|
| 193 |
def is_change_required(self): |
| 194 |
"""Determine whether change is required.""" |
| 195 |
changed_required = False |
| 196 |
iface = self.get_target_interface() |
| 197 |
if (iface["ioInterfaceTypeData"]["interfaceType"] == "iscsi" and |
| 198 |
iface["ioInterfaceTypeData"]["iscsi"]["ipv4Data"]["ipv4AddressData"]["ipv4Address"] != self.address): |
| 199 |
changed_required = True |
| 200 |
|
| 201 |
elif iface["ioInterfaceTypeData"]["interfaceType"] == "ib" and iface["ioInterfaceTypeData"]["ib"]["isISERSupported"]: |
| 202 |
for properties in iface["commandProtocolPropertiesList"]["commandProtocolProperties"]: |
| 203 |
if (properties["commandProtocol"] == "scsi" and |
| 204 |
properties["scsiProperties"]["scsiProtocolType"] == "iser" and |
| 205 |
properties["scsiProperties"]["iserProperties"]["ipv4Data"]["ipv4AddressData"]["ipv4Address"] != self.address): |
| 206 |
changed_required = True |
| 207 |
|
| 208 |
return changed_required |
| 209 |
|
| 210 |
def make_request_body(self): |
| 211 |
iface = self.get_target_interface() |
| 212 |
body = {"iscsiInterface": iface["ioInterfaceTypeData"][iface["ioInterfaceTypeData"]["interfaceType"]]["id"], |
| 213 |
"settings": {"tcpListenPort": [], |
| 214 |
"ipv4Address": [self.address], |
| 215 |
"ipv4SubnetMask": [], |
| 216 |
"ipv4GatewayAddress": [], |
| 217 |
"ipv4AddressConfigMethod": [], |
| 218 |
"maximumFramePayloadSize": [], |
| 219 |
"ipv4VlanId": [], |
| 220 |
"ipv4OutboundPacketPriority": [], |
| 221 |
"ipv4Enabled": [], |
| 222 |
"ipv6Enabled": [], |
| 223 |
"ipv6LocalAddresses": [], |
| 224 |
"ipv6RoutableAddresses": [], |
| 225 |
"ipv6PortRouterAddress": [], |
| 226 |
"ipv6AddressConfigMethod": [], |
| 227 |
"ipv6OutboundPacketPriority": [], |
| 228 |
"ipv6VlanId": [], |
| 229 |
"ipv6HopLimit": [], |
| 230 |
"ipv6NdReachableTime": [], |
| 231 |
"ipv6NdRetransmitTime": [], |
| 232 |
"ipv6NdStaleTimeout": [], |
| 233 |
"ipv6DuplicateAddressDetectionAttempts": [], |
| 234 |
"maximumInterfaceSpeed": []}} |
| 235 |
return body |
| 236 |
|
| 237 |
def update(self): |
| 238 |
"""Make any necessary updates.""" |
| 239 |
update_required = self.is_change_required() |
| 240 |
if update_required and not self.check_mode: |
| 241 |
try: |
| 242 |
rc, result = self.request("storage-systems/%s/symbol/setIscsiInterfaceProperties" |
| 243 |
% self.ssid, method="POST", data=self.make_request_body()) |
| 244 |
except Exception as error: |
| 245 |
self.module.fail_json(msg="Failed to modify the interface! Array Id [%s]. Error [%s]." |
| 246 |
% (self.ssid, to_native(error))) |
| 247 |
self.module.exit_json(msg="The interface settings have been updated.", changed=update_required) |
| 248 |
|
| 249 |
self.module.exit_json(msg="No changes were required.", changed=update_required) |
| 250 |
|
| 251 |
|
| 252 |
def main(): |
| 253 |
ib_iser = NetAppESeriesIbIserInterface() |
| 254 |
ib_iser.update() |
| 255 |
|
| 256 |
|
| 257 |
if __name__ == "__main__": |
| 258 |
main() |