From e10a759d9bc471e0089ce773ae81440fb9a8d854 Mon Sep 17 00:00:00 2001 From: "Chris St. Pierre" Date: Tue, 12 Jun 2012 09:04:41 -0400 Subject: added ClientRunHooks plugin role --- src/lib/Bcfg2/Server/Core.py | 18 ++++++++++++++++++ src/lib/Bcfg2/Server/Plugin.py | 9 +++++++++ 2 files changed, 27 insertions(+) (limited to 'src') diff --git a/src/lib/Bcfg2/Server/Core.py b/src/lib/Bcfg2/Server/Core.py index 898d5e20e..1843dd756 100644 --- a/src/lib/Bcfg2/Server/Core.py +++ b/src/lib/Bcfg2/Server/Core.py @@ -211,6 +211,20 @@ class Core(Component): for plugin in list(self.plugins.values()): plugin.shutdown() + def client_run_hook(self, hook, metadata): + """Checks the data structure.""" + for plugin in self.plugins_by_type(Bcfg2.Server.Plugin.ClientRunHooks): + try: + getattr(plugin, hook)(metadata) + except AttributeError: + err = sys.exc_info()[1] + logger.error("Unknown attribute: %s" % err) + raise + except: + err = sys.exc_info()[1] + logger.error("%s: Error invoking hook %s: %s" % (plugin, hook, + err)) + def validate_structures(self, metadata, data): """Checks the data structure.""" for plugin in self.plugins_by_type(Bcfg2.Server.Plugin.StructureValidator): @@ -320,6 +334,8 @@ class Core(Component): logger.error("Metadata consistency error for client %s" % client) return lxml.etree.Element("error", type='metadata error') + self.client_run_hook("start_client_run", meta) + try: structures = self.GetStructures(meta) except: @@ -348,6 +364,8 @@ class Core(Component): logger.error("error in BindStructure", exc_info=1) self.validate_goals(meta, config) + self.client_run_hook("end_client_run", meta) + sort_xml(config, key=lambda e: e.get('name')) logger.info("Generated config for %s in %.03f seconds" % \ diff --git a/src/lib/Bcfg2/Server/Plugin.py b/src/lib/Bcfg2/Server/Plugin.py index 5e5abe0f6..06a491562 100644 --- a/src/lib/Bcfg2/Server/Plugin.py +++ b/src/lib/Bcfg2/Server/Plugin.py @@ -361,6 +361,15 @@ class Version(object): pass +class ClientRunHooks(object): + """ Provides hooks to interact with client runs """ + def start_client_run(self, metadata): + pass + + def end_client_run(self, metadata): + pass + + # the rest of the file contains classes for coherent file caching class FileBacked(object): -- cgit v1.2.3-1-g7c22