libcloud-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From quent...@apache.org
Subject [2/3] libcloud git commit: Adds rebuild and resize commands for DigitalOcean
Date Mon, 29 Jan 2018 18:18:20 GMT
Adds rebuild and resize commands for DigitalOcean

Implement the following DigitalOcean APIs as driver-specific extensions,
* https://developers.digitalocean.com/documentation/v2/#rebuild-a-droplet
* https://developers.digitalocean.com/documentation/v2/#resize-a-droplet

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


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

Branch: refs/heads/trunk
Commit: 8fadb9c7c9b65993b84d12b63dc6ab8e1277ea24
Parents: 889a58a
Author: Adam Wight <awight@wikimedia.org>
Authored: Fri Jan 26 13:02:41 2018 -0500
Committer: Quentin Pradet <quentinp@apache.org>
Committed: Mon Jan 29 22:17:55 2018 +0400

----------------------------------------------------------------------
 libcloud/compute/drivers/digitalocean.py        | 34 ++++++++++++++++++++
 .../digitalocean_v2/ex_rebuild_node.json        | 12 +++++++
 .../digitalocean_v2/ex_resize_node.json         | 12 +++++++
 libcloud/test/compute/test_digitalocean_v2.py   | 25 ++++++++++++++
 4 files changed, 83 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/libcloud/blob/8fadb9c7/libcloud/compute/drivers/digitalocean.py
----------------------------------------------------------------------
diff --git a/libcloud/compute/drivers/digitalocean.py b/libcloud/compute/drivers/digitalocean.py
index c8acdf0..5815955 100644
--- a/libcloud/compute/drivers/digitalocean.py
+++ b/libcloud/compute/drivers/digitalocean.py
@@ -280,6 +280,40 @@ class DigitalOcean_v2_NodeDriver(DigitalOcean_v2_BaseDriver,
                                       data=json.dumps(attr), method='POST')
         return res.status == httplib.CREATED
 
+    def ex_rebuild_node(self, node):
+        """
+        Destroy and rebuild the node using its base image.
+
+        :param node: Node to rebuild
+        :type node: :class:`Node`
+
+        :return True if the operation began successfully
+        :rtype ``bool``
+        """
+        attr = {'type': 'rebuild', 'image': node.extra['image']['id']}
+        res = self.connection.request('/v2/droplets/%s/actions' % (node.id),
+                                      data=json.dumps(attr), method='POST')
+        return res.status == httplib.CREATED
+
+    def ex_resize_node(self, node, size):
+        """
+        Resize the node to a different machine size.  Note that some resize
+        operations are reversible, and others are irreversible.
+
+        :param node: Node to rebuild
+        :type node: :class:`Node`
+
+        :param size: New size for this machine
+        :type node: :class:`NodeSize`
+
+        :return True if the operation began successfully
+        :rtype ``bool``
+        """
+        attr = {'type': 'resize', 'size': size.name}
+        res = self.connection.request('/v2/droplets/%s/actions' % (node.id),
+                                      data=json.dumps(attr), method='POST')
+        return res.status == httplib.CREATED
+
     def create_key_pair(self, name, public_key=''):
         """
         Create a new SSH key.

http://git-wip-us.apache.org/repos/asf/libcloud/blob/8fadb9c7/libcloud/test/compute/fixtures/digitalocean_v2/ex_rebuild_node.json
----------------------------------------------------------------------
diff --git a/libcloud/test/compute/fixtures/digitalocean_v2/ex_rebuild_node.json b/libcloud/test/compute/fixtures/digitalocean_v2/ex_rebuild_node.json
new file mode 100644
index 0000000..154ddce
--- /dev/null
+++ b/libcloud/test/compute/fixtures/digitalocean_v2/ex_rebuild_node.json
@@ -0,0 +1,12 @@
+{
+  "action": {
+    "id": 36804758,
+    "status": "in-progress",
+    "type": "rebuild",
+    "started_at": "2014-11-14T16:31:19Z",
+    "completed_at": null,
+    "resource_id": 3164450,
+    "resource_type": "droplet",
+    "region_slug": "nyc3"
+  }
+}

http://git-wip-us.apache.org/repos/asf/libcloud/blob/8fadb9c7/libcloud/test/compute/fixtures/digitalocean_v2/ex_resize_node.json
----------------------------------------------------------------------
diff --git a/libcloud/test/compute/fixtures/digitalocean_v2/ex_resize_node.json b/libcloud/test/compute/fixtures/digitalocean_v2/ex_resize_node.json
new file mode 100644
index 0000000..94f5f0c
--- /dev/null
+++ b/libcloud/test/compute/fixtures/digitalocean_v2/ex_resize_node.json
@@ -0,0 +1,12 @@
+{
+  "action": {
+    "id": 36804758,
+    "status": "in-progress",
+    "type": "resize",
+    "started_at": "2014-11-14T16:31:19Z",
+    "completed_at": null,
+    "resource_id": 3164450,
+    "resource_type": "droplet",
+    "region_slug": "nyc3"
+  }
+}

http://git-wip-us.apache.org/repos/asf/libcloud/blob/8fadb9c7/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 c0065e7..1b049f9 100644
--- a/libcloud/test/compute/test_digitalocean_v2.py
+++ b/libcloud/test/compute/test_digitalocean_v2.py
@@ -155,6 +155,19 @@ class DigitalOcean_v2_Tests(LibcloudTestCase):
         result = self.driver.ex_hard_reboot(node)
         self.assertTrue(result)
 
+    def test_ex_rebuild_node_success(self):
+        node = self.driver.list_nodes()[0]
+        DigitalOceanMockHttp.type = 'REBUILD'
+        result = self.driver.ex_rebuild_node(node)
+        self.assertTrue(result)
+
+    def test_ex_resize_node_success(self):
+        node = self.driver.list_nodes()[0]
+        size = self.driver.list_sizes()[0]
+        DigitalOceanMockHttp.type = 'RESIZE'
+        result = self.driver.ex_resize_node(node, size)
+        self.assertTrue(result)
+
     def test_destroy_node_success(self):
         node = self.driver.list_nodes()[0]
         DigitalOceanMockHttp.type = 'DESTROY'
@@ -362,6 +375,18 @@ class DigitalOceanMockHttp(MockHttp):
         body = self.fixtures.load('ex_hard_reboot.json')
         return (httplib.CREATED, body, {}, httplib.responses[httplib.OK])
 
+    def _v2_droplets_3164444_actions_REBUILD(self, method, url,
+                                             body, headers):
+        # ex_rebuild_node
+        body = self.fixtures.load('ex_rebuild_node.json')
+        return (httplib.CREATED, body, {}, httplib.responses[httplib.OK])
+
+    def _v2_droplets_3164444_actions_RESIZE(self, method, url,
+                                            body, headers):
+        # ex_resize_node
+        body = self.fixtures.load('ex_resize_node.json')
+        return (httplib.CREATED, body, {}, httplib.responses[httplib.OK])
+
     def _v2_account_keys(self, method, url, body, headers):
         body = self.fixtures.load('list_key_pairs.json')
         return (httplib.OK, body, {}, httplib.responses[httplib.OK])


Mime
View raw message