ctx.obj.cluster.update(name, changes_dict=cluster_changes)
+@click.command(
+ name="cluster-upgrade", short_help="changes the version of a K8s cluster"
+)
+@click.argument("name")
+@click.option("--version", prompt=True, help="Kubernetes version")
+@click.pass_context
+def cluster_upgrade(ctx, name, version, **kwargs):
+ """changes the version of a K8s cluster
+
+ NAME: name or ID of the K8s cluster
+ """
+ logger.debug("")
+ cluster_changes = {
+ "k8s_version": version,
+ }
+ ctx.obj.cluster.upgrade(name, cluster_changes)
+
+
+@click.command(name="cluster-scale", short_help="scales a K8s cluster")
+@click.argument("name")
+@click.option("--node-count", "-n", prompt=True, type=int, help="number of nodes")
+@click.pass_context
+def cluster_scale(ctx, name, node_count, **kwargs):
+ """scales the number of nodes of a K8s cluster
+
+ NAME: name or ID of the K8s cluster
+ """
+ logger.debug("")
+ cluster_changes = {
+ "node_count": node_count,
+ }
+ ctx.obj.cluster.scale(name, cluster_changes)
+
+
@click.command(
name="cluster-get-credentials", short_help="gets kubeconfig of a K8s cluster"
)
for ksu in ksu_params:
verify_and_update_ksu(ctx, ksu)
logger.debug(f"ksu_params:\n{yaml.safe_dump(ksu_params)}")
- ctx.obj.ksu.multi_create_update({"ksus": ksu_params}, "")
+ ctx.obj.ksu.multi_create_update({"ksus": ksu_params})
@click.command(name="ksu-delete", short_help="deletes one or several KSU")
cli_osm.add_command(cluster.cluster_list)
cli_osm.add_command(cluster.cluster_show)
cli_osm.add_command(cluster.cluster_update)
+ cli_osm.add_command(cluster.cluster_upgrade)
+ cli_osm.add_command(cluster.cluster_scale)
cli_osm.add_command(cluster.cluster_get_credentials)
cli_osm.add_command(cluster.cluster_get_kubeconfig)
cli_osm.add_command(cluster.cluster_register)
endpoint = f"{self._apiBase}/register"
self.create(name, cluster, None, endpoint=endpoint)
+ def upgrade(self, name, cluster_changes):
+ """
+ Upgrades a K8s cluster
+ """
+ self._logger.debug("")
+ item = self.get(name)
+ endpoint_suffix = f"{item['_id']}/upgrade"
+ self.generic_operation(cluster_changes, endpoint_suffix=endpoint_suffix)
+
+ def scale(self, name, cluster_changes):
+ """
+ Scales a K8s cluster
+ """
+ self._logger.debug("")
+ item = self.get(name)
+ endpoint_suffix = f"{item['_id']}/scale"
+ 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("")
skip_query_admin=True,
)
- def multi_create_update(self, content, endpoint_suffix):
+ def generic_operation(self, content, endpoint_suffix):
+ """
+ Send a POST message for a generic operation over a Generic OSM API Object
+ :param: content: the content of the message
+ :param: endpoint_suffix: the suffix to be added to the endpoint
+ :return: op_id, the operation identifier provided by OSM
+ """
+ self._logger.debug("")
+ self._client.get_token()
+ endpoint = f"{self._apiBase}/{endpoint_suffix}"
+ http_code, resp = self.generic_post(endpoint=endpoint, content=content)
+ if http_code in (200, 201, 202):
+ if not resp:
+ raise ClientException(f"unexpected response from server - {resp}")
+ resp = json.loads(resp)
+ output = resp["op_id"]
+ print(output)
+ elif http_code == 204:
+ print("Received")
+
+ def multi_create_update(self, content, endpoint_suffix=None):
"""Create or update a bundle of Generic OSM API Object specified by content"""
self._logger.debug("")
self._client.get_token()