Skip to content

Commit e6718c0

Browse files
new: add support for listing nodebalancer firewalls (#356)
## 📝 Description **What does this PR do and why is this change necessary?** Add support for `nodebalancers/{nb_id}/firewalls` endpoint ## ✔️ How to Test **How do I run the relevant unit/integration tests?** ```bash make testunit ```
1 parent ddb0b98 commit e6718c0

3 files changed

Lines changed: 87 additions & 1 deletion

File tree

linode_api4/objects/nodebalancer.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
Property,
1010
Region,
1111
)
12-
from linode_api4.objects.networking import IPAddress
12+
from linode_api4.objects.networking import Firewall, IPAddress
1313

1414

1515
class NodeBalancerNode(DerivedBase):
@@ -303,3 +303,21 @@ def statistics(self):
303303
"Unexpected response generating stats!", json=result
304304
)
305305
return MappedObject(**result)
306+
307+
def firewalls(self):
308+
"""
309+
View Firewall information for Firewalls associated with this NodeBalancer.
310+
311+
API Documentation: https://www.linode.com/docs/api/nodebalancers/#nodebalancer-firewalls-list
312+
313+
:returns: A List of Firewalls of the Linode NodeBalancer.
314+
:rtype: List[Firewall]
315+
"""
316+
result = self._client.get(
317+
"{}/firewalls".format(NodeBalancer.api_endpoint), model=self
318+
)
319+
320+
return [
321+
Firewall(self._client, firewall["id"])
322+
for firewall in result["data"]
323+
]
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
{
2+
"data": [
3+
{
4+
"created": "2018-01-01T00:01:01",
5+
"id": 123,
6+
"label": "firewall123",
7+
"rules": {
8+
"inbound": [
9+
{
10+
"action": "ACCEPT",
11+
"addresses": {
12+
"ipv4": [
13+
"192.0.2.0/24"
14+
],
15+
"ipv6": [
16+
"2001:DB8::/32"
17+
]
18+
},
19+
"description": "An example firewall rule description.",
20+
"label": "firewallrule123",
21+
"ports": "22-24, 80, 443",
22+
"protocol": "TCP"
23+
}
24+
],
25+
"inbound_policy": "DROP",
26+
"outbound": [
27+
{
28+
"action": "ACCEPT",
29+
"addresses": {
30+
"ipv4": [
31+
"192.0.2.0/24"
32+
],
33+
"ipv6": [
34+
"2001:DB8::/32"
35+
]
36+
},
37+
"description": "An example firewall rule description.",
38+
"label": "firewallrule123",
39+
"ports": "22-24, 80, 443",
40+
"protocol": "TCP"
41+
}
42+
],
43+
"outbound_policy": "DROP"
44+
},
45+
"status": "enabled",
46+
"tags": [
47+
"example tag",
48+
"another example"
49+
],
50+
"updated": "2018-01-02T00:01:01"
51+
}
52+
],
53+
"page": 1,
54+
"pages": 1,
55+
"results": 1
56+
}

test/unit/objects/nodebalancers_test.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,3 +193,15 @@ def test_statistics(self):
193193
"linode.com - balancer12345 (12345) - day (5 min avg)",
194194
)
195195
self.assertEqual(m.call_url, statistics_url)
196+
197+
def test_firewalls(self):
198+
"""
199+
Test that you can get the firewalls for the requested NodeBalancer.
200+
"""
201+
nb = NodeBalancer(self.client, 12345)
202+
firewalls_url = "/nodebalancers/12345/firewalls"
203+
204+
with self.mock_get(firewalls_url) as m:
205+
result = nb.firewalls()
206+
self.assertEqual(m.call_url, firewalls_url)
207+
self.assertEqual(len(result), 1)

0 commit comments

Comments
 (0)