| 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_nvme_interface |
| 12 |
short_description: NetApp E-Series manage NVMe interface configuration |
| 13 |
description: Configure settings of an E-Series NVMe interface |
| 14 |
author: |
| 15 |
- Nathan Swartz (@swartzn) |
| 16 |
- Vu Tran (@VuTran007) |
| 17 |
extends_documentation_fragment: |
| 18 |
- netapp_eseries.santricity.santricity.santricity_doc |
| 19 |
options: |
| 20 |
address: |
| 21 |
description: |
| 22 |
- The IPv4 address to assign to the NVMe interface |
| 23 |
type: str |
| 24 |
required: false |
| 25 |
subnet_mask: |
| 26 |
description: |
| 27 |
- The subnet mask to utilize for the interface. |
| 28 |
- Only applicable when configuring RoCE |
| 29 |
- Mutually exclusive with I(config_method=dhcp) |
| 30 |
type: str |
| 31 |
required: false |
| 32 |
gateway: |
| 33 |
description: |
| 34 |
- The IPv4 gateway address to utilize for the interface. |
| 35 |
- Only applicable when configuring RoCE |
| 36 |
- Mutually exclusive with I(config_method=dhcp) |
| 37 |
type: str |
| 38 |
required: false |
| 39 |
config_method: |
| 40 |
description: |
| 41 |
- The configuration method type to use for this interface. |
| 42 |
- Only applicable when configuring RoCE |
| 43 |
- dhcp is mutually exclusive with I(address), I(subnet_mask), and I(gateway). |
| 44 |
type: str |
| 45 |
choices: |
| 46 |
- dhcp |
| 47 |
- static |
| 48 |
required: false |
| 49 |
default: dhcp |
| 50 |
mtu: |
| 51 |
description: |
| 52 |
- The maximum transmission units (MTU), in bytes. |
| 53 |
- Only applicable when configuring RoCE |
| 54 |
- This allows you to configure a larger value for the MTU, in order to enable jumbo frames |
| 55 |
(any value > 1500). |
| 56 |
- Generally, it is necessary to have your host, switches, and other components not only support jumbo |
| 57 |
frames, but also have it configured properly. Therefore, unless you know what you're doing, it's best to |
| 58 |
leave this at the default. |
| 59 |
type: int |
| 60 |
default: 1500 |
| 61 |
required: false |
| 62 |
aliases: |
| 63 |
- max_frame_size |
| 64 |
speed: |
| 65 |
description: |
| 66 |
- This is the ethernet port speed measured in Gb/s. |
| 67 |
- Value must be a supported speed or auto for automatically negotiating the speed with the port. |
| 68 |
- Only applicable when configuring RoCE |
| 69 |
- The configured ethernet port speed should match the speed capability of the SFP on the selected port. |
| 70 |
type: str |
| 71 |
required: false |
| 72 |
default: auto |
| 73 |
state: |
| 74 |
description: |
| 75 |
- Whether or not the specified RoCE interface should be enabled. |
| 76 |
- Only applicable when configuring RoCE |
| 77 |
choices: |
| 78 |
- enabled |
| 79 |
- disabled |
| 80 |
type: str |
| 81 |
required: false |
| 82 |
default: enabled |
| 83 |
channel: |
| 84 |
description: |
| 85 |
- This option specifies the which NVMe controller channel to configure. |
| 86 |
- The list of choices is not necessarily comprehensive. It depends on the number of ports |
| 87 |
that are available in the system. |
| 88 |
- The numerical value represents the number of the channel (typically from left to right on the HIC), |
| 89 |
beginning with a value of 1. |
| 90 |
type: int |
| 91 |
required: true |
| 92 |
controller: |
| 93 |
description: |
| 94 |
- The controller that owns the port you want to configure. |
| 95 |
- Controller names are presented alphabetically, with the first controller as A and the second as B. |
| 96 |
type: str |
| 97 |
required: true |
| 98 |
choices: [A, B] |
| 99 |
""" |
| 100 |
EXAMPLES = """ |
| 101 |
""" |
| 102 |
|
| 103 |
RETURN = """ |
| 104 |
msg: |
| 105 |
description: Success message |
| 106 |
returned: on success |
| 107 |
type: str |
| 108 |
sample: The interface settings have been updated. |
| 109 |
""" |
| 110 |
import re |
| 111 |
|
| 112 |
from ansible_collections.netapp_eseries.santricity.plugins.module_utils.santricity import NetAppESeriesModule |
| 113 |
from ansible.module_utils._text import to_native |
| 114 |
|
| 115 |
|
| 116 |
class NetAppESeriesNvmeInterface(NetAppESeriesModule): |
| 117 |
def __init__(self): |
| 118 |
ansible_options = dict(address=dict(type="str", required=False), |
| 119 |
subnet_mask=dict(type="str", required=False), |
| 120 |
gateway=dict(type="str", required=False), |
| 121 |
config_method=dict(type="str", required=False, default="dhcp", choices=["dhcp", "static"]), |
| 122 |
mtu=dict(type="int", default=1500, required=False, aliases=["max_frame_size"]), |
| 123 |
speed=dict(type="str", default="auto", required=False), |
| 124 |
state=dict(type="str", default="enabled", required=False, choices=["enabled", "disabled"]), |
| 125 |
channel=dict(type="int", required=True), |
| 126 |
controller=dict(type="str", required=True, choices=["A", "B"])) |
| 127 |
|
| 128 |
required_if = [["config_method", "static", ["address", "subnet_mask"]]] |
| 129 |
super(NetAppESeriesNvmeInterface, self).__init__(ansible_options=ansible_options, |
| 130 |
web_services_version="02.00.0000.0000", |
| 131 |
required_if=required_if, |
| 132 |
supports_check_mode=True) |
| 133 |
|
| 134 |
args = self.module.params |
| 135 |
self.address = args["address"] |
| 136 |
self.subnet_mask = args["subnet_mask"] |
| 137 |
self.gateway = args["gateway"] |
| 138 |
self.config_method = "configDhcp" if args["config_method"] == "dhcp" else "configStatic" |
| 139 |
self.mtu = args["mtu"] |
| 140 |
self.speed = args["speed"] |
| 141 |
self.enabled = args["state"] == "enabled" |
| 142 |
self.channel = args["channel"] |
| 143 |
self.controller = args["controller"] |
| 144 |
|
| 145 |
address_regex = re.compile(r"^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$") |
| 146 |
if self.address and not address_regex.match(self.address): |
| 147 |
self.module.fail_json(msg="An invalid ip address was provided for address. Address [%s]." % self.address) |
| 148 |
if self.subnet_mask and not address_regex.match(self.subnet_mask): |
| 149 |
self.module.fail_json(msg="An invalid ip address was provided for subnet_mask. Subnet mask [%s]." % self.subnet_mask) |
| 150 |
if self.gateway and not address_regex.match(self.gateway): |
| 151 |
self.module.fail_json(msg="An invalid ip address was provided for gateway. Gateway [%s]." % self.gateway) |
| 152 |
|
| 153 |
self.get_target_interface_cache = None |
| 154 |
|
| 155 |
def get_nvmeof_interfaces(self): |
| 156 |
"""Retrieve all interfaces that are using nvmeof""" |
| 157 |
ifaces = list() |
| 158 |
try: |
| 159 |
rc, ifaces = self.request("storage-systems/%s/interfaces?channelType=hostside" % self.ssid) |
| 160 |
except Exception as error: |
| 161 |
self.module.fail_json(msg="Failed to retrieve defined host interfaces. Array Id [%s]. Error [%s]." |
| 162 |
% (self.ssid, to_native(error))) |
| 163 |
|
| 164 |
# Filter out all not nvme-nvmeof hostside interfaces. |
| 165 |
nvmeof_ifaces = [] |
| 166 |
for iface in ifaces: |
| 167 |
interface_type = iface["ioInterfaceTypeData"]["interfaceType"] |
| 168 |
properties = iface["commandProtocolPropertiesList"]["commandProtocolProperties"] |
| 169 |
|
| 170 |
try: |
| 171 |
link_status = iface["ioInterfaceTypeData"]["ib"]["linkState"] |
| 172 |
except Exception as error: |
| 173 |
link_status = iface["ioInterfaceTypeData"]["ethernet"]["interfaceData"]["ethernetData"]["linkStatus"] |
| 174 |
|
| 175 |
if (properties and properties[0]["commandProtocol"] == "nvme" and |
| 176 |
properties[0]["nvmeProperties"]["commandSet"] == "nvmeof"): |
| 177 |
nvmeof_ifaces.append({"properties": properties[0]["nvmeProperties"]["nvmeofProperties"], |
| 178 |
"reference": iface["interfaceRef"], |
| 179 |
"channel": iface["ioInterfaceTypeData"][iface["ioInterfaceTypeData"]["interfaceType"]]["channel"], |
| 180 |
"interface_type": interface_type, |
| 181 |
"interface": iface["ioInterfaceTypeData"][interface_type], |
| 182 |
"controller_id": iface["controllerRef"], |
| 183 |
"link_status": link_status}) |
| 184 |
return nvmeof_ifaces |
| 185 |
|
| 186 |
def get_controllers(self): |
| 187 |
"""Retrieve a mapping of controller labels to their references""" |
| 188 |
controllers = list() |
| 189 |
try: |
| 190 |
rc, controllers = self.request("storage-systems/%s/graph/xpath-filter?query=/controller/id" % self.ssid) |
| 191 |
except Exception as error: |
| 192 |
self.module.fail_json(msg="Failed to retrieve controller list! Array Id [%s]. Error [%s]." |
| 193 |
% (self.ssid, to_native(error))) |
| 194 |
|
| 195 |
controllers.sort() |
| 196 |
controllers_dict = {} |
| 197 |
i = ord("A") |
| 198 |
for controller in controllers: |
| 199 |
label = chr(i) |
| 200 |
controllers_dict[label] = controller |
| 201 |
i += 1 |
| 202 |
|
| 203 |
return controllers_dict |
| 204 |
|
| 205 |
def get_target_interface(self): |
| 206 |
"""Retrieve the targeted controller interface""" |
| 207 |
if self.get_target_interface_cache is None: |
| 208 |
ifaces = self.get_nvmeof_interfaces() |
| 209 |
controller_id = self.get_controllers()[self.controller] |
| 210 |
|
| 211 |
controller_ifaces = [] |
| 212 |
for iface in ifaces: |
| 213 |
if iface["controller_id"] == controller_id: |
| 214 |
controller_ifaces.append(iface) |
| 215 |
|
| 216 |
sorted_controller_ifaces = sorted(controller_ifaces, key=lambda x: x["channel"]) |
| 217 |
if self.channel < 1 or self.channel > len(controller_ifaces): |
| 218 |
status_msg = ", ".join(["%s (link %s)" % (index + 1, iface["link_status"]) |
| 219 |
for index, iface in enumerate(sorted_controller_ifaces)]) |
| 220 |
self.module.fail_json(msg="Invalid controller %s NVMe channel. Available channels: %s, Array Id [%s]." |
| 221 |
% (self.controller, status_msg, self.ssid)) |
| 222 |
|
| 223 |
self.get_target_interface_cache = sorted_controller_ifaces[self.channel - 1] |
| 224 |
|
| 225 |
return self.get_target_interface_cache |
| 226 |
|
| 227 |
def update(self): |
| 228 |
"""Update the storage system's controller nvme interface if needed.""" |
| 229 |
update_required = False |
| 230 |
body = {} |
| 231 |
|
| 232 |
iface = self.get_target_interface() |
| 233 |
if iface["properties"]["provider"] == "providerInfiniband": |
| 234 |
if (iface["properties"]["ibProperties"]["ipAddressData"]["addressType"] != "ipv4" or |
| 235 |
iface["properties"]["ibProperties"]["ipAddressData"]["ipv4Data"]["ipv4Address"] != self.address): |
| 236 |
update_required = True |
| 237 |
body = {"settings": {"ibSettings": {"networkSettings": {"ipv4Address": self.address}}}} |
| 238 |
|
| 239 |
elif iface["properties"]["provider"] == "providerRocev2": |
| 240 |
interface_data = iface["interface"]["interfaceData"]["ethernetData"] |
| 241 |
current_speed = interface_data["currentInterfaceSpeed"].lower().replace("speed", "").replace("gig", "") |
| 242 |
interface_supported_speeds = [str(speed).lower().replace("speed", "").replace("gig", "") |
| 243 |
for speed in interface_data["supportedInterfaceSpeeds"]] |
| 244 |
if self.speed not in interface_supported_speeds: |
| 245 |
self.module.fail_json(msg="Unsupported interface speed! Options %s. Array [%s]." |
| 246 |
% (interface_supported_speeds, self.ssid)) |
| 247 |
|
| 248 |
roce_properties = iface["properties"]["roceV2Properties"] |
| 249 |
if self.enabled != roce_properties["ipv4Enabled"]: |
| 250 |
update_required = True |
| 251 |
if self.address and roce_properties["ipv4Data"]["ipv4AddressConfigMethod"] != self.config_method: |
| 252 |
update_required = True |
| 253 |
if self.address and roce_properties["ipv4Data"]["ipv4AddressData"]["ipv4Address"] != self.address: |
| 254 |
update_required = True |
| 255 |
if self.subnet_mask and roce_properties["ipv4Data"]["ipv4AddressData"]["ipv4SubnetMask"] != self.subnet_mask: |
| 256 |
update_required = True |
| 257 |
if self.gateway and roce_properties["ipv4Data"]["ipv4AddressData"]["ipv4GatewayAddress"] != self.gateway: |
| 258 |
update_required = True |
| 259 |
if self.speed and self.speed != current_speed: |
| 260 |
update_required = True |
| 261 |
if (self.mtu and iface["interface"]["interfaceData"]["ethernetData"][ |
| 262 |
"maximumFramePayloadSize"] != self.mtu): |
| 263 |
update_required = True |
| 264 |
|
| 265 |
if update_required: |
| 266 |
body = {"id": iface["reference"], "settings": {"roceV2Settings": { |
| 267 |
"networkSettings": {"ipv4Enabled": self.enabled, |
| 268 |
"ipv4Settings": {"configurationMethod": self.config_method}}}}} |
| 269 |
|
| 270 |
if self.config_method == "configStatic": |
| 271 |
if self.address: |
| 272 |
body["settings"]["roceV2Settings"]["networkSettings"]["ipv4Settings"].update( |
| 273 |
{"address": self.address}) |
| 274 |
if self.subnet_mask: |
| 275 |
body["settings"]["roceV2Settings"]["networkSettings"]["ipv4Settings"].update( |
| 276 |
{"subnetMask": self.subnet_mask}) |
| 277 |
if self.gateway: |
| 278 |
body["settings"]["roceV2Settings"]["networkSettings"]["ipv4Settings"].update( |
| 279 |
{"gatewayAddress": self.gateway}) |
| 280 |
if self.speed: |
| 281 |
if self.speed == "auto": |
| 282 |
body["settings"]["roceV2Settings"]["networkSettings"].update({"interfaceSpeed": "speedAuto"}) |
| 283 |
else: |
| 284 |
body["settings"]["roceV2Settings"]["networkSettings"].update( |
| 285 |
{"interfaceSpeed": "speed%sgig" % self.speed}) |
| 286 |
if self.mtu: |
| 287 |
body["settings"]["roceV2Settings"]["networkSettings"].update({"interfaceMtu": self.mtu}) |
| 288 |
|
| 289 |
if update_required and not self.module.check_mode: |
| 290 |
try: |
| 291 |
rc, iface = self.request("storage-systems/%s/nvmeof/interfaces/%s" % (self.ssid, iface["reference"]), |
| 292 |
method="POST", data=body) |
| 293 |
except Exception as error: |
| 294 |
self.module.fail_json(msg="Failed to configure interface. Array Id [%s]. Error [%s]." |
| 295 |
% (self.ssid, to_native(error))) |
| 296 |
|
| 297 |
self.module.exit_json(msg="NVMeoF interface settings have been updated.", changed=update_required) |
| 298 |
self.module.exit_json(msg="No changes have been made.", changed=update_required) |
| 299 |
|
| 300 |
|
| 301 |
def main(): |
| 302 |
nvmeof_interface = NetAppESeriesNvmeInterface() |
| 303 |
nvmeof_interface.update() |
| 304 |
|
| 305 |
|
| 306 |
if __name__ == "__main__": |
| 307 |
main() |