From 391c4e7551f0de2e29a3d1a4fcbc03bcdfec6f62 Mon Sep 17 00:00:00 2001 From: Lena Garber Date: Wed, 15 Jan 2025 15:31:24 -0500 Subject: [PATCH] Add APL-related fields --- linode_api4/groups/lke.py | 11 +++++++++-- linode_api4/objects/lke.py | 31 +++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 2 deletions(-) diff --git a/linode_api4/groups/lke.py b/linode_api4/groups/lke.py index d0de66f3..af539711 100644 --- a/linode_api4/groups/lke.py +++ b/linode_api4/groups/lke.py @@ -66,6 +66,7 @@ def cluster_create( control_plane: Union[ LKEClusterControlPlaneOptions, Dict[str, Any] ] = None, + apl_enabled: bool = False, **kwargs, ): """ @@ -100,8 +101,10 @@ def cluster_create( formatted dicts. :param kube_version: The version of Kubernetes to use :type kube_version: KubeVersion or str - :param control_plane: Dict[str, Any] or LKEClusterControlPlaneRequest - :type control_plane: The control plane configuration of this LKE cluster. + :param control_plane: The control plane configuration of this LKE cluster. + :type control_plane: Dict[str, Any] or LKEClusterControlPlaneRequest + :param apl_enabled: Whether this cluster should use APL. + :type apl_enabled: bool :param kwargs: Any other arguments to pass along to the API. See the API docs for possible values. @@ -120,6 +123,10 @@ def cluster_create( } params.update(kwargs) + # Prevent errors for users without access to APL + if apl_enabled: + params["apl_enabled"] = apl_enabled + result = self.client.post( "/lke/clusters", data=_flatten_request_body_recursive(drop_null_keys(params)), diff --git a/linode_api4/objects/lke.py b/linode_api4/objects/lke.py index 7ff6b0fd..bdea1c1c 100644 --- a/linode_api4/objects/lke.py +++ b/linode_api4/objects/lke.py @@ -257,6 +257,7 @@ class LKECluster(Base): "k8s_version": Property(slug_relationship=KubeVersion, mutable=True), "pools": Property(derived_class=LKENodePool), "control_plane": Property(mutable=True), + "apl_enabled": Property(mutable=True), } def invalidate(self): @@ -353,6 +354,36 @@ def control_plane_acl(self) -> LKEClusterControlPlaneACL: return LKEClusterControlPlaneACL.from_json(self._control_plane_acl) + @property + def apl_console_url(self) -> Optional[str]: + """ + Returns the URL of this cluster's APL installation if this cluster + is APL-enabled, else None. + + :returns: The URL of the APL console for this cluster. + :rtype: str or None + """ + + if not self.apl_enabled: + return None + + return f"https://console.lke{self.id}.akamai-apl.net" + + @property + def apl_health_check_url(self) -> Optional[str]: + """ + Returns the URL of this cluster's APL health check endpoint if this cluster + is APL-enabled, else None. + + :returns: The URL of the APL console for this cluster. + :rtype: str or None + """ + + if not self.apl_enabled: + return None + + return f"https://auth.lke{self.id}.akamai-apl.net/ready" + def node_pool_create( self, node_type: Union[Type, str],