Skip to content

Commit 8d042be

Browse files
VPC Dual Stack: Support changes related to Linode Interfaces (#559)
* Implementation; needs tests * Add integration tests
1 parent 980affb commit 8d042be

File tree

5 files changed

+143
-1
lines changed

5 files changed

+143
-1
lines changed

linode_api4/objects/linode_interfaces.py

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,41 @@ class LinodeInterfaceVPCIPv4Options(JSONObject):
104104
ranges: Optional[List[LinodeInterfaceVPCIPv4RangeOptions]] = None
105105

106106

107+
@dataclass
108+
class LinodeInterfaceVPCIPv6SLAACOptions(JSONObject):
109+
"""
110+
Options accepted for a single SLAAC when creating or updating the IPv6 configuration of a VPC Linode Interface.
111+
112+
NOTE: Linode interfaces may not currently be available to all users.
113+
"""
114+
115+
range: Optional[str] = None
116+
117+
118+
@dataclass
119+
class LinodeInterfaceVPCIPv6RangeOptions(JSONObject):
120+
"""
121+
Options accepted for a single range when creating or updating the IPv6 configuration of a VPC Linode Interface.
122+
123+
NOTE: Linode interfaces may not currently be available to all users.
124+
"""
125+
126+
range: Optional[str] = None
127+
128+
129+
@dataclass
130+
class LinodeInterfaceVPCIPv6Options(JSONObject):
131+
"""
132+
Options accepted when creating or updating the IPv6 configuration of a VPC Linode Interface.
133+
134+
NOTE: Linode interfaces may not currently be available to all users.
135+
"""
136+
137+
is_public: Optional[bool] = None
138+
slaac: Optional[List[LinodeInterfaceVPCIPv6SLAACOptions]] = None
139+
ranges: Optional[List[LinodeInterfaceVPCIPv6RangeOptions]] = None
140+
141+
107142
@dataclass
108143
class LinodeInterfaceVPCOptions(JSONObject):
109144
"""
@@ -114,6 +149,7 @@ class LinodeInterfaceVPCOptions(JSONObject):
114149

115150
subnet_id: int = 0
116151
ipv4: Optional[LinodeInterfaceVPCIPv4Options] = None
152+
ipv6: Optional[LinodeInterfaceVPCIPv6Options] = None
117153

118154

119155
@dataclass
@@ -265,6 +301,44 @@ class LinodeInterfaceVPCIPv4(JSONObject):
265301
ranges: List[LinodeInterfaceVPCIPv4Range] = field(default_factory=list)
266302

267303

304+
@dataclass
305+
class LinodeInterfaceVPCIPv6SLAAC(JSONObject):
306+
"""
307+
A single SLAAC entry under the IPv6 configuration of a VPC Linode Interface.
308+
309+
NOTE: Linode interfaces may not currently be available to all users.
310+
"""
311+
312+
range: str = ""
313+
address: str = ""
314+
315+
316+
@dataclass
317+
class LinodeInterfaceVPCIPv6Range(JSONObject):
318+
"""
319+
A single range under the IPv6 configuration of a VPC Linode Interface.
320+
321+
NOTE: Linode interfaces may not currently be available to all users.
322+
"""
323+
324+
range: str = ""
325+
326+
327+
@dataclass
328+
class LinodeInterfaceVPCIPv6(JSONObject):
329+
"""
330+
A single address under the IPv6 configuration of a VPC Linode Interface.
331+
332+
NOTE: Linode interfaces may not currently be available to all users.
333+
"""
334+
335+
put_class = LinodeInterfaceVPCIPv6Options
336+
337+
is_public: bool = False
338+
slaac: List[LinodeInterfaceVPCIPv6SLAAC] = field(default_factory=list)
339+
ranges: List[LinodeInterfaceVPCIPv6Range] = field(default_factory=list)
340+
341+
268342
@dataclass
269343
class LinodeInterfaceVPC(JSONObject):
270344
"""
@@ -279,6 +353,7 @@ class LinodeInterfaceVPC(JSONObject):
279353
subnet_id: int = 0
280354

281355
ipv4: Optional[LinodeInterfaceVPCIPv4] = None
356+
ipv6: Optional[LinodeInterfaceVPCIPv6] = None
282357

283358

284359
@dataclass

test/fixtures/linode_instances_124_interfaces.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,20 @@
8080
"range": "192.168.22.32/28"
8181
}
8282
]
83+
},
84+
"ipv6": {
85+
"is_public": true,
86+
"slaac": [
87+
{
88+
"range": "1234::/64",
89+
"address": "1234::5678"
90+
}
91+
],
92+
"ranges": [
93+
{
94+
"range": "4321::/64"
95+
}
96+
]
8397
}
8498
},
8599
"public": null,

