From 0477caec6af762d251d80ed0016e53d7ec517e5b Mon Sep 17 00:00:00 2001 From: astarovo Date: Tue, 26 Nov 2024 02:50:58 +0300 Subject: [PATCH 1/6] ADCM-6138: Implement Bundle object --- adcm_aio_client/core/client.py | 11 ++++-- adcm_aio_client/core/objects/cm.py | 55 ++++++++++++++++++++++++++---- 2 files changed, 57 insertions(+), 9 deletions(-) diff --git a/adcm_aio_client/core/client.py b/adcm_aio_client/core/client.py index e9a538f..2ec2239 100644 --- a/adcm_aio_client/core/client.py +++ b/adcm_aio_client/core/client.py @@ -13,9 +13,10 @@ 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, ClustersNode, HostProvidersNode +from adcm_aio_client.core.objects.cm import HostsAccessor +from adcm_aio_client.core.requesters import Requester +from adcm_aio_client.core.types import AuthToken, Cert, Credentials, Verify class ADCMClient: @@ -38,6 +39,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=(), requester=self._requester) + async def build_client( url: str, diff --git a/adcm_aio_client/core/objects/cm.py b/adcm_aio_client/core/objects/cm.py index 656835a..37d57b7 100644 --- a/adcm_aio_client/core/objects/cm.py +++ b/adcm_aio_client/core/objects/cm.py @@ -1,6 +1,9 @@ -from functools import cached_property -from typing import Iterable, Self import asyncio +from functools import cached_property +from typing import Iterable +from typing import Literal, Self + +from asyncstdlib.functools import CachedProperty as async_cached_property from asyncstdlib.functools import cached_property as async_cached_property @@ -41,7 +44,50 @@ 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"] + + @async_cached_property + async def license(self: Self) -> License: + response = await self._requester.get(*self.get_own_path()) + return self._construct(what=License, from_data=response.as_dict()["mainPrototype"]["license"]) + + def get_own_path(self: Self) -> Endpoint: + return self.PATH_PREFIX, self.id + + +class BundlesNode(PaginatedAccessor): + class_type = Bundle + + def get_own_path(self: Self) -> Endpoint: + return ("bundles",) class Cluster( @@ -112,9 +158,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, From c11b62d70a62c913079f7651e49f8a763645a23f Mon Sep 17 00:00:00 2001 From: astarovo Date: Wed, 27 Nov 2024 11:36:04 +0300 Subject: [PATCH 2/6] ADCM-6138: Implement Bundle object --- adcm_aio_client/core/client.py | 5 ++--- adcm_aio_client/core/objects/cm.py | 7 +++---- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/adcm_aio_client/core/client.py b/adcm_aio_client/core/client.py index 2ec2239..3439db8 100644 --- a/adcm_aio_client/core/client.py +++ b/adcm_aio_client/core/client.py @@ -13,9 +13,8 @@ from functools import cached_property from typing import Self -from adcm_aio_client.core.objects.cm import ADCM, ClustersNode, HostProvidersNode -from adcm_aio_client.core.objects.cm import HostsAccessor -from adcm_aio_client.core.requesters import Requester +from adcm_aio_client.core.objects.cm import ADCM, BundlesNode, ClustersNode, HostProvidersNode, HostsAccessor +from adcm_aio_client.core.requesters import Requester, DefaultRequester from adcm_aio_client.core.types import AuthToken, Cert, Credentials, Verify diff --git a/adcm_aio_client/core/objects/cm.py b/adcm_aio_client/core/objects/cm.py index 37d57b7..0aca2c1 100644 --- a/adcm_aio_client/core/objects/cm.py +++ b/adcm_aio_client/core/objects/cm.py @@ -1,9 +1,8 @@ -import asyncio from functools import cached_property -from typing import Iterable -from typing import Literal, Self +from typing import Iterable, Literal, Self +import asyncio -from asyncstdlib.functools import CachedProperty as async_cached_property +from asyncstdlib.functools import CachedProperty as async_cached_property # noqa: N813 from asyncstdlib.functools import cached_property as async_cached_property From 030f846a40ef4a6679744e48f54c8eb0ecf08ec3 Mon Sep 17 00:00:00 2001 From: astarovo Date: Wed, 27 Nov 2024 14:59:10 +0300 Subject: [PATCH 3/6] ADCM-6138: Implement Bundle object --- adcm_aio_client/core/objects/cm.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/adcm_aio_client/core/objects/cm.py b/adcm_aio_client/core/objects/cm.py index 0aca2c1..714b2ee 100644 --- a/adcm_aio_client/core/objects/cm.py +++ b/adcm_aio_client/core/objects/cm.py @@ -4,8 +4,6 @@ from asyncstdlib.functools import CachedProperty as async_cached_property # noqa: N813 -from asyncstdlib.functools import cached_property as async_cached_property - from adcm_aio_client.core.errors import NotFoundError, OperationError, ResponseError from adcm_aio_client.core.objects._accessors import ( PaginatedAccessor, From 115be0fe52e6bf670d72a9cd9477d1916a215e55 Mon Sep 17 00:00:00 2001 From: astarovo Date: Wed, 27 Nov 2024 16:20:55 +0300 Subject: [PATCH 4/6] ADCM-6138: Implement Bundle object --- adcm_aio_client/core/client.py | 2 +- adcm_aio_client/core/objects/cm.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/adcm_aio_client/core/client.py b/adcm_aio_client/core/client.py index 3439db8..930e475 100644 --- a/adcm_aio_client/core/client.py +++ b/adcm_aio_client/core/client.py @@ -40,7 +40,7 @@ def adcm(self: Self) -> ADCM: @cached_property def bundles(self: Self) -> BundlesNode: - return BundlesNode(path=(), requester=self._requester) + return BundlesNode(path=("bundles",), requester=self._requester) async def build_client( diff --git a/adcm_aio_client/core/objects/cm.py b/adcm_aio_client/core/objects/cm.py index 714b2ee..a2246cb 100644 --- a/adcm_aio_client/core/objects/cm.py +++ b/adcm_aio_client/core/objects/cm.py @@ -2,7 +2,7 @@ from typing import Iterable, Literal, Self import asyncio -from asyncstdlib.functools import CachedProperty as async_cached_property # noqa: N813 +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 ( @@ -80,7 +80,7 @@ def get_own_path(self: Self) -> Endpoint: return self.PATH_PREFIX, self.id -class BundlesNode(PaginatedAccessor): +class BundlesNode(PaginatedAccessor[Bundle, None]): class_type = Bundle def get_own_path(self: Self) -> Endpoint: From 124fcdaa4bb1c826ecde02e9b812da9cbffbd624 Mon Sep 17 00:00:00 2001 From: astarovo Date: Fri, 29 Nov 2024 12:27:38 +0300 Subject: [PATCH 5/6] ADCM-6138: Implement Bundle object --- adcm_aio_client/core/objects/cm.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/adcm_aio_client/core/objects/cm.py b/adcm_aio_client/core/objects/cm.py index a2246cb..337c88b 100644 --- a/adcm_aio_client/core/objects/cm.py +++ b/adcm_aio_client/core/objects/cm.py @@ -71,10 +71,8 @@ def signature_status(self: Self) -> Literal["invalid", "valid", "absent"]: def _type(self: Self) -> Literal["cluster", "provider"]: return self._data["mainPrototype"]["type"] - @async_cached_property - async def license(self: Self) -> License: - response = await self._requester.get(*self.get_own_path()) - return self._construct(what=License, from_data=response.as_dict()["mainPrototype"]["license"]) + 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 From 7767d460ff1992403a0981fea5aeae0f862af069 Mon Sep 17 00:00:00 2001 From: astarovo Date: Fri, 29 Nov 2024 12:38:06 +0300 Subject: [PATCH 6/6] ADCM-6138: Implement Bundle object --- adcm_aio_client/core/client.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/adcm_aio_client/core/client.py b/adcm_aio_client/core/client.py index 930e475..b26254b 100644 --- a/adcm_aio_client/core/client.py +++ b/adcm_aio_client/core/client.py @@ -14,7 +14,7 @@ from typing import Self from adcm_aio_client.core.objects.cm import ADCM, BundlesNode, ClustersNode, HostProvidersNode, HostsAccessor -from adcm_aio_client.core.requesters import Requester, DefaultRequester +from adcm_aio_client.core.requesters import DefaultRequester, Requester from adcm_aio_client.core.types import AuthToken, Cert, Credentials, Verify