diff --git a/linode_api4/objects/linode.py b/linode_api4/objects/linode.py index 776e1f98..7a8c959a 100644 --- a/linode_api4/objects/linode.py +++ b/linode_api4/objects/linode.py @@ -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. diff --git a/test/integration/models/linode/test_linode.py b/test/integration/models/linode/test_linode.py index 6879df1d..d97a8294 100644 --- a/test/integration/models/linode/test_linode.py +++ b/test/integration/models/linode/test_linode.py @@ -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 diff --git a/test/unit/objects/linode_test.py b/test/unit/objects/linode_test.py index a911152f..44fea4f3 100644 --- a/test/unit/objects/linode_test.py +++ b/test/unit/objects/linode_test.py @@ -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