From: garciadeblas Date: Tue, 15 Oct 2024 11:11:16 +0000 (+0200) Subject: Fix register and get-credentials cluster commands X-Git-Url: https://osm.etsi.org/gitweb/?a=commitdiff_plain;h=9243b2559bc170e85847e3a41ddc03e8eafde524;p=osm%2Fosmclient.git Fix register and get-credentials cluster commands Change-Id: I76b962e07bd4e927aecd85ce58de37388d36da04 Signed-off-by: garciadeblas --- diff --git a/osmclient/cli_commands/cluster.py b/osmclient/cli_commands/cluster.py index 53991b7..46fb258 100755 --- a/osmclient/cli_commands/cluster.py +++ b/osmclient/cli_commands/cluster.py @@ -135,12 +135,12 @@ def cluster_update(ctx, name, newname, description, **kwargs): @click.command( - name="cluster-get-credentials", short_help="get kubeconfig of a K8s cluster" + name="cluster-get-credentials", short_help="gets kubeconfig of a K8s cluster" ) @click.argument("name") @click.pass_context def cluster_get_credentials(ctx, name, **kwargs): - """updates a K8s cluster + """gets the kubeconfig file to access a K8s cluster NAME: name or ID of the K8s cluster """ @@ -148,6 +148,17 @@ def cluster_get_credentials(ctx, name, **kwargs): ctx.obj.cluster.get_credentials(name) +# Alias for the cluster-get-credentials command +@click.command( + name="cluster-get-kubeconfig", short_help="gets kubeconfig of a K8s cluster" +) +@click.argument("name") +@click.pass_context +def cluster_get_kubeconfig(ctx, name, **kwargs): + """Alias for the cluster-get-credentials command""" + ctx.invoke(cluster_get_credentials, name=name) + + @click.command(name="cluster-register", short_help="registers a K8s cluster to OSM") @click.argument("name") @click.option( diff --git a/osmclient/scripts/osm.py b/osmclient/scripts/osm.py index c90e513..bb69b6a 100755 --- a/osmclient/scripts/osm.py +++ b/osmclient/scripts/osm.py @@ -194,6 +194,7 @@ def cli(): cli_osm.add_command(cluster.cluster_show) cli_osm.add_command(cluster.cluster_update) cli_osm.add_command(cluster.cluster_get_credentials) + cli_osm.add_command(cluster.cluster_get_kubeconfig) cli_osm.add_command(cluster.cluster_register) cli_osm.add_command(netslice_instance.nsi_create1) diff --git a/osmclient/sol005/cluster.py b/osmclient/sol005/cluster.py index bc961a3..21bfeba 100644 --- a/osmclient/sol005/cluster.py +++ b/osmclient/sol005/cluster.py @@ -64,8 +64,7 @@ class Cluster(GenericOSMAPIObject): def get_credentials(self, name): """ - Gets and shows an individual Generic OSM API Object - from the list of all objects of the same kind + Gets the kubeconfig file of a Kubernetes cluster """ self._logger.debug("") item = self.get(name) @@ -74,6 +73,7 @@ class Cluster(GenericOSMAPIObject): _, resp = self._http.get2_cmd(f"{self._apiBase}/{item['_id']}/get_creds") if resp: resp = json.loads(resp) + # TODO: loop to check if the credentials were populated in the db item = self.get(name) print( yaml.safe_dump( @@ -85,7 +85,7 @@ class Cluster(GenericOSMAPIObject): except Exception as e: raise ClientException(f"{e}: unexpected response from server - {resp}") - def register_cluster(self, name, cluster): + def register(self, name, cluster): """ Registers a K8s cluster """