-
Notifications
You must be signed in to change notification settings - Fork 164
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add an API method for listing instances with filtering and pagination. This method will be used in the new Instances page in the UI. It is similar to the deprecated `/api/pools/list_instances` method, except it allows filtering by fleet and not by pool. Also add the `fleet_id` and `fleet_name` fields to the instance model so that the Instances page in the UI can display fleet names and provide links to fleet details.
- Loading branch information
Showing
11 changed files
with
396 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
from typing import List | ||
|
||
from fastapi import APIRouter, Depends | ||
from sqlalchemy.ext.asyncio import AsyncSession | ||
|
||
import dstack._internal.server.services.pools as pools | ||
from dstack._internal.core.models.pools import Instance | ||
from dstack._internal.server.db import get_session | ||
from dstack._internal.server.models import UserModel | ||
from dstack._internal.server.schemas.instances import ListInstancesRequest | ||
from dstack._internal.server.security.permissions import Authenticated | ||
from dstack._internal.server.utils.routers import get_base_api_additional_responses | ||
|
||
root_router = APIRouter( | ||
prefix="/api/instances", | ||
tags=["instances"], | ||
responses=get_base_api_additional_responses(), | ||
) | ||
|
||
|
||
@root_router.post("/list") | ||
async def list_instances( | ||
body: ListInstancesRequest, | ||
session: AsyncSession = Depends(get_session), | ||
user: UserModel = Depends(Authenticated()), | ||
) -> List[Instance]: | ||
""" | ||
Returns all instances visible to user sorted by descending `created_at`. | ||
`project_names` and `fleet_ids` can be specified as filters. | ||
The results are paginated. To get the next page, pass `created_at` and `id` of | ||
the last instance from the previous page as `prev_created_at` and `prev_id`. | ||
""" | ||
return await pools.list_user_pool_instances( | ||
session=session, | ||
user=user, | ||
project_names=body.project_names, | ||
fleet_ids=body.fleet_ids, | ||
pool_name=None, | ||
only_active=body.only_active, | ||
prev_created_at=body.prev_created_at, | ||
prev_id=body.prev_id, | ||
limit=body.limit, | ||
ascending=body.ascending, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
from datetime import datetime | ||
from typing import Optional | ||
from uuid import UUID | ||
|
||
from dstack._internal.core.models.common import CoreModel | ||
|
||
|
||
class ListInstancesRequest(CoreModel): | ||
project_names: Optional[list[str]] = None | ||
fleet_ids: Optional[list[UUID]] = None | ||
only_active: bool = False | ||
prev_created_at: Optional[datetime] = None | ||
prev_id: Optional[UUID] = None | ||
limit: int = 1000 | ||
ascending: bool = False |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.