Skip to content

Commit 5cf4440

Browse files
progress
1 parent de1e981 commit 5cf4440

File tree

2 files changed

+31
-4
lines changed

2 files changed

+31
-4
lines changed

linode_api4/groups/networking.py

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,21 @@
1+
from typing import Any, Dict, Optional, Union
2+
13
from linode_api4.errors import UnexpectedResponseError
24
from linode_api4.groups import Group
35
from linode_api4.objects import (
46
VLAN,
57
Base,
68
Firewall,
9+
FirewallCreateDevicesOptions,
710
Instance,
811
IPAddress,
912
IPv6Pool,
1013
IPv6Range,
1114
NetworkTransferPrice,
1215
Region,
1316
)
17+
from linode_api4.objects.base import _flatten_request_body_recursive
18+
from linode_api4.util import drop_null_keys
1419

1520

1621
class NetworkingGroup(Group):
@@ -33,7 +38,13 @@ def firewalls(self, *filters):
3338
"""
3439
return self.client._get_and_filter(Firewall, *filters)
3540

36-
def firewall_create(self, label, rules, **kwargs):
41+
def firewall_create(
42+
self,
43+
label: str,
44+
rules: Dict[str, Any],
45+
devices: Optional[Union[FirewallCreateDevicesOptions, Dict[str, Any]]],
46+
**kwargs,
47+
):
3748
"""
3849
Creates a new Firewall, either in the given Region or
3950
attached to the given Instance.
@@ -44,6 +55,8 @@ def firewall_create(self, label, rules, **kwargs):
4455
:type label: str
4556
:param rules: The rules to apply to the new Firewall. For more information on Firewall rules, see our `Firewalls Documentation`_.
4657
:type rules: dict
58+
:param devices: Represents devices to create created alongside a Linode Firewall.
59+
:type devices: Optional[Union[FirewallCreateDevicesOptions, Dict[str, Any]]]
4760
4861
:returns: The new Firewall.
4962
:rtype: Firewall
@@ -81,10 +94,14 @@ def firewall_create(self, label, rules, **kwargs):
8194
params = {
8295
"label": label,
8396
"rules": rules,
97+
"devices": devices,
8498
}
8599
params.update(kwargs)
86100

87-
result = self.client.post("/networking/firewalls", data=params)
101+
result = self.client.post(
102+
"/networking/firewalls",
103+
data=drop_null_keys(_flatten_request_body_recursive(params)),
104+
)
88105

89106
if not "id" in result:
90107
raise UnexpectedResponseError(

linode_api4/objects/networking.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
from dataclasses import dataclass
2-
from typing import Optional
1+
from dataclasses import dataclass, field
2+
from typing import List, Optional
33

44
from linode_api4.common import Price, RegionPrice
55
from linode_api4.errors import UnexpectedResponseError
@@ -176,6 +176,16 @@ class VLAN(Base):
176176
}
177177

178178

179+
class FirewallCreateDevicesOptions(JSONObject):
180+
"""
181+
Represents devices to create created alongside a Linode Firewall.
182+
"""
183+
184+
linodes: List[int] = field(default_factory=list)
185+
nodebalancers: List[int] = field(default_factory=list)
186+
interfaces: List[int] = field(default_factory=list)
187+
188+
179189
class FirewallDevice(DerivedBase):
180190
"""
181191
An object representing the assignment between a Linode Firewall and another Linode resource.

0 commit comments

Comments
 (0)