merge r1542, r1543, r1573 from branches/ganeti/ganeti-1.2
authorAlexander Schreiber <als@google.com>
Tue, 2 Sep 2008 11:46:07 +0000 (11:46 +0000)
committerAlexander Schreiber <als@google.com>
Tue, 2 Sep 2008 11:46:07 +0000 (11:46 +0000)
Implement interactive instance OS reinstall.

Reviewed-by: ultrotter

man/gnt-instance.sgml
scripts/gnt-instance

index 8e904be..19e4bd0 100644 (file)
           <command>reinstall</command>
           <arg choice="opt">-o <replaceable>os-type</replaceable></arg>
           <arg choice="opt">-f <replaceable>force</replaceable></arg>
+          <arg>--select-os</arg>
           <arg choice="req"><replaceable>instance</replaceable></arg>
         </cmdsynopsis>
 
           <option>--os-type</option> is specified, the operating system is
           changed.
         </para>
+
+        <para>
+          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.
+        </para>
       </refsect3>
 
       <refsect3>
index 99d05eb..7ec6ed6 100755 (executable)
@@ -303,6 +303,34 @@ def ReinstallInstance(opts, args):
   """
   instance_name = args[0]
 
+  if opts.select_os is True:
+    op = opcodes.OpDiagnoseOS(output_fields=["name", "valid"], names=[])
+    result = SubmitOpCode(op)
+
+    if not result:
+      logger.ToStdout("Can't get the OS list")
+      return 1
+
+    logger.ToStdout("Available OS templates:")
+    number = 0
+    choices = []
+    for entry in result:
+      logger.ToStdout("%3s: %s" % (number, entry[0]))
+      choices.append(("%s" % number, entry[0], entry[0]))
+      number = number + 1
+
+    choices.append(('x', 'exit', 'Exit gnt-instance reinstall'))
+    selected = AskUser("Enter OS template name or number (or x to abort):",
+                       choices)
+
+    if selected == 'exit':
+      logger.ToStdout("User aborted reinstall, exiting")
+      return 1
+
+    os = selected
+  else:
+    os = opts.os
+
   if not opts.force:
     usertext = ("This will reinstall the instance %s and remove"
                 " all data. Continue?") % instance_name
@@ -310,7 +338,7 @@ def ReinstallInstance(opts, args):
       return 1
 
   op = opcodes.OpReinstallInstance(instance_name=instance_name,
-                                   os_type=opts.os)
+                                   os_type=os)
   SubmitOpCode(op)
 
   return 0
@@ -928,7 +956,12 @@ commands = {
            " ip, mac, bridge, sda_size, sdb_size, vcpus. The default field"
            " list is (in order): %s." % ", ".join(_LIST_DEF_FIELDS),
            ),
-  'reinstall': (ReinstallInstance, ARGS_ONE, [DEBUG_OPT, FORCE_OPT, os_opt],
+  'reinstall': (ReinstallInstance, ARGS_ONE,
+                [DEBUG_OPT, FORCE_OPT, os_opt,
+                 make_option("--select-os", dest="select_os",
+                             action="store_true", default=False,
+                             help="Interactive OS reinstall, lists available"
+                             " OS templates for selection")],
                 "[-f] <instance>", "Reinstall a stopped instance"),
   'remove': (RemoveInstance, ARGS_ONE,
              [DEBUG_OPT, FORCE_OPT,