From 579d4337d514981ce7ebc56892e8365fa54b4b5d Mon Sep 17 00:00:00 2001
From: Alexander Schreiber <als@google.com>
Date: Thu, 18 Oct 2007 10:26:34 +0000
Subject: [PATCH] Patch series for reboot feature, part 3

This patch series implements the reboot command for gnt-instance. It
supports three types of reboot: soft (hypervisor reboot), hard (instance
config rebuild and reboot) and full (full instance shutdown and startup
again).

This patch contains the gnt-instance script and the man page for it.

Reviewed-by: iustinp
---
 man/gnt-instance.sgml | 66 +++++++++++++++++++++++++++++++++++++++++++
 scripts/gnt-instance  | 39 +++++++++++++++++++++++++
 2 files changed, 105 insertions(+)

diff --git a/man/gnt-instance.sgml b/man/gnt-instance.sgml
index 597d8c3b5..692ac83a4 100644
--- a/man/gnt-instance.sgml
+++ b/man/gnt-instance.sgml
@@ -583,6 +583,72 @@
         </para>
       </refsect3>
 
+      <refsect3>
+        <title>REBOOT</title>
+
+        <cmdsynopsis>
+          <command>reboot</command>
+          <sbr>
+          <arg>--extra=<replaceable>PARAMS</replaceable></arg>
+          <sbr>
+          <arg>--type=<replaceable>REBOOT-TYPE</replaceable></arg>
+          <sbr>
+          <arg>--ignore-secondaries</arg>
+          <sbr>
+          <arg>--force-multiple</arg>
+          <sbr>
+          <group choice="opt">
+            <arg>--instance</arg>
+            <arg>--node</arg>
+            <arg>--primary</arg>
+            <arg>--secondary</arg>
+            <arg>--all</arg>
+          </group>
+          <sbr>
+
+          <arg choice="opt"
+          rep="repeat"><replaceable>name</replaceable></arg>
+        </cmdsynopsis>
+
+        <para>
+          Reboots one or more instances. The type of reboot depends on
+          the value of <option>--type</option>. A soft reboot does a
+          hypervisor reboot, a hard reboot does a instance stop,
+          recreates the hypervisor config for the instance and
+          starts the instance. A full reboot does the equivalent
+          of <command>gnt-instance shutdown &amp;&amp; gnt-instance
+          startup</command>. The default is soft reboot.
+        </para>
+
+        <para>
+          For the hard reboot the option
+          <option>--ignore-secondaries</option> ignores errors for the
+          secondary node while re-assembling the instance disks.
+        </para>
+
+        <para>
+          The <option>--instance</option>, <option>--node</option>,
+          <option>--primary</option>, <option>--secondary</option> and
+          <option>--all</option> options are similar as for the
+          <command>startup</command> command and they influence the
+          actual instances being rebooted.
+        </para>
+        
+        <para>
+          Use the <option>--force-multiple</option> to keep
+          gnt-instance from asking for confirmation when more than one
+          instance is affected.
+        </para>
+
+        <para>
+          Example:
+          <screen>
+# gnt-instance reboot instance1.example.com
+# gnt-instance reboot --type=full instance1.example.com
+          </screen>
+        </para>
+      </refsect3>
+
       <refsect3>
         <title>CONSOLE</title>
         <cmdsynopsis>
diff --git a/scripts/gnt-instance b/scripts/gnt-instance
index e50839b4b..fe5a9536e 100755
--- a/scripts/gnt-instance
+++ b/scripts/gnt-instance
@@ -346,6 +346,28 @@ def StartupInstance(opts, args):
     SubmitOpCode(op)
   return 0
 
+def RebootInstance(opts, args):
+  """Reboot an instance
+
+  Args:
+    opts - class with options as members
+    args - list containing a single element, the instance name
+
+  """
+  if opts.multi_mode is None:
+    opts.multi_mode = _SHUTDOWN_INSTANCES
+  inames = _ExpandMultiNames(opts.multi_mode, args)
+  multi_on = opts.multi_mode != _SHUTDOWN_INSTANCES or len(inames) > 1
+  if not (opts.force_multi or not multi_on
+          or _ConfirmOperation(inames, "reboot")):
+    return 1
+  for name in inames:
+    op = opcodes.OpRebootInstance(instance_name=name,
+                                  reboot_type=opts.reboot_type,
+                                  ignore_secondaries=opts.ignore_secondaries)
+
+    SubmitOpCode(op)
+  return 0
 
 def ShutdownInstance(opts, args):
   """Shutdown an instance.
@@ -757,6 +779,23 @@ commands = {
                m_clust_opt, m_inst_opt,
                ],
             "<instance>", "Starts an instance"),
+
+  'reboot': (RebootInstance, ARGS_ANY,
+              [DEBUG_OPT, m_force_multi,
+               make_option("-e", "--extra", dest="extra_args",
+                           help="Extra arguments for the instance's kernel",
+                           default=None, type="string", metavar="<PARAMS>"),
+               make_option("-t", "--type", dest="reboot_type",
+                           help="Type of reboot: soft/hard/full",
+                           default=constants.INSTANCE_REBOOT_SOFT,
+                           type="string", metavar="<REBOOT>"),
+               make_option("--ignore-secondaries", dest="ignore_secondaries",
+                           default=False, action="store_true",
+                           help="Ignore errors from secondaries"),
+               m_node_opt, m_pri_node_opt, m_sec_node_opt,
+               m_clust_opt, m_inst_opt,
+               ],
+            "<instance>", "Reboots an instance"),
   'activate-disks': (ActivateDisks, ARGS_ONE, [DEBUG_OPT],
                      "<instance>",
                      "Activate an instance's disks"),
-- 
GitLab