From d0834de3558c94c30618e74fc7682b2c8fc668a3 Mon Sep 17 00:00:00 2001 From: Michael Hanselmann <hansmi@google.com> Date: Fri, 27 Jul 2007 09:05:03 +0000 Subject: [PATCH] =?UTF-8?q?-=20Implement=20=E2=80=9Cgnt-instance=20reinsta?= =?UTF-8?q?ll=20--os-type=3D=E2=80=A6=E2=80=9D=20-=20Add=20the=20command?= =?UTF-8?q?=20to=20gnt-instance.sgml?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Reviewed-by: iustinp --- lib/cmdlib.py | 19 +++++++++++++++++++ lib/opcodes.py | 2 +- man/gnt-instance.sgml | 18 ++++++++++++++++++ scripts/gnt-instance | 11 +++++++---- 4 files changed, 45 insertions(+), 5 deletions(-) diff --git a/lib/cmdlib.py b/lib/cmdlib.py index 366e646bf..f5a26f386 100644 --- a/lib/cmdlib.py +++ b/lib/cmdlib.py @@ -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...") diff --git a/lib/opcodes.py b/lib/opcodes.py index dd1d7a8d8..106839ae0 100644 --- a/lib/opcodes.py +++ b/lib/opcodes.py @@ -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): diff --git a/man/gnt-instance.sgml b/man/gnt-instance.sgml index e5895d70c..c3f17ee4a 100644 --- a/man/gnt-instance.sgml +++ b/man/gnt-instance.sgml @@ -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> diff --git a/scripts/gnt-instance b/scripts/gnt-instance index e9dbc522e..867e0d573 100755 --- a/scripts/gnt-instance +++ b/scripts/gnt-instance @@ -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"), -- GitLab