Skip to content

Commit 4b06a7c

Browse files
pls
1 parent 73d985c commit 4b06a7c

File tree

4 files changed

+68
-92
lines changed

4 files changed

+68
-92
lines changed

linode_api4/objects/linode.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -681,7 +681,9 @@ class UpgradeInterfacesResult(JSONObject):
681681

682682
dry_run: bool = False
683683
config_id: int = 0
684-
interfaces: List[Union[Dict[str, Any], LinodeInterface]] = field(default_factory=list)
684+
interfaces: List[Union[Dict[str, Any], LinodeInterface]] = field(
685+
default_factory=list
686+
)
685687

686688

687689
class Instance(Base):

linode_api4/objects/linode_interfaces.py

Lines changed: 1 addition & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -110,76 +110,6 @@ class LinodeInterfaceOptions(JSONObject):
110110
vlan: Optional[LinodeInterfaceVLANOptions] = None
111111

112112

113-
# Interface PUT Options
114-
# NOTE: These classes currently match their POST equivalents
115-
# but are implemented separately for future-proofing.
116-
117-
118-
@dataclass
119-
class LinodeInterfaceDefaultRouteUpdateOptions(JSONObject):
120-
ipv4: Optional[bool] = None
121-
ipv6: Optional[bool] = None
122-
123-
124-
@dataclass
125-
class LinodeInterfaceVPCIPv4AddressUpdateOptions(JSONObject):
126-
address: str = ""
127-
primary: Optional[bool] = None
128-
nat_1_1_address: Optional[str] = None
129-
130-
131-
@dataclass
132-
class LinodeInterfaceVPCIPv4RangeUpdateOptions(JSONObject):
133-
range: str = ""
134-
135-
136-
@dataclass
137-
class LinodeInterfaceVPCIPv4UpdateOptions(JSONObject):
138-
addresses: Optional[List[LinodeInterfaceVPCIPv4AddressUpdateOptions]] = None
139-
ranges: Optional[List[LinodeInterfaceVPCIPv4RangeUpdateOptions]] = None
140-
141-
142-
@dataclass
143-
class LinodeInterfaceVPCUpdateOptions(JSONObject):
144-
subnet_id: int = 0
145-
ipv4: Optional[LinodeInterfaceVPCIPv4UpdateOptions] = None
146-
147-
148-
@dataclass
149-
class LinodeInterfacePublicIPv4AddressUpdateOptions(JSONObject):
150-
address: str = ""
151-
primary: Optional[bool] = None
152-
153-
154-
@dataclass
155-
class LinodeInterfacePublicIPv4UpdateOptions(JSONObject):
156-
addresses: Optional[List[LinodeInterfacePublicIPv4AddressUpdateOptions]] = (
157-
None
158-
)
159-
160-
161-
@dataclass
162-
class LinodeInterfacePublicIPv6RangeUpdateOptions(JSONObject):
163-
range: str = ""
164-
165-
166-
@dataclass
167-
class LinodeInterfacePublicIPv6UpdateOptions(JSONObject):
168-
ranges: Optional[List[LinodeInterfacePublicIPv6RangeUpdateOptions]] = None
169-
170-
171-
@dataclass
172-
class LinodeInterfacePublicUpdateOptions(JSONObject):
173-
ipv4: Optional[LinodeInterfacePublicIPv4UpdateOptions] = None
174-
ipv6: Optional[LinodeInterfacePublicIPv6UpdateOptions] = None
175-
176-
177-
@dataclass
178-
class LinodeInterfaceVLANUpdateOptions(JSONObject):
179-
vlan_label: str = ""
180-
ipam_address: Optional[str] = None
181-
182-
183113
# Interface GET Response
184114

185115

@@ -235,8 +165,6 @@ class LinodeInterfacePublicIPv4Address(JSONObject):
235165

236166
@dataclass
237167
class LinodeInterfacePublicIPv4Shared(JSONObject):
238-
put_class = LinodeInterfacePublicIPv4Options
239-
240168
address: str = ""
241169
linode_id: int = 0
242170

@@ -253,23 +181,19 @@ class LinodeInterfacePublicIPv4(JSONObject):
253181

254182
@dataclass
255183
class LinodeInterfacePublicIPv6SLAAC(JSONObject):
256-
put_class = LinodeInterfacePublicIPv6Options
257-
258184
address: str = ""
259185
prefix: int = 0
260186

261187

262188
@dataclass
263189
class LinodeInterfacePublicIPv6Shared(JSONObject):
264-
put_class = LinodeInterfacePublicIPv6Options
265-
266190
range: str = ""
267191
route_target: Optional[str] = None
268192

269193

270194
@dataclass
271195
class LinodeInterfacePublicIPv6Range(JSONObject):
272-
put_class = LinodeInterfacePublicIPv6Options
196+
put_class = LinodeInterfacePublicIPv6RangeOptions
273197

274198
range: str = ""
275199
route_target: Optional[str] = None

test/unit/groups/linode_test.py

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
from test.unit.base import ClientBaseCase
22

3-
from linode_api4 import InstancePlacementGroupAssignment, InterfaceGeneration
3+
from linode_api4 import (
4+
InstancePlacementGroupAssignment,
5+
InterfaceGeneration,
6+
LinodeInterfaceDefaultRouteOptions,
7+
LinodeInterfaceOptions,
8+
LinodeInterfacePublicIPv4AddressOptions,
9+
LinodeInterfacePublicIPv4Options,
10+
LinodeInterfacePublicOptions,
11+
)
412
from linode_api4.objects import ConfigInterface
513

