Add function to determine current configuration version
authorKlaus Aehlig <aehlig@google.com>
Mon, 7 Oct 2013 13:20:54 +0000 (15:20 +0200)
committerKlaus Aehlig <aehlig@google.com>
Tue, 8 Oct 2013 10:14:39 +0000 (12:14 +0200)
The 'gnt-cluster upgrade --resume' command needs to determine whether the
configuration has already been updated or not, in order to decide at which
phase to resume. So provide a function to determine the version of the
configuration on file.

Signed-off-by: Klaus Aehlig <aehlig@google.com>
Reviewed-by: Thomas Thrainer <thomasth@google.com>

lib/client/gnt_cluster.py

index 6eeb4fc..0eb23ea 100644 (file)
@@ -45,6 +45,7 @@ from ganeti import compat
 from ganeti import netutils
 from ganeti import ssconf
 from ganeti import pathutils
+from ganeti import serializer
 from ganeti import qlang
 
 
@@ -1746,6 +1747,22 @@ def _ExecuteCommands(fns):
     fn()
 
 
+def _GetConfigVersion():
+  """Determine the version the configuration file currently has.
+
+  @rtype: tuple or None
+  @return: (major, minor, revision) if the version can be determined,
+      None otherwise
+
+  """
+  config_data = serializer.LoadJson(utils.ReadFile(pathutils.CLUSTER_CONF_FILE))
+  try:
+    config_version = config_data["version"]
+  except KeyError:
+    return None
+  return utils.SplitVersion(config_version)
+
+
 def _ReadIntentToUpgrade():
   """Read the file documenting the intent to upgrade the cluster.