You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@libcloud.apache.org by an...@apache.org on 2016/10/24 12:38:38 UTC

[2/3] libcloud git commit: add ex_hard_reboot in DigitalOcean_v2 driver

add ex_hard_reboot in DigitalOcean_v2 driver

implement power_cycle
Closes #920


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

Branch: refs/heads/trunk
Commit: da5f68045147a036d189fc606fb4720951bd03e0
Parents: 3a1928a
Author: Rick van de Loo <ri...@gmail.com>
Authored: Fri Oct 21 14:17:42 2016 +0200
Committer: Anthony Shaw <an...@apache.org>
Committed: Mon Oct 24 13:37:43 2016 +0100

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


http://git-wip-us.apache.org/repos/asf/libcloud/blob/da5f6804/libcloud/compute/drivers/digitalocean.py
----------------------------------------------------------------------
diff --git a/libcloud/compute/drivers/digitalocean.py b/libcloud/compute/drivers/digitalocean.py
index 7a676b6..335e065 100644
--- a/libcloud/compute/drivers/digitalocean.py
+++ b/libcloud/compute/drivers/digitalocean.py
@@ -256,6 +256,12 @@ class DigitalOcean_v2_NodeDriver(DigitalOcean_v2_BaseDriver,
                                       data=json.dumps(attr), method='POST')
         return res.status == httplib.CREATED
 
+    def ex_hard_reboot(self, node):
+        attr = {'type': 'power_cycle'}
+        res = self.connection.request('/v2/droplets/%s/actions' % (node.id),
+                                      data=json.dumps(attr), method='POST')
+        return res.status == httplib.CREATED
+
     def ex_power_on_node(self, node):
         attr = {'type': 'power_on'}
         res = self.connection.request('/v2/droplets/%s/actions' % (node.id),

http://git-wip-us.apache.org/repos/asf/libcloud/blob/da5f6804/libcloud/test/compute/fixtures/digitalocean/ex_hard_reboot.json
----------------------------------------------------------------------
diff --git a/libcloud/test/compute/fixtures/digitalocean/ex_hard_reboot.json b/libcloud/test/compute/fixtures/digitalocean/ex_hard_reboot.json
new file mode 100644
index 0000000..891b32e
--- /dev/null
+++ b/libcloud/test/compute/fixtures/digitalocean/ex_hard_reboot.json
@@ -0,0 +1,12 @@
+{
+  "action": {
+    "id": 36077294,
+    "status": "in-progress",
+    "type": "power_cycle",
+    "started_at": "2014-11-04T17:08:03Z",
+    "completed_at": null,
+    "resource_id": 3067651,
+    "resource_type": "droplet",
+    "region": "ams3"
+  }
+}

http://git-wip-us.apache.org/repos/asf/libcloud/blob/da5f6804/libcloud/test/compute/fixtures/digitalocean_v2/ex_hard_reboot.json
----------------------------------------------------------------------
diff --git a/libcloud/test/compute/fixtures/digitalocean_v2/ex_hard_reboot.json b/libcloud/test/compute/fixtures/digitalocean_v2/ex_hard_reboot.json
new file mode 100644
index 0000000..891b32e
--- /dev/null
+++ b/libcloud/test/compute/fixtures/digitalocean_v2/ex_hard_reboot.json
@@ -0,0 +1,12 @@
+{
+  "action": {
+    "id": 36077294,
+    "status": "in-progress",
+    "type": "power_cycle",
+    "started_at": "2014-11-04T17:08:03Z",
+    "completed_at": null,
+    "resource_id": 3067651,
+    "resource_type": "droplet",
+    "region": "ams3"
+  }
+}

http://git-wip-us.apache.org/repos/asf/libcloud/blob/da5f6804/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 c7a916d..2ba7e90 100644
--- a/libcloud/test/compute/test_digitalocean_v2.py
+++ b/libcloud/test/compute/test_digitalocean_v2.py
@@ -148,6 +148,12 @@ class DigitalOcean_v2_Tests(LibcloudTestCase):
         result = self.driver.ex_shutdown_node(node)
         self.assertTrue(result)
 
+    def test_ex_hard_reboot_success(self):
+        node = self.driver.list_nodes()[0]
+        DigitalOceanMockHttp.type = 'POWERCYCLE'
+        result = self.driver.ex_hard_reboot(node)
+        self.assertTrue(result)
+
     def test_destroy_node_success(self):
         node = self.driver.list_nodes()[0]
         DigitalOceanMockHttp.type = 'DESTROY'
@@ -327,6 +333,12 @@ class DigitalOceanMockHttp(MockHttpTestCase):
         body = self.fixtures.load('ex_shutdown_node.json')
         return (httplib.CREATED, body, {}, httplib.responses[httplib.CREATED])
 
+    def _v2_droplets_3164444_actions_POWERCYCLE(self, method, url,
+                                                body, headers):
+        # ex_hard_reboot
+        body = self.fixtures.load('ex_hard_reboot.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])