From 087ed2edee08da7bd3c4872cabde13c57585ca5a Mon Sep 17 00:00:00 2001
From: Iustin Pop <iustin@google.com>
Date: Thu, 17 Sep 2009 11:21:31 +0200
Subject: [PATCH] =?UTF-8?q?Unify=20the=20=E2=80=9C--backend-parameters?=
 =?UTF-8?q?=E2=80=9D=20option?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

This is not straight-forward. First, gnt-cluster had
β€œ--backend-parameters” wheres the rest of the script had just
β€œ--backend”. I settled on the full form, since one can always abbreviate
options, but not vice-versa.

Second, the help in some cases was different, e.g. start instance
hadΒ β€œTemporary backend parameters” and modify had β€œChange backend
parameters”. I think this kind of distinctions are better served in the
man page. Alternatively, if we could copy options easily, one could
re-instantiate them with a changed help line.

Signed-off-by: Iustin Pop <iustin@google.com>
Reviewed-by: Guido Trotter <ultrotter@google.com>
---
 lib/cli.py           |  5 +++++
 scripts/gnt-backup   |  4 +---
 scripts/gnt-cluster  |  8 ++------
 scripts/gnt-instance | 12 +++---------
 4 files changed, 11 insertions(+), 18 deletions(-)

diff --git a/lib/cli.py b/lib/cli.py
index dbea1d7a6..5898d06a8 100644
--- a/lib/cli.py
+++ b/lib/cli.py
@@ -44,6 +44,7 @@ from optparse import (OptionParser, TitledHelpFormatter,
 
 __all__ = [
   # Command line options
+  "BACKEND_OPT",
   "CONFIRM_OPT",
   "DEBUG_OPT",
   "DEBUG_SIMERR_OPT",
@@ -511,6 +512,10 @@ OS_OPT = cli_option("-o", "--os-type", dest="os", help="What OS to run",
                     metavar="<os>",
                     completion_suggest=OPT_COMPL_ONE_OS)
 
+BACKEND_OPT = cli_option("-B", "--backend-parameters", dest="beparams",
+                         type="keyval", default={},
+                         help="Backend parameters")
+
 
 def _ParseArgs(argv, commands, aliases):
   """Parser for the command line arguments.
diff --git a/scripts/gnt-backup b/scripts/gnt-backup
index 8985c8a7f..0e404fa37 100755
--- a/scripts/gnt-backup
+++ b/scripts/gnt-backup
@@ -215,9 +215,7 @@ import_opts = [
              help="Target node and optional secondary node",
              metavar="<pnode>[:<snode>]",
              completion_suggest=OPT_COMPL_INST_ADD_NODES),
-  cli_option("-B", "--backend", dest="beparams",
-             type="keyval", default={},
-             help="Backend parameters"),
+  BACKEND_OPT,
   DISK_TEMPLATE_OPT,
   cli_option("--disk", help="Disk information",
              default=[], dest="disks",
diff --git a/scripts/gnt-cluster b/scripts/gnt-cluster
index fb34cca9a..eeea8eebd 100755
--- a/scripts/gnt-cluster
+++ b/scripts/gnt-cluster
@@ -641,9 +641,7 @@ commands = {
                        default=[],
                        action="append",
                        type="identkeyval"),
-            cli_option("-B", "--backend-parameters", dest="beparams",
-                       type="keyval", default={},
-                       help="Backend parameters"),
+            BACKEND_OPT,
             cli_option("-N", "--nic-parameters", dest="nicparams",
                        type="keyval", default={},
                        help="NIC parameters"),
@@ -743,9 +741,7 @@ commands = {
                          default=[],
                          action="append",
                          type="identkeyval"),
-              cli_option("-B", "--backend-parameters", dest="beparams",
-                         type="keyval", default={},
-                         help="Backend parameters"),
+              BACKEND_OPT,
               cli_option("-N", "--nic-parameters", dest="nicparams",
                          type="keyval", default={},
                          help="NIC parameters"),
diff --git a/scripts/gnt-instance b/scripts/gnt-instance
index d1c2b31a6..58a875069 100755
--- a/scripts/gnt-instance
+++ b/scripts/gnt-instance
@@ -1368,9 +1368,7 @@ add_opts = [
              metavar="<pnode>[:<snode>]",
              completion_suggest=OPT_COMPL_INST_ADD_NODES),
   OS_OPT,
-  cli_option("-B", "--backend", dest="beparams",
-             type="keyval", default={},
-             help="Backend parameters"),
+  BACKEND_OPT,
   DISK_TEMPLATE_OPT,
   cli_option("-s", "--os-size", dest="sd_size", help="Disk size for a"
              " single-disk configuration, when not using the --disk option,"
@@ -1545,9 +1543,7 @@ commands = {
               cli_option("-H", "--hypervisor", type="keyval",
                          default={}, dest="hypervisor",
                          help="Change hypervisor parameters"),
-              cli_option("-B", "--backend", type="keyval",
-                         default={}, dest="beparams",
-                         help="Change backend parameters"),
+              BACKEND_OPT,
               cli_option("--disk", help="Disk changes",
                          default=[], dest="disks",
                          action="append",
@@ -1573,9 +1569,7 @@ commands = {
                cli_option("-H", "--hypervisor", type="keyval",
                           default={}, dest="hvparams",
                           help="Temporary hypervisor parameters"),
-               cli_option("-B", "--backend", type="keyval",
-                          default={}, dest="beparams",
-                          help="Temporary backend parameters"),
+               BACKEND_OPT,
                ],
               "<instance>", "Starts an instance"),
   'reboot': (RebootInstance, [ArgInstance(min=1)],
-- 
GitLab