1010from hwinfo .pci .lspci import *
1111
1212from hwinfo .host import dmidecode
13+ from hwinfo .host import cpuinfo
1314
1415def remote_command (host , username , password , cmd ):
1516 client = paramiko .SSHClient ()
@@ -54,6 +55,9 @@ def get_lspci_data(self):
5455 def get_dmidecode_data (self ):
5556 return self .exec_command (['dmidecode' ])
5657
58+ def get_cpuinfo_data (self ):
59+ return self .exec_command (['cat /proc/cpuinfo' ])
60+
5761 def get_pci_devices (self ):
5862 data = self .get_lspci_data ()
5963 parser = LspciNNMMParser (data )
@@ -66,6 +70,11 @@ def get_info(self):
6670 rec = parser .parse ()
6771 return rec
6872
73+ def get_cpu_info (self ):
74+ data = self .get_cpuinfo_data ()
75+ parser = cpuinfo .CPUInfoParser (data )
76+ return parser .parse_items ()
77+
6978def search_for_file (dirname , filename ):
7079 for root , _ , files in os .walk (dirname ):
7180 if filename in files :
@@ -93,6 +102,9 @@ def get_lspci_data(self):
93102 def get_dmidecode_data (self ):
94103 return self ._load_from_file ('dmidecode.out' )
95104
105+ def get_cpuinfo_data (self ):
106+ return self ._load_from_file ('cpuinfo' )
107+
96108def pci_filter (devices , types ):
97109 res = []
98110 for device in devices :
@@ -122,6 +134,13 @@ def rec_to_table(rec):
122134 table .add_row ([k , v ])
123135 return table
124136
137+ def tabulate_recs (recs , header ):
138+ table = PrettyTable (header )
139+ for rec in recs :
140+ vls = [rec [k ] for k in header ]
141+ table .add_row (vls )
142+ return table
143+
125144def tabulate_pci_recs (recs ):
126145 header = [
127146 'vendor_name' ,
@@ -133,18 +152,26 @@ def tabulate_pci_recs(recs):
133152 'subdevice_name' ,
134153 'subdevice_id' ,
135154 ]
136- table = PrettyTable (header )
137- for rec in recs :
138- vls = [rec [k ] for k in header ]
139- table .add_row (vls )
140- return table
155+ return tabulate_recs (recs , header )
156+
157+ def tabulate_cpu_recs (recs ):
158+ header = [
159+ 'processor' ,
160+ 'vendor_id' ,
161+ 'cpu_family' ,
162+ 'model' ,
163+ 'stepping' ,
164+ 'model_name' ,
165+ 'cpu_mhz' ,
166+ ]
167+ return tabulate_recs (recs , header )
141168
142169def main ():
143170 """Entry Point"""
144171
145172 parser = ArgumentParser (prog = "hwinfo" )
146173
147- filter_choices = ['bios' , 'nic' , 'storage' , 'gpu' ]
174+ filter_choices = ['bios' , 'nic' , 'storage' , 'gpu' , 'cpu' ]
148175 parser .add_argument ("-f" , "--filter" , choices = filter_choices , help = "Query a specific class." )
149176 parser .add_argument ("-m" , "--machine" , default = 'localhost' , help = "Remote host address." )
150177 parser .add_argument ("-u" , "--username" , help = "Username for remote host." )
@@ -173,6 +200,12 @@ def main():
173200 print rec_to_table (host .get_info ())
174201 print ""
175202
203+ if 'cpu' in options :
204+ print "CPU Info:"
205+ print ""
206+ print tabulate_cpu_recs (host .get_cpu_info ())
207+ print ""
208+
176209 if 'nic' in options :
177210 devices = pci_filter_for_nics (host .get_pci_devices ())
178211 print "Ethernet Controller Info:"
0 commit comments