|
| 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.dbase import DerivedBase |
| 6 | +from linode_api4.objects.networking import Firewall |
| 7 | +from linode_api4.objects.serializable import JSONObject |
| 8 | + |
| 9 | + |
| 10 | +@dataclass |
| 11 | +class LinodeInterfacesSettingsDefaultRouteOptions(JSONObject): |
| 12 | + ipv4_interface_id: Optional[int] = None |
| 13 | + ipv6_interface_id: Optional[int] = None |
| 14 | + |
| 15 | + |
| 16 | +@dataclass |
| 17 | +class LinodeInterfacesSettingsDefaultRoute(JSONObject): |
| 18 | + put_body = LinodeInterfacesSettingsDefaultRouteOptions |
| 19 | + |
| 20 | + ipv4_interface_id: Optional[int] = None |
| 21 | + ipv4_eligible_interface_ids: List[int] = field(default_factory=list) |
| 22 | + ipv6_interface_id: Optional[int] = None |
| 23 | + ipv6_eligible_interface_ids: List[int] = field(default_factory=list) |
| 24 | + |
| 25 | + |
| 26 | +class LinodeInterfacesSettings(Base): |
| 27 | + api_endpoint = "/linode/instances/{linode_id}/interfaces/settings" |
| 28 | + |
| 29 | + properties = { |
| 30 | + "linode_id": Property(identifier=True), |
| 31 | + "network_helper": Property(mutable=True), |
| 32 | + "default_route": Property( |
| 33 | + mutable=True, json_object=LinodeInterfacesSettingsDefaultRoute |
| 34 | + ), |
| 35 | + } |
| 36 | + |
| 37 | + |
| 38 | +@dataclass |
| 39 | +class LinodeInterfaceDefaultRouteOptions(JSONObject): |
| 40 | + ipv4: bool = False |
| 41 | + ipv6: bool = False |
| 42 | + |
| 43 | + |
| 44 | +@dataclass |
| 45 | +class LinodeInterfaceVPCIPv4AddressOptions(JSONObject): |
| 46 | + address: str = "" |
| 47 | + primary: Optional[bool] = None |
| 48 | + nat_1_1_address: Optional[str] = None |
| 49 | + |
| 50 | + |
| 51 | +@dataclass |
| 52 | +class LinodeInterfaceVPCIPv4RangeOptions(JSONObject): |
| 53 | + range: str = "" |
| 54 | + |
| 55 | + |
| 56 | +@dataclass |
| 57 | +class LinodeInterfaceVPCIPv4Options(JSONObject): |
| 58 | + addresses: Optional[List[LinodeInterfaceVPCIPv4AddressOptions]] = None |
| 59 | + ranges: Optional[List[LinodeInterfaceVPCIPv4RangeOptions]] = None |
| 60 | + |
| 61 | + |
| 62 | +@dataclass |
| 63 | +class LinodeInterfaceVPCOptions(JSONObject): |
| 64 | + subnet_id: int = 0 |
| 65 | + ipv4: Optional[LinodeInterfaceVPCIPv4Options] = None |
| 66 | + |
| 67 | + |
| 68 | +@dataclass |
| 69 | +class LinodeInterfacePublicIPv4AddressOptions(JSONObject): |
| 70 | + address: str = "" |
| 71 | + primary: Optional[bool] = None |
| 72 | + |
| 73 | + |
| 74 | +@dataclass |
| 75 | +class LinodeInterfacePublicIPv4Options(JSONObject): |
| 76 | + addresses: Optional[List[LinodeInterfacePublicIPv4AddressOptions]] = None |
| 77 | + |
| 78 | + |
| 79 | +@dataclass |
| 80 | +class LinodeInterfacePublicIPv6RangeOptions(JSONObject): |
| 81 | + range: str = "" |
| 82 | + |
| 83 | + |
| 84 | +@dataclass |
| 85 | +class LinodeInterfacePublicIPv6Options(JSONObject): |
| 86 | + ranges: Optional[List[LinodeInterfacePublicIPv6RangeOptions]] = None |
| 87 | + |
| 88 | + |
| 89 | +@dataclass |
| 90 | +class LinodeInterfacePublicOptions(JSONObject): |
| 91 | + ipv4: Optional[LinodeInterfacePublicIPv4Options] = None |
| 92 | + ipv6: Optional[LinodeInterfacePublicIPv6Options] = None |
| 93 | + |
| 94 | + |
| 95 | +@dataclass |
| 96 | +class LinodeInterfaceVLANOptions(JSONObject): |
| 97 | + vlan_label: str = "" |
| 98 | + ipam_address: Optional[str] = None |
| 99 | + |
| 100 | + |
| 101 | +@dataclass |
| 102 | +class LinodeInterfaceDefaultRoute(JSONObject): |
| 103 | + ipv4: bool = False |
| 104 | + ipv6: bool = False |
| 105 | + |
| 106 | + |
| 107 | +@dataclass |
| 108 | +class LinodeInterfaceVPCIPv4Address(JSONObject): |
| 109 | + address: str = "" |
| 110 | + primary: bool = False |
| 111 | + nat_1_1_address: Optional[str] = None |
| 112 | + |
| 113 | + |
| 114 | +@dataclass |
| 115 | +class LinodeInterfaceVPCIPv4Range(JSONObject): |
| 116 | + range: str = "" |
| 117 | + |
| 118 | + |
| 119 | +@dataclass |
| 120 | +class LinodeInterfaceVPCIPv4(JSONObject): |
| 121 | + addresses: List[LinodeInterfaceVPCIPv4Address] = field(default_factory=list) |
| 122 | + ranges: List[LinodeInterfaceVPCIPv4Range] = field(default_factory=list) |
| 123 | + |
| 124 | + |
| 125 | +@dataclass |
| 126 | +class LinodeInterfaceVPC(JSONObject): |
| 127 | + vpc_id: int = 0 |
| 128 | + vpc_subnet: int = 0 |
| 129 | + |
| 130 | + ipv4: Optional[LinodeInterfaceVPCIPv4] = None |
| 131 | + |
| 132 | + |
| 133 | +@dataclass |
| 134 | +class LinodeInterfacePublicIPv4Address(JSONObject): |
| 135 | + address: str = "" |
| 136 | + primary: bool = False |
| 137 | + |
| 138 | + |
| 139 | +@dataclass |
| 140 | +class LinodeInterfacePublicIPv4Shared(JSONObject): |
| 141 | + address: str = "" |
| 142 | + linode_id: int = 0 |
| 143 | + |
| 144 | + |
| 145 | +@dataclass |
| 146 | +class LinodeInterfacePublicIPv4(JSONObject): |
| 147 | + addresses: List[LinodeInterfacePublicIPv4Address] = field( |
| 148 | + default_factory=list |
| 149 | + ) |
| 150 | + shared: List[LinodeInterfacePublicIPv4Shared] = field(default_factory=list) |
| 151 | + |
| 152 | + |
| 153 | +@dataclass |
| 154 | +class LinodeInterfacePublicIPv6SLAAC(JSONObject): |
| 155 | + address: str = "" |
| 156 | + prefix: int = 0 |
| 157 | + |
| 158 | + |
| 159 | +@dataclass |
| 160 | +class LinodeInterfacePublicIPv6Shared(JSONObject): |
| 161 | + range: str = "" |
| 162 | + route_target: Optional[str] = None |
| 163 | + |
| 164 | + |
| 165 | +@dataclass |
| 166 | +class LinodeInterfacePublicIPv6Range(JSONObject): |
| 167 | + range: str = "" |
| 168 | + route_target: Optional[str] = None |
| 169 | + |
| 170 | + |
| 171 | +@dataclass |
| 172 | +class LinodeInterfacePublicIPv6(JSONObject): |
| 173 | + slaac: List[LinodeInterfacePublicIPv6SLAAC] = field(default_factory=list) |
| 174 | + shared: List[LinodeInterfacePublicIPv6Shared] = field(default_factory=list) |
| 175 | + ranges: List[LinodeInterfacePublicIPv6Range] = field(default_factory=list) |
| 176 | + |
| 177 | + |
| 178 | +@dataclass |
| 179 | +class LinodeInterfacePublic(JSONObject): |
| 180 | + ipv4: Optional[LinodeInterfacePublicIPv4] = None |
| 181 | + ipv6: Optional[LinodeInterfacePublicIPv6] = None |
| 182 | + |
| 183 | + |
| 184 | +@dataclass |
| 185 | +class LinodeInterfaceVLAN(JSONObject): |
| 186 | + vlan_label: str = "" |
| 187 | + ipam_address: Optional[str] = None |
| 188 | + |
| 189 | + |
| 190 | +class LinodeInterface(DerivedBase): |
| 191 | + """ |
| 192 | + A Linode's network interface. |
| 193 | +
|
| 194 | + API Documentation: Not yet available. |
| 195 | + """ |
| 196 | + |
| 197 | + api_endpoint = "/linode/instances/{linode_id}/interfaces/{id}" |
| 198 | + derived_url_path = "interfaces" |
| 199 | + parent_id_name = "linode_id" |
| 200 | + |
| 201 | + properties = { |
| 202 | + "linode_id": Property(identifier=True), |
| 203 | + "id": Property(identifier=True), |
| 204 | + "mac_address": Property(), |
| 205 | + "created": Property(is_datetime=True), |
| 206 | + "updated": Property(is_datetime=True), |
| 207 | + "version": Property(), |
| 208 | + "default_route": Property( |
| 209 | + mutable=True, json_object=LinodeInterfaceDefaultRoute |
| 210 | + ), |
| 211 | + "public": Property(mutable=True, json_object=LinodeInterfacePublic), |
| 212 | + "vlan": Property(mutable=True, json_object=LinodeInterfaceVLAN), |
| 213 | + "vpc": Property(mutable=True, json_object=LinodeInterfaceVPC), |
| 214 | + } |
| 215 | + |
| 216 | + def firewalls(self, *filters) -> List[Firewall]: |
| 217 | + """ |
| 218 | + Retrieves a list of Firewalls for this Linode Interface. |
| 219 | +
|
| 220 | + :param filters: Any number of filters to apply to this query. |
| 221 | + See :doc:`Filtering Collections</linode_api4/objects/filtering>` |
| 222 | + for more details on filtering. |
| 223 | +
|
| 224 | + :returns: A List of Firewalls for this Linode Interface. |
| 225 | + :rtype: List[Firewall] |
| 226 | +
|
| 227 | + NOTE: Caching is disabled on this method and each call will make |
| 228 | + an additional Linode API request. |
| 229 | + """ |
| 230 | + |
| 231 | + return self._client._get_and_filter( |
| 232 | + Firewall, |
| 233 | + *filters, |
| 234 | + endpoint="{}/firewalls".format(LinodeInterface.api_endpoint).format( |
| 235 | + **vars(self) |
| 236 | + ), |
| 237 | + ) |
0 commit comments