diff options
author | Narayan Desai <desai@mcs.anl.gov> | 2009-07-18 18:11:37 +0000 |
---|---|---|
committer | Narayan Desai <desai@mcs.anl.gov> | 2009-07-18 18:11:37 +0000 |
commit | 9591d232a51411b207d6b88061147a6ce1670411 (patch) | |
tree | cf2a5a45df08680446c82a545b69186eb154b846 /src/lib | |
parent | 268c7741344ca69a0c4e196d3c32287dde06e24f (diff) | |
download | bcfg2-9591d232a51411b207d6b88061147a6ce1670411.tar.gz bcfg2-9591d232a51411b207d6b88061147a6ce1670411.tar.bz2 bcfg2-9591d232a51411b207d6b88061147a6ce1670411.zip |
Ohai: Implement Ohai plugin
The Ohai plugin runs the Ohai system profiler through the probes interface, stores the information
on the server, and makes it available for metadata operations.
git-svn-id: https://svn.mcs.anl.gov/repos/bcfg/trunk/bcfg2@5348 ce84e21b-d406-0410-9b95-82705330c041
Diffstat (limited to 'src/lib')
-rw-r--r-- | src/lib/Server/Plugins/Ohai.py | 58 | ||||
-rw-r--r-- | src/lib/Server/Plugins/__init__.py | 2 |
2 files changed, 59 insertions, 1 deletions
diff --git a/src/lib/Server/Plugins/Ohai.py b/src/lib/Server/Plugins/Ohai.py new file mode 100644 index 000000000..ea31b4460 --- /dev/null +++ b/src/lib/Server/Plugins/Ohai.py @@ -0,0 +1,58 @@ + +import json +import lxml.etree +import os +import Bcfg2.Server.Plugin + +class OhaiCache(object): + def __init__(self, dirname): + self.dirname = dirname + self.cache = dict() + + def __setitem__(self, item, value): + self.cache[item] = json.loads(value) + file("%s/%s.json" % (self.dirname, item), 'w').write(value) + + def __getitem__(self, item): + if item not in self.cache: + try: + data = open("%s/%s.json" % (self.dirname, item)).read() + except: + raise KeyError, item + self.cache[item] = json.loads(data) + return self.cache[item] + + def __iter__(self): + data = self.cache.keys() + data.extend([x[:-5] for x in os.listdir(self.dirname)]) + return data.__iter__() + +class Ohai(Bcfg2.Server.Plugin.Plugin, + Bcfg2.Server.Plugin.Probing, + Bcfg2.Server.Plugin.Connector): + name = 'Ohai' + experimental = True + + def __init__(self, core, datastore): + Bcfg2.Server.Plugin.Plugin.__init__(self, core, datastore) + Bcfg2.Server.Plugin.Probing.__init__(self) + Bcfg2.Server.Plugin.Connector.__init__(self) + self.probe = lxml.etree.Element('probe', name='Ohai', source='Ohai', + interpreter='/bin/sh') + self.probe.text = 'ohai' + try: + os.stat(self.data) + except: + self.make_path(self.data) + self.cache = OhaiCache(self.data) + + def GetProbes(self, meta, force=False): + return [self.probe] + + def ReceiveData(self, meta, datalist): + self.cache[meta.hostname] = datalist[0].text + + def get_additional_data(self, meta): + if meta.hostname in self.cache: + return self.cache[meta.hostname] + return dict() diff --git a/src/lib/Server/Plugins/__init__.py b/src/lib/Server/Plugins/__init__.py index a8e7c3f63..c95f6714d 100644 --- a/src/lib/Server/Plugins/__init__.py +++ b/src/lib/Server/Plugins/__init__.py @@ -5,4 +5,4 @@ __all__ = ['Account', 'Base', 'Bundler', 'Cfg', 'Decisions', 'GBundler', 'Git', 'Hostbase', 'Metadata', 'NagiosGen', 'Packages', 'Properties', 'Probes', 'Pkgmgr', 'Rules', 'SSHbase', 'Snapshots' 'Statistics', 'Svcmgr', 'Svn', 'TCheetah', 'Trigger', 'SGenshi', 'TGenshi', - 'GroupPatterns'] + 'GroupPatterns', 'Ohai'] |