From 83ec79613683c36cf92a26e755dabded6a872080 Mon Sep 17 00:00:00 2001
From: Michael Hanselmann <hansmi@google.com>
Date: Mon, 24 Aug 2009 16:08:04 +0200
Subject: [PATCH] Add ArgHost class

It expands to the hostnames known by bash.

Signed-off-by: Michael Hanselmann <hansmi@google.com>
Reviewed-by: Iustin Pop <iustin@google.com>
---
 autotools/build-bash-completion | 3 +++
 lib/cli.py                      | 8 +++++++-
 scripts/gnt-cluster             | 4 ++--
 scripts/gnt-instance            | 4 ++--
 scripts/gnt-node                | 2 +-
 5 files changed, 15 insertions(+), 6 deletions(-)

diff --git a/autotools/build-bash-completion b/autotools/build-bash-completion
index befbe6b72..57729dd68 100755
--- a/autotools/build-bash-completion
+++ b/autotools/build-bash-completion
@@ -321,6 +321,9 @@ class CompletionWriter:
         elif isinstance(arg, cli.ArgCommand):
           choices = ""
           compgenargs.append("-c")
+        elif isinstance(arg, cli.ArgHost):
+          choices = ""
+          compgenargs.append("-A hostname")
         else:
           raise Exception("Unknown argument type %r" % arg)
 
diff --git a/lib/cli.py b/lib/cli.py
index b47368282..cee7e2bbf 100644
--- a/lib/cli.py
+++ b/lib/cli.py
@@ -53,7 +53,7 @@ __all__ = ["DEBUG_OPT", "NOHDR_OPT", "SEP_OPT", "GenericMain",
            "ToStderr", "ToStdout", "UsesRPC",
            "GetOnlineNodes", "JobExecutor", "SYNC_OPT", "CONFIRM_OPT",
            "ArgJobId", "ArgSuggest", "ArgUnknown", "ArgFile", "ArgCommand",
-           "ArgInstance", "ArgNode", "ArgChoice",
+           "ArgInstance", "ArgNode", "ArgChoice", "ArgHost",
            "ARGS_NONE", "ARGS_ONE_INSTANCE", "ARGS_ONE_NODE",
            "ARGS_MANY_INSTANCES", "ARGS_MANY_NODES",
            ]
@@ -131,6 +131,12 @@ class ArgCommand(_Argument):
   """
 
 
+class ArgHost(_Argument):
+  """Host argument.
+
+  """
+
+
 ARGS_NONE = []
 ARGS_MANY_INSTANCES = [ArgInstance()]
 ARGS_MANY_NODES = [ArgNode()]
diff --git a/scripts/gnt-cluster b/scripts/gnt-cluster
index 0c9bccd17..ec0be431c 100755
--- a/scripts/gnt-cluster
+++ b/scripts/gnt-cluster
@@ -541,7 +541,7 @@ node_option = cli_option("-n", "--node", action="append", dest="nodes",
                          metavar="<node>", default=[])
 
 commands = {
-  'init': (InitCluster, [ArgUnknown(min=1, max=1)],
+  'init': (InitCluster, [ArgHost(min=1, max=1)],
            [DEBUG_OPT,
             cli_option("-s", "--secondary-ip", dest="secondary_ip",
                        help="Specify the secondary ip for this node;"
@@ -608,7 +608,7 @@ commands = {
                           action="store_true"),
               ],
               "", "Destroy cluster"),
-  'rename': (RenameCluster, [ArgUnknown(min=1, max=1)],
+  'rename': (RenameCluster, [ArgHost(min=1, max=1)],
              [DEBUG_OPT, FORCE_OPT],
              "<new_name>",
              "Renames the cluster"),
diff --git a/scripts/gnt-instance b/scripts/gnt-instance
index 6280413c9..d0a0c807f 100755
--- a/scripts/gnt-instance
+++ b/scripts/gnt-instance
@@ -1418,7 +1418,7 @@ add_opts = [
   ]
 
 commands = {
-  'add': (AddInstance, [ArgUnknown(min=1, max=1)], add_opts,
+  'add': (AddInstance, [ArgHost(min=1, max=1)], add_opts,
           "[...] -t disk-type -n node[:secondary-node] -o os-type <name>",
           "Creates and adds a new instance to the cluster"),
   'batch-create': (BatchCreate, [ArgFile(min=1, max=1)],
@@ -1517,7 +1517,7 @@ commands = {
               ],
              "[-f] <instance>", "Shuts down the instance and removes it"),
   'rename': (RenameInstance,
-             [ArgInstance(min=1, max=1), ArgUnknown(min=1, max=1)],
+             [ArgInstance(min=1, max=1), ArgHost(min=1, max=1)],
              [DEBUG_OPT,
               cli_option("--no-ip-check", dest="ignore_ip",
                          help="Do not check that the IP of the new name"
diff --git a/scripts/gnt-node b/scripts/gnt-node
index cffa1d972..6aa57f296 100755
--- a/scripts/gnt-node
+++ b/scripts/gnt-node
@@ -622,7 +622,7 @@ def SetNodeParams(opts, args):
 
 
 commands = {
-  'add': (AddNode, [ArgUnknown(min=1, max=1)],
+  'add': (AddNode, [ArgHost(min=1, max=1)],
           [DEBUG_OPT,
            cli_option("-s", "--secondary-ip", dest="secondary_ip",
                       help="Specify the secondary ip for the node",
-- 
GitLab