Extend export OS RPC and backend to allow the environment file that goes in the OS archive to be overridden. This will be necessary to introduce new OS environment variables, as well as, override the disk labels.
Signed-off-by: Jose A. Lopes <[email protected]> --- lib/backend.py | 8 +++++++- lib/rpc_defs.py | 1 + lib/server/noded.py | 3 ++- 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/lib/backend.py b/lib/backend.py index f246eb6..a27ddd0 100644 --- a/lib/backend.py +++ b/lib/backend.py @@ -3876,7 +3876,7 @@ def ValidateOS(required, osname, checks, osparams, force_variant): return True -def ExportOS(instance): +def ExportOS(instance, override_env): """Creates a GZIPed tarball with an OS definition and environment. The archive contains a file with the environment variables needed by @@ -3885,6 +3885,10 @@ def ExportOS(instance): @type instance: L{objects.Instance} @param instance: instance for which the OS definition is exported + @type override_env: dict of string to string + @param override_env: if supplied, it overrides the environment on a + key-by-key basis that is part of the archive + @rtype: string @return: filepath of the archive @@ -3902,6 +3906,8 @@ def ExportOS(instance): inst_os, temp_dir, result.fail_reason, result.output) env = OSEnvironment(instance, inst_os) + env.update(override_env) + with open(utils.PathJoin(temp_dir, "environment"), "w") as f: for var in env: f.write(var + "=" + env[var] + "\n") diff --git a/lib/rpc_defs.py b/lib/rpc_defs.py index 7eb53f0..e709a37 100644 --- a/lib/rpc_defs.py +++ b/lib/rpc_defs.py @@ -468,6 +468,7 @@ _OS_CALLS = [ ], None, None, "Run a validation routine for a given OS"), ("os_export", SINGLE, None, constants.RPC_TMO_FAST, [ ("instance", ED_INST_DICT, None), + ("override_env", None, None), ], None, None, "Export an OS for a given instance"), ] diff --git a/lib/server/noded.py b/lib/server/noded.py index 7c11b5a..ee6103d 100644 --- a/lib/server/noded.py +++ b/lib/server/noded.py @@ -1000,7 +1000,8 @@ class NodeRequestHandler(http.server.HttpServerHandler): """ instance = objects.Instance.FromDict(params[0]) - return backend.ExportOS(instance) + override_env = params[1] + return backend.ExportOS(instance, override_env) # extstorage ----------------------- -- 1.9.1.423.g4596e3a
