You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@libcloud.apache.org by qu...@apache.org on 2018/03/09 04:55:47 UTC

[5/6] libcloud git commit: implement ex_delete_floating_ip for DigitalOcean

implement ex_delete_floating_ip for DigitalOcean

delete a floating IP by passing the object into conn.ex_delete_floating_ip
or by running .delete on the floating IP object

Signed-off-by: Quentin Pradet <qu...@apache.org>


Project: http://git-wip-us.apache.org/repos/asf/libcloud/repo
Commit: http://git-wip-us.apache.org/repos/asf/libcloud/commit/c069603b
Tree: http://git-wip-us.apache.org/repos/asf/libcloud/tree/c069603b
Diff: http://git-wip-us.apache.org/repos/asf/libcloud/diff/c069603b

Branch: refs/heads/trunk
Commit: c069603b3bb2c35032a8c742cd1b3efab0c45934
Parents: d613edf
Author: Rick van de Loo <ri...@gmail.com>
Authored: Sun Mar 4 14:26:25 2018 +0100
Committer: Quentin Pradet <qu...@apache.org>
Committed: Fri Mar 9 08:54:34 2018 +0400

----------------------------------------------------------------------
 libcloud/compute/drivers/digitalocean.py        | 13 ++++++++++++
 .../delete_floating_ip_167_138_123_111.json     |  0
 libcloud/test/compute/test_digitalocean_v2.py   | 22 ++++++++++++++++++++
 3 files changed, 35 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/libcloud/blob/c069603b/libcloud/compute/drivers/digitalocean.py
----------------------------------------------------------------------
diff --git a/libcloud/compute/drivers/digitalocean.py b/libcloud/compute/drivers/digitalocean.py
index 91dee7b..d1f44ba 100644
--- a/libcloud/compute/drivers/digitalocean.py
+++ b/libcloud/compute/drivers/digitalocean.py
@@ -511,6 +511,19 @@ class DigitalOcean_v2_NodeDriver(DigitalOcean_v2_BaseDriver,
                                        data=json.dumps(attr), method='POST')
         return self._to_floating_ip(resp.object['floating_ip'])
 
+    def ex_delete_floating_ip(self, ip):
+        """
+        Delete specified floating IP
+
+        :param      ip: floating IP to remove
+        :type       ip: :class:`DigitalOcean_v2_FloatingIpAddress`
+
+        :rtype: ``bool``
+        """
+        resp = self.connection.request('/v2/floating_ips/{}'.format(ip.id),
+                                       method='DELETE')
+        return resp.status == httplib.NO_CONTENT
+
     def _to_node(self, data):
         extra_keys = ['memory', 'vcpus', 'disk', 'region', 'image',
                       'size_slug', 'locked', 'created_at', 'networks',

http://git-wip-us.apache.org/repos/asf/libcloud/blob/c069603b/libcloud/test/compute/fixtures/openstack_v1.1/delete_floating_ip_167_138_123_111.json
----------------------------------------------------------------------
diff --git a/libcloud/test/compute/fixtures/openstack_v1.1/delete_floating_ip_167_138_123_111.json b/libcloud/test/compute/fixtures/openstack_v1.1/delete_floating_ip_167_138_123_111.json
new file mode 100644
index 0000000..e69de29

http://git-wip-us.apache.org/repos/asf/libcloud/blob/c069603b/libcloud/test/compute/test_digitalocean_v2.py
----------------------------------------------------------------------
diff --git a/libcloud/test/compute/test_digitalocean_v2.py b/libcloud/test/compute/test_digitalocean_v2.py
index f2cc3f7..9e87bd2 100644
--- a/libcloud/test/compute/test_digitalocean_v2.py
+++ b/libcloud/test/compute/test_digitalocean_v2.py
@@ -307,6 +307,21 @@ class DigitalOcean_v2_Tests(LibcloudTestCase):
         # from the start. This API call creates an unattached IP.
         self.assertIsNone(floating_ip.node_id)
 
+    def test_ex_delete_floating_ip(self):
+        nyc1 = [r for r in self.driver.list_locations() if r.id == 'nyc1'][0]
+        floating_ip = self.driver.ex_create_floating_ip(nyc1)
+        ret = self.driver.ex_delete_floating_ip(floating_ip)
+
+        # The API returns 204 NO CONTENT if all is well.
+        self.assertTrue(ret)
+
+    def test_floating_ip_can_be_deleted_by_calling_delete_on_floating_ip_object(self):
+        nyc1 = [r for r in self.driver.list_locations() if r.id == 'nyc1'][0]
+        floating_ip = self.driver.ex_create_floating_ip(nyc1)
+        ret = floating_ip.delete()
+
+        self.assertTrue(ret)
+
 
 class DigitalOceanMockHttp(MockHttp):
     fixtures = ComputeFileFixtures('digitalocean_v2')
@@ -474,6 +489,13 @@ class DigitalOceanMockHttp(MockHttp):
         else:
             raise NotImplementedError()
 
+    def _v2_floating_ips_167_138_123_111(self, method, url, body, headers):
+        if method == 'DELETE':
+            body = ''
+            return (httplib.NO_CONTENT, body, {}, httplib.responses[httplib.NO_CONTENT])
+        else:
+            raise NotImplementedError()
+
 
 if __name__ == '__main__':
     sys.exit(unittest.main())