summaryrefslogtreecommitdiffstats
path: root/src/lib/Bcfg2/Server/Plugins/Ohai.py
diff options
context:
space:
mode:
authorChris St. Pierre <chris.a.st.pierre@gmail.com>2013-04-24 13:47:31 -0400
committerChris St. Pierre <chris.a.st.pierre@gmail.com>2013-04-24 13:47:31 -0400
commit0ff6b2788de683dd89203c7ae1393ea922a62c32 (patch)
tree54ce843377ab26c6336de7f1abf3ec906d49aa69 /src/lib/Bcfg2/Server/Plugins/Ohai.py
parent46a47b4120b3d892b8149a5e181e4d976ad87f99 (diff)
parent29399cbc599919fd9c88448bde692132c803e69b (diff)
downloadbcfg2-0ff6b2788de683dd89203c7ae1393ea922a62c32.tar.gz
bcfg2-0ff6b2788de683dd89203c7ae1393ea922a62c32.tar.bz2
bcfg2-0ff6b2788de683dd89203c7ae1393ea922a62c32.zip
Merge branch 'maint'
Conflicts: src/lib/Bcfg2/Client/Client.py src/lib/Bcfg2/Client/Frame.py src/lib/Bcfg2/Client/Tools/YUM.py src/lib/Bcfg2/Options.py src/lib/Bcfg2/Server/Admin/Perf.py src/lib/Bcfg2/Server/Admin/Xcmd.py src/lib/Bcfg2/Server/Admin/__init__.py src/lib/Bcfg2/Server/Core.py src/lib/Bcfg2/Server/FileMonitor/Fam.py src/lib/Bcfg2/Server/Lint/RequiredAttrs.py src/lib/Bcfg2/Server/Plugin/helpers.py src/lib/Bcfg2/Server/Plugins/Base.py src/lib/Bcfg2/Server/Plugins/Bundler.py src/lib/Bcfg2/Server/Plugins/Cfg/CfgPrivateKeyCreator.py src/lib/Bcfg2/Server/Plugins/Cvs.py src/lib/Bcfg2/Server/Plugins/Darcs.py src/lib/Bcfg2/Server/Plugins/Decisions.py src/lib/Bcfg2/Server/Plugins/FileProbes.py src/lib/Bcfg2/Server/Plugins/Fossil.py src/lib/Bcfg2/Server/Plugins/Git.py src/lib/Bcfg2/Server/Plugins/Metadata.py src/lib/Bcfg2/Server/Plugins/NagiosGen.py src/lib/Bcfg2/Server/Plugins/Packages/PackagesSources.py src/lib/Bcfg2/Server/Plugins/Packages/Source.py src/lib/Bcfg2/Server/Plugins/Packages/Yum.py src/lib/Bcfg2/Server/Plugins/Properties.py src/lib/Bcfg2/Server/Plugins/__init__.py src/lib/Bcfg2/Server/__init__.py src/sbin/bcfg2-build-reports src/sbin/bcfg2-crypt testsuite/Testsrc/Testlib/TestServer/TestPlugin/Testhelpers.py testsuite/Testsrc/Testlib/TestServer/TestPlugins/TestMetadata.py testsuite/Testsrc/Testlib/TestServer/TestPlugins/TestProperties.py
Diffstat (limited to 'src/lib/Bcfg2/Server/Plugins/Ohai.py')
-rw-r--r--src/lib/Bcfg2/Server/Plugins/Ohai.py31
1 files changed, 23 insertions, 8 deletions
diff --git a/src/lib/Bcfg2/Server/Plugins/Ohai.py b/src/lib/Bcfg2/Server/Plugins/Ohai.py
index 8b73f0ba7..18261be10 100644
--- a/src/lib/Bcfg2/Server/Plugins/Ohai.py
+++ b/src/lib/Bcfg2/Server/Plugins/Ohai.py
@@ -2,8 +2,10 @@
operating system using ohai
(http://wiki.opscode.com/display/chef/Ohai) """
-import lxml.etree
import os
+import sys
+import glob
+import lxml.etree
import Bcfg2.Server.Plugin
try:
@@ -31,22 +33,39 @@ class OhaiCache(object):
self.dirname = dirname
self.cache = dict()
+ def hostpath(self, host):
+ """ Get the path to the file that contains Ohai data for the
+ given host """
+ return os.path.join(self.dirname, "%s.json" % host)
+
def __setitem__(self, item, value):
- if value == None:
+ if value is None:
# simply return if the client returned nothing
return
self.cache[item] = json.loads(value)
- open("%s/%s.json" % (self.dirname, item), 'w').write(value)
+ open(self.hostpath(item), 'w').write(value)
def __getitem__(self, item):
if item not in self.cache:
try:
- data = open("%s/%s.json" % (self.dirname, item)).read()
+ data = open(self.hostpath(item)).read()
except:
raise KeyError(item)
self.cache[item] = json.loads(data)
return self.cache[item]
+ def __delitem__(self, item):
+ if item in self.cache:
+ del self.cache[item]
+ try:
+ os.unlink(self.hostpath(item))
+ except:
+ raise IndexError("Could not unlink %s: %s" % (self.hostpath(item),
+ sys.exc_info()[1]))
+
+ def __len__(self):
+ return len(glob.glob(self.hostpath('*')))
+
def __iter__(self):
data = list(self.cache.keys())
data.extend([x[:-5] for x in os.listdir(self.dirname)])
@@ -67,10 +86,6 @@ class Ohai(Bcfg2.Server.Plugin.Plugin,
self.probe = lxml.etree.Element('probe', name='Ohai', source='Ohai',
interpreter='/bin/sh')
self.probe.text = PROBECODE
- try:
- os.stat(self.data)
- except OSError:
- os.makedirs(self.data)
self.cache = OhaiCache(self.data)
def GetProbes(self, _):