From 51c6e7b5cd995818b6c6c13dd035af3c309c5309 Mon Sep 17 00:00:00 2001 From: Michael Hanselmann <hansmi@google.com> Date: Thu, 27 Mar 2008 14:39:47 +0000 Subject: [PATCH] =?UTF-8?q?Add=20--print=20parameter=20to=20=E2=80=9Cgnt-i?= =?UTF-8?q?nstance=20console=E2=80=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This enables us to run automated tests on βgnt-instance consoleβ, at least to some degree. Reviewed-by: iustinp --- man/gnt-instance.sgml | 4 +++- scripts/gnt-instance | 28 ++++++++++++++++++---------- 2 files changed, 21 insertions(+), 11 deletions(-) diff --git a/man/gnt-instance.sgml b/man/gnt-instance.sgml index ace4a9e8c..708516ff4 100644 --- a/man/gnt-instance.sgml +++ b/man/gnt-instance.sgml @@ -797,12 +797,14 @@ <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> diff --git a/scripts/gnt-instance b/scripts/gnt-instance index fbd116458..e93e56467 100755 --- a/scripts/gnt-instance +++ b/scripts/gnt-instance @@ -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, -- GitLab