From ac2b24941e53a35057aca4d165ed8ea0d7a80c1d Mon Sep 17 00:00:00 2001 From: Tomasz Paluszkiewicz Date: Wed, 15 Jun 2022 01:09:37 +0200 Subject: [PATCH 1/6] feat: add TLD endpoints Add the TLD endpoints to list all endpoints and retrieve a single endpoint by name. --- transip/__init__.py | 3 +++ transip/v6/objects.py | 14 ++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/transip/__init__.py b/transip/__init__.py index 57d808a..08eaca5 100644 --- a/transip/__init__.py +++ b/transip/__init__.py @@ -115,6 +115,9 @@ def __init__( self.colocations: Type['ApiService'] = ( objects.ColocationService(self) # type: ignore ) + self.tlds: Type['ApiService'] = ( + objects.TldService(self) # type: ignore + ) @property def url(self) -> str: diff --git a/transip/v6/objects.py b/transip/v6/objects.py index 467de04..263b252 100644 --- a/transip/v6/objects.py +++ b/transip/v6/objects.py @@ -373,6 +373,20 @@ class DomainService(CreateMixin, GetMixin, DeleteMixin, ListMixin, ApiService): ("domainName",), # required ("contacts", "nameservers", "dnsEntries") # optional ) + + +class Tld(ApiObject): + + _id_attr: str = "name" + + +class TldService(GetMixin, ListMixin, ApiService): + + _path: str = "/tlds" + _obj_cls: Optional[Type[ApiObject]] = Tld + + _resp_list_attr: str = "tlds" + _resp_get_attr: str = "tld" class InvoiceItem(ApiObject): From 4c7202839fe2fc9ac9af8af171143989f6d78843 Mon Sep 17 00:00:00 2001 From: Tomasz Paluszkiewicz Date: Sun, 19 Jun 2022 23:57:06 +0200 Subject: [PATCH 2/6] feat: add listing active vps addons --- transip/v6/objects.py | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/transip/v6/objects.py b/transip/v6/objects.py index 263b252..ebe5b44 100644 --- a/transip/v6/objects.py +++ b/transip/v6/objects.py @@ -462,9 +462,31 @@ class InvoiceService(GetMixin, ListMixin, ApiService): _resp_get_attr: str = "invoice" +class VpsAddon(ApiObject): + + _id_attr: str = "name" + + +class VpsAddonService(ListMixin, ApiService): + """Service to manage addons of a VPS.""" + + _path: str = "/vps/{parent_id}/addons" + _obj_cls: Optional[Type[ApiObject]] = VpsAddon + + _resp_list_attr: str = "active" # or cancellable or available? + + class Vps(ApiObject): _id_attr: str = "name" + + @property + def addons(self) -> VpsAddonService: + """Return the service to manage the addons of the VPS.""" + return VpsAddonService( + self.service.client, + parent=self # type: ignore + ) class VpsService(GetMixin, DeleteMixin, ListMixin, ApiService): @@ -474,8 +496,8 @@ class VpsService(GetMixin, DeleteMixin, ListMixin, ApiService): _resp_list_attr: str = "vpss" _resp_get_attr: str = "vps" - - + + class Colocation(ApiObject): _id_attr: str = "name" From 029ec14b704a130c158fb23bcee5e95588ab69bb Mon Sep 17 00:00:00 2001 From: Tomasz Paluszkiewicz Date: Mon, 20 Jun 2022 00:10:29 +0200 Subject: [PATCH 3/6] fix: vps addons --- transip/v6/objects.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/transip/v6/objects.py b/transip/v6/objects.py index ebe5b44..ab18cff 100644 --- a/transip/v6/objects.py +++ b/transip/v6/objects.py @@ -473,7 +473,7 @@ class VpsAddonService(ListMixin, ApiService): _path: str = "/vps/{parent_id}/addons" _obj_cls: Optional[Type[ApiObject]] = VpsAddon - _resp_list_attr: str = "active" # or cancellable or available? + _resp_list_attr: str = "addons" # or cancellable or available? class Vps(ApiObject): From 080bdff9abbe7258ef5e54e640a864da308770d5 Mon Sep 17 00:00:00 2001 From: Tomasz Paluszkiewicz Date: Mon, 20 Jun 2022 09:15:27 +0200 Subject: [PATCH 4/6] snapshot --- transip/v6/objects.py | 59 ++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 55 insertions(+), 4 deletions(-) diff --git a/transip/v6/objects.py b/transip/v6/objects.py index ab18cff..04fb2e9 100644 --- a/transip/v6/objects.py +++ b/transip/v6/objects.py @@ -473,17 +473,68 @@ class VpsAddonService(ListMixin, ApiService): _path: str = "/vps/{parent_id}/addons" _obj_cls: Optional[Type[ApiObject]] = VpsAddon - _resp_list_attr: str = "addons" # or cancellable or available? + _resp_list_attr: str = "addons" + + def list(self) -> List[Type[ApiObject]]: + """ + Retrieve a list of addons. + Overwrites the default list() method of the ListMixin as the addons + are stored in further down in the result dictionary. + """ + objs: List[Type[ApiObject]] = [] + data = self.client.get(self.path)[self._resp_list_attr] + # Loop over the individual product lists of all product categories, + # e.g. vps, haip + for obj_list in data.values(): + for obj in obj_list: + objs.append(self._obj_cls(self, obj)) # type: ignore + return objs + + +class VpsLicense(ApiObject): + + _id_attr: str = "name" +class VpsLicenseService(ListMixin, ApiService): + """Service to manage licenses of a VPS.""" + + _path: str = "/vps/{parent_id}/licenses" + _obj_cls: Optional[Type[ApiObject]] = VpsLicense + + _resp_list_attr: str = "licenses" + + def list(self) -> List[Type[ApiObject]]: + """ + Retrieve a list of licenses. + Overwrites the default list() method of the ListMixin as the licenses + are stored in further down in the result dictionary. + """ + objs: List[Type[ApiObject]] = [] + data = self.client.get(self.path)[self._resp_list_attr] + # Loop over the individual product lists of all product categories, + # e.g. vps, haip + for obj_list in data.values(): + for obj in obj_list: + objs.append(self._obj_cls(self, obj)) # type: ignore + return objs + class Vps(ApiObject): _id_attr: str = "name" + # @property + # def addons(self) -> VpsAddonService: + # """Return the service to manage the addons of the VPS.""" + # return VpsAddonService( + # self.service.client, + # parent=self # type: ignore + # ) + @property - def addons(self) -> VpsAddonService: - """Return the service to manage the addons of the VPS.""" - return VpsAddonService( + def licenses(self) -> VpsLicenseService: + """Return the service to manage the licenses of the VPS.""" + return VpsLicenseService( self.service.client, parent=self # type: ignore ) From 3eab90da71e05f73121e0d84278f18793a634156 Mon Sep 17 00:00:00 2001 From: Tomasz Paluszkiewicz Date: Tue, 21 Jun 2022 22:46:48 +0200 Subject: [PATCH 5/6] snapshot --- transip/v6/objects.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/transip/v6/objects.py b/transip/v6/objects.py index 04fb2e9..98d29e1 100644 --- a/transip/v6/objects.py +++ b/transip/v6/objects.py @@ -523,13 +523,13 @@ class Vps(ApiObject): _id_attr: str = "name" - # @property - # def addons(self) -> VpsAddonService: - # """Return the service to manage the addons of the VPS.""" - # return VpsAddonService( - # self.service.client, - # parent=self # type: ignore - # ) + @property + def addons(self) -> VpsAddonService: + """Return the service to manage the addons of the VPS.""" + return VpsAddonService( + self.service.client, + parent=self # type: ignore + ) @property def licenses(self) -> VpsLicenseService: From 08bdd3525355c6c6711e2e9864ac0d6984867070 Mon Sep 17 00:00:00 2001 From: Tomasz Paluszkiewicz Date: Fri, 24 Jun 2022 08:54:12 +0200 Subject: [PATCH 6/6] snapshot --- transip/v6/objects.py | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/transip/v6/objects.py b/transip/v6/objects.py index 98d29e1..b077dfb 100644 --- a/transip/v6/objects.py +++ b/transip/v6/objects.py @@ -475,7 +475,7 @@ class VpsAddonService(ListMixin, ApiService): _resp_list_attr: str = "addons" - def list(self) -> List[Type[ApiObject]]: + def list(self, needle: Optional[str] = None) -> List[Type[ApiObject]]: """ Retrieve a list of addons. Overwrites the default list() method of the ListMixin as the addons @@ -483,8 +483,14 @@ def list(self) -> List[Type[ApiObject]]: """ objs: List[Type[ApiObject]] = [] data = self.client.get(self.path)[self._resp_list_attr] + haystack = [] # Loop over the individual product lists of all product categories, # e.g. vps, haip + if needle is None: + haystack = data.values() + else: + haystack.append(data[needle]) + for obj_list in data.values(): for obj in obj_list: objs.append(self._obj_cls(self, obj)) # type: ignore @@ -504,7 +510,7 @@ class VpsLicenseService(ListMixin, ApiService): _resp_list_attr: str = "licenses" - def list(self) -> List[Type[ApiObject]]: + def list(self, needle: Optional[str] = None) -> List[Type[ApiObject]]: """ Retrieve a list of licenses. Overwrites the default list() method of the ListMixin as the licenses @@ -512,9 +518,15 @@ def list(self) -> List[Type[ApiObject]]: """ objs: List[Type[ApiObject]] = [] data = self.client.get(self.path)[self._resp_list_attr] + haystack = [] # Loop over the individual product lists of all product categories, # e.g. vps, haip - for obj_list in data.values(): + if needle is None: + haystack = data.values() + else: + haystack.append(data[needle]) + + for obj_list in haystack: for obj in obj_list: objs.append(self._obj_cls(self, obj)) # type: ignore return objs