Skip to content

Commit c5b970d

Browse files
Add interfaces settings GET
1 parent 4148907 commit c5b970d

File tree

5 files changed

+45
-5
lines changed

5 files changed

+45
-5
lines changed

linode_api4/objects/linode.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -707,7 +707,6 @@ class Instance(Base):
707707
"disk_encryption": Property(),
708708
"lke_cluster_id": Property(),
709709
"capabilities": Property(unordered=True),
710-
"interfaces_settings": Property(relationship=LinodeInterfacesSettings),
711710
}
712711

713712
@property
@@ -1903,6 +1902,25 @@ def interface_create(
19031902

19041903
return LinodeInterface(self._client, result["id"], self.id, json=result)
19051904

1905+
@property
1906+
def interfaces_settings(self):
1907+
# NOTE: We do not implement this as a Property because Property does
1908+
# not currently have a mechanism for 1:1 sub-entities.
1909+
result = self._client.get(
1910+
"{}/interfaces/settings".format(Instance.api_endpoint), model=self
1911+
)
1912+
1913+
if not "network_helper" in result:
1914+
raise UnexpectedResponseError(
1915+
"Unexpected response when getting settings for Linode interfaces!",
1916+
json=result,
1917+
)
1918+
1919+
# TODO (Enhanced Interfaces): Error handling for Linodes using legacy interfaces?
1920+
1921+
s = LinodeInterfacesSettings(self._client, self.id, result)
1922+
return s
1923+
19061924
@property
19071925
def interfaces(self):
19081926
if not hasattr(self, "_interfaces"):

linode_api4/objects/linode_interfaces.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@ class LinodeInterfacesSettingsDefaultRoute(JSONObject):
2424

2525

2626
class LinodeInterfacesSettings(Base):
27-
api_endpoint = "/linode/instances/{linode_id}/interfaces/settings"
27+
api_endpoint = "/linode/instances/{id}/interfaces/settings"
2828

2929
properties = {
30-
"linode_id": Property(identifier=True),
30+
"id": Property(identifier=True),
3131
"network_helper": Property(mutable=True),
3232
"default_route": Property(
3333
mutable=True, json_object=LinodeInterfacesSettingsDefaultRoute

test/fixtures/linode_instances_124_interfaces_settings.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22
"network_helper": true,
33
"default_route": {
44
"ipv4_interface_id": 123,
5-
"ipv4_eligable_interface_ids": [
5+
"ipv4_eligible_interface_ids": [
66
123,
77
456,
88
789
99
],
1010
"ipv6_interface_id": 456,
11-
"ipv6_eligable_interface_ids": [
11+
"ipv6_eligible_interface_ids": [
1212
123,
1313
456
1414
]

test/unit/objects/linode_interface_test.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,3 +119,5 @@ def test_get_vlan(self):
119119
self.assert_linode_124_interface_789(iface)
120120
iface.invalidate()
121121
self.assert_linode_124_interface_789(iface)
122+
123+
# TODO (Enhanced Interfaces): iface update tests

test/unit/objects/linode_test.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -485,6 +485,26 @@ def test_get_interfaces(self):
485485
next(iface for iface in interfaces if iface.id == 789)
486486
)
487487

488+
def test_get_interfaces_settings(self):
489+
instance = Instance(self.client, 124)
490+
491+
iface_settings = instance.interfaces_settings
492+
493+
assert iface_settings.network_helper
494+
495+
assert iface_settings.default_route.ipv4_interface_id == 123
496+
assert iface_settings.default_route.ipv4_eligible_interface_ids == [
497+
123,
498+
456,
499+
789,
500+
]
501+
502+
assert iface_settings.default_route.ipv6_interface_id == 456
503+
assert iface_settings.default_route.ipv6_eligible_interface_ids == [
504+
123,
505+
456,
506+
]
507+
488508

489509
class DiskTest(ClientBaseCase):
490510
"""

0 commit comments

Comments
 (0)