Add --print parameter to “gnt-instance console”
authorMichael Hanselmann <hansmi@google.com>
Thu, 27 Mar 2008 14:39:47 +0000 (14:39 +0000)
committerMichael Hanselmann <hansmi@google.com>
Thu, 27 Mar 2008 14:39:47 +0000 (14:39 +0000)
This enables us to run automated tests on “gnt-instance console”, at least
to some degree.

Reviewed-by: iustinp

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

index ace4a9e..708516f 100644 (file)
         <title>CONSOLE</title>
         <cmdsynopsis>
           <command>console</command>
+          <arg choice="opt">--show-cmd</arg>
           <arg choice="req"><replaceable>instance</replaceable></arg>
         </cmdsynopsis>
 
         <para>
           Connects to the console of the given instance. If the instance
-          is not up, an error is returned.
+          is not up, an error is returned. Use the <option>--show-cmd</option>
+          option to display the command instead of executing it.
         </para>
 
         <para>
index fbd1164..e93e564 100755 (executable)
@@ -506,14 +506,18 @@ def ConnectToInstanceConsole(opts, args):
 
   op = opcodes.OpConnectConsole(instance_name=instance_name)
   cmd = SubmitOpCode(op)
-  # drop lock and exec so other commands can run while we have console
-  utils.Unlock("cmd")
-  try:
-    os.execvp(cmd[0], cmd)
-  finally:
-    sys.stderr.write("Can't run console command %s with arguments:\n'%s'" %
-                     (cmd, " ".join(argv)))
-    os._exit(1)
+
+  if opts.show_command:
+    print utils.ShellQuoteArgs(cmd)
+  else:
+    # drop lock and exec so other commands can run while we have console
+    utils.Unlock("cmd")
+    try:
+      os.execvp(cmd[0], cmd)
+    finally:
+      sys.stderr.write("Can't run console command %s with arguments:\n'%s'" %
+                       (cmd, " ".join(argv)))
+      os._exit(1)
 
 
 def _FormatBlockDevInfo(buf, dev, indent_level):
@@ -762,8 +766,12 @@ commands = {
   'add': (AddInstance, ARGS_ONE, add_opts,
           "[opts...] <name>",
           "Creates and adds a new instance to the cluster"),
-  'console': (ConnectToInstanceConsole, ARGS_ONE, [DEBUG_OPT],
-              "<instance>",
+  'console': (ConnectToInstanceConsole, ARGS_ONE,
+              [DEBUG_OPT,
+               make_option("--show-cmd", dest="show_command",
+                           action="store_true", default=False,
+                           help=("Show command instead of executing it"))],
+              "[--show-cmd] <instance>",
               "Opens a console on the specified instance"),
   'failover': (FailoverInstance, ARGS_ONE,
                [DEBUG_OPT, FORCE_OPT,