From eb28ecf69da8f2307896407e50df76e1c4a1e6e6 Mon Sep 17 00:00:00 2001
From: Guido Trotter <ultrotter@google.com>
Date: Fri, 29 Oct 2010 12:43:13 +0100
Subject: [PATCH] Merge the common options between import and add

The "I always wanted to do this" commit.

Signed-off-by: Guido Trotter <ultrotter@google.com>
Reviewed-by: Michael Hanselmann <hansmi@google.com>
---
 lib/cli.py                 | 24 ++++++++++++++++++++++++
 lib/client/__init__.py     |  3 +--
 lib/client/gnt_backup.py   | 20 +-------------------
 lib/client/gnt_instance.py | 20 +-------------------
 4 files changed, 27 insertions(+), 40 deletions(-)

diff --git a/lib/cli.py b/lib/cli.py
index eceebe098..ad4e4e7b2 100644
--- a/lib/cli.py
+++ b/lib/cli.py
@@ -207,6 +207,7 @@ __all__ = [
   "SplitNodeOption",
   "CalculateOSNames",
   "ParseFields",
+  "COMMON_CREATE_OPTS",
   ]
 
 NO_PREFIX = "no_"
@@ -1103,6 +1104,29 @@ PREALLOC_WIPE_DISKS_OPT = cli_option("--prealloc-wipe-disks", default=None,
 #: Options provided by all commands
 COMMON_OPTS = [DEBUG_OPT]
 
+# common options for creating instances. add and import then add their own
+# specific ones.
+COMMON_CREATE_OPTS = [
+  BACKEND_OPT,
+  DISK_OPT,
+  DISK_TEMPLATE_OPT,
+  FILESTORE_DIR_OPT,
+  FILESTORE_DRIVER_OPT,
+  HYPERVISOR_OPT,
+  IALLOCATOR_OPT,
+  NET_OPT,
+  NODE_PLACEMENT_OPT,
+  NOIPCHECK_OPT,
+  NONAMECHECK_OPT,
+  NONICS_OPT,
+  NWSYNC_OPT,
+  OSPARAMS_OPT,
+  OS_SIZE_OPT,
+  SUBMIT_OPT,
+  DRY_RUN_OPT,
+  PRIORITY_OPT,
+  ]
+
 
 def _ParseArgs(argv, commands, aliases):
   """Parser for the command line arguments.
diff --git a/lib/client/__init__.py b/lib/client/__init__.py
index aee6aa0c4..308b5fece 100644
--- a/lib/client/__init__.py
+++ b/lib/client/__init__.py
@@ -18,7 +18,6 @@
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
 # 02110-1301, USA.
 
-
-"""Empty file for package definition.
+"""Common command line client code.
 
 """
diff --git a/lib/client/gnt_backup.py b/lib/client/gnt_backup.py
index 3d13d406c..c154ae8fb 100644
--- a/lib/client/gnt_backup.py
+++ b/lib/client/gnt_backup.py
@@ -115,27 +115,9 @@ def RemoveExport(opts, args):
 
 # this is defined separately due to readability only
 import_opts = [
-  BACKEND_OPT,
-  DISK_OPT,
-  DISK_TEMPLATE_OPT,
-  FILESTORE_DIR_OPT,
-  FILESTORE_DRIVER_OPT,
-  HYPERVISOR_OPT,
-  IALLOCATOR_OPT,
   IDENTIFY_DEFAULTS_OPT,
-  NET_OPT,
-  NODE_PLACEMENT_OPT,
-  NOIPCHECK_OPT,
-  NONAMECHECK_OPT,
-  NONICS_OPT,
-  NWSYNC_OPT,
-  OSPARAMS_OPT,
-  OS_SIZE_OPT,
   SRC_DIR_OPT,
   SRC_NODE_OPT,
-  SUBMIT_OPT,
-  DRY_RUN_OPT,
-  PRIORITY_OPT,
   ]
 
 
@@ -152,7 +134,7 @@ commands = {
     "-n <target_node> [opts...] <name>",
     "Exports an instance to an image"),
   'import': (
-    ImportInstance, ARGS_ONE_INSTANCE, import_opts,
+    ImportInstance, ARGS_ONE_INSTANCE, COMMON_CREATE_OPTS + import_opts,
     "[...] -t disk-type -n node[:secondary-node] <name>",
     "Imports an instance from an exported image"),
   'remove': (
diff --git a/lib/client/gnt_instance.py b/lib/client/gnt_instance.py
index cbe44f907..431bc1746 100644
--- a/lib/client/gnt_instance.py
+++ b/lib/client/gnt_instance.py
@@ -1377,33 +1377,15 @@ m_inst_tags_opt = cli_option("--tags", dest="multi_mode",
 
 # this is defined separately due to readability only
 add_opts = [
-  BACKEND_OPT,
-  DISK_OPT,
-  DISK_TEMPLATE_OPT,
-  FILESTORE_DIR_OPT,
-  FILESTORE_DRIVER_OPT,
-  HYPERVISOR_OPT,
-  IALLOCATOR_OPT,
-  NET_OPT,
-  NODE_PLACEMENT_OPT,
-  NOIPCHECK_OPT,
-  NONAMECHECK_OPT,
-  NONICS_OPT,
   NOSTART_OPT,
-  NWSYNC_OPT,
-  OSPARAMS_OPT,
   OS_OPT,
   FORCE_VARIANT_OPT,
   NO_INSTALL_OPT,
-  OS_SIZE_OPT,
-  SUBMIT_OPT,
-  DRY_RUN_OPT,
-  PRIORITY_OPT,
   ]
 
 commands = {
   'add': (
-    AddInstance, [ArgHost(min=1, max=1)], add_opts,
+    AddInstance, [ArgHost(min=1, max=1)], COMMON_CREATE_OPTS + add_opts,
     "[...] -t disk-type -n node[:secondary-node] -o os-type <name>",
     "Creates and adds a new instance to the cluster"),
   'batch-create': (
-- 
GitLab