gnt-cluster command: Add option to prepend node name to output
authorMichael Hanselmann <hansmi@google.com>
Fri, 20 Jan 2012 18:30:52 +0000 (19:30 +0100)
committerMichael Hanselmann <hansmi@google.com>
Mon, 23 Jan 2012 11:21:12 +0000 (12:21 +0100)
With this patch a new option (“-M”, like dsh) is added to “gnt-cluster
command” to prepend the node name to all output lines.

$ gnt-cluster command -M uname -a | grep Linux
node18.example.com: Linux node18.example.com [...]
node19.example.com: Linux node19.example.com [...]

Signed-off-by: Michael Hanselmann <hansmi@google.com>
Reviewed-by: Iustin Pop <iustin@google.com>

lib/client/gnt_cluster.py
man/gnt-cluster.rst

index f462504..4350f16 100644 (file)
@@ -52,6 +52,10 @@ GROUPS_OPT = cli_option("--groups", default=False,
                     action="store_true", dest="groups",
                     help="Arguments are node groups instead of nodes")
 
+SHOW_MACHINE_OPT = cli_option("-M", "--show-machine-names", default=False,
+                              action="store_true",
+                              help="Show machine name for every line in output")
+
 _EPO_PING_INTERVAL = 30 # 30 seconds between pings
 _EPO_PING_TIMEOUT = 1 # 1 second
 _EPO_REACHABLE_TIMEOUT = 15 * 60 # 15 minutes
@@ -529,8 +533,12 @@ def RunClusterCommand(opts, args):
   for name in nodes:
     result = srun.Run(name, "root", command)
     ToStdout("------------------------------------------------")
-    ToStdout("node: %s", name)
-    ToStdout("%s", result.output)
+    if opts.show_machine_names:
+      for line in result.output.splitlines():
+        ToStdout("%s: %s", name, line)
+    else:
+      ToStdout("node: %s", name)
+      ToStdout("%s", result.output)
     ToStdout("return code = %s", result.exit_code)
 
   return 0
@@ -1500,7 +1508,7 @@ commands = {
     "[-n node...] <filename>", "Copies a file to all (or only some) nodes"),
   "command": (
     RunClusterCommand, [ArgCommand(min=1)],
-    [NODE_LIST_OPT, NODEGROUP_OPT],
+    [NODE_LIST_OPT, NODEGROUP_OPT, SHOW_MACHINE_OPT],
     "[-n node...] <command>", "Runs a command on all (or only some) nodes"),
   "info": (
     ShowClusterConfig, ARGS_NONE, [ROMAN_OPT],
index 34d517f..eaa41a8 100644 (file)
@@ -44,7 +44,7 @@ interpreted as stdin.
 COMMAND
 ~~~~~~~
 
-**command** [-n *node*] [-g *group*] {*command*}
+**command** [-n *node*] [-g *group*] [-M] {*command*}
 
 Executes a command on all nodes. If the option ``-n`` is not given,
 the command will be executed on all nodes, otherwise it will be
@@ -58,6 +58,9 @@ group, e.g.::
 
     # gnt-cluster command -g default date
 
+The ``-M`` option can be used to prepend the node name to all output
+lines.
+
 The command is executed serially on the selected nodes. If the
 master node is present in the list, the command will be executed
 last on the master. Regarding the other nodes, the execution order