diff options
author | Narayan Desai <desai@mcs.anl.gov> | 2008-10-08 20:22:41 +0000 |
---|---|---|
committer | Narayan Desai <desai@mcs.anl.gov> | 2008-10-08 20:22:41 +0000 |
commit | 26f2687927ed180c82ed0d60ce5fb8fa90be65d0 (patch) | |
tree | 6896e09393edfc8066ed6159436d6ca73b1cda1b /src/lib/Server/Plugins/Decisions.py | |
parent | fde846836107c325bcaa055cfe2545d35827d897 (diff) | |
download | bcfg2-26f2687927ed180c82ed0d60ce5fb8fa90be65d0.tar.gz bcfg2-26f2687927ed180c82ed0d60ce5fb8fa90be65d0.tar.bz2 bcfg2-26f2687927ed180c82ed0d60ce5fb8fa90be65d0.zip |
Implement the balance of decision mode support (tested and working)
git-svn-id: https://svn.mcs.anl.gov/repos/bcfg/trunk/bcfg2@4933 ce84e21b-d406-0410-9b95-82705330c041
Diffstat (limited to 'src/lib/Server/Plugins/Decisions.py')
-rw-r--r-- | src/lib/Server/Plugins/Decisions.py | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/src/lib/Server/Plugins/Decisions.py b/src/lib/Server/Plugins/Decisions.py new file mode 100644 index 000000000..4b758cdd4 --- /dev/null +++ b/src/lib/Server/Plugins/Decisions.py @@ -0,0 +1,51 @@ +import Bcfg2.Server.Plugin, lxml.etree + +class DecisionFile(Bcfg2.Server.Plugin.SpecificData): + def handle_event(self, event): + Bcfg2.Server.Plugin.SpecificData.handle_event(self, event) + self.contents = lxml.etree.XML(self.data) + + def get_decisions(self): + return [(x.get('type'), x.get('name')) for x in self.contents.xpath('.//Decision')] + +class DecisionSet(Bcfg2.Server.Plugin.EntrySet): + def __init__(self, path, fam, encoding): + """Container for decision specification files + + Arguments: + - `path`: repository path + - `fam`: reference to the file monitor + - `encoding`: XML character encoding + """ + pattern = '(white|black)list' + Bcfg2.Server.Plugin.EntrySet.__init__(self, pattern, path, False, \ + DecisionFile, encoding) + fam.AddMonitor(path, self) + + def HandleEvent(self, event): + if event.filename != self.path: + return self.handle_event(event) + + def GetDecisions(self, metadata, mode): + ret = [] + candidates = [c for c in self.get_matching(metadata) + if c.name.split('/')[-1].startswith(mode)] + for c in candidates: + ret += c.get_decisions() + return ret + +class Decisions(DecisionSet, Bcfg2.Server.Plugin.DecisionPlugin): + __name__ = 'Decisions' + __version__ = '$Id: $' + __author__ = 'bcfg-dev@mcs.anl.gov' + + def __init__(self, core, datastore): + """Decisions plugins + + Arguments: + - `core`: Bcfg2.Core instance + - `datastore`: File repository location + """ + Bcfg2.Server.Plugin.DecisionPlugin.__init__(self, core, datastore) + DecisionSet.__init__(self, self.data, core.fam, core.encoding) + |