Fix register and get-credentials cluster commands 37/14637/2
authorgarciadeblas <gerardo.garciadeblas@telefonica.com>
Tue, 15 Oct 2024 11:11:16 +0000 (13:11 +0200)
committergarciadeblas <gerardo.garciadeblas@telefonica.com>
Tue, 15 Oct 2024 22:31:00 +0000 (00:31 +0200)
Change-Id: I76b962e07bd4e927aecd85ce58de37388d36da04
Signed-off-by: garciadeblas <gerardo.garciadeblas@telefonica.com>
osmclient/cli_commands/cluster.py
osmclient/scripts/osm.py
osmclient/sol005/cluster.py

index 53991b7..46fb258 100755 (executable)
@@ -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(
index c90e513..bb69b6a 100755 (executable)
@@ -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)
index bc961a3..21bfeba 100644 (file)
@@ -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
         """