|
1 | | -""" |
2 | | -Defines the resource class for the Metadata API endpoints. |
3 | | -""" |
4 | | - |
5 | 1 | from typing import List |
6 | | -from ...core import APIOperation, AsyncCallable |
| 2 | +from pydantic import Field |
| 3 | +from ...core.base import ResourceList |
| 4 | +from ...core import AsyncCallable |
7 | 5 | from ...core import ResourceBase |
8 | | -from .models import Datacenter, WsPlan, Image |
| 6 | +from .operations import _LIST_DC_OP, _LIST_IMAGES_OP, _LIST_PLANS_OP |
| 7 | +from .schemas import Datacenter, WsPlan, Image |
9 | 8 |
|
10 | 9 |
|
11 | 10 | class MetadataResource(ResourceBase): |
12 | | - list_datacenters: AsyncCallable[List[Datacenter]] |
13 | | - """Fetches a list of all available data centers.""" |
14 | | - list_datacenters = APIOperation( |
15 | | - method="GET", |
16 | | - endpoint_template="/metadata/datacenters", |
17 | | - input_model=None, |
18 | | - response_model=List[Datacenter], |
| 11 | + list_datacenters_op: AsyncCallable[ResourceList[Datacenter]] = Field( |
| 12 | + default=_LIST_DC_OP, exclude=True |
19 | 13 | ) |
20 | | - |
21 | | - list_plans: AsyncCallable[List[WsPlan]] |
22 | | - """Fetches a list of all available workspace plans.""" |
23 | | - list_plans = APIOperation( |
24 | | - method="GET", |
25 | | - endpoint_template="/metadata/workspace-plans", |
26 | | - input_model=None, |
27 | | - response_model=List[WsPlan], |
| 14 | + list_plans_op: AsyncCallable[ResourceList[WsPlan]] = Field( |
| 15 | + default=_LIST_PLANS_OP, exclude=True |
28 | 16 | ) |
29 | | - |
30 | | - list_images: AsyncCallable[List[Image]] |
31 | | - """Fetches a list of all available workspace base images.""" |
32 | | - list_images = APIOperation( |
33 | | - method="GET", |
34 | | - endpoint_template="/metadata/workspace-base-images", |
35 | | - input_model=None, |
36 | | - response_model=List[Image], |
| 17 | + list_images_op: AsyncCallable[ResourceList[Image]] = Field( |
| 18 | + default=_LIST_IMAGES_OP, exclude=True |
37 | 19 | ) |
| 20 | + |
| 21 | + async def list_datacenters(self) -> List[Datacenter]: |
| 22 | + result = await self.list_datacenters_op() |
| 23 | + return result.root |
| 24 | + |
| 25 | + async def list_plans(self) -> List[WsPlan]: |
| 26 | + result = await self.list_plans_op() |
| 27 | + return result.root |
| 28 | + |
| 29 | + async def list_images(self) -> List[Image]: |
| 30 | + result = await self.list_images_op() |
| 31 | + return result.root |
0 commit comments