test/fixtures/linode_instances_124_interfaces_456.json

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"vpc": {
1111
"vpc_id": 123456,
1212
"subnet_id": 789,
13-
"ipv4" : {
13+
"ipv4": {
1414
"addresses": [
1515
{
1616
"address": "192.168.22.3",
@@ -21,6 +21,20 @@
2121
{ "range": "192.168.22.16/28"},
2222
{ "range": "192.168.22.32/28"}
2323
]
24+
},
25+
"ipv6": {
26+
"is_public": true,
27+
"slaac": [
28+
{
29+
"range": "1234::/64",
30+
"address": "1234::5678"
31+
}
32+
],
33+
"ranges": [
34+
{
35+
"range": "4321::/64"
36+
}
37+
]
2438
}
2539
},
2640
"public": null,

test/fixtures/linode_instances_124_upgrade-interfaces.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,20 @@
8282
"range": "192.168.22.32/28"
8383
}
8484
]
85+
},
86+
"ipv6": {
87+
"is_public": true,
88+
"slaac": [
89+
{
90+
"range": "1234::/64",
91+
"address": "1234::5678"
92+
}
93+
],
94+
"ranges": [
95+
{
96+
"range": "4321::/64"
97+
}
98+
]
8599
}
86100
},
87101
"public": null,

test/unit/objects/linode_interface_test.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
LinodeInterfaceVPCIPv4AddressOptions,
1515
LinodeInterfaceVPCIPv4Options,
1616
LinodeInterfaceVPCIPv4RangeOptions,
17+
LinodeInterfaceVPCIPv6SLAACOptions,
1718
LinodeInterfaceVPCOptions,
1819
)
1920

@@ -149,6 +150,13 @@ def assert_linode_124_interface_456(iface: LinodeInterface):
149150
assert iface.vpc.ipv4.ranges[0].range == "192.168.22.16/28"
150151
assert iface.vpc.ipv4.ranges[1].range == "192.168.22.32/28"
151152

153+
assert iface.vpc.ipv6.is_public
154+
155+
assert iface.vpc.ipv6.slaac[0].range == "1234::/64"
156+
assert iface.vpc.ipv6.slaac[0].address == "1234::5678"
157+
158+
assert iface.vpc.ipv6.ranges[0].range == "4321::/64"
159+
152160
@staticmethod
153161
def assert_linode_124_interface_789(iface: LinodeInterface):
154162
assert iface.id == 789
@@ -261,6 +269,18 @@ def test_update_vpc(self):
261269
)
262270
]
263271

272+
iface.vpc.ipv6.is_public = False
273+
274+
iface.vpc.ipv6.slaac = [
275+
LinodeInterfaceVPCIPv6SLAACOptions(
276+
range="1233::/64",
277+
)
278+
]
279+
280+
iface.vpc.ipv6.ranges = [
281+
LinodeInterfacePublicIPv6RangeOptions(range="9876::/64")
282+
]
283+
264284
with self.mock_put("/linode/instances/124/interfaces/456") as m:
265285
iface.save()
266286

@@ -282,6 +302,11 @@ def test_update_vpc(self):
282302
],
283303
"ranges": [{"range": "192.168.22.17/28"}],
284304
},
305+
"ipv6": {
306+
"is_public": False,
307+
"slaac": [{"range": "1233::/64"}],
308+
"ranges": [{"range": "9876::/64"}],
309+
},
285310
},
286311
}
287312

0 commit comments

Comments
 (0)