Debian Codegraph @

ansible_collections/dellemc/openmanage/plugins/module_utils/idrac_utils/info/nic.py

raw symbols SCIP
1 # -*- coding: utf-8 -*-
2
3 # Dell OpenManage Ansible Modules
4 # Version 9.12.0
5 # Copyright (C) 2025 Dell Inc. or its subsidiaries. All Rights Reserved.
6
7 # Redistribution and use in source and binary forms, with or without modification,
8 # are permitted provided that the following conditions are met:
9
10 # * Redistributions of source code must retain the above copyright notice,
11 # this list of conditions and the following disclaimer.
12
13 # * Redistributions in binary form must reproduce the above copyright notice,
14 # this list of conditions and the following disclaimer in the documentation
15 # and/or other materials provided with the distribution.
16
17 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
18 # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 # IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
21 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
22 # PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
25 # USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 #
27
28 GET_IDRAC_NIC_DETAILS_URI = "/redfish/v1/Chassis/System.Embedded.1/Oem/Dell/DellNIC"
29 GET_IDRAC_NIC_CAPABILITY_DETAILS_URI = "/redfish/v1/Chassis/System.Embedded.1/Oem/Dell/DellNICCapabilities"
30 GET_IDRAC_NIC_PORT_METRICS_DETAILS_URI = "/redfish/v1/Chassis/System.Embedded.1//Oem/Dell/DellNICPortMetrics"
31 GET_IDRAC_ETHERNET_DETAILS_URI = "/redfish/v1/Managers/iDRAC.Embedded.1/EthernetInterfaces/"
32 GET_IDRAC_STATISTICS_DETAILS_URI = "/redfish/v1/Chassis/System.Embedded.1/Oem/Dell/DellNICStatistics"
33 GET_IDRAC_MANAGER_ATTRIBUTES = "/redfish/v1/Managers/iDRAC.Embedded.1/Oem/Dell/DellAttributes/iDRAC.Embedded.1"
34 NA = "Not Available"
35
36
37 class IDRACNICInfo(object):
38 def __init__(self, idrac):
39 self.idrac = idrac
40
41 def get_nic_capability_details(self, id):
42 response = self.idrac.invoke_request(method='GET', uri=GET_IDRAC_NIC_CAPABILITY_DETAILS_URI)
43 if response.status_code == 200:
44 for member in response.json_data.get("Members", []):
45 if member.get("Id", "") == id:
46 dcb_protocol = member.get("DCBExchangeProtocol", "")
47 fcoe_boot_support = member.get("FCoEBootSupport", "")
48 fcoe_offload_support = member.get("FCoEOffloadSupport", "")
49 flex_add_support = member.get("FlexAddressingSupport", "")
50 nic_part_support = member.get("NicPartitioningSupport", "")
51 pxe_boot_support = member.get("PXEBootSupport", "")
52 tcp_chimney_support = member.get("TCPChimneySupport", "")
53 wol_support = member.get("PartitionWOLSupport", "")
54 iscsi_boot_support = member.get("iSCSIBootSupport", "")
55 iscsi_offload_support = member.get("iSCSIOffloadSupport", "")
56 return dcb_protocol, fcoe_boot_support, fcoe_offload_support, flex_add_support, \
57 nic_part_support, pxe_boot_support, tcp_chimney_support, wol_support, \
58 iscsi_boot_support, iscsi_offload_support
59
60 return "", "", "", "", "", "", "", "", "", ""
61
62 def get_nic_port_metrics_details(self, id):
63 response = self.idrac.invoke_request(method='GET', uri=GET_IDRAC_NIC_PORT_METRICS_DETAILS_URI)
64 if response.status_code == 200:
65 for member in response.json_data.get("Members", []):
66 if member.get("Id", "") == id:
67 link_status = member.get("PartitionLinkStatus", "")
68 return link_status
69 return ""
70
71 def get_nic_statistics_details(self, id):
72 response = self.idrac.invoke_request(method='GET', uri=GET_IDRAC_STATISTICS_DETAILS_URI)
73 if response.status_code == 200:
74 for member in response.json_data.get("Members", []):
75 if member.get("Id", "") == id:
76 rx_bytes = member.get("RxBytes", "")
77 rx_multicast = member.get("RxMutlicastPackets", "")
78 rx_unicast = member.get("RxUnicastPackets", "")
79 tx_bytes = member.get("TxBytes", "")
80 tx_multicast = member.get("TxMutlicastPackets", "")
81 tx_unicast = member.get("TxUnicastPackets", "")
82 return rx_bytes, rx_multicast, rx_unicast, tx_bytes, tx_multicast, tx_unicast
83 return "", "", "", "", "", ""
84
85 def get_ethernet_details(self):
86 response = self.idrac.invoke_request(method='GET', uri=GET_IDRAC_ETHERNET_DETAILS_URI)
87 if response.status_code == 200:
88 members = response.json_data.get("Members", [])
89 if members:
90 first_member_uri = members[0].get("@odata.id")
91 if first_member_uri:
92 eth_resp = self.idrac.invoke_request(method='GET', uri=first_member_uri)
93 if eth_resp.status_code == 200:
94 mac_address = eth_resp.json_data.get("MACAddress", "")
95 link_speed = eth_resp.json_data.get("SpeedMbps", "")
96 auto_neg = eth_resp.json_data.get("AutoNeg", "")
97 perm_mac_addr = eth_resp.json_data.get("PermanentMACAddress", "")
98 health = eth_resp.json_data.get("Status", {}).get("Health", NA)
99 return mac_address, link_speed, auto_neg, perm_mac_addr, health
100 return "", "", "", "", ""
101
102 def map_nic_data(self, nic, id):
103 """Maps NIC fields from the API response to a structured format."""
104 def sanitize(value):
105 return NA if value == "" else value
106
107 dcb_protocol, fcoe_boot_support, fcoe_offload_support, flex_add_support, nic_part_support, \
108 pxe_boot_support, tcp_chimney_support, wol_support, iscsi_boot_support, iscsi_offload_support = self.get_nic_capability_details(id)
109
110 link_status = self.get_nic_port_metrics_details(id)
111 mac_address, link_speed, auto_neg, perm_mac_addr, health = self.get_ethernet_details()
112 rx_bytes, rx_multicast, rx_unicast, tx_bytes, tx_multicast, tx_unicast = self.get_nic_statistics_details(id)
113
114 output = {
115 "AutoNegotiation": sanitize(auto_neg),
116 "ControllerBIOSVersion": nic.get("ControllerBIOSVersion", NA),
117 "CurrentMACAddress": sanitize(mac_address),
118 "DCBExchangeProtocol": sanitize(dcb_protocol),
119 "DataBusWidth": nic.get("DataBusWidth", NA),
120 "DeviceDescription": nic.get("Description", NA),
121 "EFIVersion": nic.get("EFIVersion", NA),
122 "FCoEBootSupport": sanitize(fcoe_boot_support),
123 "FCoEOffloadMode": nic.get("FCoEOffloadMode", NA),
124 "FCoEOffloadSupport": sanitize(fcoe_offload_support),
125 "FCoEWWNN": nic.get("FCoEWWNN", NA),
126 "FQDD": nic.get("Id", NA),
127 "FamilyVersion": nic.get("FamilyVersion", NA),
128 "FlexAddressingSupport": sanitize(flex_add_support),
129 "IPv4Address": nic.get("IPv4Addresses", NA),
130 "IPv6Address": nic.get("IPv6Addresses", NA),
131 "Key": nic.get("Id", NA),
132 "LinkDuplex": nic.get("LinkDuplex", NA),
133 "LinkSpeed": sanitize(link_speed),
134 "LinkStatus": sanitize(link_status),
135 "MaxBandwidthPercent": nic.get("MaxBandwidthPercent", NA),
136 "MediaType": nic.get("MediaType", NA),
137 "NICCapabilities": nic.get("NICCapabilities", NA),
138 "NicMode": nic.get("NicMode", NA),
139 "NicPartitioningSupport": sanitize(nic_part_support),
140 "PXEBootSupport": sanitize(pxe_boot_support),
141 "PermanentFCOEMACAddress": nic.get("PermanentFCOEMACAddress", NA),
142 "PermanentMACAddress": sanitize(perm_mac_addr),
143 "PermanentiSCSIMACAddress": nic.get("PermanentiSCSIMACAddress", NA),
144 "PrimaryStatus": "Healthy" if health == "OK" else health,
145 "ProductName": nic.get("ProductName", NA),
146 "Protocol": nic.get("Protocol", NA),
147 "RxBytes": sanitize(rx_bytes),
148 "RxMutlicast": sanitize(rx_multicast),
149 "RxUnicast": sanitize(rx_unicast),
150 "SupportedBootProtocol": nic.get("SupportedBootProtocol", NA),
151 "SwitchConnectionID": nic.get("SwitchConnectionID", NA),
152 "SwitchPortConnectionID": nic.get("SwitchPortConnectionID", NA),
153 "TCPChimneySupport": sanitize(tcp_chimney_support),
154 "TxBytes": sanitize(tx_bytes),
155 "TxMutlicast": sanitize(tx_multicast),
156 "TxUnicast": sanitize(tx_unicast),
157 "VFSRIOVSupport": nic.get("VFSRIOVSupport", NA),
158 "VendorName": nic.get("VendorName", NA),
159 "VirtMacAddr": sanitize(mac_address),
160 "VirtWWN": nic.get("VirtWWN", NA),
161 "VirtWWPN": nic.get("VirtWWPN", NA),
162 "WOLSupport": sanitize(wol_support),
163 "WWN": nic.get("WWN", NA),
164 "WWPN": nic.get("WWPN", NA),
165 "iSCSIBootSupport": sanitize(iscsi_boot_support),
166 "iSCSIOffloadSupport": sanitize(iscsi_offload_support),
167 "iScsiOffloadMode": nic.get("iScsiOffloadMode", NA)
168 }
169 return output
170
171 def get_nic_info(self):
172 """Fetches NIC data from iDRAC and maps it."""
173 output = []
174 resp = self.idrac.invoke_request(method='GET', uri=GET_IDRAC_NIC_DETAILS_URI)
175
176 if resp.status_code == 200:
177 nic_members = resp.json_data.get("Members", [])
178 for nic in nic_members:
179 output.append(self.map_nic_data(nic, nic.get("Id")))
180 return output