parameters: (devices_type)
docstring: 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.
docstring_summary: 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.
docstring_tokens: 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 .
function: def get_device_details(devices_type):
      """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."""
  
      # pylint:disable=too-many-branches
  
      global _DEVICES  # pylint:disable=global-statement
  
      # first loop through and read details for all devices
      # request machine readable format, with numeric IDs and String
      dev = {}
      dev_lines = check_output(["lspci", "-Dvmmnnk"]).splitlines()
      for dev_line in dev_lines:
          if len(dev_line) == 0:
              if device_type_match(dev, devices_type):
                  # Replace "Driver" with "Driver_str" to have consistency of
                  # of dictionary key names
                  if "Driver" in dev.keys():
                      dev["Driver_str"] = dev.pop("Driver")
                  if "Module" in dev.keys():
                      dev["Module_str"] = dev.pop("Module")
                  # use dict to make copy of dev
                  _DEVICES[dev["Slot"]] = dict(dev)
              # Clear previous device's data
              dev = {}
          else:
              name, value = dev_line.decode().split("\t", 1)
              value_list = value.rsplit(" ", 1)
              if len(value_list) > 1:
                  # String stored in <name>_str
                  dev[name.rstrip(":") + "_str"] = value_list[0]
              # Numeric IDs
              dev[name.rstrip(":")] = (
                  value_list[len(value_list) - 1].rstrip("]").lstrip("[")
              )
  
      if devices_type == network_devices:
          # check what is the interface if any for an ssh connection if
          # any to this host, so we can mark it later.
          ssh_if = []
          route = check_output(["ip", "-o", "route"])
          # filter out all lines for 169.254 routes
          route = "\n".join(
              filter(lambda ln: not ln.startswith("169.254"), route.decode().splitlines())
          )
          rt_info = route.split()
          for i in range(len(rt_info) - 1):
              if rt_info[i] == "dev":
                  ssh_if.append(rt_info[i + 1])
  
      # based on the basic info, get extended text details
      for dev in _DEVICES:
          if not device_type_match(_DEVICES[dev], devices_type):
              continue
  
          # get additional info and add it to existing data
          _DEVICES[dev] = _DEVICES[dev].copy()
          # No need to probe lspci
          _DEVICES[dev].update(get_pci_device_details(dev, False).items())
  
          if devices_type == network_devices:
              for _if in ssh_if:
                  if _if in _DEVICES[dev]["Interface"].split(","):
                      _DEVICES[dev]["Ssh_if"] = True
                      _DEVICES[dev]["Active"] = "*Active*"
                      break
  
          # add igb_uio to list of supporting modules if needed
          if "Module_str" in _DEVICES[dev]:
              for driver in _DPDK_DRIVERS:
                  if driver not in _DEVICES[dev]["Module_str"]:
                      _DEVICES[dev]["Module_str"] = (
                          _DEVICES[dev]["Module_str"] + ",%s" % driver
                      )
          else:
              _DEVICES[dev]["Module_str"] = ",".join(_DPDK_DRIVERS)
  
          # make sure the driver and module strings do not have any duplicates
          if has_driver(dev):
              modules = _DEVICES[dev]["Module_str"].split(",")
              if _DEVICES[dev]["Driver_str"] in modules:
                  modules.remove(_DEVICES[dev]["Driver_str"])
                  _DEVICES[dev]["Module_str"] = ",".join(modules)
function_tokens: def get_device_details ( devices_type ) : # pylint:disable=too-many-branches global _DEVICES # pylint:disable=global-statement # first loop through and read details for all devices # request machine readable format, with numeric IDs and String dev = { } dev_lines = check_output ( [ "lspci" , "-Dvmmnnk" ] ) . splitlines ( ) for dev_line in dev_lines : if len ( dev_line ) == 0 : if device_type_match ( dev , devices_type ) : # Replace "Driver" with "Driver_str" to have consistency of # of dictionary key names if "Driver" in dev . keys ( ) : dev [ "Driver_str" ] = dev . pop ( "Driver" ) if "Module" in dev . keys ( ) : dev [ "Module_str" ] = dev . pop ( "Module" ) # use dict to make copy of dev _DEVICES [ dev [ "Slot" ] ] = dict ( dev ) # Clear previous device's data dev = { } else : name , value = dev_line . decode ( ) . split ( "\t" , 1 ) value_list = value . rsplit ( " " , 1 ) if len ( value_list ) > 1 : # String stored in <name>_str dev [ name . rstrip ( ":" ) + "_str" ] = value_list [ 0 ] # Numeric IDs dev [ name . rstrip ( ":" ) ] = ( value_list [ len ( value_list ) - 1 ] . rstrip ( "]" ) . lstrip ( "[" ) ) if devices_type == network_devices : # check what is the interface if any for an ssh connection if # any to this host, so we can mark it later. ssh_if = [ ] route = check_output ( [ "ip" , "-o" , "route" ] ) # filter out all lines for 169.254 routes route = "\n" . join ( filter ( lambda ln : not ln . startswith ( "169.254" ) , route . decode ( ) . splitlines ( ) ) ) rt_info = route . split ( ) for i in range ( len ( rt_info ) - 1 ) : if rt_info [ i ] == "dev" : ssh_if . append ( rt_info [ i + 1 ] ) # based on the basic info, get extended text details for dev in _DEVICES : if not device_type_match ( _DEVICES [ dev ] , devices_type ) : continue # get additional info and add it to existing data _DEVICES [ dev ] = _DEVICES [ dev ] . copy ( ) # No need to probe lspci _DEVICES [ dev ] . update ( get_pci_device_details ( dev , False ) . items ( ) ) if devices_type == network_devices : for _if in ssh_if : if _if in _DEVICES [ dev ] [ "Interface" ] . split ( "," ) : _DEVICES [ dev ] [ "Ssh_if" ] = True _DEVICES [ dev ] [ "Active" ] = "*Active*" break # add igb_uio to list of supporting modules if needed if "Module_str" in _DEVICES [ dev ] : for driver in _DPDK_DRIVERS : if driver not in _DEVICES [ dev ] [ "Module_str" ] : _DEVICES [ dev ] [ "Module_str" ] = ( _DEVICES [ dev ] [ "Module_str" ] + ",%s" % driver ) else : _DEVICES [ dev ] [ "Module_str" ] = "," . join ( _DPDK_DRIVERS ) # make sure the driver and module strings do not have any duplicates if has_driver ( dev ) : modules = _DEVICES [ dev ] [ "Module_str" ] . split ( "," ) if _DEVICES [ dev ] [ "Driver_str" ] in modules : modules . remove ( _DEVICES [ dev ] [ "Driver_str" ] ) _DEVICES [ dev ] [ "Module_str" ] = "," . join ( modules )