diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/lib/Server/Admin/Bundle.py | 14 | ||||
-rw-r--r-- | src/lib/Server/Admin/Init.py | 2 | ||||
-rw-r--r-- | src/lib/Server/Admin/Pull.py | 7 | ||||
-rw-r--r--[-rwxr-xr-x] | src/lib/Server/Admin/Reports.py | 0 | ||||
-rw-r--r-- | src/lib/Server/Admin/__init__.py | 21 | ||||
-rw-r--r-- | src/lib/Server/Plugin.py | 2 | ||||
-rw-r--r-- | src/lib/Server/Plugins/Svn2.py | 102 |
7 files changed, 136 insertions, 12 deletions
diff --git a/src/lib/Server/Admin/Bundle.py b/src/lib/Server/Admin/Bundle.py index 41cd5727e..893fde489 100644 --- a/src/lib/Server/Admin/Bundle.py +++ b/src/lib/Server/Admin/Bundle.py @@ -46,7 +46,7 @@ class Bundle(Bcfg2.Server.Admin.MetadataCore): # except MetadataConsistencyError: # print "Error in deleting bundle." # raise SystemExit(1) - #Lists all available xml bundles + # Lists all available xml bundles elif args[0] in ['list-xml', 'ls-xml']: bundle_name = [] for bundle_path in xml_list: @@ -54,7 +54,7 @@ class Bundle(Bcfg2.Server.Admin.MetadataCore): bundle_name.append(rg.search(bundle_path).group(1)) for bundle in bundle_name: print bundle.split('.')[0] - #Lists all available genshi bundles + # Lists all available genshi bundles elif args[0] in ['list-genshi', 'ls-gen']: bundle_name = [] for bundle_path in genshi_list: @@ -62,9 +62,11 @@ class Bundle(Bcfg2.Server.Admin.MetadataCore): bundle_name.append(rg.search(bundle_path).group(1)) for bundle in bundle_name: print bundle.split('.')[0] - #Shows a list of all available bundles and prints bundle - #details after the user choose one bundle. - #FIXME: Add support for detailed output of genshi bundles + # Shows a list of all available bundles and prints bundle + # details after the user choose one bundle. + # FIXME: Add support for detailed output of genshi bundles + # FIXME: This functionality is almost identical with + # bcfg2-info bundles elif args[0] in ['show']: bundle_name = [] bundle_list = xml_list + genshi_list @@ -84,7 +86,7 @@ class Bundle(Bcfg2.Server.Admin.MetadataCore): else: if '%s/Bundler/%s' % \ (repo, bundle_name[int(lineno)]) in genshi_list: - print "Detailed output for *.genshi bundle is not supported." + print "Detailed output for *.genshi bundles is not supported." else: print 'Details for the "%s" bundle:' % \ (bundle_name[int(lineno)].split('.')[0]) diff --git a/src/lib/Server/Admin/Init.py b/src/lib/Server/Admin/Init.py index 384ba6929..c6d1f9e3d 100644 --- a/src/lib/Server/Admin/Init.py +++ b/src/lib/Server/Admin/Init.py @@ -66,7 +66,7 @@ clients = '''<Clients version="3.0"> # Mapping of operating system names to groups os_list = [ - ('Redhat/Fedora/RHEL/RHAS/Centos', 'redhat'), + ('Red Hat/Fedora/RHEL/RHAS/Centos', 'redhat'), ('SUSE/SLES', 'suse'), ('Mandrake', 'mandrake'), ('Debian', 'debian'), diff --git a/src/lib/Server/Admin/Pull.py b/src/lib/Server/Admin/Pull.py index aa732c67f..289852f79 100644 --- a/src/lib/Server/Admin/Pull.py +++ b/src/lib/Server/Admin/Pull.py @@ -135,4 +135,9 @@ class Pull(Bcfg2.Server.Admin.MetadataCore): except Bcfg2.Server.Plugin.PluginExecutionError: self.errExit("Configuration upload not supported by plugin %s" \ % (plugin.name)) - # FIXME svn commit if running under svn + # commit if running under a VCS + for vcsplugin in self.bcore.plugins.values(): + if isinstance(vcsplugin, Bcfg2.Server.Plugin.Version): + files = "%s/%s" % (plugin.data, ename) + comment = 'file "%s" pulled from host %s' % (files, client) + vcsplugin.commit_data([files], comment) diff --git a/src/lib/Server/Admin/Reports.py b/src/lib/Server/Admin/Reports.py index a4dd19064..a4dd19064 100755..100644 --- a/src/lib/Server/Admin/Reports.py +++ b/src/lib/Server/Admin/Reports.py diff --git a/src/lib/Server/Admin/__init__.py b/src/lib/Server/Admin/__init__.py index bb5c41895..a22d8521a 100644 --- a/src/lib/Server/Admin/__init__.py +++ b/src/lib/Server/Admin/__init__.py @@ -1,8 +1,23 @@ __revision__ = '$Revision$' -__all__ = ['Mode', 'Client', 'Compare', 'Init', 'Minestruct', 'Perf', - 'Pull', 'Query', 'Reports', 'Snapshots', 'Tidy', 'Viz', - 'Xcmd', 'Group', 'Backup'] +__all__ = [ + 'Backup', + 'Bundle', + 'Client', + 'Compare', + 'Group', + 'Init', + 'Minestruct', + 'Mode', + 'Perf', + 'Pull', + 'Query', + 'Reports', + 'Snapshots', + 'Tidy', + 'Viz', + 'Xcmd' + ] import ConfigParser import logging diff --git a/src/lib/Server/Plugin.py b/src/lib/Server/Plugin.py index 95569e3ac..186d1198a 100644 --- a/src/lib/Server/Plugin.py +++ b/src/lib/Server/Plugin.py @@ -293,7 +293,7 @@ class Version(object): """Interact with various version control systems.""" def get_revision(self): return [] - def commit_data(self): + def commit_data(self, file_list, comment=None): pass # the rest of the file contains classes for coherent file caching diff --git a/src/lib/Server/Plugins/Svn2.py b/src/lib/Server/Plugins/Svn2.py new file mode 100644 index 000000000..875e9e6a6 --- /dev/null +++ b/src/lib/Server/Plugins/Svn2.py @@ -0,0 +1,102 @@ +import os +try: + import pysvn + missing = False +except: + missing = True +import Bcfg2.Server.Plugin + +class Svn2(Bcfg2.Server.Plugin.Plugin, + Bcfg2.Server.Plugin.Version): + """Svn is a version plugin for dealing with Bcfg2 repos.""" + name = 'Svn2' + __version__ = '$Id$' + __author__ = 'bcfg-dev@mcs.anl.gov' + + conflicts = ['Svn'] + experimental = True + __rmi__ = Bcfg2.Server.Plugin.Plugin.__rmi__ + ['Update','Commit'] + + def __init__(self, core, datastore): + Bcfg2.Server.Plugin.Plugin.__init__(self, core, datastore) + + if missing: + self.logger.error("Svn2: Missing PySvn") + raise Bcfg2.Server.Plugin.PluginInitError + + self.client = pysvn.Client() + + self.core = core + self.datastore = datastore + self.svn_root = None + self.revision = None + + # Read revision from bcfg2 repo + revision = self.get_revision() + if not self.revision: + raise Bcfg2.Server.Plugin.PluginInitError + + self.logger.debug("Initialized svn plugin with svn root %s at revision %s" \ + % (self.svn_root, revision)) + + def get_revision(self): + """Read svn revision information for the Bcfg2 repository.""" + try: + info = self.client.info(self.datastore) + self.revision = info.revision + self.svn_root = info.url + return str(self.revision.number) + except: + self.logger.error("Svn2: Failed to get revision", exc_info=1) + self.revision = None + return str(-1) + + def commit_data(self, file_list, comment=None): + """Commit changes into the repository""" + if not comment: + comment = 'Svn2: autocommit' + + # First try to update + if not self.Update(): + self.logger.error("Failed to update svn repository, refusing to commit changes") + return + + #FIXME - look for conflicts? + + for file in file_list: + stat = self.client.status(file) + self.client.add([f.path for f in stat \ + if f.text_status == pysvn.wc_status_kind.unversioned]) + try: + self.revision = self.client.checkin([self.datastore], comment, + recurse=True) + self.revision = self.client.update(self.datastore, recurse=True)[0] + self.logger.info("Svn2: Commited changes. At %s" % self.revision.number) + except: + self.logger.error("Svn2: Failed to commit changes", exc_info=1) + + def Update(self): + '''Svn2.Update() => True|False\nUpdate svn working copy\n''' + try: + old_revision = self.revision.number + self.revision = self.client.update(self.datastore, recurse=True)[0] + except: + self.logger.error("Svn2: Failed to update server repository", exc_info=1) + return False + + if old_revision == self.revision.number: + self.logger.debug("repository is current") + else: + self.logger.info("Updated %s from revision %s to %s" % \ + (self.datastore, old_revision, self.revision.number)) + return True + + def Commit(self): + """Svn2.Commit() => True|False\nCommit svn repository\n""" + try: + self.commit_changes([]) + return True + except: + return False + + |