Fix require_hostname function to consider nested commands such as cluster-get-kubeconfig
Change-Id: I04e30b0cf7d7d94c7b9859758a564e687725b726
Signed-off-by: garciadeblas <gerardo.garciadeblas@telefonica.com>
diff --git a/osmclient/cli_commands/cluster.py b/osmclient/cli_commands/cluster.py
index 83d5c65..31fe137 100755
--- a/osmclient/cli_commands/cluster.py
+++ b/osmclient/cli_commands/cluster.py
@@ -280,7 +280,8 @@
@click.pass_context
def cluster_get_kubeconfig(ctx, name, **kwargs):
"""Alias for the cluster-get-credentials command"""
- ctx.invoke(cluster_get_credentials, name=name)
+ logger.debug("")
+ ctx.forward(cluster_get_credentials)
@click.command(name="cluster-register", short_help="registers a K8s cluster to OSM")
diff --git a/osmclient/cli_commands/utils.py b/osmclient/cli_commands/utils.py
index 4ef7ad4..33bae82 100755
--- a/osmclient/cli_commands/utils.py
+++ b/osmclient/cli_commands/utils.py
@@ -113,9 +113,15 @@
logger.debug("")
hostname = ctx.parent.params.get("hostname") if ctx.parent else None
if not hostname:
- raise click.UsageError(
- "This command requires --hostname or OSM_HOSTNAME to be set."
+ # Also check the parent of the parent in case of nested commands
+ # e.g., in 'osm cluster-get-kubeconfig'
+ hostname2 = (
+ ctx.parent.parent.params.get("hostname") if ctx.parent.parent else None
)
+ if not hostname2:
+ raise click.UsageError(
+ "This command requires --hostname or OSM_HOSTNAME to be set."
+ )
return ctx.invoke(command, *args, **kwargs)
return wrapper