From 7f6172b9d57a4be0338f1c6883a2b89f209a7e05 Mon Sep 17 00:00:00 2001 From: garciadeblas Date: Mon, 18 Nov 2024 12:52:21 +0100 Subject: [PATCH] Rename cluster-update to cluster-edit; add cluster-update for node count, node size and version Change-Id: I4d3bf435e38706302f1b7e90f6acb7cfed21c8bf Signed-off-by: garciadeblas --- osmclient/cli_commands/cluster.py | 30 +++++++++++++++++++++++++++--- osmclient/scripts/osm.py | 1 + osmclient/sol005/cluster.py | 9 +++++++++ 3 files changed, 37 insertions(+), 3 deletions(-) diff --git a/osmclient/cli_commands/cluster.py b/osmclient/cli_commands/cluster.py index 8fce6ac..4cb15b9 100755 --- a/osmclient/cli_commands/cluster.py +++ b/osmclient/cli_commands/cluster.py @@ -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" ) diff --git a/osmclient/scripts/osm.py b/osmclient/scripts/osm.py index 0aff0a5..f0a10ba 100755 --- a/osmclient/scripts/osm.py +++ b/osmclient/scripts/osm.py @@ -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) diff --git a/osmclient/sol005/cluster.py b/osmclient/sol005/cluster.py index 2bbc157..545844a 100644 --- a/osmclient/sol005/cluster.py +++ b/osmclient/sol005/cluster.py @@ -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("") -- 2.25.1