Skip to content

Commit

Permalink
Merge branch 'main' into fix/cluster/uuid-repr
Browse files Browse the repository at this point in the history
  • Loading branch information
fubuloubu authored Feb 14, 2025
2 parents 49915c7 + 8b0e511 commit d24df43
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 1 deletion.
41 changes: 41 additions & 0 deletions silverback/_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,47 @@ def update_cluster(
click.echo(f"{click.style('SUCCESS', fg='green')}: Updated '{updated_cluster.name}'")


@cluster.command(name="migrate", section="Platform Commands (https://silverback.apeworx.io)")
@click.option("--version", default=None)
@click.argument("cluster_path")
@platform_client
def migrate_cluster(
platform: "PlatformClient",
cluster_path: str,
version: str | None,
):
"""Migrate CLUSTER running software version to VERSION"""
if "/" not in cluster_path or len(cluster_path.split("/")) > 2:
raise click.BadArgumentUsage(f"Invalid cluster path: '{cluster_path}'")

workspace_name, cluster_name = cluster_path.split("/")
if not (workspace_client := platform.workspaces.get(workspace_name)):
raise click.BadArgumentUsage(f"Unknown workspace: '{workspace_name}'")

elif not (cluster := workspace_client.clusters.get(cluster_name)):
raise click.BadArgumentUsage(
f"Unknown cluster in workspace '{workspace_name}': '{cluster_name}'"
)

elif version and version not in (available_versions := workspace_client.available_versions):
available_versions_str = "', '".join(available_versions)
raise click.BadOptionUsage(
"version",
f"Cannot migrate to version '{version}', must be one of: '{available_versions_str}'",
)

click.echo(
f"{click.style('INFO', fg='blue')}: "
f"Migrating '{cluster_path}' from '{cluster.version}' to '{version or 'stable'}'"
)
workspace_client.migrate_cluster(str(cluster.id), version=version)
click.echo(f"{click.style('SUCCESS', fg='green')}: Migration of '{cluster.name}' started")
click.echo(
f"{click.style('INFO', fg='blue')}: "
"This may take a couple of minutes, check `silverback cluster info` for version change"
)


@cluster.group(cls=SectionedHelpGroup, section="Platform Commands (https://silverback.apeworx.io)")
def pay():
"""Pay for CLUSTER with Crypto using ApePay streaming payments"""
Expand Down
20 changes: 19 additions & 1 deletion silverback/cluster/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -392,12 +392,30 @@ def update_cluster(
data["slug"] = slug
response = self.client.patch(
f"/clusters/{cluster_id}",
params=dict(workspace=str(self.id), cluster_id=cluster_id),
params=dict(workspace=str(self.id)),
data=data,
)
handle_error_with_response(response)
return ClusterInfo.model_validate(response.json())

@property
def available_versions(self) -> list[str]:
response = self.client.get("/versions")
handle_error_with_response(response)
return response.json()

def migrate_cluster(self, cluster_id: str, version: str | None = None):
data = dict()
if version:
data["version"] = version

response = self.client.put(
f"/clusters/{cluster_id}",
params=dict(workspace=str(self.id)),
data=data,
)
handle_error_with_response(response)

def get_payment_stream(self, cluster: ClusterInfo, chain_id: int) -> Stream | None:
response = self.client.get(
f"/clusters/{cluster.id}/stream",
Expand Down

0 comments on commit d24df43

Please sign in to comment.