|
| 1 | +from dataclasses import dataclass, field |
| 2 | +from typing import List, Optional |
| 3 | + |
| 4 | +from linode_api4.objects.base import Base, Property |
| 5 | +from linode_api4.objects.serializable import JSONObject |
| 6 | + |
| 7 | + |
| 8 | +@dataclass |
| 9 | +class LinodeInterfaceDefaultRoute(JSONObject): |
| 10 | + ipv4: bool = False |
| 11 | + ipv6: bool = False |
| 12 | + |
| 13 | + |
| 14 | +@dataclass |
| 15 | +class LinodeInterfaceVPCIPv4Address(JSONObject): |
| 16 | + address: str = "" |
| 17 | + primary: bool = False |
| 18 | + |
| 19 | + |
| 20 | +@dataclass |
| 21 | +class LinodeInterfaceVPCIPv4Range(JSONObject): |
| 22 | + range: str = "" |
| 23 | + |
| 24 | + |
| 25 | +@dataclass |
| 26 | +class LinodeInterfaceVPCIPv4(JSONObject): |
| 27 | + addresses: List[LinodeInterfaceVPCIPv4Address] = field(default_factory=list) |
| 28 | + ranges: List[LinodeInterfaceVPCIPv4Range] = field(default_factory=list) |
| 29 | + |
| 30 | + |
| 31 | +@dataclass |
| 32 | +class LinodeInterfaceVPC(JSONObject): |
| 33 | + vpc_id: int = 0 |
| 34 | + vpc_subnet: int = 0 |
| 35 | + |
| 36 | + ipv4: Optional[LinodeInterfaceVPCIPv4] = None |
| 37 | + |
| 38 | + |
| 39 | +@dataclass |
| 40 | +class LinodeInterfacePublicIPv4Address(JSONObject): |
| 41 | + address: str = "" |
| 42 | + primary: bool = False |
| 43 | + |
| 44 | + |
| 45 | +@dataclass |
| 46 | +class LinodeInterfacePublicIPv4Shared(JSONObject): |
| 47 | + address: str = "" |
| 48 | + linode_id: int = 0 |
| 49 | + |
| 50 | + |
| 51 | +@dataclass |
| 52 | +class LinodeInterfacePublicIPv4(JSONObject): |
| 53 | + addresses: List[LinodeInterfacePublicIPv4Address] = field( |
| 54 | + default_factory=list |
| 55 | + ) |
| 56 | + shared: List[LinodeInterfacePublicIPv4Shared] = field(default_factory=list) |
| 57 | + |
| 58 | + |
| 59 | +@dataclass |
| 60 | +class LinodeInterfacePublicIPv6SLAAC(JSONObject): |
| 61 | + address: str = "" |
| 62 | + prefix: int = 0 |
| 63 | + |
| 64 | + |
| 65 | +@dataclass |
| 66 | +class LinodeInterfacePublicIPv6Shared(JSONObject): |
| 67 | + range: str = "" |
| 68 | + route_target: Optional[str] = "" |
| 69 | + |
| 70 | + |
| 71 | +@dataclass |
| 72 | +class LinodeInterfacePublicIPv6Range(JSONObject): |
| 73 | + range: str = "" |
| 74 | + route_target: Optional[str] = "" |
| 75 | + |
| 76 | + |
| 77 | +@dataclass |
| 78 | +class LinodeInterfacePublicIPv6(JSONObject): |
| 79 | + slaac: List[LinodeInterfacePublicIPv6SLAAC] = field(default_factory=list) |
| 80 | + shared: List[LinodeInterfacePublicIPv6Shared] = field(default_factory=list) |
| 81 | + ranges: List[LinodeInterfacePublicIPv6Range] = field(default_factory=list) |
| 82 | + |
| 83 | + |
| 84 | +@dataclass |
| 85 | +class LinodeInterfacePublic(JSONObject): |
| 86 | + ipv4: Optional[LinodeInterfacePublicIPv4] = None |
| 87 | + ipv6: Optional[LinodeInterfacePublicIPv6] = None |
| 88 | + |
| 89 | + |
| 90 | +@dataclass |
| 91 | +class LinodeInterfaceVLAN(JSONObject): |
| 92 | + vlan_label: str = "" |
| 93 | + ipam_address: Optional[str] = "" |
| 94 | + |
| 95 | + |
| 96 | +class LinodeInterface(Base): |
| 97 | + """ |
| 98 | + A Linode's network interface. |
| 99 | +
|
| 100 | + API Documentation: Not yet available. |
| 101 | + """ |
| 102 | + |
| 103 | + api_endpoint = "/linode/instances/{linode_id}/interfaces/{id}" |
| 104 | + derived_url_path = "interfaces" |
| 105 | + parent_id_name = "linode_id" |
| 106 | + |
| 107 | + properties = { |
| 108 | + "id": Property(identifier=True), |
| 109 | + "mac_address": Property(), |
| 110 | + "created": Property(is_datetime=True), |
| 111 | + "updated": Property(is_datetime=True), |
| 112 | + "version": Property(), |
| 113 | + "default_route": Property(json_object=LinodeInterfaceDefaultRoute), |
| 114 | + "public": Property(json_object=LinodeInterfacePublic), |
| 115 | + "vlan": Property(json_object=LinodeInterfaceVLAN), |
| 116 | + "vpc": Property(json_object=LinodeInterfaceVPC), |
| 117 | + } |
0 commit comments