From d1a7d66f2c2c9ca2cd3e0f55bcecf687eafb1fdd Mon Sep 17 00:00:00 2001 From: Guido Trotter <ultrotter@google.com> Date: Mon, 22 Jun 2009 15:31:15 +0100 Subject: [PATCH] Introduce OS api version 15 Also, since Ganeti 2.1 will be compatible with both 10 and 15, change the OS_API_VERSION constant to be an OS_API_VERSIONS set, and update the places in the code that used that constat to use something else. In particular: - in the qa for now we just create a fake version 10 OS - in the os environment we use the highest common version (which means we need to pass in the os to OSEnvironment) - when loading an OS any common version will do Signed-off-by: Guido Trotter <ultrotter@google.com> Reviewed-by: Iustin Pop <iustin@google.com> --- lib/backend.py | 21 ++++++++++++--------- lib/cmdlib.py | 2 +- lib/constants.py | 4 +++- qa/qa_os.py | 2 +- 4 files changed, 17 insertions(+), 12 deletions(-) diff --git a/lib/backend.py b/lib/backend.py index 01fd28dc2..0b922884d 100644 --- a/lib/backend.py +++ b/lib/backend.py @@ -712,7 +712,7 @@ def InstanceOsAdd(instance, reinstall): """ inst_os = OSFromDisk(instance.os) - create_env = OSEnvironment(instance) + create_env = OSEnvironment(instance, inst_os) if reinstall: create_env['INSTANCE_REINSTALL'] = "1" @@ -744,7 +744,7 @@ def RunRenameInstance(instance, old_name): """ inst_os = OSFromDisk(instance.os) - rename_env = OSEnvironment(instance) + rename_env = OSEnvironment(instance, inst_os) rename_env['OLD_INSTANCE_NAME'] = old_name logfile = "%s/rename-%s-%s-%s-%d.log" % (constants.LOG_OS_DIR, instance.os, @@ -1569,9 +1569,9 @@ def _TryOSFromDisk(name, base_dir=None): # push the error up return status, api_versions - if constants.OS_API_VERSION not in api_versions: + if not constants.OS_API_VERSIONS.intersection(api_versions): return False, ("API version mismatch for path '%s': found %s, want %s." % - (os_dir, api_versions, constants.OS_API_VERSION)) + (os_dir, api_versions, constants.OS_API_VERSIONS)) # OS Scripts dictionary, we will populate it with the actual script names os_scripts = dict.fromkeys(constants.OS_SCRIPTS) @@ -1628,11 +1628,13 @@ def OSFromDisk(name, base_dir=None): return payload -def OSEnvironment(instance, debug=0): +def OSEnvironment(instance, os, debug=0): """Calculate the environment for an os script. @type instance: L{objects.Instance} @param instance: target instance for the os script run + @type os: L{objects.OS} + @param os: operating system for which the environment is being built @type debug: integer @param debug: debug level (0 or 1, for OS Api 10) @rtype: dict @@ -1642,7 +1644,8 @@ def OSEnvironment(instance, debug=0): """ result = {} - result['OS_API_VERSION'] = '%d' % constants.OS_API_VERSION + api_version = max(constants.OS_API_VERSIONS.intersection(os.api_versions)) + result['OS_API_VERSION'] = '%d' % api_version result['INSTANCE_NAME'] = instance.name result['INSTANCE_OS'] = instance.os result['HYPERVISOR'] = instance.hypervisor @@ -1759,9 +1762,9 @@ def ExportSnapshot(disk, dest_node, instance, cluster_name, idx): @rtype: None """ - export_env = OSEnvironment(instance) - inst_os = OSFromDisk(instance.os) + export_env = OSEnvironment(instance, inst_os) + export_script = inst_os.export_script logfile = "%s/exp-%s-%s-%s.log" % (constants.LOG_OS_DIR, inst_os.name, @@ -1903,8 +1906,8 @@ def ImportOSIntoInstance(instance, src_node, src_images, cluster_name): @return: each boolean represent the success of importing the n-th disk """ - import_env = OSEnvironment(instance) inst_os = OSFromDisk(instance.os) + import_env = OSEnvironment(instance, inst_os) import_script = inst_os.import_script logfile = "%s/import-%s-%s-%s.log" % (constants.LOG_OS_DIR, instance.os, diff --git a/lib/cmdlib.py b/lib/cmdlib.py index 03660c153..91a35a35b 100644 --- a/lib/cmdlib.py +++ b/lib/cmdlib.py @@ -2577,7 +2577,7 @@ class LUQueryClusterInfo(NoHooksLU): "software_version": constants.RELEASE_VERSION, "protocol_version": constants.PROTOCOL_VERSION, "config_version": constants.CONFIG_VERSION, - "os_api_version": constants.OS_API_VERSION, + "os_api_version": max(constants.OS_API_VERSIONS), "export_version": constants.EXPORT_VERSION, "architecture": (platform.architecture()[0], platform.machine()), "name": cluster.cluster_name, diff --git a/lib/constants.py b/lib/constants.py index 01034051e..13dad7ad9 100644 --- a/lib/constants.py +++ b/lib/constants.py @@ -26,7 +26,9 @@ from ganeti import _autoconf # various versions PROTOCOL_VERSION = 20 RELEASE_VERSION = _autoconf.PACKAGE_VERSION -OS_API_VERSION = 10 +OS_API_V10 = 10 +OS_API_V15 = 15 +OS_API_VERSIONS = frozenset([OS_API_V10, OS_API_V15]) EXPORT_VERSION = 0 RAPI_VERSION = 2 diff --git a/qa/qa_os.py b/qa/qa_os.py index b39e3ca39..4b6fa5e22 100644 --- a/qa/qa_os.py +++ b/qa/qa_os.py @@ -72,7 +72,7 @@ def _SetupTempOs(node, dir, valid): if valid: parts.append(sq(["ln", "-fs", "/bin/true", "create"])) - parts.append(sq(["echo", str(constants.OS_API_VERSION)]) + + parts.append(sq(["echo", str(constants.OS_API_V10)]) + " >ganeti_api_version") cmd = ' && '.join(parts) -- GitLab