diff options
author | Narayan Desai <desai@mcs.anl.gov> | 2007-04-03 12:47:24 +0000 |
---|---|---|
committer | Narayan Desai <desai@mcs.anl.gov> | 2007-04-03 12:47:24 +0000 |
commit | 6c6b0ad8d13ddcea625dbd3130ea0b9d4bc00ba8 (patch) | |
tree | da4d12d4e2a95333f39f7292bda0faf76920c007 /src/lib/Server/Plugins/Cfg.py | |
parent | 74e5a39920606a8c6e4ef24c351480dba81f11eb (diff) | |
download | bcfg2-6c6b0ad8d13ddcea625dbd3130ea0b9d4bc00ba8.tar.gz bcfg2-6c6b0ad8d13ddcea625dbd3130ea0b9d4bc00ba8.tar.bz2 bcfg2-6c6b0ad8d13ddcea625dbd3130ea0b9d4bc00ba8.zip |
Move logic for repository interactions in bcfg2-admin pull into individual plugins
(This change introduces all new infrastructure, and is in preparation for doing support in SSHbase)
git-svn-id: https://svn.mcs.anl.gov/repos/bcfg/trunk/bcfg2@3005 ce84e21b-d406-0410-9b95-82705330c041
Diffstat (limited to 'src/lib/Server/Plugins/Cfg.py')
-rw-r--r-- | src/lib/Server/Plugins/Cfg.py | 40 |
1 files changed, 39 insertions, 1 deletions
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) |