Skip to content

Commit 1030276

Browse files
authored
Minor Hotaisle Cleanup (#2978)
Co-authored-by: Bihan Rana
1 parent 9732db7 commit 1030276

File tree

2 files changed

+26
-39
lines changed

2 files changed

+26
-39
lines changed

src/dstack/_internal/core/backends/hotaisle/api_client.py

Lines changed: 25 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -16,46 +16,38 @@ def __init__(self, api_key: str, team_handle: str):
1616
self.team_handle = team_handle
1717

1818
def validate_api_key(self) -> bool:
19+
url = f"{API_URL}/user/"
1920
try:
20-
self._validate_user_and_team()
21-
return True
21+
response = self._make_request("GET", url)
22+
response.raise_for_status()
2223
except requests.HTTPError as e:
23-
if e.response.status_code == 401:
24-
raise_invalid_credentials_error(
25-
fields=[["creds", "api_key"]], details="Invalid API key"
26-
)
27-
elif e.response.status_code == 403:
28-
raise_invalid_credentials_error(
29-
fields=[["creds", "api_key"]],
30-
details="Authenticated user does note have required permissions",
31-
)
32-
raise e
33-
except ValueError as e:
34-
error_message = str(e)
35-
if "No Hot Aisle teams found" in error_message:
36-
raise_invalid_credentials_error(
37-
fields=[["creds", "api_key"]],
38-
details="Valid API key but no teams found for this user",
39-
)
40-
elif "not found" in error_message:
41-
raise_invalid_credentials_error(
42-
fields=[["team_handle"]], details=f"Team handle '{self.team_handle}' not found"
43-
)
44-
raise e
45-
46-
def _validate_user_and_team(self) -> None:
47-
url = f"{API_URL}/user/"
48-
response = self._make_request("GET", url)
49-
response.raise_for_status()
50-
user_data = response.json()
24+
if e.response is not None:
25+
if e.response.status_code == 401:
26+
raise_invalid_credentials_error(
27+
fields=[["creds", "api_key"]], details="Invalid API key"
28+
)
29+
if e.response.status_code == 403:
30+
raise_invalid_credentials_error(
31+
fields=[["creds", "api_key"]],
32+
details="Authenticated user does not have required permissions",
33+
)
34+
raise
5135

52-
teams = user_data.get("teams", [])
36+
user_data = response.json()
37+
teams = user_data["teams"]
5338
if not teams:
54-
raise ValueError("No Hot Aisle teams found for this user")
39+
raise_invalid_credentials_error(
40+
fields=[["creds", "api_key"]],
41+
details="Valid API key but no teams found for this user",
42+
)
5543

5644
available_teams = [team["handle"] for team in teams]
5745
if self.team_handle not in available_teams:
58-
raise ValueError(f"Hot Aisle team '{self.team_handle}' not found.")
46+
raise_invalid_credentials_error(
47+
fields=[["team_handle"]],
48+
details=f"Team handle '{self.team_handle}' not found",
49+
)
50+
return True
5951

6052
def upload_ssh_key(self, public_key: str) -> bool:
6153
url = f"{API_URL}/user/ssh_keys/"

src/dstack/_internal/core/backends/hotaisle/compute.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@
2828

2929
logger = get_logger(__name__)
3030

31-
MAX_INSTANCE_NAME_LEN = 60
32-
3331

3432
INSTANCE_TYPE_SPECS = {
3533
"1x MI300X 8x Xeon Platinum 8462Y+": {
@@ -130,9 +128,7 @@ def create_instance(
130128
ssh_port=22,
131129
dockerized=True,
132130
ssh_proxy=None,
133-
backend_data=HotAisleInstanceBackendData(
134-
ip_address=vm_data["ip_address"], vm_id=vm_data["name"]
135-
).json(),
131+
backend_data=HotAisleInstanceBackendData(ip_address=vm_data["ip_address"]).json(),
136132
)
137133

138134
def update_provisioning_data(
@@ -217,7 +213,6 @@ def _run_ssh_command(hostname: str, ssh_private_key: str, command: str):
217213

218214
class HotAisleInstanceBackendData(CoreModel):
219215
ip_address: str
220-
vm_id: Optional[str] = None
221216

222217
@classmethod
223218
def load(cls, raw: Optional[str]) -> "HotAisleInstanceBackendData":

0 commit comments

Comments
 (0)