| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 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 |