Skip to content

Commit

Permalink
feat(cli): show prettier display of config when creating a new cluster
Browse files Browse the repository at this point in the history
  • Loading branch information
fubuloubu committed Aug 1, 2024
1 parent e722166 commit 2850498
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
14 changes: 13 additions & 1 deletion silverback/_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,18 @@ def new_cluster(
for k, v in config_updates:
setattr(configuration, k, int(v) if v.isnumeric() else v)

if cluster_name:
click.echo(f"name: {cluster_name}")
click.echo(f"slug: {cluster_slug or cluster_name.lower().replace(' ', '-')}")

elif cluster_slug:
click.echo(f"slug: {cluster_slug}")

click.echo(yaml.safe_dump(dict(configuration=configuration.settings_display_dict())))

if not click.confirm("Do you want to make a new cluster with this configuration?"):
return

cluster = workspace_client.create_cluster(
cluster_name=cluster_name,
cluster_slug=cluster_slug,
Expand All @@ -258,7 +270,7 @@ def cluster_info(cluster: ClusterClient):
click.echo(f"Cluster Version: v{cluster.version}")

if config := cluster.state.configuration:
click.echo(yaml.safe_dump(config.model_dump()))
click.echo(yaml.safe_dump(config.settings_display_dict()))

else:
click.secho("No Cluster Configuration detected", fg="yellow", bold=True)
Expand Down
20 changes: 20 additions & 0 deletions silverback/cluster/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,26 @@ def parse_storage_value(cls, value: str | int) -> int:
assert units.lower() == "tb"
return int(storage)

def settings_display_dict(self) -> dict:
return dict(
version=self.version,
bots=dict(
cpu=f"{256 * 2**self.cpu / 1024} vCPU",
memory=f"{self.memory} GB" if self.memory > 0 else "512 MiB",
),
general=dict(
bots=self.bots,
secrets=self.secrets,
),
runner=dict(
networks=self.networks,
triggers=self.triggers,
),
recorder=dict(
storage=f"{self.storage} TB" if self.storage > 0 else "512 GB",
),
)

@staticmethod
def _decode_byte(value: int, byte: int) -> int:
# NOTE: All configuration settings must be uint8 integer values when encoded
Expand Down

0 comments on commit 2850498

Please sign in to comment.