Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TPT-3319: Add support for Apply Linode Firewalls #492

Merged
merged 3 commits into from
Jan 17, 2025
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions linode_api4/objects/linode.py
Original file line number Diff line number Diff line change
Expand Up @@ -1638,6 +1638,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
10 changes: 9 additions & 1 deletion test/integration/models/linode/test_linode.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def linode_with_volume_firewall(test_linode_client):
linode_instance, password = client.linode.instance_create(
"g6-nanode-1",
region,
image="linode/debian10",
image="linode/debian12",
label=label + "_modlinode",
)

Expand Down Expand Up @@ -426,6 +426,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
Loading