summaryrefslogtreecommitdiffstats
path: root/modules/hardware.py
diff options
context:
space:
mode:
authorSeth Vidal <skvidal@fedoraproject.org>2007-09-24 11:45:08 -0400
committerSeth Vidal <skvidal@fedoraproject.org>2007-09-24 11:45:08 -0400
commita656879954105065b2fabed8f77993387c73f9b6 (patch)
tree904d37c4c2e4cb98460f2969bb61e0f632e82714 /modules/hardware.py
parenta4680ef456b87d73ccdb6a6a9beba1992ebdd7c6 (diff)
parent2d1bb13794d1f3e9dfca2047195e5ab368db628b (diff)
downloadthird_party-func-a656879954105065b2fabed8f77993387c73f9b6.tar.gz
third_party-func-a656879954105065b2fabed8f77993387c73f9b6.tar.xz
third_party-func-a656879954105065b2fabed8f77993387c73f9b6.zip
Merge branch 'master' of ssh://git.fedoraproject.org/git/hosted/func
* 'master' of ssh://git.fedoraproject.org/git/hosted/func: Rename yummod as yum so each module doesn't end up ending in mod :) Added kill and pkill to the process module Process module. Accepts flags to PS, returns nicely formatted tabular output. Added a smolt-based hardware profiler module. Remove underscores from exported function names as they are now redundant. update to new calling conventions Fix up virt code some more. change to module loader to allow subdirs in the module path. ignore the build/ dir
Diffstat (limited to 'modules/hardware.py')
-rwxr-xr-xmodules/hardware.py100
1 files changed, 100 insertions, 0 deletions
diff --git a/modules/hardware.py b/modules/hardware.py
new file mode 100755
index 0000000..2c41b9f
--- /dev/null
+++ b/modules/hardware.py
@@ -0,0 +1,100 @@
+#!/usr/bin/python
+
+##
+## Hardware profiler plugin
+## requires the "smolt" client package be installed
+##
+## Copyright 2007, Red Hat, Inc
+## Michael DeHaan <mdehaan@redhat.com>
+##
+## This software may be freely redistributed under the terms of the GNU
+## general public license.
+##
+## You should have received a copy of the GNU General Public License
+## along with this program; if not, write to the Free Software
+## Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+##
+
+
+# other modules
+import sys
+# hack: smolt is not installed in site-packages
+sys.path.append("/usr/share/smolt/client")
+import smolt
+
+# our modules
+from codes import *
+from modules import func_module
+
+# =================================
+
+class HardwareModule(func_module.FuncModule):
+ def __init__(self):
+ self.methods = {
+ "info": self.info
+ }
+ func_module.FuncModule.__init__(self)
+
+ def info(self,with_devices=True):
+ """
+ Returns a struct of hardware information. By default, this pulls down
+ all of the devices. If you don't care about them, set with_devices to
+ False.
+ """
+ return hw_info(with_devices)
+
+# =================================
+
+def hw_info(with_devices=True):
+
+ hardware = smolt.Hardware()
+ host = hardware.host
+
+ # NOTE: casting is needed because these are DBusStrings, not real strings
+ data = {
+ 'os' : str(host.os),
+ 'defaultRunlevel' : str(host.defaultRunlevel),
+ 'bogomips' : str(host.bogomips),
+ 'cpuVendor' : str(host.cpuVendor),
+ 'cpuModel' : str(host.cpuModel),
+ 'numCpus' : str(host.numCpus),
+ 'cpuSpeed' : str(host.cpuSpeed),
+ 'systemMemory' : str(host.systemMemory),
+ 'systemSwap' : str(host.systemSwap),
+ 'kernelVersion' : str(host.kernelVersion),
+ 'language' : str(host.language),
+ 'platform' : str(host.platform),
+ 'systemVendor' : str(host.systemVendor),
+ 'systemModel' : str(host.systemModel),
+ 'formfactor' : str(host.formfactor),
+ 'selinux_enabled' : str(host.selinux_enabled),
+ 'selinux_enforce' : str(host.selinux_enforce)
+ }
+
+ # if no hardware info requested, just return the above bits
+ if not with_devices:
+ return data
+
+ collection = data["devices"] = []
+
+ for item in hardware.deviceIter():
+
+ (VendorID,DeviceID,SubsysVendorID,SubsysDeviceID,Bus,Driver,Type,Description) = item
+
+ collection.append({
+ "VendorID" : str(VendorID),
+ "DeviceID" : str(DeviceID),
+ "SubsysVendorID" : str(SubsysVendorID),
+ "Bus" : str(Bus),
+ "Driver" : str(Driver),
+ "Type" : str(Type),
+ "Description" : str(Description)
+ })
+
+ return data
+
+methods = HardwareModule()
+register_rpc = methods.register_rpc
+
+
+