Skip to content
Merged
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
22 changes: 9 additions & 13 deletions src/dstack/_internal/core/backends/vastai/api_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import dstack._internal.utils.docker as docker
from dstack._internal.core.consts import DSTACK_RUNNER_SSH_PORT
from dstack._internal.core.errors import NoCapacityError
from dstack._internal.core.errors import ComputeError, NoCapacityError
from dstack._internal.core.models.common import RegistryAuth


Expand Down Expand Up @@ -86,19 +86,15 @@ def create_instance(
self._invalidate_cache()
return data

def destroy_instance(self, instance_id: Union[str, int]) -> bool:
"""
Args:
instance_id: instance to destroy

Returns:
True if instance was destroyed successfully
"""
def destroy_instance(self, instance_id: Union[str, int]) -> None:
resp = self.s.delete(self._url(f"/instances/{instance_id}/"))
if resp.status_code != 200 or not resp.json()["success"]:
return False
self._invalidate_cache()
return True
try:
data = resp.json()
except requests.exceptions.JSONDecodeError:
raise ComputeError(resp.text)
if resp.status_code != 200 or not data["success"]:
if data.get("error") != "no_such_instance":
raise ComputeError(resp.text)

def get_instances(self, cache_ttl: float = 3.0) -> List[dict]:
with self.lock:
Expand Down
Loading