Commit e557bae9 authored by Guido Trotter's avatar Guido Trotter
Browse files

Inform the OS create script of reinstalls



Sometimes reinstalls are slightly different than new installs. For
example certain partitions may need to be preserved accross reinstalls.
In order to do that on a per-os basis we pass in the INSTANCE_REINSTALL
variable to inform the create script about when a reinstall is
happening.
Signed-off-by: default avatarGuido Trotter <ultrotter@google.com>
Reviewed-by: default avatarIustin Pop <iustin@google.com>
parent 82a1c938
......@@ -365,7 +365,8 @@ class NodeHttpServer(http.server.HttpServer):
"""
inst_s = params[0]
inst = objects.Instance.FromDict(inst_s)
return backend.InstanceOsAdd(inst)
reinstall = params[1]
return backend.InstanceOsAdd(inst, reinstall)
@staticmethod
def perspective_instance_run_rename(params):
......
......@@ -673,11 +673,13 @@ def GetAllInstancesInfo(hypervisor_list):
return output
def InstanceOsAdd(instance):
def InstanceOsAdd(instance, reinstall):
"""Add an OS to an instance.
@type instance: L{objects.Instance}
@param instance: Instance whose OS is to be installed
@type reinstall: boolean
@param reinstall: whether this is an instance reinstall
@rtype: boolean
@return: the success of the operation
......@@ -693,6 +695,8 @@ def InstanceOsAdd(instance):
(os_name, os_dir, os_err))
create_env = OSEnvironment(instance)
if reinstall:
create_env['INSTANCE_REINSTALL'] = "1"
logfile = "%s/add-%s-%s-%d.log" % (constants.LOG_OS_DIR, instance.os,
instance.name, int(time.time()))
......
......@@ -2995,7 +2995,7 @@ class LUReinstallInstance(LogicalUnit):
_StartInstanceDisks(self, inst, None)
try:
feedback_fn("Running the instance OS create scripts...")
result = self.rpc.call_instance_os_add(inst.primary_node, inst)
result = self.rpc.call_instance_os_add(inst.primary_node, inst, True)
msg = result.RemoteFailMsg()
if msg:
raise errors.OpExecError("Could not install OS for instance %s"
......@@ -4763,7 +4763,7 @@ class LUCreateInstance(LogicalUnit):
if iobj.disk_template != constants.DT_DISKLESS:
if self.op.mode == constants.INSTANCE_CREATE:
feedback_fn("* running the instance OS create scripts...")
result = self.rpc.call_instance_os_add(pnode_name, iobj)
result = self.rpc.call_instance_os_add(pnode_name, iobj, False)
msg = result.RemoteFailMsg()
if msg:
raise errors.OpExecError("Could not add os for instance %s"
......
......@@ -524,14 +524,14 @@ class RpcRunner(object):
return self._SingleNodeCall(node, "instance_reboot",
[self._InstDict(instance), reboot_type])
def call_instance_os_add(self, node, inst):
def call_instance_os_add(self, node, inst, reinstall):
"""Installs an OS on the given instance.
This is a single-node call.
"""
return self._SingleNodeCall(node, "instance_os_add",
[self._InstDict(inst)])
[self._InstDict(inst), reinstall])
def call_instance_run_rename(self, node, inst, old_name):
"""Run the OS rename script for an instance.
......
......@@ -215,6 +215,11 @@
according to this name. It can configure the IP statically or
not, depending on the deployment environment.</para>
<para>The <envar>INSTANCE_REINSTALL</envar> variable is set to '1' when
this create request is reinstalling and existing instance, rather than
creating one anew. This can be used, for example, to preserve some
data in the old instance in an os-specific way.</para>
</refsect2>
<refsect2>
......
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