summaryrefslogtreecommitdiffstats
path: root/src/lib
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/Server/Plugin.py10
-rw-r--r--src/lib/Server/Plugins/Cfg.py40
2 files changed, 49 insertions, 1 deletions
diff --git a/src/lib/Server/Plugin.py b/src/lib/Server/Plugin.py
index 9a3b73e82..3c32dcad7 100644
--- a/src/lib/Server/Plugin.py
+++ b/src/lib/Server/Plugin.py
@@ -59,6 +59,16 @@ class Plugin(object):
'''This is the slow-path handler for configuration entry binding'''
raise PluginExecutionError
+ def AcceptEntry(self, metadata, entry_type, entry_name, data):
+ '''This is the null per-plugin implementation
+ of bcfg2-admin pull'''
+ raise PluginExecutionError
+
+ def CommitChanges(self):
+ '''Handle revctl commits, if needed'''
+ # not implemented yet
+ pass
+
# the rest of the file contains classes for coherent file caching
class FileBacked(object):
diff --git a/src/lib/Server/Plugins/Cfg.py b/src/lib/Server/Plugins/Cfg.py
index d5829a016..c75afbc18 100644
--- a/src/lib/Server/Plugins/Cfg.py
+++ b/src/lib/Server/Plugins/Cfg.py
@@ -1,7 +1,8 @@
'''This module implements a config file repository'''
__revision__ = '$Revision$'
-import binascii, logging, os, re, stat, tempfile, Bcfg2.Server.Plugin, lxml.etree
+import binascii, difflib, logging, os, re, stat, tempfile, \
+ xml.sax.saxutils, Bcfg2.Server.Plugin, lxml.etree
logger = logging.getLogger('Bcfg2.Plugins.Cfg')
@@ -9,6 +10,12 @@ specific = re.compile('(.*/)(?P<filename>[\S\-.]+)\.((H_(?P<hostname>\S+))|' +
'(G(?P<prio>\d+)_(?P<group>\S+)))$')
probeData = {}
+def update_file(path, diff):
+ '''Update file at path using diff'''
+ newdata = '\n'.join(difflib.restore(xml.sax.saxutils.unescape(diff).split('\n'), 1))
+ print "writing file, %s" % path
+ open(path, 'w').write(newdata)
+
class SpecificityError(Exception):
'''Thrown in case of filename parse failure'''
pass
@@ -352,3 +359,34 @@ class Cfg(Bcfg2.Server.Plugin.Plugin):
logger.error("Got unknown event %s %s:%s" % (action, event.requestID, event.filename))
self.interpolate = len([entry for entry in self.entries.values() if entry.interpolate ]) > 0
+ def AcceptEntry(self, meta, _, entry_name, diff):
+ '''per-plugin bcfg2-admin pull support'''
+ hsq = "Found host-specific file %s; Should it be updated (n/Y): "
+ repo_vers = lxml.etree.Element('ConfigFile', name=entry_name)
+ self.Entries['ConfigFile'][entry_name](repo_vers, meta)
+ repo_curr = repo_vers.text
+ # find the file fragment
+ basefile = [frag for frag in \
+ self.entries[entry_name].fragments \
+ if frag.applies(meta)][-1]
+ gsq = "Should this change apply to this host of all hosts effected by file %s? (N/y): " % (basefile.name)
+ if ".H_%s" % (meta.hostname) in basefile.name:
+ answer = raw_input(hsq)
+ else:
+ answer = raw_input(gsq)
+
+ if answer in 'Yy':
+ update_file(basefile.name, diff)
+ return
+
+ if ".H_%s" % (meta.hostname) in basefile.name:
+ raise SystemExit, 1
+ # figure out host-specific filename
+ if '.G_' in basefile.name:
+ idx = basefile.name.find(".G_")
+ newname = basefile.name[:idx] + ".H_%s" % (meta.hostname)
+ else:
+ newname = basefile.name + ".H_%s" % (meta.hostname)
+ print "This file will be installed as file %s" % newname
+ if raw_input("Should it be installed? (N/y): ") in 'Yy':
+ update_file(newname, diff)