Skip to content

Commit

Permalink
ADCM-6119: Implement HostProvider object
Browse files Browse the repository at this point in the history
  • Loading branch information
astarovo committed Nov 18, 2024
1 parent ec97062 commit 06eeceb
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 48 deletions.
6 changes: 5 additions & 1 deletion adcm_aio_client/core/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from functools import cached_property
from typing import Self

from adcm_aio_client.core.objects.cm import ClustersNode
from adcm_aio_client.core.objects.cm import ClustersNode, HostprovidersNode
from adcm_aio_client.core.requesters import Requester
from adcm_aio_client.core.types import AuthToken, Cert, Credentials, Verify

Expand All @@ -26,6 +26,10 @@ def __init__(self: Self, requester: Requester) -> None:
def clusters(self: Self) -> ClustersNode:
return ClustersNode(path=(), requester=self._requester)

@cached_property
def hostproviders(self: Self) -> HostprovidersNode:
return HostprovidersNode(path=(), requester=self._requester)


async def build_client(
url: str | list[str],
Expand Down
54 changes: 7 additions & 47 deletions adcm_aio_client/core/objects/cm.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,50 +122,6 @@ class ComponentsNode(NonPaginatedChildAccessor[Service, Component, None]):
class_type = Component


class Prototype[ParentObject: InteractiveObject](InteractiveChildObject[ParentObject]):
@property
def id(self: Self) -> int:
return int(self._data["id"])

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

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

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

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

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

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

@cached_property
async def bundle(self: Self) -> Bundle:
bundle_id = self._data["bundle"]["id"]
response = await self._requester.get("bundles", bundle_id)

return self._construct(what=Bundle, from_data=response.as_dict())

def get_own_path(self: Self) -> Endpoint:
return (*self._parent.get_own_path(), "prototypes", self.id)


class PrototypeNode[ParentObject: InteractiveObject](PaginatedChildAccessor[ParentObject, Prototype, None]):
class_type = Prototype


class HostProvider(Deletable, InteractiveObject):
# data-based properties

Expand All @@ -181,6 +137,10 @@ def name(self: Self) -> str:
def description(self: Self) -> str:
return str(self._data["description"])

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

@property
def is_upgradable(self: Self) -> str:
return str(self._data["isUpgradable"])
Expand All @@ -192,6 +152,6 @@ def main_info(self: Self) -> str:
def get_own_path(self: Self) -> Endpoint:
return "hostproviders", self.id

@cached_property
def prototype(self: Self) -> "PrototypeNode":
return PrototypeNode(parent=self, path=(*self.get_own_path(), "prototypes"), requester=self._requester)

class HostprovidersNode(PaginatedAccessor[HostProvider, None]):
class_type = HostProvider

0 comments on commit 06eeceb

Please sign in to comment.