diff options
author | Narayan Desai <desai@mcs.anl.gov> | 2006-11-22 21:33:39 +0000 |
---|---|---|
committer | Narayan Desai <desai@mcs.anl.gov> | 2006-11-22 21:33:39 +0000 |
commit | 83bfca94f8d864846e22ad79a9d96bf805e1b515 (patch) | |
tree | 3cc0fa24f7d94f75e09495f1aaf54c197a801ac7 /src/lib | |
parent | c57c79a36f1e4d2b66ef7f01bc0a82ef7d5996e8 (diff) | |
download | bcfg2-83bfca94f8d864846e22ad79a9d96bf805e1b515.tar.gz bcfg2-83bfca94f8d864846e22ad79a9d96bf805e1b515.tar.bz2 bcfg2-83bfca94f8d864846e22ad79a9d96bf805e1b515.zip |
Part 1 of metadata changes
git-svn-id: https://svn.mcs.anl.gov/repos/bcfg/trunk/bcfg2@2522 ce84e21b-d406-0410-9b95-82705330c041
Diffstat (limited to 'src/lib')
-rw-r--r-- | src/lib/Server/Core.py | 9 | ||||
-rw-r--r-- | src/lib/Server/Metadata.py | 51 | ||||
-rw-r--r-- | src/lib/Server/Plugins/__init__.py | 3 | ||||
-rw-r--r-- | src/lib/Server/__init__.py | 2 |
4 files changed, 47 insertions, 18 deletions
diff --git a/src/lib/Server/Core.py b/src/lib/Server/Core.py index 1ca4cdea1..95b9fb08e 100644 --- a/src/lib/Server/Core.py +++ b/src/lib/Server/Core.py @@ -219,19 +219,13 @@ class Core(object): except: self.svn = False - mpath = self.cfile.get('server','repository') - try: - self.metadata = Bcfg2.Server.Metadata.Metadata(self.fam, mpath) - except OSError: - raise CoreInitError, "metadata path incorrect" - self.stats = Statistics("%s/etc/statistics.xml" % (mpath)) structures = self.cfile.get('server', 'structures').split(',') generators = self.cfile.get('server', 'generators').split(',') [data.remove('') for data in [structures, generators] if '' in data] - for plugin in structures + generators: + for plugin in structures + generators + ['Metadata']: if not self.plugins.has_key(plugin): try: mod = getattr(__import__("Bcfg2.Server.Plugins.%s" % @@ -247,6 +241,7 @@ class Core(object): except: logger.error("Unexpected initiantiation failure for plugin %s" % (plugin), exc_info=1) + self.metadata = self.plugins['Metadata'] for plugin in structures: if self.plugins.has_key(plugin): self.structures.append(self.plugins[plugin]) diff --git a/src/lib/Server/Metadata.py b/src/lib/Server/Metadata.py index 7bfc42c8f..61fbaa95c 100644 --- a/src/lib/Server/Metadata.py +++ b/src/lib/Server/Metadata.py @@ -1,7 +1,8 @@ '''This file stores persistent metadata for the BCFG Configuration Repository''' __revision__ = '$Revision$' -import logging, lxml.etree, os, socket, time +import lxml.etree, re, socket +import Bcfg2.Server.Plugin class MetadataConsistencyError(Exception): '''This error gets raised when metadata is internally inconsistent''' @@ -13,23 +14,25 @@ class MetadataRuntimeError(Exception): class ClientMetadata(object): '''This object contains client metadata''' - def __init__(self, client, groups, bundles, toolset, categories): + def __init__(self, client, groups, bundles, toolset, categories, probed): self.hostname = client self.bundles = bundles self.groups = groups self.toolset = toolset self.categories = categories + self.probes = probed -class Metadata: +class Metadata(Bcfg2.Server.Plugin.Plugin): '''This class contains data for bcfg2 server metadata''' __version__ = '$Id$' __author__ = 'bcfg-dev@mcs.anl.gov' + __name__ = "Metadata" - def __init__(self, fam, datastore): + def __init__(self, core, datastore): + Bcfg2.Server.Plugin.Plugin.__init__(self, core, datastore) self.__name__ = 'Metadata' - self.data = "%s/%s" % (datastore, self.__name__) - fam.AddMonitor("%s/%s" % (self.data, "groups.xml"), self) - fam.AddMonitor("%s/%s" % (self.data, "clients.xml"), self) + core.fam.AddMonitor("%s/%s" % (self.data, "groups.xml"), self) + core.fam.AddMonitor("%s/%s" % (self.data, "clients.xml"), self) self.states = {'groups.xml':False, 'clients.xml':False} self.addresses = {} self.clients = {} @@ -41,7 +44,12 @@ class Metadata: self.categories = {} self.clientdata = None self.default = None - self.logger = logging.getLogger('Bcfg2.Server.Metadata') + try: + self.probes = Bcfg2.Server.Plugin.DirectoryBacked(datastore + "/Probes", + core.fam) + except: + self.probes = False + self.probedata = {} def HandleEvent(self, event): '''Handle update events for data files''' @@ -189,5 +197,30 @@ class Metadata: self.logger.error("Cannot determine toolset for client %s" % (client)) raise MetadataConsistencyError toolset = toolinfo[0] - return ClientMetadata(client, groups, bundles, toolset, categories) + probed = self.probedata.get(client, {}) + return ClientMetadata(client, groups, bundles, toolset, categories, probed) + def GetProbes(self, _): + '''Return a set of probes for execution on client''' + ret = [] + if self.probes: + bangline = re.compile('^#!(?P<interpreter>(/\w+)+)$') + for name, entry in [x for x in self.probes.entries.iteritems() if x.data]: + probe = lxml.etree.Element('probe') + probe.set('name', name ) + probe.set('source', self.__name__) + probe.text = entry.data + match = bangline.match(entry.data.split('\n')[0]) + if match: + probe.set('interpreter', match.group('interpreter')) + else: + probe.set('interpreter', '/bin/sh') + ret.append(probe) + return ret + + def ReceiveData(self, client, data): + '''Receive probe results pertaining to client''' + try: + self.probedata[client.hostname].update({ data.get('name'):data.text }) + except KeyError: + self.probedata[client.hostname] = { data.get('name'):data.text } diff --git a/src/lib/Server/Plugins/__init__.py b/src/lib/Server/Plugins/__init__.py index cbabf0ca5..21351fe8f 100644 --- a/src/lib/Server/Plugins/__init__.py +++ b/src/lib/Server/Plugins/__init__.py @@ -1,4 +1,5 @@ '''imports for Bcfg2.Server.Plugins''' __revision__ = '$Revision$' -all = ['Account', 'Base', 'Bundler', 'Cfg', 'Chiba', 'Hostbase', 'Pkgmgr', 'Rules', 'SSHbase', 'Svcmgr', 'Vhost'] +all = ['Account', 'Base', 'Bundler', 'Cfg', 'Chiba', 'Hostbase', 'Metadata', + 'Pkgmgr', 'Rules', 'SSHbase', 'Svcmgr', 'Vhost'] diff --git a/src/lib/Server/__init__.py b/src/lib/Server/__init__.py index c998f1c12..bc89db87e 100644 --- a/src/lib/Server/__init__.py +++ b/src/lib/Server/__init__.py @@ -2,5 +2,5 @@ '''This is the set of modules for Bcfg2.Server''' __revision__ = '$Revision$' -__all__ = ["Component", "Core", "Metadata", "Plugin", "Plugins", "Statistics"] +__all__ = ["Component", "Core", "Plugin", "Plugins", "Statistics"] |