Skip to content

Commit 8e5134e

Browse files
jcallahan-akamaiykim-akamailgarber-akamai
authored
TPT-3319: Add support for Apply Linode Firewalls (#492)
* Add support for linode/instances/:id/firewalls/apply * updating the test image --------- Co-authored-by: ykim-1 <ykim@akamai.com> Co-authored-by: Lena Garber <114949949+lgarber-akamai@users.noreply.github.com>
1 parent f1fa70e commit 8e5134e

3 files changed

Lines changed: 37 additions & 0 deletions

File tree

linode_api4/objects/linode.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1639,6 +1639,22 @@ def firewalls(self):
16391639
for firewall in result["data"]
16401640
]
16411641

1642+
def apply_firewalls(self):
1643+
"""
1644+
Reapply assigned firewalls to a Linode in case they were not applied successfully.
1645+
1646+
API Documentation: https://techdocs.akamai.com/linode-api/reference/post-apply-firewalls
1647+
1648+
:returns: Returns True if the operation was successful
1649+
:rtype: bool
1650+
"""
1651+
1652+
self._client.post(
1653+
"{}/firewalls/apply".format(Instance.api_endpoint), model=self
1654+
)
1655+
1656+
return True
1657+
16421658
def nodebalancers(self):
16431659
"""
16441660
View a list of NodeBalancers that are assigned to this Linode and readable by the requesting User.

test/integration/models/linode/test_linode.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -453,6 +453,14 @@ def test_linode_firewalls(linode_with_volume_firewall):
453453
assert "firewall" in firewalls[0].label
454454

455455

456+
def test_linode_apply_firewalls(linode_with_volume_firewall):
457+
linode = linode_with_volume_firewall
458+
459+
result = linode.apply_firewalls()
460+
461+
assert result
462+
463+
456464
def test_linode_volumes(linode_with_volume_firewall):
457465
linode = linode_with_volume_firewall
458466

test/unit/objects/linode_test.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,19 @@ def test_firewalls(self):
284284
self.assertEqual(m.call_url, "/linode/instances/123/firewalls")
285285
self.assertEqual(len(result), 1)
286286

287+
def test_apply_firewalls(self):
288+
"""
289+
Tests that you can submit a correct apply firewalls api request
290+
"""
291+
linode = Instance(self.client, 123)
292+
293+
with self.mock_post({}) as m:
294+
result = linode.apply_firewalls()
295+
self.assertEqual(
296+
m.call_url, "/linode/instances/123/firewalls/apply"
297+
)
298+
self.assertEqual(result, True)
299+
287300
def test_volumes(self):
288301
"""
289302
Tests that you can submit a correct volumes api request

0 commit comments

Comments
 (0)