614

@@ -32,7 +40,7 @@ def test_instance_create_with_user_data(self):
3240
},
3341
)
3442

35-
def test_instance_create_with_interfaces(self):
43+
def test_instance_create_with_interfaces_legacy(self):
3644
"""
3745
Tests that user can pass a list of interfaces on Linode create.
3846
"""
@@ -46,6 +54,7 @@ def test_instance_create_with_interfaces(self):
4654
self.client.linode.instance_create(
4755
"us-southeast",
4856
"g6-nanode-1",
57+
interface_generation=InterfaceGeneration.LEGACY_CONFIG,
4958
interfaces=interfaces,
5059
)
5160

@@ -96,22 +105,40 @@ def test_create_with_placement_group(self):
96105
m.call_data["placement_group"], {"id": 123, "compliant_only": True}
97106
)
98107

99-
def test_instance_create_with_interface_generation(self):
108+
def test_instance_create_with_interfaces_linode(self):
100109
"""
101-
Tests that the metadata field is populated on Linode create.
110+
Tests that a Linode can be created alongside LinodeInterfaces.
102111
"""
103112

104113
with self.mock_post("linode/instances/124") as m:
105114
self.client.linode.instance_create(
106115
"g6-nanode-1",
107-
"us-southeast",
116+
"us-mia",
108117
interface_generation=InterfaceGeneration.LINODE,
118+
interfaces=[
119+
LinodeInterfaceOptions(
120+
123,
121+
default_route=LinodeInterfaceDefaultRouteOptions(
122+
ipv4=True,
123+
ipv6=True,
124+
),
125+
public=LinodeInterfacePublicOptions(
126+
ipv4=LinodeInterfacePublicIPv4Options(
127+
addresses=[
128+
LinodeInterfacePublicIPv4AddressOptions(
129+
address="172.30.0.50", primary=True
130+
)
131+
],
132+
),
133+
),
134+
)
135+
],
109136
)
110137

111138
self.assertEqual(
112139
m.call_data,
113140
{
114-
"region": "us-southeast",
141+
"region": "us-mia",
115142
"type": "g6-nanode-1",
116143
"interface_generation": "linode",
117144
},

test/unit/objects/linode_interface_test.py

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,36 @@
33

44
from linode_api4 import (
55
LinodeInterface,
6-
LinodeInterfacePublicIPv4AddressUpdateOptions,
7-
LinodeInterfacePublicIPv6RangeUpdateOptions,
8-
LinodeInterfaceVPCIPv4AddressUpdateOptions,
9-
LinodeInterfaceVPCIPv4RangeUpdateOptions,
6+
LinodeInterfaceDefaultRouteOptions,
7+
LinodeInterfaceOptions,
8+
LinodeInterfacePublicIPv4AddressOptions,
9+
LinodeInterfacePublicIPv4Options,
10+
LinodeInterfacePublicIPv6RangeOptions,
11+
LinodeInterfacePublicOptions,
12+
LinodeInterfaceVPCIPv4AddressOptions,
13+
LinodeInterfaceVPCIPv4RangeOptions,
1014
)
1115

1216

17+
def build_interface_options_public():
18+
return LinodeInterfaceOptions(
19+
123,
20+
default_route=LinodeInterfaceDefaultRouteOptions(
21+
ipv4=True,
22+
ipv6=True,
23+
),
24+
public=LinodeInterfacePublicOptions(
25+
ipv4=LinodeInterfacePublicIPv4Options(
26+
addresses=[
27+
LinodeInterfacePublicIPv4AddressOptions(
28+
address="172.30.0.50", primary=True
29+
)
30+
],
31+
),
32+
),
33+
)
34+
35+
1336
class LinodeInterfaceTest(ClientBaseCase):
1437
"""
1538
Tests methods of the LinodeInterface class
@@ -133,14 +156,14 @@ def test_update_public(self):
133156
iface.default_route.ipv6 = False
134157

135158
iface.public.ipv4.addresses = [
136-
LinodeInterfacePublicIPv4AddressUpdateOptions(
159+
LinodeInterfacePublicIPv4AddressOptions(
137160
address="172.30.0.51",
138161
primary=False,
139162
)
140163
]
141164

142165
iface.public.ipv6.ranges = [
143-
LinodeInterfacePublicIPv6RangeUpdateOptions(
166+
LinodeInterfacePublicIPv6RangeOptions(
144167
range="2600:3cO9:e001:58::/64"
145168
)
146169
]
@@ -184,13 +207,13 @@ def test_update_vpc(self):
184207
iface.vpc.subnet_id = 456
185208

186209
iface.vpc.ipv4.addresses = [
187-
LinodeInterfaceVPCIPv4AddressUpdateOptions(
210+
LinodeInterfaceVPCIPv4AddressOptions(
188211
address="192.168.22.4", primary=False, nat_1_1_address="auto"
189212
)
190213
]
191214

192215
iface.vpc.ipv4.ranges = [
193-
LinodeInterfaceVPCIPv4RangeUpdateOptions(
216+
LinodeInterfaceVPCIPv4RangeOptions(
194217
range="192.168.22.17/28",
195218
)
196219
]

0 commit comments

Comments
 (0)