Skip to content

Commit 5750267

Browse files
progress
1 parent c6bf20c commit 5750267

File tree

2 files changed

+60
-5
lines changed

2 files changed

+60
-5
lines changed

linode_api4/objects/linode.py

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import string
22
import sys
3-
from dataclasses import dataclass
3+
from dataclasses import dataclass, field
44
from datetime import datetime
55
from enum import Enum
66
from os import urandom
@@ -653,6 +653,13 @@ class MigrationType:
653653
WARM = "warm"
654654

655655

656+
@dataclass
657+
class UpgradeInterfacesResult(JSONObject):
658+
dry_run: bool = False
659+
config_id: int = 0
660+
interfaces: List[ConfigInterface] = field(default_factory=list)
661+
662+
656663
class Instance(Base):
657664
"""
658665
A Linode Instance.
@@ -1846,6 +1853,27 @@ def stats_for(self, dt):
18461853
model=self,
18471854
)
18481855

1856+
def upgrade_interfaces(
1857+
self,
1858+
config: Union[Config, int],
1859+
dry_run: bool = False,
1860+
) -> UpgradeInterfacesResult:
1861+
"""
1862+
Automatically upgrades all legacy config interfaces of a single configuration profile to Linode interfaces.
1863+
1864+
API Documentation: Not yet available.
1865+
"""
1866+
params = {"config_id": config, dry_run: dry_run}
1867+
1868+
result = self._client.post(
1869+
"{}/upgrade-interfaces".format(Instance.api_endpoint),
1870+
model=self,
1871+
data=_flatten_request_body_recursive(drop_null_keys(params)),
1872+
)
1873+
1874+
# TODO: Inject LinodeInterface objects here
1875+
return UpgradeInterfacesResult.from_json(result)
1876+
18491877

18501878
class UserDefinedFieldType(Enum):
18511879
text = 1

linode_api4/objects/linode_interfaces.py

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from typing import List, Optional
33

44
from linode_api4.objects.base import Base, Property
5+
from linode_api4.objects.networking import Firewall
56
from linode_api4.objects.serializable import JSONObject
67

78

@@ -169,13 +170,39 @@ class LinodeInterface(Base):
169170
parent_id_name = "linode_id"
170171

171172
properties = {
173+
"linode_id": Property(identifier=True),
172174
"id": Property(identifier=True),
173175
"mac_address": Property(),
174176
"created": Property(is_datetime=True),
175177
"updated": Property(is_datetime=True),
176178
"version": Property(),
177-
"default_route": Property(json_object=LinodeInterfaceDefaultRoute),
178-
"public": Property(json_object=LinodeInterfacePublic),
179-
"vlan": Property(json_object=LinodeInterfaceVLAN),
180-
"vpc": Property(json_object=LinodeInterfaceVPC),
179+
"default_route": Property(
180+
mutable=True, json_object=LinodeInterfaceDefaultRoute
181+
),
182+
"public": Property(mutable=True, json_object=LinodeInterfacePublic),
183+
"vlan": Property(mutable=True, json_object=LinodeInterfaceVLAN),
184+
"vpc": Property(mutable=True, json_object=LinodeInterfaceVPC),
181185
}
186+
187+
def firewalls(self, *filters) -> List[Firewall]:
188+
"""
189+
Retrieves a list of Firewalls for this Linode Interface.
190+
191+
:param filters: Any number of filters to apply to this query.
192+
See :doc:`Filtering Collections</linode_api4/objects/filtering>`
193+
for more details on filtering.
194+
195+
:returns: A List of Firewalls for this Linode Interface.
196+
:rtype: List[Firewall]
197+
198+
NOTE: Caching is disabled on this method and each call will make
199+
an additional Linode API request.
200+
"""
201+
202+
return self._client._get_and_filter(
203+
Firewall,
204+
*filters,
205+
endpoint="{}/firewalls".format(LinodeInterface.api_endpoint).format(
206+
**vars(self)
207+
),
208+
)

0 commit comments

Comments
 (0)