diff --git a/daemons/ganeti-noded b/daemons/ganeti-noded index 3a2b4a092d5ae99cb4a35d0b8e917d6fffa5cdee..ac90090845ac366cd0de093a78c7c1fa3c2d0e12 100755 --- a/daemons/ganeti-noded +++ b/daemons/ganeti-noded @@ -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): diff --git a/lib/backend.py b/lib/backend.py index 18d439e869c08ff0f27edff13218e99dc81d7a6d..183286b36aea2b2e39ce567b30399cf5c707e44c 100644 --- a/lib/backend.py +++ b/lib/backend.py @@ -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())) diff --git a/lib/cmdlib.py b/lib/cmdlib.py index ab404492995c6093be89fc392b57bfbb17fd2f4f..c9eae6859ae3ad7ed386b5cb7e61b2e809ecfff0 100644 --- a/lib/cmdlib.py +++ b/lib/cmdlib.py @@ -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" diff --git a/lib/rpc.py b/lib/rpc.py index 70dd3128ac955de41256b31a2d64c26631e3a9cc..599de0ac966726202663a0c4008cabeeb4aba872 100644 --- a/lib/rpc.py +++ b/lib/rpc.py @@ -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. diff --git a/man/ganeti-os-interface.sgml b/man/ganeti-os-interface.sgml index 5a127e4986d0ab9d1aace9e4200ac08e44a12880..c61ea5ab5ae0f8b5c45f68d56d243215afcd640f 100644 --- a/man/ganeti-os-interface.sgml +++ b/man/ganeti-os-interface.sgml @@ -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>