Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 25 additions & 33 deletions src/dstack/_internal/core/backends/hotaisle/api_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,46 +16,38 @@ def __init__(self, api_key: str, team_handle: str):
self.team_handle = team_handle

def validate_api_key(self) -> bool:
url = f"{API_URL}/user/"
try:
self._validate_user_and_team()
return True
response = self._make_request("GET", url)
response.raise_for_status()
except requests.HTTPError as e:
if e.response.status_code == 401:
raise_invalid_credentials_error(
fields=[["creds", "api_key"]], details="Invalid API key"
)
elif e.response.status_code == 403:
raise_invalid_credentials_error(
fields=[["creds", "api_key"]],
details="Authenticated user does note have required permissions",
)
raise e
except ValueError as e:
error_message = str(e)
if "No Hot Aisle teams found" in error_message:
raise_invalid_credentials_error(
fields=[["creds", "api_key"]],
details="Valid API key but no teams found for this user",
)
elif "not found" in error_message:
raise_invalid_credentials_error(
fields=[["team_handle"]], details=f"Team handle '{self.team_handle}' not found"
)
raise e

def _validate_user_and_team(self) -> None:
url = f"{API_URL}/user/"
response = self._make_request("GET", url)
response.raise_for_status()
user_data = response.json()
if e.response is not None:
if e.response.status_code == 401:
raise_invalid_credentials_error(
fields=[["creds", "api_key"]], details="Invalid API key"
)
if e.response.status_code == 403:
raise_invalid_credentials_error(
fields=[["creds", "api_key"]],
details="Authenticated user does not have required permissions",
)
raise

teams = user_data.get("teams", [])
user_data = response.json()
teams = user_data["teams"]
if not teams:
raise ValueError("No Hot Aisle teams found for this user")
raise_invalid_credentials_error(
fields=[["creds", "api_key"]],
details="Valid API key but no teams found for this user",
)

available_teams = [team["handle"] for team in teams]
if self.team_handle not in available_teams:
raise ValueError(f"Hot Aisle team '{self.team_handle}' not found.")
raise_invalid_credentials_error(
fields=[["team_handle"]],
details=f"Team handle '{self.team_handle}' not found",
)
return True

def upload_ssh_key(self, public_key: str) -> bool:
url = f"{API_URL}/user/ssh_keys/"
Expand Down
7 changes: 1 addition & 6 deletions src/dstack/_internal/core/backends/hotaisle/compute.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@

logger = get_logger(__name__)

MAX_INSTANCE_NAME_LEN = 60


INSTANCE_TYPE_SPECS = {
"1x MI300X 8x Xeon Platinum 8462Y+": {
Expand Down Expand Up @@ -130,9 +128,7 @@ def create_instance(
ssh_port=22,
dockerized=True,
ssh_proxy=None,
backend_data=HotAisleInstanceBackendData(
ip_address=vm_data["ip_address"], vm_id=vm_data["name"]
).json(),
backend_data=HotAisleInstanceBackendData(ip_address=vm_data["ip_address"]).json(),
)

def update_provisioning_data(
Expand Down Expand Up @@ -217,7 +213,6 @@ def _run_ssh_command(hostname: str, ssh_private_key: str, command: str):

class HotAisleInstanceBackendData(CoreModel):
ip_address: str
vm_id: Optional[str] = None

@classmethod
def load(cls, raw: Optional[str]) -> "HotAisleInstanceBackendData":
Expand Down
Loading