-
Notifications
You must be signed in to change notification settings - Fork 85
Expand file tree
/
Copy pathlinode_interfaces.py
More file actions
552 lines (374 loc) · 15.4 KB
/
linode_interfaces.py
File metadata and controls
552 lines (374 loc) · 15.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
from dataclasses import dataclass, field
from typing import List, Optional
from linode_api4.objects.base import Base, Property
from linode_api4.objects.dbase import DerivedBase
from linode_api4.objects.networking import Firewall
from linode_api4.objects.serializable import JSONObject
@dataclass
class LinodeInterfacesSettingsDefaultRouteOptions(JSONObject):
"""
The options used to configure the default route settings for a Linode's network interfaces.
NOTE: Linode interfaces may not currently be available to all users.
"""
ipv4_interface_id: Optional[int] = None
ipv6_interface_id: Optional[int] = None
@dataclass
class LinodeInterfacesSettingsDefaultRoute(JSONObject):
"""
The default route settings for a Linode's network interfaces.
NOTE: Linode interfaces may not currently be available to all users.
"""
put_class = LinodeInterfacesSettingsDefaultRouteOptions
ipv4_interface_id: Optional[int] = None
ipv4_eligible_interface_ids: List[int] = field(default_factory=list)
ipv6_interface_id: Optional[int] = None
ipv6_eligible_interface_ids: List[int] = field(default_factory=list)
class LinodeInterfacesSettings(Base):
"""
The settings related to a Linode's network interfaces.
API Documentation: https://techdocs.akamai.com/linode-api/reference/get-linode-interface-settings
NOTE: Linode interfaces may not currently be available to all users.
"""
api_endpoint = "/linode/instances/{id}/interfaces/settings"
properties = {
"id": Property(identifier=True),
"network_helper": Property(mutable=True),
"default_route": Property(
mutable=True, json_object=LinodeInterfacesSettingsDefaultRoute
),
}
# Interface POST Options
@dataclass
class LinodeInterfaceDefaultRouteOptions(JSONObject):
"""
Options accepted when creating or updating a Linode Interface's default route settings.
NOTE: Linode interfaces may not currently be available to all users.
"""
ipv4: Optional[bool] = None
ipv6: Optional[bool] = None
@dataclass
class LinodeInterfaceVPCIPv4AddressOptions(JSONObject):
"""
Options accepted for a single address when creating or updating the IPv4 configuration of a VPC Linode Interface.
NOTE: Linode interfaces may not currently be available to all users.
"""
address: Optional[str] = None
primary: Optional[bool] = None
nat_1_1_address: Optional[str] = None
@dataclass
class LinodeInterfaceVPCIPv4RangeOptions(JSONObject):
"""
Options accepted for a single range when creating or updating the IPv4 configuration of a VPC Linode Interface.
NOTE: Linode interfaces may not currently be available to all users.
"""
range: str = ""
@dataclass
class LinodeInterfaceVPCIPv4Options(JSONObject):
"""
Options accepted when creating or updating the IPv4 configuration of a VPC Linode Interface.
NOTE: Linode interfaces may not currently be available to all users.
"""
addresses: Optional[List[LinodeInterfaceVPCIPv4AddressOptions]] = None
ranges: Optional[List[LinodeInterfaceVPCIPv4RangeOptions]] = None
@dataclass
class LinodeInterfaceVPCIPv6SLAACOptions(JSONObject):
"""
Options accepted for a single SLAAC when creating or updating the IPv6 configuration of a VPC Linode Interface.
NOTE: Linode interfaces may not currently be available to all users.
"""
range: Optional[str] = None
@dataclass
class LinodeInterfaceVPCIPv6RangeOptions(JSONObject):
"""
Options accepted for a single range when creating or updating the IPv6 configuration of a VPC Linode Interface.
NOTE: Linode interfaces may not currently be available to all users.
"""
range: Optional[str] = None
@dataclass
class LinodeInterfaceVPCIPv6Options(JSONObject):
"""
Options accepted when creating or updating the IPv6 configuration of a VPC Linode Interface.
NOTE: Linode interfaces may not currently be available to all users.
"""
is_public: Optional[bool] = None
slaac: Optional[List[LinodeInterfaceVPCIPv6SLAACOptions]] = None
ranges: Optional[List[LinodeInterfaceVPCIPv6RangeOptions]] = None
@dataclass
class LinodeInterfaceVPCOptions(JSONObject):
"""
VPC-exclusive options accepted when creating or updating a Linode Interface.
NOTE: Linode interfaces may not currently be available to all users.
"""
subnet_id: int = 0
ipv4: Optional[LinodeInterfaceVPCIPv4Options] = None
ipv6: Optional[LinodeInterfaceVPCIPv6Options] = None
@dataclass
class LinodeInterfacePublicIPv4AddressOptions(JSONObject):
"""
Options accepted for a single address when creating or updating the IPv4 configuration of a public Linode Interface.
NOTE: Linode interfaces may not currently be available to all users.
"""
address: str = ""
primary: Optional[bool] = None
@dataclass
class LinodeInterfacePublicIPv4Options(JSONObject):
"""
Options accepted when creating or updating the IPv4 configuration of a public Linode Interface.
NOTE: Linode interfaces may not currently be available to all users.
"""
addresses: Optional[List[LinodeInterfacePublicIPv4AddressOptions]] = None
@dataclass
class LinodeInterfacePublicIPv6RangeOptions(JSONObject):
"""
Options accepted for a single range when creating or updating the IPv6 configuration of a public Linode Interface.
NOTE: Linode interfaces may not currently be available to all users.
"""
range: str = ""
@dataclass
class LinodeInterfacePublicIPv6Options(JSONObject):
"""
Options accepted when creating or updating the IPv6 configuration of a public Linode Interface.
NOTE: Linode interfaces may not currently be available to all users.
"""
ranges: Optional[List[LinodeInterfacePublicIPv6RangeOptions]] = None
@dataclass
class LinodeInterfacePublicOptions(JSONObject):
"""
Public-exclusive options accepted when creating or updating a Linode Interface.
NOTE: Linode interfaces may not currently be available to all users.
"""
ipv4: Optional[LinodeInterfacePublicIPv4Options] = None
ipv6: Optional[LinodeInterfacePublicIPv6Options] = None
@dataclass
class LinodeInterfaceVLANOptions(JSONObject):
"""
VLAN-exclusive options accepted when creating or updating a Linode Interface.
NOTE: Linode interfaces may not currently be available to all users.
"""
vlan_label: str = ""
ipam_address: Optional[str] = None
@dataclass
class LinodeInterfaceOptions(JSONObject):
"""
Options accepted when creating or updating a Linode Interface.
NOTE: Linode interfaces may not currently be available to all users.
"""
always_include = {
# If a default firewall_id isn't configured, the API requires that
# firewall_id is defined in the LinodeInterface POST body.
"firewall_id"
}
firewall_id: Optional[int] = None
default_route: Optional[LinodeInterfaceDefaultRouteOptions] = None
vpc: Optional[LinodeInterfaceVPCOptions] = None
public: Optional[LinodeInterfacePublicOptions] = None
vlan: Optional[LinodeInterfaceVLANOptions] = None
# Interface GET Response
@dataclass
class LinodeInterfaceDefaultRoute(JSONObject):
"""
The default route configuration of a Linode Interface.
NOTE: Linode interfaces may not currently be available to all users.
"""
put_class = LinodeInterfaceDefaultRouteOptions
ipv4: bool = False
ipv6: bool = False
@dataclass
class LinodeInterfaceVPCIPv4Address(JSONObject):
"""
A single address under the IPv4 configuration of a VPC Linode Interface.
NOTE: Linode interfaces may not currently be available to all users.
"""
put_class = LinodeInterfaceVPCIPv4AddressOptions
address: str = ""
primary: bool = False
nat_1_1_address: Optional[str] = None
@dataclass
class LinodeInterfaceVPCIPv4Range(JSONObject):
"""
A single range under the IPv4 configuration of a VPC Linode Interface.
NOTE: Linode interfaces may not currently be available to all users.
"""
put_class = LinodeInterfaceVPCIPv4RangeOptions
range: str = ""
@dataclass
class LinodeInterfaceVPCIPv4(JSONObject):
"""
A single address under the IPv4 configuration of a VPC Linode Interface.
NOTE: Linode interfaces may not currently be available to all users.
"""
put_class = LinodeInterfaceVPCIPv4Options
addresses: List[LinodeInterfaceVPCIPv4Address] = field(default_factory=list)
ranges: List[LinodeInterfaceVPCIPv4Range] = field(default_factory=list)
@dataclass
class LinodeInterfaceVPCIPv6SLAAC(JSONObject):
"""
A single SLAAC entry under the IPv6 configuration of a VPC Linode Interface.
NOTE: Linode interfaces may not currently be available to all users.
"""
range: str = ""
address: str = ""
@dataclass
class LinodeInterfaceVPCIPv6Range(JSONObject):
"""
A single range under the IPv6 configuration of a VPC Linode Interface.
NOTE: Linode interfaces may not currently be available to all users.
"""
range: str = ""
@dataclass
class LinodeInterfaceVPCIPv6(JSONObject):
"""
A single address under the IPv6 configuration of a VPC Linode Interface.
NOTE: Linode interfaces may not currently be available to all users.
"""
put_class = LinodeInterfaceVPCIPv6Options
is_public: bool = False
slaac: List[LinodeInterfaceVPCIPv6SLAAC] = field(default_factory=list)
ranges: List[LinodeInterfaceVPCIPv6Range] = field(default_factory=list)
@dataclass
class LinodeInterfaceVPC(JSONObject):
"""
VPC-specific configuration field for a Linode Interface.
NOTE: Linode interfaces may not currently be available to all users.
"""
put_class = LinodeInterfaceVPCOptions
vpc_id: int = 0
subnet_id: int = 0
ipv4: Optional[LinodeInterfaceVPCIPv4] = None
ipv6: Optional[LinodeInterfaceVPCIPv6] = None
@dataclass
class LinodeInterfacePublicIPv4Address(JSONObject):
"""
A single address under the IPv4 configuration of a public Linode Interface.
NOTE: Linode interfaces may not currently be available to all users.
"""
put_class = LinodeInterfacePublicIPv4AddressOptions
address: str = ""
primary: bool = False
@dataclass
class LinodeInterfacePublicIPv4Shared(JSONObject):
"""
A single shared address under the IPv4 configuration of a public Linode Interface.
NOTE: Linode interfaces may not currently be available to all users.
"""
address: str = ""
linode_id: int = 0
@dataclass
class LinodeInterfacePublicIPv4(JSONObject):
"""
The IPv4 configuration of a public Linode Interface.
NOTE: Linode interfaces may not currently be available to all users.
"""
put_class = LinodeInterfacePublicIPv4Options
addresses: List[LinodeInterfacePublicIPv4Address] = field(
default_factory=list
)
shared: List[LinodeInterfacePublicIPv4Shared] = field(default_factory=list)
@dataclass
class LinodeInterfacePublicIPv6SLAAC(JSONObject):
"""
A single SLAAC entry under the IPv6 configuration of a public Linode Interface.
NOTE: Linode interfaces may not currently be available to all users.
"""
address: str = ""
prefix: int = 0
@dataclass
class LinodeInterfacePublicIPv6Shared(JSONObject):
"""
A single shared range under the IPv6 configuration of a public Linode Interface.
NOTE: Linode interfaces may not currently be available to all users.
"""
range: str = ""
route_target: Optional[str] = None
@dataclass
class LinodeInterfacePublicIPv6Range(JSONObject):
"""
A single range under the IPv6 configuration of a public Linode Interface.
NOTE: Linode interfaces may not currently be available to all users.
"""
put_class = LinodeInterfacePublicIPv6RangeOptions
range: str = ""
route_target: Optional[str] = None
@dataclass
class LinodeInterfacePublicIPv6(JSONObject):
"""
The IPv6 configuration of a Linode Interface.
NOTE: Linode interfaces may not currently be available to all users.
"""
put_class = LinodeInterfacePublicIPv6Options
slaac: List[LinodeInterfacePublicIPv6SLAAC] = field(default_factory=list)
shared: List[LinodeInterfacePublicIPv6Shared] = field(default_factory=list)
ranges: List[LinodeInterfacePublicIPv6Range] = field(default_factory=list)
@dataclass
class LinodeInterfacePublic(JSONObject):
"""
Public-specific configuration fields for a Linode Interface.
NOTE: Linode interfaces may not currently be available to all users.
"""
put_class = LinodeInterfacePublicOptions
ipv4: Optional[LinodeInterfacePublicIPv4] = None
ipv6: Optional[LinodeInterfacePublicIPv6] = None
@dataclass
class LinodeInterfaceVLAN(JSONObject):
"""
VLAN-specific configuration fields for a Linode Interface.
NOTE: Linode interfaces may not currently be available to all users.
"""
put_class = LinodeInterfaceVLANOptions
vlan_label: str = ""
ipam_address: Optional[str] = None
class LinodeInterface(DerivedBase):
"""
A Linode's network interface.
NOTE: Linode interfaces may not currently be available to all users.
NOTE: When using the ``save()`` method, certain local fields with computed values will
not be refreshed on the local object until after ``invalidate()`` has been called::
# Automatically assign an IPv4 address from the associated VPC Subnet
interface.vpc.ipv4.addresses[0].address = "auto"
# Save the interface
interface.save()
# Invalidate the interface
interface.invalidate()
# Access the new address
print(interface.vpc.ipv4.addresses[0].address)
API Documentation: https://techdocs.akamai.com/linode-api/reference/get-linode-interface
"""
api_endpoint = "/linode/instances/{linode_id}/interfaces/{id}"
derived_url_path = "interfaces"
parent_id_name = "linode_id"
properties = {
"linode_id": Property(identifier=True),
"id": Property(identifier=True),
"mac_address": Property(),
"created": Property(is_datetime=True),
"updated": Property(is_datetime=True),
"version": Property(),
"default_route": Property(
mutable=True,
json_object=LinodeInterfaceDefaultRoute,
),
"public": Property(mutable=True, json_object=LinodeInterfacePublic),
"vlan": Property(mutable=True, json_object=LinodeInterfaceVLAN),
"vpc": Property(mutable=True, json_object=LinodeInterfaceVPC),
}
def firewalls(self, *filters) -> List[Firewall]:
"""
Retrieves a list of Firewalls for this Linode Interface.
Linode interfaces are not interchangeable with Config interfaces.
NOTE: Linode interfaces may not currently be available to all users.
:param filters: Any number of filters to apply to this query.
See :doc:`Filtering Collections</linode_api4/objects/filtering>`
for more details on filtering.
:returns: A List of Firewalls for this Linode Interface.
:rtype: List[Firewall]
NOTE: Caching is disabled on this method and each call will make
an additional Linode API request.
API Documentation: https://techdocs.akamai.com/linode-api/reference/get-linode-interface-firewalls
"""
return self._client._get_and_filter(
Firewall,
*filters,
endpoint="{}/firewalls".format(LinodeInterface.api_endpoint).format(
**vars(self)
),
)