Rename cluster-update to cluster-edit; add cluster-update for node count, node size... 43/14743/4
authorgarciadeblas <gerardo.garciadeblas@telefonica.com>
Mon, 18 Nov 2024 11:52:21 +0000 (12:52 +0100)
committergarciadeblas <gerardo.garciadeblas@telefonica.com>
Mon, 25 Nov 2024 09:54:13 +0000 (10:54 +0100)
Change-Id: I4d3bf435e38706302f1b7e90f6acb7cfed21c8bf
Signed-off-by: garciadeblas <gerardo.garciadeblas@telefonica.com>
osmclient/cli_commands/cluster.py
osmclient/scripts/osm.py
osmclient/sol005/cluster.py

index 8fce6ac..4cb15b9 100755 (executable)
@@ -156,13 +156,15 @@ def cluster_show(ctx, name, output):
     common.generic_show(callback=ctx.obj.cluster.get_both, name=name, format=output)
 
 
-@click.command(name="cluster-update", short_help="updates a K8s cluster")
+@click.command(
+    name="cluster-edit", short_help="updates name or description of a K8s cluster"
+)
 @click.argument("name")
 @click.option("--newname", help="New name for the K8s cluster")
 @click.option("--description", help="human readable description")
 @click.pass_context
-def cluster_update(ctx, name, newname, description, **kwargs):
-    """updates a K8s cluster
+def cluster_edit(ctx, name, newname, description, **kwargs):
+    """updates the name or description of a K8s cluster
 
     NAME: name or ID of the K8s cluster
     """
@@ -205,6 +207,28 @@ def cluster_scale(ctx, name, node_count, **kwargs):
     ctx.obj.cluster.scale(name, cluster_changes)
 
 
+@click.command(name="cluster-update", short_help="updates a K8s cluster")
+@click.argument("name")
+@click.option("--version", help="Kubernetes version")
+@click.option("--node-count", "-n", type=int, help="number of nodes")
+@click.option("--node-size", help="size of the worker nodes")
+@click.pass_context
+def cluster_update(ctx, name, version, node_count, node_size, **kwargs):
+    """updates the number of nodes, the version or the node size of a K8s cluster
+
+    NAME: name or ID of the K8s cluster
+    """
+    logger.debug("")
+    cluster_changes = {}
+    if version:
+        cluster_changes["k8s_version"] = version
+    if node_count:
+        cluster_changes["node_count"] = node_count
+    if node_size:
+        cluster_changes["node_size"] = node_size
+    ctx.obj.cluster.fullupdate(name, cluster_changes)
+
+
 @click.command(
     name="cluster-get-credentials", short_help="gets kubeconfig of a K8s cluster"
 )
index 0aff0a5..f0a10ba 100755 (executable)
@@ -192,6 +192,7 @@ def cli():
         cli_osm.add_command(cluster.cluster_delete)
         cli_osm.add_command(cluster.cluster_list)
         cli_osm.add_command(cluster.cluster_show)
+        cli_osm.add_command(cluster.cluster_edit)
         cli_osm.add_command(cluster.cluster_update)
         cli_osm.add_command(cluster.cluster_upgrade)
         cli_osm.add_command(cluster.cluster_scale)
index 2bbc157..545844a 100644 (file)
@@ -125,6 +125,15 @@ class Cluster(GenericOSMAPIObject):
         endpoint_suffix = f"{item['_id']}/scale"
         self.generic_operation(cluster_changes, endpoint_suffix=endpoint_suffix)
 
+    def fullupdate(self, name, cluster_changes):
+        """
+        Updates a K8s cluster (version, node size or node count)
+        """
+        self._logger.debug("")
+        item = self.get(name)
+        endpoint_suffix = f"{item['_id']}/update"
+        self.generic_operation(cluster_changes, endpoint_suffix=endpoint_suffix)
+
     def list_both(self, filter=None):
         """List all clusters from both new and old APIs"""
         self._logger.debug("")