Skip to content

Commit

Permalink
TPT-3319: Add support for Apply Linode Firewalls (linode#492)
Browse files Browse the repository at this point in the history
* Add support for linode/instances/:id/firewalls/apply

* updating the test image

---------

Co-authored-by: ykim-1 <[email protected]>
Co-authored-by: Lena Garber <[email protected]>
  • Loading branch information
3 people authored Jan 17, 2025
1 parent f1fa70e commit 8e5134e
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 0 deletions.
16 changes: 16 additions & 0 deletions linode_api4/objects/linode.py
Original file line number Diff line number Diff line change
Expand Up @@ -1639,6 +1639,22 @@ def firewalls(self):
for firewall in result["data"]
]

def apply_firewalls(self):
"""
Reapply assigned firewalls to a Linode in case they were not applied successfully.
API Documentation: https://techdocs.akamai.com/linode-api/reference/post-apply-firewalls
:returns: Returns True if the operation was successful
:rtype: bool
"""

self._client.post(
"{}/firewalls/apply".format(Instance.api_endpoint), model=self
)

return True

def nodebalancers(self):
"""
View a list of NodeBalancers that are assigned to this Linode and readable by the requesting User.
Expand Down
8 changes: 8 additions & 0 deletions test/integration/models/linode/test_linode.py
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,14 @@ def test_linode_firewalls(linode_with_volume_firewall):
assert "firewall" in firewalls[0].label


def test_linode_apply_firewalls(linode_with_volume_firewall):
linode = linode_with_volume_firewall

result = linode.apply_firewalls()

assert result


def test_linode_volumes(linode_with_volume_firewall):
linode = linode_with_volume_firewall

Expand Down
13 changes: 13 additions & 0 deletions test/unit/objects/linode_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,19 @@ def test_firewalls(self):
self.assertEqual(m.call_url, "/linode/instances/123/firewalls")
self.assertEqual(len(result), 1)

def test_apply_firewalls(self):
"""
Tests that you can submit a correct apply firewalls api request
"""
linode = Instance(self.client, 123)

with self.mock_post({}) as m:
result = linode.apply_firewalls()
self.assertEqual(
m.call_url, "/linode/instances/123/firewalls/apply"
)
self.assertEqual(result, True)

def test_volumes(self):
"""
Tests that you can submit a correct volumes api request
Expand Down

0 comments on commit 8e5134e

Please sign in to comment.