Skip to content

Commit

Permalink
ADCM-6138: Implement Bundle object (#20)
Browse files Browse the repository at this point in the history
Co-authored-by: astarovo <a.starovoitov@arenadata.io>
  • Loading branch information
Starovoitov and Starovoitov authored Nov 29, 2024
1 parent 924a0ae commit 7bac632
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 9 deletions.
10 changes: 7 additions & 3 deletions adcm_aio_client/core/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
from functools import cached_property
from typing import Self

from adcm_aio_client.core.objects.cm import ADCM, ClustersNode, HostProvidersNode, HostsAccessor
from adcm_aio_client.core.requesters import DefaultRequester
from adcm_aio_client.core.types import AuthToken, Cert, Credentials, Requester, Verify
from adcm_aio_client.core.objects.cm import ADCM, BundlesNode, ClustersNode, HostProvidersNode, HostsAccessor
from adcm_aio_client.core.requesters import DefaultRequester, Requester
from adcm_aio_client.core.types import AuthToken, Cert, Credentials, Verify


class ADCMClient:
Expand All @@ -38,6 +38,10 @@ def hostproviders(self: Self) -> HostProvidersNode:
def adcm(self: Self) -> ADCM:
return ADCM(requester=self._requester, data={})

@cached_property
def bundles(self: Self) -> BundlesNode:
return BundlesNode(path=("bundles",), requester=self._requester)


async def build_client(
url: str,
Expand Down
50 changes: 44 additions & 6 deletions adcm_aio_client/core/objects/cm.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from functools import cached_property
from typing import Iterable, Self
from typing import Iterable, Literal, Self
import asyncio

from asyncstdlib.functools import cached_property as async_cached_property
from asyncstdlib.functools import cached_property as async_cached_property # noqa: N813

from adcm_aio_client.core.errors import NotFoundError, OperationError, ResponseError
from adcm_aio_client.core.objects._accessors import (
Expand Down Expand Up @@ -41,7 +41,48 @@ def get_own_path(self: Self) -> Endpoint:
return ("adcm",)


class Bundle(Deletable, InteractiveObject): ...
class License(InteractiveObject): ...


class Bundle(Deletable, RootInteractiveObject):
PATH_PREFIX = "bundles"

@property
def name(self: Self) -> str:
return str(self._data["name"])

@property
def display_name(self: Self) -> str:
return str(self._data["display_name"])

@property
def version(self: Self) -> str:
return str(self._data["version"])

@property
def edition(self: Self) -> Literal["community", "enterprise"]:
return self._data["edition"]

@property
def signature_status(self: Self) -> Literal["invalid", "valid", "absent"]:
return self._data["signatureStatus"]

@property
def _type(self: Self) -> Literal["cluster", "provider"]:
return self._data["mainPrototype"]["type"]

def license(self: Self) -> License:
return self._construct(what=License, from_data=self._data["mainPrototype"]["license"])

def get_own_path(self: Self) -> Endpoint:
return self.PATH_PREFIX, self.id


class BundlesNode(PaginatedAccessor[Bundle, None]):
class_type = Bundle

def get_own_path(self: Self) -> Endpoint:
return ("bundles",)


class Cluster(
Expand Down Expand Up @@ -112,9 +153,6 @@ def get_own_path(self: Self) -> Endpoint:
class ClustersNode(PaginatedAccessor[Cluster, None]):
class_type = Cluster

def get_own_path(self: Self) -> Endpoint:
return ("clusters",)


class Service(
WithStatus,
Expand Down

0 comments on commit 7bac632

Please sign in to comment.