summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorNarayan Desai <desai@mcs.anl.gov>2007-10-30 03:14:44 +0000
committerNarayan Desai <desai@mcs.anl.gov>2007-10-30 03:14:44 +0000
commit77cbb937c108869fbde5ab6fb132a8a05cd406a3 (patch)
treec4aef4ff2645fd20af4a3a75f145aafd27508f8e /src
parent23fcbe41f466bd4269a96f1730cbe4ae230a521f (diff)
downloadbcfg2-77cbb937c108869fbde5ab6fb132a8a05cd406a3.tar.gz
bcfg2-77cbb937c108869fbde5ab6fb132a8a05cd406a3.tar.bz2
bcfg2-77cbb937c108869fbde5ab6fb132a8a05cd406a3.zip
Implement bcfg2-admin pull support for info files/metadata changes (Resolves Ticket #480)
git-svn-id: https://svn.mcs.anl.gov/repos/bcfg/trunk/bcfg2@3886 ce84e21b-d406-0410-9b95-82705330c041
Diffstat (limited to 'src')
-rw-r--r--src/lib/Server/Plugins/Cfg.py15
-rw-r--r--src/lib/Server/Plugins/SSHbase.py2
-rwxr-xr-xsrc/sbin/bcfg2-admin31
3 files changed, 38 insertions, 10 deletions
diff --git a/src/lib/Server/Plugins/Cfg.py b/src/lib/Server/Plugins/Cfg.py
index 987cc2da8..f653f53f3 100644
--- a/src/lib/Server/Plugins/Cfg.py
+++ b/src/lib/Server/Plugins/Cfg.py
@@ -127,7 +127,6 @@ class ConfigFileEntry(object):
if basename in [':info', 'info']:
return self.read_info(basename)
elif basename in ['info.xml', ':info.xml']:
- print "here"
fpath = self.repopath + '/' + basename
self.infoxml = Bcfg2.Server.Plugin.XMLSrc(fpath, True)
return
@@ -372,8 +371,20 @@ 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, fulldata):
+ def AcceptEntry(self, meta, _, entry_name, diff, fulldata, metadata_updates={}):
'''per-plugin bcfg2-admin pull support'''
+ if metadata_updates:
+ if hasattr(self.Entries['ConfigFile'][entry_name], 'infoxml'):
+ print "InfoXML support not yet implemented"
+ elif raw_input("Should metadata updates apply to all hosts? (n/Y) ") in 'yY':
+ self.entries[entry_name].metadata.update(metadata_updates)
+ infofile = open(self.entries[entry_name].repopath + '/:info', 'w')
+ for x in self.entries[entry_name].metadata.iteritems():
+ infofile.write("%s: %s\n" % x)
+ infofile.close()
+ if not diff or fulldata:
+ raise SystemExit, 0
+
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)
diff --git a/src/lib/Server/Plugins/SSHbase.py b/src/lib/Server/Plugins/SSHbase.py
index 9e87a4fdc..4bf8909de 100644
--- a/src/lib/Server/Plugins/SSHbase.py
+++ b/src/lib/Server/Plugins/SSHbase.py
@@ -181,7 +181,7 @@ class SSHbase(Bcfg2.Server.Plugin.Plugin, Bcfg2.Server.Plugin.DirectoryBacked):
except OSError:
self.logger.error("Failed to unlink temporary ssh keys")
- def AcceptEntry(self, meta, _, entry_name, diff, fulldata):
+ def AcceptEntry(self, meta, _, entry_name, diff, fulldata, metadata_updates={}):
'''per-plugin bcfg2-admin pull support'''
filename = "%s/%s.H_%s" % (self.data, entry_name.split('/')[-1],
meta.hostname)
diff --git a/src/sbin/bcfg2-admin b/src/sbin/bcfg2-admin
index 9d7584d96..efd493341 100755
--- a/src/sbin/bcfg2-admin
+++ b/src/sbin/bcfg2-admin
@@ -317,6 +317,16 @@ def do_pull(cfile, repopath, client, etype, ename):
err_exit("Could not find state data for entry; rerun bcfg2 on client system")
cfentry = entry[-1]
+
+ badfields = [field for field in ['perms', 'owner', 'group'] \
+ if cfentry.get(field) != cfentry.get('current_' + field) and \
+ cfentry.get('current_' + field)]
+ if badfields:
+ m_updates = dict([(field, cfentry.get('current_' + field)) for field in badfields])
+ print "got metadata_updates", m_updates
+ else:
+ m_updates = {}
+
if 'current_bdiff' in cfentry.attrib:
data = False
diff = binascii.a2b_base64(cfentry.get('current_bdiff'))
@@ -327,14 +337,23 @@ def do_pull(cfile, repopath, client, etype, ename):
data = binascii.a2b_base64(cfentry.get('current_bfile'))
diff = False
else:
- print "having trouble processing entry. Entry is:"
- print lxml.etree.tostring(cfentry)
- raise SystemExit, 1
+ if not m_updates:
+ print "having trouble processing entry. Entry is:"
+ print lxml.etree.tostring(cfentry)
+ raise SystemExit, 1
+ else:
+ data = False
+ diff = False
if diff:
print "Located diff:\n %s" % diff
- else:
+ elif data:
print "Found full (binary) file data"
+ if m_updates:
+ print "Found metadata updates"
+
+ if not diff and not data and not m_updates:
+ err_exit("Failed to locate diff or full data or metadata updates\nStatistics entry was:\n%s" % lxml.etree.tostring(cfentry))
try:
bcore = Bcfg2.Server.Core.Core({}, cfile)
@@ -352,10 +371,8 @@ def do_pull(cfile, repopath, client, etype, ename):
err_exit("Got wrong numbers of matching generators for entry:" \
+ "%s" % ([g.__name__ for g in glist]))
plugin = glist[0]
- if not diff and not data:
- err_exit("Failed to locate diff or full data\nStatistics entry was:\n%s" % lxml.etree.tostring(cfentry))
try:
- plugin.AcceptEntry(m, 'ConfigFile', ename, diff, data)
+ plugin.AcceptEntry(m, 'ConfigFile', ename, diff, data, m_updates)
except Bcfg2.Server.Plugin.PluginExecutionError:
err_exit("Configuration upload not supported by plugin %s" \
% (plugin.__name__))