From d13c20de096f34dc32a611114e0e7efff43bf067 Mon Sep 17 00:00:00 2001 From: John Callahan Date: Thu, 26 Dec 2024 16:05:49 -0500 Subject: [PATCH 1/2] Add support for linode/instances/:id/firewalls/apply --- linode_api4/objects/linode.py | 16 ++++++++++++++++ test/integration/models/linode/test_linode.py | 8 ++++++++ test/unit/objects/linode_test.py | 13 +++++++++++++ 3 files changed, 37 insertions(+) diff --git a/linode_api4/objects/linode.py b/linode_api4/objects/linode.py index 8fe71bb7d..c1490b67d 100644 --- a/linode_api4/objects/linode.py +++ b/linode_api4/objects/linode.py @@ -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. diff --git a/test/integration/models/linode/test_linode.py b/test/integration/models/linode/test_linode.py index a8ba2b21e..3b24af5d6 100644 --- a/test/integration/models/linode/test_linode.py +++ b/test/integration/models/linode/test_linode.py @@ -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 diff --git a/test/unit/objects/linode_test.py b/test/unit/objects/linode_test.py index 700e5d0db..755a050d6 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 From 4c4f29ab1f712e68298251cfbc445b69cfa0a4f2 Mon Sep 17 00:00:00 2001 From: ykim-1 Date: Fri, 10 Jan 2025 11:38:56 -0800 Subject: [PATCH 2/2] updating the test image --- test/integration/models/linode/test_linode.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/integration/models/linode/test_linode.py b/test/integration/models/linode/test_linode.py index 3b24af5d6..513bac7aa 100644 --- a/test/integration/models/linode/test_linode.py +++ b/test/integration/models/linode/test_linode.py @@ -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", )