From 33d36c4c8d28aafeffb0fbbaf4ccf56358271fe8 Mon Sep 17 00:00:00 2001 From: Jvst Me Date: Tue, 3 Mar 2026 11:00:51 +0100 Subject: [PATCH] Do not show SSH fleet resources in `dstack fleet` Always show `-` for SSH fleets, because resources are not applicable to them. Also simplify the implementation by building `fleet_row` and `instance_row` without `if verbose` checks. `if verbose` is only necessary when building the table header, and then `add_row_from_dict()` will include only the columns specified in the header. --- src/dstack/_internal/cli/utils/fleet.py | 24 +++++++++------------ src/tests/_internal/cli/utils/test_fleet.py | 1 + 2 files changed, 11 insertions(+), 14 deletions(-) diff --git a/src/dstack/_internal/cli/utils/fleet.py b/src/dstack/_internal/cli/utils/fleet.py index 70e6b5d74..2253d0a73 100644 --- a/src/dstack/_internal/cli/utils/fleet.py +++ b/src/dstack/_internal/cli/utils/fleet.py @@ -51,12 +51,16 @@ def get_fleets_table( if config.ssh_config is not None: # SSH fleet: fixed number of hosts, no cloud billing nodes = str(len(config.ssh_config.hosts)) + resources = "-" + gpu = "-" backend = "ssh" spot_policy = "-" max_price = "-" else: # Backend fleet: dynamic nodes, cloud billing nodes = _format_nodes(config.nodes) + resources = config.resources.pretty_format() if config.resources else "-" + gpu = _format_fleet_gpu(config.resources) backend = _format_backends(config.backends) spot_policy = "-" if merged_profile and merged_profile.spot_policy: @@ -74,6 +78,8 @@ def get_fleets_table( fleet_row: Dict[Union[str, int], Any] = { "NAME": name, "NODES": nodes, + "RESOURCES": resources, + "GPU": gpu, "BACKEND": backend, "PRICE": max_price, "SPOT": spot_policy, @@ -81,12 +87,6 @@ def get_fleets_table( "CREATED": format_date(fleet.created_at), } - if verbose: - fleet_row["RESOURCES"] = config.resources.pretty_format() if config.resources else "-" - fleet_row["ERROR"] = "" - else: - fleet_row["GPU"] = _format_fleet_gpu(config.resources) - add_row_from_dict(table, fleet_row) # Instance rows (indented) @@ -119,6 +119,8 @@ def get_fleets_table( instance_row: Dict[Union[str, int], Any] = { "NAME": f" instance={instance.instance_num}", "NODES": "", + "RESOURCES": _format_instance_resources(instance), + "GPU": _format_instance_gpu(instance), "BACKEND": backend_with_region, "PRICE": instance_price, "SPOT": instance_spot, @@ -126,14 +128,8 @@ def get_fleets_table( "CREATED": format_date(instance.created), } - if verbose: - instance_row["RESOURCES"] = _format_instance_resources(instance) - error = "" - if instance.status == InstanceStatus.TERMINATED and instance.termination_reason: - error = instance.termination_reason - instance_row["ERROR"] = error - else: - instance_row["GPU"] = _format_instance_gpu(instance) + if instance.status == InstanceStatus.TERMINATED and instance.termination_reason: + instance_row["ERROR"] = instance.termination_reason add_row_from_dict(table, instance_row, style="secondary") diff --git a/src/tests/_internal/cli/utils/test_fleet.py b/src/tests/_internal/cli/utils/test_fleet.py index 82b489409..00fedff68 100644 --- a/src/tests/_internal/cli/utils/test_fleet.py +++ b/src/tests/_internal/cli/utils/test_fleet.py @@ -354,6 +354,7 @@ def test_ssh_fleet_with_verbose(self): fleet_row = cells[0] assert fleet_row["NAME"] == "my-ssh" assert fleet_row["NODES"] == "1 (cluster)" + assert fleet_row["RESOURCES"] == "-" assert fleet_row["BACKEND"] == "ssh" assert fleet_row["SPOT"] == "-" assert fleet_row["PRICE"] == "-"