Skip to content

Commit 0186837

Browse files
committed
Adding support for quering data from a bugtool.
Signed-off-by: Rob Dobson <[email protected]>
1 parent 52840ec commit 0186837

File tree

1 file changed

+45
-8
lines changed

1 file changed

+45
-8
lines changed

hwinfo/tools/inspector.py

Lines changed: 45 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from prettytable import PrettyTable
55
import paramiko
66
import subprocess
7+
import os
78

89
from hwinfo.pci import PCIDevice
910
from hwinfo.pci.lspci import *
@@ -47,19 +48,51 @@ def exec_command(self, cmd):
4748
else:
4849
return remote_command(self.host, self.username, self.password, cmd)
4950

51+
def get_lspci_data(self):
52+
return self.exec_command(['lspci', '-nnmm'])
53+
54+
def get_dmidecode_data(self):
55+
return self.exec_command(['dmidecode'])
56+
5057
def get_pci_devices(self):
51-
data = self.exec_command(['lspci', '-nnmm'])
58+
data = self.get_lspci_data()
5259
parser = LspciNNMMParser(data)
5360
devices = parser.parse_items()
5461
return [PCIDevice(device) for device in devices]
5562

5663
def get_info(self):
57-
data = self.exec_command(['dmidecode'])
64+
data = self.get_dmidecode_data()
5865
parser = dmidecode.DmidecodeParser(data)
59-
print "test : '%s'" % parser
6066
rec = parser.parse()
6167
return rec
6268

69+
def search_for_file(dirname, filename):
70+
for root, _, files in os.walk(dirname):
71+
if filename in files:
72+
return os.path.join(root, filename)
73+
raise Exception("Could not find '%s' in directory '%s'" % (filename, dirname))
74+
75+
def read_from_file(filename):
76+
fh = open(filename, 'r')
77+
data = fh.read()
78+
fh.close()
79+
return data
80+
81+
class HostFromLogs(Host):
82+
83+
def __init__(self, dirname):
84+
self.dirname = dirname
85+
86+
def _load_from_file(self, filename):
87+
filename = search_for_file(self.dirname, filename)
88+
return read_from_file(filename)
89+
90+
def get_lspci_data(self):
91+
return self._load_from_file('lspci-nnm.out')
92+
93+
def get_dmidecode_data(self):
94+
return self._load_from_file('dmidecode.out')
95+
6396
def pci_filter(devices, types):
6497
res = []
6598
for device in devices:
@@ -112,14 +145,18 @@ def main():
112145
parser = ArgumentParser(prog="hwinfo")
113146

114147
filter_choices = ['bios', 'nic', 'storage', 'gpu']
115-
parser.add_argument("-f", "--filter", choices=filter_choices)
116-
parser.add_argument("-m", "--machine", default='localhost')
117-
parser.add_argument("-u", "--username")
118-
parser.add_argument("-p", "--password")
148+
parser.add_argument("-f", "--filter", choices=filter_choices, help="Query a specific class.")
149+
parser.add_argument("-m", "--machine", default='localhost', help="Remote host address.")
150+
parser.add_argument("-u", "--username", help="Username for remote host.")
151+
parser.add_argument("-p", "--password", help="Password for remote host.")
152+
parser.add_argument("-l", "--logs", help="Path to the directory with the logfiles.")
119153

120154
args = parser.parse_args()
121155

122-
host = Host(args.machine, args.username, args.password)
156+
if args.logs:
157+
host = HostFromLogs(args.logs)
158+
else:
159+
host = Host(args.machine, args.username, args.password)
123160

124161
options = []
125162

0 commit comments

Comments
 (0)