Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,10 @@ For example, to parse a list of PCI devices:

from hwinfo.pci import PCIDevice
from hwinfo.pci.lspci import LspciNNMMParser
from subprocess import check_output

# Obtain the output of lspci -nnmm from somewhere
lspci_output = exec_command('lspci -nnmm')
lspci_output = check_output(["lspci", "-nnmm"])

# Parse the output using the LspciNNMMParser object
parser = LspciNNMMParser(lspci_output)
Expand Down Expand Up @@ -84,11 +85,11 @@ For inspecting the hardware present on a local machine, execute:

Ethernet Controller Info:

+-------------------+-----------+------------------------------------+-----------+----------------+--------------+----------------+--------------+
| vendor_name | vendor_id | device_name | device_id | subvendor_name | subvendor_id | subdevice_name | subdevice_id |
+-------------------+-----------+------------------------------------+-----------+----------------+--------------+----------------+--------------+
| Intel Corporation | 8086 | 82579LM Gigabit Network Connection | 1502 | Dell | 1028 | [Device 05d2] | 05d2 |
+-------------------+-----------+------------------------------------+-----------+----------------+--------------+----------------+--------------+
+---------------+-------------------+-----------+------------------------------------+-----------+----------------+--------------+----------------+--------------+
| device_bus_id | vendor_name | vendor_id | device_name | device_id | subvendor_name | subvendor_id | subdevice_name | subdevice_id |
+---------------+-------------------+-----------+------------------------------------+-----------+----------------+--------------+----------------+--------------+
| 02:00.0 | Intel Corporation | 8086 | 82579LM Gigabit Network Connection | 1502 | Dell | 1028 | [Device 05d2] | 05d2 |
+---------------+-------------------+-----------+------------------------------------+-----------+----------------+--------------+----------------+--------------+

Storage Controller Info:

Expand Down
4 changes: 4 additions & 0 deletions hwinfo/pci/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ def get_device_name(self):
def get_device_id(self):
return self._fmt(self.lookup_value('pci_device_id'))

def get_device_bus_id(self):
return self._fmt(self.lookup_value('pci_device_bus_id'))

def get_vendor_name(self):
return self._fmt(self.lookup_value('pci_vendor_name'))

Expand Down Expand Up @@ -96,6 +99,7 @@ def get_info(self):

def get_rec(self):
rec = {}
rec['device_bus_id'] = self.get_device_bus_id()
rec['vendor_name'] = self.get_vendor_name()
rec['device_name'] = self.get_device_name()
rec['vendor_id'] = self.get_vendor_id()
Expand Down
30 changes: 15 additions & 15 deletions hwinfo/tools/inspector.py
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,7 @@ def tabulate_recs(recs, header):

def tabulate_pci_recs(recs):
header = [
'device_bus_id',
'vendor_name',
'vendor_id',
'device_name',
Expand All @@ -338,39 +339,38 @@ def tabulate_cpu_recs(recs):
]
return tabulate_recs(recs, header)

def print_unit(title, content):
print "%s" % title
print ""
print content
print ""

def create_unit(title, content):
return "\n%s\n\n%s\n" % (str(title), str(content))

def validate_args(args):
if args.machine != 'localhost':
if not args.username or not args.password:
print "Error: you must specify a username and password to query a remote machine."
sys.exit(1)

def print_system_info(host, options):
def system_info(host, options):
info = []

if 'bios' in options:
print_unit("Bios Info:", rec_to_table(host.get_info()))
info.append(create_unit("Bios Info:", rec_to_table(host.get_info())))

if 'cpu' in options:
print_unit("CPU Info:", tabulate_cpu_recs(host.get_cpu_info()))
info.append(create_unit("CPU Info:", tabulate_cpu_recs(host.get_cpu_info())))

if 'nic' in options:
devices = pci_filter_for_nics(host.get_pci_devices())
print_unit("Ethernet Controller Info:", tabulate_pci_recs([dev.get_rec() for dev in devices]))
info.append(create_unit("Ethernet Controller Info:", tabulate_pci_recs([dev.get_rec() for dev in devices])))

if 'storage' in options:
devices = pci_filter_for_storage(host.get_pci_devices())
print_unit("Storage Controller Info:", tabulate_pci_recs([dev.get_rec() for dev in devices]))
info.append(create_unit("Storage Controller Info:", tabulate_pci_recs([dev.get_rec() for dev in devices])))

if 'gpu' in options:
devices = pci_filter_for_gpu(host.get_pci_devices())
if devices:
print_unit("GPU Info:", tabulate_pci_recs([dev.get_rec() for dev in devices]))
info.append(create_unit("GPU Info:", tabulate_pci_recs([dev.get_rec() for dev in devices])))

return "".join(info).strip()

def export_system_info(host, options):
rec = {}
Expand All @@ -393,7 +393,7 @@ def export_system_info(host, options):
devices = pci_filter_for_gpu(host.get_pci_devices())
rec["gpus"] = [dev.get_rec() for dev in devices]

print json.dumps(rec, indent=4, separators=(',', ': '))
return json.dumps(rec, indent=4, separators=(',', ': '))

def main():
"""Entry Point"""
Expand Down Expand Up @@ -429,6 +429,6 @@ def main():
options = filter_choices

if args.export:
export_system_info(host, options)
print export_system_info(host, options)
else:
print_system_info(host, options)
print system_info(host, options)
Loading