Commit ec9c1bf8 authored by Jose A. Lopes's avatar Jose A. Lopes
Browse files

RPC 'os_export'

The 'os_export' RPC is used to export an OS to a compressed tarball.
The path to this tarball will be given to the metadata daemon, which
will then be used to serve this package to the instances via the
instance communication mechanism.
Signed-off-by: default avatarJose A. Lopes <>
Reviewed-by: default avatarHrvoje Ribicic <>
parent b8dd2853
......@@ -3876,6 +3876,55 @@ def ValidateOS(required, osname, checks, osparams, force_variant):
return True
def ExportOS(instance):
"""Creates a GZIPed tarball with an OS definition and environment.
The archive contains a file with the environment variables needed by
the OS scripts.
@type instance: L{objects.Instance}
@param instance: instance for which the OS definition is exported
@rtype: string
@return: filepath of the archive
assert instance
assert instance.os
temp_dir = tempfile.mkdtemp()
inst_os = OSFromDisk(instance.os)
result = utils.RunCmd(["ln", "-s", inst_os.path,
utils.PathJoin(temp_dir, "os")])
if result.failed:
_Fail("Failed to copy OS package '%s' to '%s': %s, output '%s'",
inst_os, temp_dir, result.fail_reason, result.output)
env = OSEnvironment(instance, inst_os)
with open(utils.PathJoin(temp_dir, "environment"), "w") as f:
for var in env:
f.write(var + "=" + env[var] + "\n")
(fd, os_package) = tempfile.mkstemp(suffix=".tgz")
result = utils.RunCmd(["tar", "--dereference", "-czv",
"-f", os_package,
"-C", temp_dir,
if result.failed:
_Fail("Failed to create OS archive '%s': %s, output '%s'",
os_package, result.fail_reason, result.output)
result = utils.RunCmd(["rm", "-rf", temp_dir])
if result.failed:
_Fail("Failed to remove copy of OS package '%s' in '%s': %s, output '%s'",
inst_os, temp_dir, result.fail_reason, result.output)
return os_package
def DemoteFromMC():
"""Demotes the current node from master candidate role.
......@@ -466,6 +466,9 @@ _OS_CALLS = [
("params", None, None),
("force_variant", None, None),
], None, None, "Run a validation routine for a given OS"),
("os_export", SINGLE, None, constants.RPC_TMO_FAST, [
("instance", ED_INST_DICT, None),
], None, None, "Export an OS for a given instance"),
......@@ -994,6 +994,14 @@ class NodeRequestHandler(http.server.HttpServerHandler):
required, name, checks, params, force_variant = params
return backend.ValidateOS(required, name, checks, params, force_variant)
def perspective_os_export(params):
"""Export an OS definition into an instance specific package.
instance = objects.Instance.FromDict(params[0])
return backend.ExportOS(instance)
# extstorage -----------------------
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment