Commit 8d8c4eff authored by Michael Hanselmann's avatar Michael Hanselmann
Browse files

gnt-instance reinstall: Allow overriding OS parameters

This allows OS installation scripts to make use of special parameters,
e.g. to retain some data on reinstallation.

The RAPI resource is not updated as it takes all parameters via the
query string and encoding arbitrary data in a query string is tricky.
The resource will need to be changed to use the POST body instead.
Signed-off-by: default avatarMichael Hanselmann <>
Reviewed-by: default avatarIustin Pop <>
parent b44bd844
......@@ -4672,6 +4672,7 @@ class LUReinstallInstance(LogicalUnit):
("os_type", None, ht.TMaybeString),
("force_variant", False, ht.TBool),
("osparams", None, ht.TOr(ht.TDict, ht.TNone)),
REQ_BGL = False
......@@ -4709,6 +4710,18 @@ class LUReinstallInstance(LogicalUnit):
# OS verification
pnode = _ExpandNodeName(self.cfg, instance.primary_node)
_CheckNodeHasOS(self, pnode, self.op.os_type, self.op.force_variant)
instance_os = self.op.os_name
instance_os = instance.os
nodelist = list(instance.all_nodes)
if self.op.osparams:
i_osdict = _GetUpdatedParams(instance.osparams, self.op.osparams)
_CheckOSParams(self, True, nodelist, instance_os, i_osdict)
self.os_inst = i_osdict # the new dict (without defaults)
self.os_inst = None
self.instance = instance
......@@ -4721,6 +4734,7 @@ class LUReinstallInstance(LogicalUnit):
if self.op.os_type is not None:
feedback_fn("Changing OS to '%s'..." % self.op.os_type)
inst.os = self.op.os_type
# Write to configuration
self.cfg.Update(inst, feedback_fn)
_StartInstanceDisks(self, inst, None)
......@@ -4728,7 +4742,8 @@ class LUReinstallInstance(LogicalUnit):
feedback_fn("Running the instance OS create scripts...")
# FIXME: pass debug option from opcode to backend
result = self.rpc.call_instance_os_add(inst.primary_node, inst, True,
result.Raise("Could not install OS for instance %s on node %s" %
(, inst.primary_node))
......@@ -492,7 +492,7 @@ class OpReinstallInstance(OpCode):
"""Reinstall an instance's OS."""
OP_DSC_FIELD = "instance_name"
__slots__ = ["instance_name", "os_type", "force_variant"]
__slots__ = ["instance_name", "os_type", "force_variant", "osparams"]
class OpRemoveInstance(OpCode):
......@@ -433,7 +433,7 @@ class RpcRunner(object):
@type bep: dict or None
@param bep: a dictionary with overridden backend parameters
@type osp: dict or None
@param osp: a dictionary with overriden os parameters
@param osp: a dictionary with overridden os parameters
@rtype: dict
@return: the instance dict, with the hvparams filled with the
cluster defaults
......@@ -752,14 +752,15 @@ class RpcRunner(object):
def call_instance_os_add(self, node, inst, reinstall, debug):
def call_instance_os_add(self, node, inst, reinstall, debug, osparams=None):
"""Installs an OS on the given instance.
This is a single-node call.
return self._SingleNodeCall(node, "instance_os_add",
[self._InstDict(inst), reinstall, debug])
[self._InstDict(inst, osp=osparams),
reinstall, debug])
def call_instance_run_rename(self, node, inst, old_name, debug):
......@@ -1651,6 +1651,8 @@ instance5: 11225
<arg choice="opt">-O <replaceable>OS_PARAMETERS</replaceable></arg>
<arg choice="opt" rep="repeat"><replaceable>instance</replaceable></arg>
......@@ -1665,7 +1667,8 @@ instance5: 11225
The <option>--select-os</option> option switches to an
interactive OS reinstall. The user is prompted to select the OS
template from the list of available OS templates.
template from the list of available OS templates. OS parameters
can be overridden using <option>-O</option>.
......@@ -1687,7 +1690,6 @@ instance5: 11225
<command>gnt-job info</command>.
......@@ -572,7 +572,8 @@ def ReinstallInstance(opts, args):
for instance_name in inames:
op = opcodes.OpReinstallInstance(instance_name=instance_name,
jex.QueueJob(instance_name, op)
jex.WaitOrShow(not opts.submit_only)
......@@ -1459,7 +1460,7 @@ commands = {
[FORCE_OPT, OS_OPT, FORCE_VARIANT_OPT, m_force_multi, m_node_opt,
m_pri_node_opt, m_sec_node_opt, m_clust_opt, m_inst_opt, m_node_tags_opt,
m_pri_node_tags_opt, m_sec_node_tags_opt, m_inst_tags_opt, SELECT_OS_OPT,
"[-f] <instance>", "Reinstall a stopped instance"),
'remove': (
RemoveInstance, ARGS_ONE_INSTANCE,
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