summaryrefslogtreecommitdiffstats
path: root/src/lib/Bcfg2/Server/Plugins/Decisions.py
diff options
context:
space:
mode:
authorChris St. Pierre <chris.a.st.pierre@gmail.com>2012-10-12 11:37:14 -0400
committerChris St. Pierre <chris.a.st.pierre@gmail.com>2012-10-15 09:10:21 -0400
commit1a6160ebeecffc57b5066ebf343188edf6a63eaa (patch)
tree92918e45ca04cf9a753715b84be638ac748d5dbe /src/lib/Bcfg2/Server/Plugins/Decisions.py
parent0a083d2dd024b193338a61193ffc8d0c0c03561d (diff)
downloadbcfg2-1a6160ebeecffc57b5066ebf343188edf6a63eaa.tar.gz
bcfg2-1a6160ebeecffc57b5066ebf343188edf6a63eaa.tar.bz2
bcfg2-1a6160ebeecffc57b5066ebf343188edf6a63eaa.zip
wrote sphinx docs for base server Core
Diffstat (limited to 'src/lib/Bcfg2/Server/Plugins/Decisions.py')
-rw-r--r--src/lib/Bcfg2/Server/Plugins/Decisions.py88
1 files changed, 44 insertions, 44 deletions
diff --git a/src/lib/Bcfg2/Server/Plugins/Decisions.py b/src/lib/Bcfg2/Server/Plugins/Decisions.py
index 90d9ecbe3..5521ea045 100644
--- a/src/lib/Bcfg2/Server/Plugins/Decisions.py
+++ b/src/lib/Bcfg2/Server/Plugins/Decisions.py
@@ -1,67 +1,67 @@
-import logging
-import lxml.etree
-import sys
+""" The Decisions plugin provides a flexible method to whitelist or
+blacklist certain entries. """
+import os
+import sys
+import lxml.etree
import Bcfg2.Server.Plugin
-logger = logging.getLogger('Bcfg2.Plugins.Decisions')
+
class DecisionFile(Bcfg2.Server.Plugin.SpecificData):
+ """ Representation of a Decisions XML file """
+
+ def __init__(self, name, specific, encoding):
+ Bcfg2.Server.Plugin.SpecificData.__init__(self, name, specific,
+ encoding)
+ self.contents = None
+
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')]
+ """ Get a list of whitelist or blacklist tuples """
+ return [(x.get('type'), x.get('name'))
+ for x in self.contents.xpath('.//Decision')]
-class DecisionSet(Bcfg2.Server.Plugin.EntrySet):
- basename_is_regex = True
- def __init__(self, path, fam, encoding):
- """Container for decision specification files.
+class Decisions(Bcfg2.Server.Plugin.EntrySet,
+ Bcfg2.Server.Plugin.Plugin,
+ Bcfg2.Server.Plugin.Decision):
+ """ Decisions plugin
- Arguments:
- - `path`: repository path
- - `fam`: reference to the file monitor
- - `encoding`: XML character encoding
+ Arguments:
+ - `core`: Bcfg2.Core instance
+ - `datastore`: File repository location
+ """
+ basename_is_regex = True
+ __author__ = 'bcfg-dev@mcs.anl.gov'
- """
- Bcfg2.Server.Plugin.EntrySet.__init__(self, '(white|black)list', path,
- DecisionFile, encoding)
+ def __init__(self, core, datastore):
+ Bcfg2.Server.Plugin.Plugin.__init__(self, core, datastore)
+ Bcfg2.Server.Plugin.Decision.__init__(self)
+
+ Bcfg2.Server.Plugin.EntrySet.__init__(self, '(white|black)list',
+ self.data,
+ DecisionFile,
+ core.setup['encoding'])
try:
- fam.AddMonitor(path, self)
+ core.fam.AddMonitor(self.data, self)
except OSError:
- e = sys.exc_info()[1]
- logger.error('Adding filemonitor for %s failed. '
- 'Make sure directory exists' % path)
- raise Bcfg2.Server.Plugin.PluginInitError(e)
+ err = sys.exc_info()[1]
+ msg = 'Adding filemonitor for %s failed: %s' % (self.data, err)
+ self.logger.error(msg)
+ raise Bcfg2.Server.Plugin.PluginInitError(msg)
def HandleEvent(self, event):
+ """ Handle events on Decision files by passing them off to
+ EntrySet.handle_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()
+ for cdt in self.get_matching(metadata):
+ if os.path.basename(cdt).startswith(mode):
+ ret.extend(cdt.get_decisions())
return ret
-
-class Decisions(DecisionSet,
- Bcfg2.Server.Plugin.Plugin,
- Bcfg2.Server.Plugin.Decision):
- name = 'Decisions'
- __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.Plugin.__init__(self, core, datastore)
- Bcfg2.Server.Plugin.Decision.__init__(self)
- DecisionSet.__init__(self, self.data, core.fam, core.encoding)
-