From 7edc463782b5299ae4061a7ec2f0b71be39e1f55 Mon Sep 17 00:00:00 2001
From: Iustin Pop <iustin@google.com>
Date: Thu, 17 Sep 2009 13:07:35 +0200
Subject: [PATCH] =?UTF-8?q?Unify=20the=20=E2=80=9C--node=E2=80=9D=20(as=20?=
 =?UTF-8?q?list=20of=20nodes)=20option?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Signed-off-by: Iustin Pop <iustin@google.com>
Reviewed-by: Michael Hanselmann <hansmi@google.com>
---
 lib/cli.py          |  7 +++++++
 scripts/gnt-backup  |  7 +------
 scripts/gnt-cluster | 12 +++---------
 3 files changed, 11 insertions(+), 15 deletions(-)

diff --git a/lib/cli.py b/lib/cli.py
index bebe52e2d..f242a4ac1 100644
--- a/lib/cli.py
+++ b/lib/cli.py
@@ -61,6 +61,7 @@ __all__ = [
   "IGNORE_CONSIST_OPT",
   "FORCE_OPT",
   "NET_OPT",
+  "NODE_LIST_OPT",
   "NODE_PLACEMENT_OPT",
   "NOHDR_OPT",
   "NOIPCHECK_OPT",
@@ -580,6 +581,12 @@ NODE_PLACEMENT_OPT = cli_option("-n", "--node", dest="node",
                                 metavar="<pnode>[:<snode>]",
                                 completion_suggest=OPT_COMPL_INST_ADD_NODES)
 
+NODE_LIST_OPT = cli_option("-n", "--node", dest="nodes", default=[],
+                           action="append", metavar="<node>",
+                           help="Use only this node (can be used multiple"
+                           " times, if not given defaults to all nodes)",
+                           completion_suggest=OPT_COMPL_ONE_NODE)
+
 
 def _ParseArgs(argv, commands, aliases):
   """Parser for the command line arguments.
diff --git a/scripts/gnt-backup b/scripts/gnt-backup
index ecca74425..5f5bff993 100755
--- a/scripts/gnt-backup
+++ b/scripts/gnt-backup
@@ -233,12 +233,7 @@ import_opts = [
 
 commands = {
   'list': (PrintExportList, ARGS_NONE,
-           [DEBUG_OPT,
-            cli_option("--node", dest="nodes", default=[], action="append",
-                       help="List only backups stored on this node"
-                            " (can be used multiple times)",
-                       completion_suggest=OPT_COMPL_ONE_NODE),
-            ],
+           [DEBUG_OPT, NODE_LIST_OPT],
            "", "Lists instance exports available in the ganeti cluster"),
   'export': (ExportInstance, ARGS_ONE_INSTANCE,
              [DEBUG_OPT, FORCE_OPT,
diff --git a/scripts/gnt-cluster b/scripts/gnt-cluster
index 33ddd762f..f939e30cd 100755
--- a/scripts/gnt-cluster
+++ b/scripts/gnt-cluster
@@ -586,13 +586,6 @@ def WatcherOps(opts, args):
   return 0
 
 
-# this is an option common to more than one command, so we declare
-# it here and reuse it
-node_option = cli_option("-n", "--node", action="append", dest="nodes",
-                         help="Node to copy to (if not given, all nodes),"
-                              " can be given multiple times",
-                         metavar="<node>", default=[])
-
 commands = {
   'init': (InitCluster, [ArgHost(min=1, max=1)],
            [DEBUG_OPT,
@@ -688,10 +681,11 @@ commands = {
   'getmaster': (ShowClusterMaster, ARGS_NONE, [DEBUG_OPT],
                 "", "Shows the cluster master"),
   'copyfile': (ClusterCopyFile, [ArgFile(min=1, max=1)],
-               [DEBUG_OPT, node_option],
+               [DEBUG_OPT, NODE_LIST_OPT],
                "[-n node...] <filename>",
                "Copies a file to all (or only some) nodes"),
-  'command': (RunClusterCommand, [ArgCommand(min=1)], [DEBUG_OPT, node_option],
+  'command': (RunClusterCommand, [ArgCommand(min=1)],
+              [DEBUG_OPT, NODE_LIST_OPT],
               "[-n node...] <command>",
               "Runs a command on all (or only some) nodes"),
   'info': (ShowClusterConfig, ARGS_NONE, [DEBUG_OPT],
-- 
GitLab