Skip to content

Commit 8cd5ec1

Browse files
Fetch Crusoe locations dynamically instead of hardcoding
Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent e5c2d21 commit 8cd5ec1

2 files changed

Lines changed: 12 additions & 5 deletions

File tree

src/dstack/_internal/core/backends/crusoe/configurator.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@
1616
from dstack._internal.core.backends.crusoe.resources import CrusoeClient
1717
from dstack._internal.core.models.backends.base import BackendType
1818

19-
KNOWN_LOCATIONS = {"us-east1-a", "us-southcentral1-a", "eu-iceland1-a", "us-west1-a"}
20-
2119

2220
class CrusoeConfigurator(
2321
Configurator[
@@ -38,13 +36,16 @@ def validate_config(self, config: CrusoeBackendConfigWithCreds, default_creds_en
3836
details=str(e),
3937
)
4038
if config.regions:
41-
invalid = set(config.regions) - KNOWN_LOCATIONS
39+
try:
40+
available = set(client.list_locations())
41+
except Exception:
42+
return
43+
invalid = set(config.regions) - available
4244
if invalid:
4345
raise_invalid_credentials_error(
4446
fields=[["regions"]],
4547
details=(
46-
f"Unknown regions: {sorted(invalid)}."
47-
f" Valid regions: {sorted(KNOWN_LOCATIONS)}"
48+
f"Unknown regions: {sorted(invalid)}. Valid regions: {sorted(available)}"
4849
),
4950
)
5051

src/dstack/_internal/core/backends/crusoe/resources.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,12 @@ def list_quotas(self) -> List[dict]:
136136
resp = self._request("GET", self._project_path("/quotas"))
137137
return resp.json().get("quotas", [])
138138

139+
# --- Location operations ---
140+
141+
def list_locations(self) -> List[str]:
142+
resp = self._request("GET", "/locations")
143+
return resp.json().get("items", [])
144+
139145
# --- IB operations ---
140146

141147
def list_ib_networks(self) -> List[dict]:

0 commit comments

Comments
 (0)