From 94a9474fc15c17e1f9bf4c85a98f975a7d044fc3 Mon Sep 17 00:00:00 2001 From: Jvst Me Date: Tue, 16 Jun 2026 22:25:49 +0200 Subject: [PATCH] Improve replicated gateway display in older CLIs Adjust server-side gateway object patching for pre-0.20.25 clients, so that such clients display all replica hostnames (even though they are not aware of replicated gateways). Before: ```shell $ dstack --version 0.20.24 $ dstack gateway list NAME BACKEND HOSTNAME DOMAIN DEFAULT STATUS replicated gcp (us-west4) example.com running ``` After: ```shell $ dstack gateway list NAME BACKEND HOSTNAME DOMAIN DEFAULT STATUS replicated gcp (us-west4) 34.125.203.210 example.com running 34.186.30.65 ``` --- src/dstack/_internal/server/compatibility/gateways.py | 4 ++-- src/tests/_internal/server/compatibility/test_gateways.py | 7 ++++--- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/dstack/_internal/server/compatibility/gateways.py b/src/dstack/_internal/server/compatibility/gateways.py index 3e410b5a9..653f3d6e2 100644 --- a/src/dstack/_internal/server/compatibility/gateways.py +++ b/src/dstack/_internal/server/compatibility/gateways.py @@ -8,8 +8,8 @@ def patch_gateway(gateway: Gateway, client_version: Optional[Version]) -> None: if client_version is None: return - if client_version < Version("0.20.25") and len(gateway.replicas) < 2: + if client_version < Version("0.20.25"): gateway.instance_id = "" - gateway.ip_address = gateway.replicas[0].hostname if gateway.replicas else "" + gateway.ip_address = "\n".join(r.hostname for r in gateway.replicas) if gateway.hostname is None: gateway.hostname = gateway.ip_address diff --git a/src/tests/_internal/server/compatibility/test_gateways.py b/src/tests/_internal/server/compatibility/test_gateways.py index 4bbd2a80d..4313be095 100644 --- a/src/tests/_internal/server/compatibility/test_gateways.py +++ b/src/tests/_internal/server/compatibility/test_gateways.py @@ -80,9 +80,10 @@ def test_old_version_no_replicas_sets_empty_strings(self): assert gw.instance_id == "" assert gw.hostname == "" - def test_old_version_multi_replica_is_noop(self): + def test_old_version_multi_replica_concatenates_hostnames(self): replicas = [_make_gateway_replica("1.2.3.4"), _make_gateway_replica("5.6.7.8")] gw = _make_gateway(replicas=replicas) patch_gateway(gw, Version("0.20.24")) - assert gw.ip_address is None - assert gw.instance_id is None + assert gw.hostname == "1.2.3.4\n5.6.7.8" + assert gw.ip_address == "1.2.3.4\n5.6.7.8" + assert gw.instance_id == ""