Skip to content

Commit 18fd035

Browse files
authored
Do not show SSH fleet resources in dstack fleet (#3632)
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.
1 parent 86a4639 commit 18fd035

File tree

2 files changed

+11
-14
lines changed

2 files changed

+11
-14
lines changed

src/dstack/_internal/cli/utils/fleet.py

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,16 @@ def get_fleets_table(
5151
if config.ssh_config is not None:
5252
# SSH fleet: fixed number of hosts, no cloud billing
5353
nodes = str(len(config.ssh_config.hosts))
54+
resources = "-"
55+
gpu = "-"
5456
backend = "ssh"
5557
spot_policy = "-"
5658
max_price = "-"
5759
else:
5860
# Backend fleet: dynamic nodes, cloud billing
5961
nodes = _format_nodes(config.nodes)
62+
resources = config.resources.pretty_format() if config.resources else "-"
63+
gpu = _format_fleet_gpu(config.resources)
6064
backend = _format_backends(config.backends)
6165
spot_policy = "-"
6266
if merged_profile and merged_profile.spot_policy:
@@ -74,19 +78,15 @@ def get_fleets_table(
7478
fleet_row: Dict[Union[str, int], Any] = {
7579
"NAME": name,
7680
"NODES": nodes,
81+
"RESOURCES": resources,
82+
"GPU": gpu,
7783
"BACKEND": backend,
7884
"PRICE": max_price,
7985
"SPOT": spot_policy,
8086
"STATUS": _format_fleet_status(fleet),
8187
"CREATED": format_date(fleet.created_at),
8288
}
8389

84-
if verbose:
85-
fleet_row["RESOURCES"] = config.resources.pretty_format() if config.resources else "-"
86-
fleet_row["ERROR"] = ""
87-
else:
88-
fleet_row["GPU"] = _format_fleet_gpu(config.resources)
89-
9090
add_row_from_dict(table, fleet_row)
9191

9292
# Instance rows (indented)
@@ -119,21 +119,17 @@ def get_fleets_table(
119119
instance_row: Dict[Union[str, int], Any] = {
120120
"NAME": f" instance={instance.instance_num}",
121121
"NODES": "",
122+
"RESOURCES": _format_instance_resources(instance),
123+
"GPU": _format_instance_gpu(instance),
122124
"BACKEND": backend_with_region,
123125
"PRICE": instance_price,
124126
"SPOT": instance_spot,
125127
"STATUS": _format_instance_status(instance),
126128
"CREATED": format_date(instance.created),
127129
}
128130

129-
if verbose:
130-
instance_row["RESOURCES"] = _format_instance_resources(instance)
131-
error = ""
132-
if instance.status == InstanceStatus.TERMINATED and instance.termination_reason:
133-
error = instance.termination_reason
134-
instance_row["ERROR"] = error
135-
else:
136-
instance_row["GPU"] = _format_instance_gpu(instance)
131+
if instance.status == InstanceStatus.TERMINATED and instance.termination_reason:
132+
instance_row["ERROR"] = instance.termination_reason
137133

138134
add_row_from_dict(table, instance_row, style="secondary")
139135

src/tests/_internal/cli/utils/test_fleet.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,7 @@ def test_ssh_fleet_with_verbose(self):
354354
fleet_row = cells[0]
355355
assert fleet_row["NAME"] == "my-ssh"
356356
assert fleet_row["NODES"] == "1 (cluster)"
357+
assert fleet_row["RESOURCES"] == "-"
357358
assert fleet_row["BACKEND"] == "ssh"
358359
assert fleet_row["SPOT"] == "-"
359360
assert fleet_row["PRICE"] == "-"

0 commit comments

Comments
 (0)