OS API: support for multiple versions in an OS
authorGuido Trotter <ultrotter@google.com>
Mon, 13 Oct 2008 13:19:20 +0000 (13:19 +0000)
committerGuido Trotter <ultrotter@google.com>
Mon, 13 Oct 2008 13:19:20 +0000 (13:19 +0000)
Allow multiple api versions in an OS. This is according to the OS API
changes design doc, by which an OS can support multiple versions of the
Ganeti API and if one is supported by Ganeti it will work. Since up to
version 5 of the API mandates an OS could support only one version, this
change is retrocompatible with it and requires no version bump up.

Reviewed-by: iustinp

lib/backend.py
lib/objects.py

index b7df899..6bf9c8d 100644 (file)
@@ -1149,21 +1149,21 @@ def _OSOndiskVersion(name, os_dir):
   try:
     f = open(api_file)
     try:
-      api_version = f.read(256)
+      api_versions = f.readlines()
     finally:
       f.close()
   except EnvironmentError, err:
     raise errors.InvalidOS(name, os_dir, "error while reading the"
                            " API version (%s)" % _ErrnoOrStr(err))
 
-  api_version = api_version.strip()
+  api_versions = [version.strip() for version in api_versions]
   try:
-    api_version = int(api_version)
+    api_versions = [int(version) for version in api_versions]
   except (TypeError, ValueError), err:
     raise errors.InvalidOS(name, os_dir,
                            "API version is not integer (%s)" % str(err))
 
-  return api_version
+  return api_versions
 
 
 def DiagnoseOS(top_dirs=None):
@@ -1219,12 +1219,12 @@ def OSFromDisk(name, base_dir=None):
   else:
     os_dir = os.path.sep.join([base_dir, name])
 
-  api_version = _OSOndiskVersion(name, os_dir)
+  api_versions = _OSOndiskVersion(name, os_dir)
 
-  if api_version != constants.OS_API_VERSION:
+  if constants.OS_API_VERSION not in api_versions:
     raise errors.InvalidOS(name, os_dir, "API version mismatch"
                            " (found %s want %s)"
-                           % (api_version, constants.OS_API_VERSION))
+                           % (api_versions, constants.OS_API_VERSION))
 
   # OS Scripts dictionary, we will populate it with the actual script names
   os_scripts = {'create': '', 'export': '', 'import': '', 'rename': ''}
@@ -1252,7 +1252,7 @@ def OSFromDisk(name, base_dir=None):
                     export_script=os_scripts['export'],
                     import_script=os_scripts['import'],
                     rename_script=os_scripts['rename'],
-                    api_version=api_version)
+                    api_versions=api_versions)
 
 
 def GrowBlockDevice(disk, amount):
index 68473c9..fc3ed09 100644 (file)
@@ -663,7 +663,7 @@ class OS(ConfigObject):
     "name",
     "path",
     "status",
-    "api_version",
+    "api_versions",
     "create_script",
     "export_script",
     "import_script",