46b182132b1d8fb4ef0b39c1557478316063eb97
2 ## Hardware profiler plugin
3 ## requires the "smolt" client package be installed
4 ## but also relies on lspci for some things
6 ## Copyright 2007, Red Hat, Inc
7 ## Michael DeHaan <mdehaan@redhat.com>
9 ## This software may be freely redistributed under the terms of the GNU
10 ## general public license.
12 ## You should have received a copy of the GNU General Public License
13 ## along with this program; if not, write to the Free Software
14 ## Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 # =================================
27 class HardwareModule(func_module
.FuncModule
):
31 description
= "Hardware profiler."
35 Returns the output of lshal, but split up into seperate devices
36 for easier parsing. Each device is a entry in the return hash.
39 cmd
= sub_process
.Popen(["/usr/bin/lshal"],shell
=False,stdout
=sub_process
.PIPE
)
40 data
= cmd
.communicate()[0]
42 data
= data
.split("\n")
49 results
[label
] = current
60 data
= hw_info(with_devices
=True)
61 # remove bogomips because it keeps changing for laptops
62 # and makes inventory tracking noisy
63 if data
.has_key("bogomips"):
67 def info(self
,with_devices
=True):
69 Returns a struct of hardware information. By default, this pulls down
70 all of the devices. If you don't care about them, set with_devices to
73 return hw_info(with_devices
)
75 # =================================
77 def hw_info(with_devices
=True):
79 # this may fail if smolt is not installed. That's ok. hal_info will
82 # hack: smolt is not installed in site-packages
83 sys
.path
.append("/usr/share/smolt/client")
86 hardware
= smolt
.Hardware()
89 # NOTE: casting is needed because these are DBusStrings, not real strings
92 'defaultRunlevel' : str(host
.defaultRunlevel
),
93 'bogomips' : str(host
.bogomips
),
94 'cpuVendor' : str(host
.cpuVendor
),
95 'cpuModel' : str(host
.cpuModel
),
96 'numCpus' : str(host
.numCpus
),
97 'cpuSpeed' : str(host
.cpuSpeed
),
98 'systemMemory' : str(host
.systemMemory
),
99 'systemSwap' : str(host
.systemSwap
),
100 'kernelVersion' : str(host
.kernelVersion
),
101 'language' : str(host
.language
),
102 'platform' : str(host
.platform
),
103 'systemVendor' : str(host
.systemVendor
),
104 'systemModel' : str(host
.systemModel
),
105 'formfactor' : str(host
.formfactor
),
106 'selinux_enabled' : str(host
.selinux_enabled
),
107 'selinux_enforce' : str(host
.selinux_enforce
)
110 # if no hardware info requested, just return the above bits
114 collection
= data
["devices"] = []
116 for item
in hardware
.deviceIter():
118 (VendorID
,DeviceID
,SubsysVendorID
,SubsysDeviceID
,Bus
,Driver
,Type
,Description
) = item
121 "VendorID" : str(VendorID
),
122 "DeviceID" : str(DeviceID
),
123 "SubsysVendorID" : str(SubsysVendorID
),
125 "Driver" : str(Driver
),
127 "Description" : str(Description
)