summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/lib/Client/Frame.py13
-rw-r--r--src/lib/Server/Core.py10
-rw-r--r--src/lib/Server/Plugins/Decisions.py51
-rw-r--r--src/lib/Server/Plugins/__init__.py2
-rwxr-xr-xsrc/sbin/bcfg22
-rwxr-xr-xsrc/sbin/bcfg2-server9
6 files changed, 72 insertions, 15 deletions
diff --git a/src/lib/Client/Frame.py b/src/lib/Client/Frame.py
index a2312e495..6d778f6ba 100644
--- a/src/lib/Client/Frame.py
+++ b/src/lib/Client/Frame.py
@@ -28,14 +28,14 @@ def promptFilter(prompt, entries):
return ret
def matches_white_list(entry, whitelist):
- return (entry.tag, entry.get('name')) in whitelist or \
- (entry.tag, '*') in whitelist or \
- ('*', entry.get('name')) in whitelist
+ return [entry.tag, entry.get('name')] in whitelist or \
+ [entry.tag, '*'] in whitelist or \
+ ['*', entry.get('name')] in whitelist
def passes_black_list(entry, blacklist):
- return (entry.tag, entry.get('name')) not in blacklist and \
- and (entry.tag, '*') not in blacklist and \
- ('*', entry.get('name')) not in blacklist
+ return [entry.tag, entry.get('name')] not in blacklist and \
+ [entry.tag, '*'] not in blacklist and \
+ ['*', entry.get('name')] not in blacklist
class Frame:
'''Frame is the container for all Tool objects and state information'''
@@ -167,6 +167,7 @@ class Frame:
self.logger.info("In whitelist mode: suppressing installation of:")
self.logger.info(["%s:%s" % (e.tag, e.get('name')) for e in w_to_rem])
self.whitelist = [x for x in self.whitelist if x not in w_to_rem]
+
elif self.setup['decision'] == 'blacklist':
b_to_rem = [e for e in self.whitelist \
if not passes_black_list(e, self.setup['decision_list'])]
diff --git a/src/lib/Server/Core.py b/src/lib/Server/Core.py
index b29c9bf05..e6d71c3bd 100644
--- a/src/lib/Server/Core.py
+++ b/src/lib/Server/Core.py
@@ -234,3 +234,13 @@ class Core(object):
logger.error('''Ran command "svn info %s"''' % (self.datastore))
logger.error("Got output: %s" % data)
self.svn = False
+
+ def GetDecisions(self, metadata, mode):
+ result = []
+ for plugin in self.plugins.values():
+ try:
+ if isinstance(plugin, Bcfg2.Server.Plugin.DecisionPlugin):
+ result += plugin.GetDecisions(metadata, mode)
+ except:
+ logger.error("Plugin: %s failed to generate decision list" % plugin.__name__, exc_info=1)
+ return result
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)
+
diff --git a/src/lib/Server/Plugins/__init__.py b/src/lib/Server/Plugins/__init__.py
index 9707fbfeb..f80fa1b11 100644
--- a/src/lib/Server/Plugins/__init__.py
+++ b/src/lib/Server/Plugins/__init__.py
@@ -1,6 +1,6 @@
'''imports for Bcfg2.Server.Plugins'''
__revision__ = '$Revision$'
-__all__ = ['Account', 'Base', 'Bundler', 'Cfg', 'Hostbase', 'Metadata', 'NagiosGen',
+__all__ = ['Account', 'Base', 'Bundler', 'Cfg', 'Decisions', 'Hostbase', 'Metadata', 'NagiosGen',
'Pkgmgr', 'Rules', 'SSHbase', 'Statistics', 'Svcmgr', 'TCheetah',
'SGenshi', 'TGenshi', 'Vhost']
diff --git a/src/sbin/bcfg2 b/src/sbin/bcfg2
index abcf2ec49..7e78935ba 100755
--- a/src/sbin/bcfg2
+++ b/src/sbin/bcfg2
@@ -261,6 +261,8 @@ class Client:
try:
self.setup['decision_list'] = proxy.GetDecisionList( \
self.setup['decision'])
+ self.logger.info("Got Decision List from server:")
+ self.logger.info(self.setup['decision_list'])
except xmlrpclib.Fault, f:
if f.faultCode == 1:
print "GetDecisionList method not supported by server"
diff --git a/src/sbin/bcfg2-server b/src/sbin/bcfg2-server
index 08e3f3d87..8fe1b82ff 100755
--- a/src/sbin/bcfg2-server
+++ b/src/sbin/bcfg2-server
@@ -192,14 +192,7 @@ class Bcfg2Serv(Bcfg2.Component.Component):
def Bcfg2GetDecisionList(self, address, mode):
client = self.Core.metadata.resolve_client(address)
meta = self.Core.metadata.get_metadata(client)
- result = []
- for plugin in self.Core.plugins.values():
- try:
- if isinstance(plugin, Bcfg2.Server.Plugin.DecisionPlugin):
- result += plugin.GetDecision(meta, mode)
- except:
- self.logger.error("Plugin: %s failed to generate decision list" % plugin.__name__)
- return []
+ return self.Core.GetDecisions(meta, mode)
if __name__ == '__main__':