From 8b438fda3ae2d9516dbfb6014c280b68036c17e1 Mon Sep 17 00:00:00 2001 From: "Chris St. Pierre" Date: Mon, 30 Jul 2012 10:24:12 -0400 Subject: Metadata and other improvements: * Added support for Client tag in groups.xml * Added support for nested Group tags in groups.xml * Added support for negated groups in groups.xml * Added DatabaseBacked plugin mixin to easily allow plugins to connect to a database specified in global database settings in bcfg2.conf * Added DBMetadata plugin that uses relational DB to store client records instead of writing to clients.xml --- src/lib/Bcfg2/Server/Plugin.py | 39 +++++++++++++++++++++------------------ 1 file changed, 21 insertions(+), 18 deletions(-) (limited to 'src/lib/Bcfg2/Server/Plugin.py') diff --git a/src/lib/Bcfg2/Server/Plugin.py b/src/lib/Bcfg2/Server/Plugin.py index 6b4276444..51d1b1cdb 100644 --- a/src/lib/Bcfg2/Server/Plugin.py +++ b/src/lib/Bcfg2/Server/Plugin.py @@ -102,6 +102,16 @@ class Debuggable(object): self.logger.error(message) +class DatabaseBacked(object): + def __init__(self): + pass + + +class PluginDatabaseModel(object): + class Meta: + app_label = "Server" + + class Plugin(Debuggable): """This is the base class for all Bcfg2 Server plugins. Several attributes must be defined in the subclass: @@ -139,8 +149,7 @@ class Plugin(Debuggable): @classmethod def init_repo(cls, repo): - path = "%s/%s" % (repo, cls.name) - os.makedirs(path) + os.makedirs(os.path.join(repo, cls.name)) def shutdown(self): self.running = False @@ -169,7 +178,7 @@ class Structure(object): class Metadata(object): """Signal metadata capabilities for this plugin""" - def add_client(self, client_name, attribs): + def add_client(self, client_name): """Add client.""" pass @@ -181,6 +190,9 @@ class Metadata(object): """Create viz str for viz admin mode.""" pass + def _handle_default_event(self, event): + pass + def get_initial_metadata(self, client_name): raise PluginExecutionError @@ -650,7 +662,7 @@ class XMLFileBacked(FileBacked): def add_monitor(self, fpath, fname): self.extras.append(fname) - if self.fam: + if self.fam and self.should_monitor: self.fam.AddMonitor(fpath, self) def __iter__(self): @@ -666,22 +678,13 @@ class StructFile(XMLFileBacked): def _include_element(self, item, metadata): """ determine if an XML element matches the metadata """ + negate = item.get('negate', 'false').lower() == 'true' if item.tag == 'Group': - if ((item.get('negate', 'false').lower() == 'true' and - item.get('name') not in metadata.groups) or - (item.get('negate', 'false').lower() == 'false' and - item.get('name') in metadata.groups)): - return True - else: - return False + return ((negate and item.get('name') not in metadata.groups) or + (not negate and item.get('name') in metadata.groups)) elif item.tag == 'Client': - if ((item.get('negate', 'false').lower() == 'true' and - item.get('name') != metadata.hostname) or - (item.get('negate', 'false').lower() == 'false' and - item.get('name') == metadata.hostname)): - return True - else: - return False + return ((negate and item.get('name') != metadata.hostname) or + (not negate and item.get('name') == metadata.hostname)) elif isinstance(item, lxml.etree._Comment): return False else: -- cgit v1.2.3-1-g7c22