Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions linode_api4/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ""
3 changes: 2 additions & 1 deletion linode_api4/objects/nodebalancer.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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(),
}
Expand Down
7 changes: 7 additions & 0 deletions test/fixtures/nodebalancers.json
Original file line number Diff line number Diff line change
Expand Up @@ -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
},
Expand All @@ -29,6 +35,7 @@
"tags": [],
"locks": [],
"type": "premium_40gb",
"lke_cluster": null,
"frontend_address_type": "vpc",
"frontend_vpc_subnet_id": 6666
}
Expand Down
6 changes: 6 additions & 0 deletions test/fixtures/nodebalancers_123456.json
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
11 changes: 10 additions & 1 deletion test/unit/objects/nodebalancers_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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)

Expand All @@ -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)

Expand Down
Loading