diff --git a/linode_api4/common.py b/linode_api4/common.py index 7e98b1977..a093930b6 100644 --- a/linode_api4/common.py +++ b/linode_api4/common.py @@ -81,3 +81,15 @@ class RegionPrice(JSONObject): id: int = 0 hourly: int = 0 monthly: int = 0 + + +@dataclass +class LKECluster(JSONObject): + """ + LKECluster contains the core fields of a lke_cluster object returned by various node balancer endpoints. + """ + + id: int = 0 + label: str = "" + type: str = "" + url: str = "" diff --git a/linode_api4/objects/nodebalancer.py b/linode_api4/objects/nodebalancer.py index bae9621ff..31d0f1a4d 100644 --- a/linode_api4/objects/nodebalancer.py +++ b/linode_api4/objects/nodebalancer.py @@ -1,7 +1,7 @@ import os from urllib import parse -from linode_api4.common import Price, RegionPrice +from linode_api4.common import LKECluster, Price, RegionPrice from linode_api4.errors import UnexpectedResponseError from linode_api4.objects.base import Base, MappedObject, Property from linode_api4.objects.dbase import DerivedBase @@ -276,6 +276,7 @@ class NodeBalancer(Base): "client_udp_sess_throttle": Property(mutable=True), "locks": Property(unordered=True), "type": Property(), + "lke_cluster": Property(json_object=LKECluster), "frontend_address_type": Property(), "frontend_vpc_subnet_id": Property(), } diff --git a/test/fixtures/nodebalancers.json b/test/fixtures/nodebalancers.json index 2ccbed4b1..aef3c473f 100644 --- a/test/fixtures/nodebalancers.json +++ b/test/fixtures/nodebalancers.json @@ -13,6 +13,12 @@ "tags": ["something"], "locks": ["cannot_delete_with_subresources"], "type": "common", + "lke_cluster": { + "id": 1234, + "type": "lkecluster", + "label": "test-cluster", + "url": "/v4/lke/clusters/1234" + }, "frontend_address_type": "vpc", "frontend_vpc_subnet_id": 5555 }, @@ -29,6 +35,7 @@ "tags": [], "locks": [], "type": "premium_40gb", + "lke_cluster": null, "frontend_address_type": "vpc", "frontend_vpc_subnet_id": 6666 } diff --git a/test/fixtures/nodebalancers_123456.json b/test/fixtures/nodebalancers_123456.json index d6d66233c..a78f1eccf 100644 --- a/test/fixtures/nodebalancers_123456.json +++ b/test/fixtures/nodebalancers_123456.json @@ -15,6 +15,12 @@ "cannot_delete_with_subresources" ], "type": "common", + "lke_cluster": { + "id": 1234, + "type": "lkecluster", + "label": "test-cluster", + "url": "/v4/lke/clusters/1234" + }, "frontend_address_type": "vpc", "frontend_vpc_subnet_id": 5555 } \ No newline at end of file diff --git a/test/unit/objects/nodebalancers_test.py b/test/unit/objects/nodebalancers_test.py index 2eae14664..b6ff86f37 100644 --- a/test/unit/objects/nodebalancers_test.py +++ b/test/unit/objects/nodebalancers_test.py @@ -208,7 +208,7 @@ def test_firewalls(self): def test_config_rebuild(self): """ - Test that you can rebuild the cofig of a node balancer. + Test that you can rebuild the config of a node balancer. """ config_rebuild_url = "/nodebalancers/12345/configs/4567/rebuild" with self.mock_post(config_rebuild_url) as m: @@ -279,12 +279,17 @@ def test_list_nodebalancers(self): self.assertEqual(nbs[0].id, 123456) self.assertEqual(nbs[0].label, "balancer123456") self.assertEqual(nbs[0].type, "common") + self.assertEqual(nbs[0].lke_cluster.id, 1234) + self.assertEqual(nbs[0].lke_cluster.type, "lkecluster") + self.assertEqual(nbs[0].lke_cluster.label, "test-cluster") + self.assertEqual(nbs[0].lke_cluster.url, "/v4/lke/clusters/1234") self.assertEqual(nbs[0].frontend_address_type, "vpc") self.assertEqual(nbs[0].frontend_vpc_subnet_id, 5555) self.assertEqual(nbs[1].id, 123457) self.assertEqual(nbs[1].label, "balancer123457") self.assertEqual(nbs[1].type, "premium_40gb") + self.assertEqual(nbs[1].lke_cluster, None) self.assertEqual(nbs[1].frontend_address_type, "vpc") self.assertEqual(nbs[1].frontend_vpc_subnet_id, 6666) @@ -297,6 +302,10 @@ def test_get_nodebalancer(self): self.assertEqual(nb.id, 123456) self.assertEqual(nb.label, "balancer123456") self.assertEqual(nb.type, "common") + self.assertEqual(nb.lke_cluster.id, 1234) + self.assertEqual(nb.lke_cluster.type, "lkecluster") + self.assertEqual(nb.lke_cluster.label, "test-cluster") + self.assertEqual(nb.lke_cluster.url, "/v4/lke/clusters/1234") self.assertEqual(nb.frontend_address_type, "vpc") self.assertEqual(nb.frontend_vpc_subnet_id, 5555)