Commit d0834de3 authored by Michael Hanselmann's avatar Michael Hanselmann
Browse files

- Implement “gnt-instance reinstall --os-type=…”

- Add the command to gnt-instance.sgml

Reviewed-by: iustinp
parent 59322403
......@@ -1887,6 +1887,20 @@ class LUReinstallInstance(LogicalUnit):
raise errors.OpPrereqError, ("Instance '%s' is running on the node %s" %
(self.op.instance_name,
instance.primary_node))
self.op.os_type = getattr(self.op, "os_type", None)
if self.op.os_type is not None:
# OS verification
pnode = self.cfg.GetNodeInfo(
self.cfg.ExpandNodeName(instance.primary_node))
if pnode is None:
raise errors.OpPrereqError, ("Primary node '%s' is unknown" %
self.op.pnode)
os_obj = rpc.call_os_get([pnode.name], self.op.os_type)[pnode.name]
if not isinstance(os_obj, objects.OS):
raise errors.OpPrereqError, ("OS '%s' not in supported OS list for"
" primary node" % self.op.os_type)
self.instance = instance
def Exec(self, feedback_fn):
......@@ -1895,6 +1909,11 @@ class LUReinstallInstance(LogicalUnit):
"""
inst = self.instance
if self.op.os_type is not None:
feedback_fn("Changing OS to '%s'..." % self.op.os_type)
inst.os = self.op.os_type
self.cfg.AddInstance(inst)
_StartInstanceDisks(self.cfg, inst, None)
try:
feedback_fn("Running the instance OS create scripts...")
......
......@@ -142,7 +142,7 @@ class OpCreateInstance(OpCode):
class OpReinstallInstance(OpCode):
"""Reinstall an instance."""
OP_ID = "OP_INSTANCE_REINSTALL"
__slots__ = ["instance_name"]
__slots__ = ["instance_name", "os_type"]
class OpRemoveInstance(OpCode):
......
......@@ -377,6 +377,24 @@
</para>
</refsect3>
<refsect3>
<title>REINSTALL</title>
<cmdsynopsis>
<command>reinstall</command>
<arg choice="opt">-o <replaceable>os-type</replaceable></arg>
<arg choice="opt">-f <replaceable>force</replaceable></arg>
<arg choice="req"><replaceable>instance</replaceable></arg>
</cmdsynopsis>
<para>
Reinstalls the operating system on the given instance. The instance
must be stopped when running this command. If the
<option>--os-type</option> is specified, the operating system is
changed.
</para>
</refsect3>
</refsect2>
<refsect2>
......
......@@ -111,7 +111,8 @@ def ReinstallInstance(opts, args):
if not opts._ask_user(usertext):
return 1
op = opcodes.OpReinstallInstance(instance_name=instance_name)
op = opcodes.OpReinstallInstance(instance_name=instance_name,
os_type=opts.os)
SubmitOpCode(op)
return 0
......@@ -421,6 +422,9 @@ def SetInstanceParms(opts, args):
node_opt = make_option("-n", "--node", dest="node", help="Target node",
metavar="<node>")
os_opt = cli_option("-o", "--os-type", dest="os", help="What OS to run",
metavar="<os>"),
# this is defined separately due to readability only
add_opts = [
DEBUG_OPT,
......@@ -429,8 +433,7 @@ add_opts = [
default=20 * 1024, type="unit", metavar="<size>"),
cli_option("--swap-size", dest="swap", help="Swap size",
default=4 * 1024, type="unit", metavar="<size>"),
cli_option("-o", "--os-type", dest="os", help="What OS to run",
metavar="<os>"),
os_opt,
cli_option("-m", "--memory", dest="mem", help="Memory size",
default=128, type="unit", metavar="<mem>"),
make_option("-p", "--cpu", dest="vcpus", help="Number of virtual CPUs",
......@@ -480,7 +483,7 @@ commands = {
'list': (ListInstances, ARGS_NONE,
[DEBUG_OPT, NOHDR_OPT, SEP_OPT, USEUNITS_OPT, FIELDS_OPT],
"", "Lists the instances and their status"),
'reinstall': (ReinstallInstance, ARGS_ONE, [DEBUG_OPT, FORCE_OPT],
'reinstall': (ReinstallInstance, ARGS_ONE, [DEBUG_OPT, FORCE_OPT, os_opt],
"[-f] <instance>", "Reinstall the instance"),
'remove': (RemoveInstance, ARGS_ONE, [DEBUG_OPT, FORCE_OPT],
"[-f] <instance>", "Shuts down the instance and removes it"),
......
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