libcloud-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From anthonys...@apache.org
Subject libcloud git commit: add ex_change_kernel in DigitalOcean_v2 driver
Date Mon, 24 Oct 2016 15:43:49 GMT
Repository: libcloud
Updated Branches:
  refs/heads/trunk 5ef94eb3a -> 1e19061df


add ex_change_kernel in DigitalOcean_v2 driver

> To change the kernel of a Droplet, send a POST request to
> /v2/droplets/$DROPLET_ID/actions. Set the "type" attribute to
> change_kernel and the "kernel" attribute to the new kernel's ID.

https://developers.digitalocean.com/documentation/v2/#change-the-kernel

Closes #922


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

Branch: refs/heads/trunk
Commit: 1e19061dffed59008ca110dae7afe032d31287ce
Parents: 5ef94eb
Author: Rick van de Loo <rickvandeloo@gmail.com>
Authored: Mon Oct 24 14:42:59 2016 +0200
Committer: Anthony Shaw <anthonyshaw@apache.org>
Committed: Mon Oct 24 16:43:30 2016 +0100

----------------------------------------------------------------------
 libcloud/compute/drivers/digitalocean.py                |  6 ++++++
 .../compute/fixtures/digitalocean/ex_change_kernel.json | 12 ++++++++++++
 .../fixtures/digitalocean_v2/ex_change_kernel.json      | 12 ++++++++++++
 libcloud/test/compute/test_digitalocean_v2.py           | 11 +++++++++++
 4 files changed, 41 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/libcloud/blob/1e19061d/libcloud/compute/drivers/digitalocean.py
----------------------------------------------------------------------
diff --git a/libcloud/compute/drivers/digitalocean.py b/libcloud/compute/drivers/digitalocean.py
index 335e065..9800023 100644
--- a/libcloud/compute/drivers/digitalocean.py
+++ b/libcloud/compute/drivers/digitalocean.py
@@ -244,6 +244,12 @@ class DigitalOcean_v2_NodeDriver(DigitalOcean_v2_BaseDriver,
         data = self._paginated_request('/v2/images/%s' % (image_id), 'image')
         return self._to_image(data)
 
+    def ex_change_kernel(self, node, kernel_id):
+        attr = {'type': 'change_kernel', 'kernel': kernel_id}
+        res = self.connection.request('/v2/droplets/%s/actions' % (node.id),
+                                      data=json.dumps(attr), method='POST')
+        return res.status == httplib.CREATED
+
     def ex_rename_node(self, node, name):
         attr = {'type': 'rename', 'name': name}
         res = self.connection.request('/v2/droplets/%s/actions' % (node.id),

http://git-wip-us.apache.org/repos/asf/libcloud/blob/1e19061d/libcloud/test/compute/fixtures/digitalocean/ex_change_kernel.json
----------------------------------------------------------------------
diff --git a/libcloud/test/compute/fixtures/digitalocean/ex_change_kernel.json b/libcloud/test/compute/fixtures/digitalocean/ex_change_kernel.json
new file mode 100644
index 0000000..561101f
--- /dev/null
+++ b/libcloud/test/compute/fixtures/digitalocean/ex_change_kernel.json
@@ -0,0 +1,12 @@
+{
+  "action": {
+    "id": 36077295,
+    "status": "in-progress",
+    "type": "kernel_change",
+    "started_at": "2014-11-04T17:08:03Z",
+    "completed_at": null,
+    "resource_id": 3067650,
+    "resource_type": "droplet",
+    "region": "ams2"
+  }
+}

http://git-wip-us.apache.org/repos/asf/libcloud/blob/1e19061d/libcloud/test/compute/fixtures/digitalocean_v2/ex_change_kernel.json
----------------------------------------------------------------------
diff --git a/libcloud/test/compute/fixtures/digitalocean_v2/ex_change_kernel.json b/libcloud/test/compute/fixtures/digitalocean_v2/ex_change_kernel.json
new file mode 100644
index 0000000..561101f
--- /dev/null
+++ b/libcloud/test/compute/fixtures/digitalocean_v2/ex_change_kernel.json
@@ -0,0 +1,12 @@
+{
+  "action": {
+    "id": 36077295,
+    "status": "in-progress",
+    "type": "kernel_change",
+    "started_at": "2014-11-04T17:08:03Z",
+    "completed_at": null,
+    "resource_id": 3067650,
+    "resource_type": "droplet",
+    "region": "ams2"
+  }
+}

http://git-wip-us.apache.org/repos/asf/libcloud/blob/1e19061d/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 2ba7e90..88dcea6 100644
--- a/libcloud/test/compute/test_digitalocean_v2.py
+++ b/libcloud/test/compute/test_digitalocean_v2.py
@@ -160,6 +160,12 @@ class DigitalOcean_v2_Tests(LibcloudTestCase):
         result = self.driver.destroy_node(node)
         self.assertTrue(result)
 
+    def test_ex_change_kernel_success(self):
+        node = self.driver.list_nodes()[0]
+        DigitalOceanMockHttp.type = 'KERNELCHANGE'
+        result = self.driver.ex_change_kernel(node, 7515)
+        self.assertTrue(result)
+
     def test_ex_rename_node_success(self):
         node = self.driver.list_nodes()[0]
         DigitalOceanMockHttp.type = 'RENAME'
@@ -301,6 +307,11 @@ class DigitalOceanMockHttp(MockHttpTestCase):
         return (httplib.NO_CONTENT, body, {},
                 httplib.responses[httplib.NO_CONTENT])
 
+    def _v2_droplets_3164444_actions_KERNELCHANGE(self, method, url, body, headers):
+        # change_kernel
+        body = self.fixtures.load('ex_change_kernel.json')
+        return (httplib.CREATED, body, {}, httplib.responses[httplib.CREATED])
+
     def _v2_droplets_3164444_actions_RENAME(self, method, url, body, headers):
         # rename_node
         body = self.fixtures.load('ex_rename_node.json')


Mime
View raw message