Debian Codegraph @

ansible_collections/dellemc/openmanage/plugins/module_utils/idrac_utils/info/pcidevice.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
29 GET_IDRAC_PCI_DETAILS_URI = "/redfish/v1/Chassis/System.Embedded.1/PCIeDevices/"
30 NA = "Not Available"
31 SLOT_TYPE_MAPPING = {
32 "Other": "0001",
33 "Unknown": "0002",
34 "ISA": "0003",
35 "MCA": "0004",
36 "EISA": "0005",
37 "PCI": "0006",
38 "PC Card (PCMCIA)": "0007",
39 "VL-VESA": "0008",
40 "Proprietary": "0009",
41 "Processor Card Slot": "000A",
42 "Proprietary Memory Card Slot": "000B",
43 "I/O Riser Card Slot": "000C",
44 "NuBus": "000D",
45 "PCI - 66MHz Capable": "000E",
46 "AGP": "000F",
47 "AGP 2X": "0010",
48 "AGP 4X": "0011",
49 "PCI-X": "0012",
50 "AGP 8X": "0013",
51 "PC-98/C20": "00A0",
52 "PC-98/C24": "00A1",
53 "PC-98/E": "00A2",
54 "PC-98/Local Bus": "00A3",
55 "PC-98/Card": "00A4",
56 "PCI Express": "00A5",
57 "PCI Express x1": "00A6",
58 "PCI Express x2": "00A7",
59 "PCI Express x4": "00A8",
60 "PCI Express x8": "00A9",
61 "PCI Express x16": "00AA",
62 "PCI Express Gen 2": "00AB",
63 "PCI Express Gen 2 x1": "00AC",
64 "PCI Express Gen 2 x2": "00AD",
65 "PCI Express Gen 2 x4": "00AE",
66 "PCI Express Gen 2 x8": "00AF",
67 "PCI Express Gen 2 x16": "00B0",
68 "PCI Express Gen 3": "00B1",
69 "PCI Express Gen 3 x1": "00B2",
70 "PCI Express Gen 3 x2": "00B3",
71 "PCI Express Gen 3 x4": "00B4",
72 "PCI Express Gen 3 x8": "00B5",
73 "PCI Express Gen 3 x16": "00B6"
74 }
75 SLOT_LENGTH_MAPPING = {
76 "Other": "0001",
77 "Unknown": "0002",
78 "Short Length": "0003",
79 "Long Length": "0004"
80 }
81 BUS_WIDTH_MAPPING = {
82 "Other": "0001",
83 "Unknown": "0002",
84 "8Bit": "0003",
85 "16Bit": "0004",
86 "32Bit": "0005",
87 "64Bit": "0006",
88 "128Bit": "0007",
89 "1XOrX1": "0008",
90 "2XOrX2": "0009",
91 "4XOrX4": "000A",
92 "8XOrX8": "000B",
93 "12XOrX12": "000C",
94 "16XOrX16": "000D",
95 "32XOrX32": "000E"
96 }
97
98
99 class IDRACPCIDeviceInfo(object):
100 def __init__(self, idrac):
101 self.idrac = idrac
102
103 def get_device_links(self):
104 response = self.idrac.invoke_request(method='GET', uri=GET_IDRAC_PCI_DETAILS_URI)
105 device_links_list = []
106 if response.status_code == 200:
107 members = response.json_data.get("Members")
108 for each in members:
109 device_links_list.append(each.get("@odata.id"))
110 return device_links_list
111
112 def get_device_function_details(self, function_link):
113 response = self.idrac.invoke_request(method='GET', uri=function_link)
114 buswidth = NA
115 slot_type = NA
116 deviceid = NA
117 buswidth_api = NA
118 slot_type_api = NA
119 slot_length = NA
120 slot_length_api = NA
121 if response.status_code == 200:
122 resp = response.json_data.get("Oem", {}).\
123 get("Dell", {}).get("DellPCIeFunction", {})
124 buswidth = \
125 BUS_WIDTH_MAPPING.get(resp.get("DataBusWidth"), NA)
126 buswidth_api = resp.get("DataBusWidth")
127 deviceid = resp.get("Id", NA)
128 slot_type = \
129 SLOT_TYPE_MAPPING.get(resp.get("SlotType"), NA)
130 slot_type_api = resp.get("SlotType")
131 slot_length = \
132 SLOT_LENGTH_MAPPING.get(resp.get("SlotLength"), NA)
133 slot_length_api = resp.get("SlotLength")
134 return buswidth, buswidth_api, deviceid, slot_type, slot_type_api, slot_length, slot_length_api
135
136 def get_device_details(self, device_link):
137 response = self.idrac.invoke_request(method='GET', uri=device_link)
138 functions_output = []
139 if response.status_code == 200:
140 pci_functions = response.json_data.get("Links", {}).\
141 get("PCIeFunctions", [{}])
142 for link in pci_functions:
143 output = {}
144 device_link = link.get("@odata.id")
145 if device_link is not None:
146 buswidth, buswidth_api, deviceid, slot_type, \
147 slot_type_api, slot_length, slot_length_api = \
148 self.get_device_function_details(device_link)
149 else:
150 buswidth = NA
151 slot_type = NA
152 deviceid = NA
153 buswidth_api = NA
154 slot_type_api = NA
155 slot_length = NA
156 slot_length_api = NA
157 output["DataBusWidth"] = buswidth
158 output["DataBusWidth_API"] = buswidth_api
159 output["DeviceDescription"] = response.json_data.get("Description")
160 output["FQDD"] = deviceid
161 output["Key"] = deviceid
162 output["Manufacturer"] = response.json_data.get("Manufacturer")
163 output["SlotLength"] = slot_length
164 output["SlotLength_API"] = slot_length_api
165 output["SlotType"] = slot_type
166 output["SlotType_API"] = slot_type_api
167 output["Description"] = response.json_data.get("Description")
168 functions_output.append(output)
169 return functions_output
170
171 def get_pcidevice_info(self):
172 pcidevice_output = []
173 device_links_list = self.get_device_links()
174 for each_link in device_links_list:
175 pcidevice_output.extend(self.get_device_details(each_link))
176 return pcidevice_output