Skip to content

Commit

Permalink
delete ip
Browse files Browse the repository at this point in the history
  • Loading branch information
yec-akamai committed Jan 17, 2025
1 parent 8e5134e commit c5d519f
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 1 deletion.
14 changes: 14 additions & 0 deletions linode_api4/objects/networking.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,20 @@ def to(self, linode):

return {"address": self.address, "linode_id": linode.id}

def delete(self):
"""
Override the delete() function from Base to use the correct endpoint.
"""
resp = self._client.delete(
"/linode/instances/{}/ips/{}".format(self.linode_id, self.address),
model=self,
)

if "error" in resp:
return False
self.invalidate()
return True


@dataclass
class VPCIPAddress(JSONObject):
Expand Down
13 changes: 13 additions & 0 deletions test/integration/models/networking/test_networking.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,3 +150,16 @@ def test_network_transfer_prices(test_linode_client):
transfer_prices[0].price is None
or transfer_prices[0].price.hourly >= 0
)


def test_allocate_and_delete_ip(test_linode_client, create_linode):
linode = create_linode
ip = test_linode_client.networking.ip_allocate(linode.id)
linode.invalidate()

assert ip.linode_id == linode.id
assert ip.address in linode.ipv4

is_deleted = ip.delete()

assert is_deleted is True
13 changes: 12 additions & 1 deletion test/unit/objects/networking_test.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from test.unit.base import ClientBaseCase

from linode_api4 import ExplicitNullValue
from linode_api4 import ExplicitNullValue, Instance
from linode_api4.objects import Firewall, IPAddress, IPv6Range


Expand Down Expand Up @@ -83,3 +83,14 @@ def test_vpc_nat_1_1(self):
self.assertEqual(ip.vpc_nat_1_1.vpc_id, 242)
self.assertEqual(ip.vpc_nat_1_1.subnet_id, 194)
self.assertEqual(ip.vpc_nat_1_1.address, "139.144.244.36")

def test_delete_ip(self):
"""
Tests that deleting an IP creates the correct api request
"""
with self.mock_delete() as m:
ip = IPAddress(self.client, "127.0.0.1")
ip.to(Instance(self.client, 123))
ip.delete()

self.assertEqual(m.call_url, "/linode/instances/123/ips/127.0.0.1")

0 comments on commit c5d519f

Please sign in to comment.