MCPcopy Create free account
hub / github.com/F-Stack/f-stack / get_device_details

Function get_device_details

dpdk/usertools/dpdk-devbind.py:204–282  ·  view source on GitHub ↗

This function populates the "devices" dictionary. The keys used are the pci addresses (domain:bus:slot.func). The values are themselves dictionaries - one for each NIC.

(devices_type)

Source from the content-addressed store, hash-verified

202
203
204def get_device_details(devices_type):
205 '''This function populates the "devices" dictionary. The keys used are
206 the pci addresses (domain:bus:slot.func). The values are themselves
207 dictionaries - one for each NIC.'''
208 global devices
209 global dpdk_drivers
210
211 # first loop through and read details for all devices
212 # request machine readable format, with numeric IDs and String
213 dev = {}
214 dev_lines = subprocess.check_output(["lspci", "-Dvmmnnk"]).splitlines()
215 for dev_line in dev_lines:
216 if not dev_line:
217 if device_type_match(dev, devices_type):
218 # Replace "Driver" with "Driver_str" to have consistency of
219 # of dictionary key names
220 if "Driver" in dev.keys():
221 dev["Driver_str"] = dev.pop("Driver")
222 if "Module" in dev.keys():
223 dev["Module_str"] = dev.pop("Module")
224 # use dict to make copy of dev
225 devices[dev["Slot"]] = dict(dev)
226 # Clear previous device's data
227 dev = {}
228 else:
229 name, value = dev_line.decode("utf8").split("\t", 1)
230 value_list = value.rsplit(' ', 1)
231 if value_list:
232 # String stored in <name>_str
233 dev[name.rstrip(":") + '_str'] = value_list[0]
234 # Numeric IDs
235 dev[name.rstrip(":")] = value_list[len(value_list) - 1] \
236 .rstrip("]").lstrip("[")
237
238 if devices_type == network_devices:
239 # check what is the interface if any for an ssh connection if
240 # any to this host, so we can mark it later.
241 ssh_if = []
242 route = subprocess.check_output(["ip", "-o", "route"])
243 # filter out all lines for 169.254 routes
244 route = "\n".join(filter(lambda ln: not ln.startswith("169.254"),
245 route.decode().splitlines()))
246 rt_info = route.split()
247 for i in range(len(rt_info) - 1):
248 if rt_info[i] == "dev":
249 ssh_if.append(rt_info[i + 1])
250
251 # based on the basic info, get extended text details
252 for d in devices.keys():
253 if not device_type_match(devices[d], devices_type):
254 continue
255
256 # get additional info and add it to existing data
257 devices[d] = devices[d].copy()
258 # No need to probe lspci
259 devices[d].update(get_pci_device_details(d, False).items())
260
261 if devices_type == network_devices:

Callers 2

do_arg_actionsFunction · 0.85
mainFunction · 0.85

Calls 7

device_type_matchFunction · 0.85
rangeClass · 0.85
get_pci_device_detailsFunction · 0.85
has_driverFunction · 0.85
updateMethod · 0.80
dictClass · 0.50
filterClass · 0.50

Tested by

no test coverage detected