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/09/26 04:52:20 UTC
[2/3] libcloud git commit: Add ex_stop_node to OS driver
Add ex_stop_node to OS driver
Project: http://git-wip-us.apache.org/repos/asf/libcloud/repo
Commit: http://git-wip-us.apache.org/repos/asf/libcloud/commit/30965d73
Tree: http://git-wip-us.apache.org/repos/asf/libcloud/tree/30965d73
Diff: http://git-wip-us.apache.org/repos/asf/libcloud/diff/30965d73
Branch: refs/heads/trunk
Commit: 30965d738803126499444b79c13fc8119f32334a
Parents: 7695cf2
Author: Allard Hoeve <al...@gmail.com>
Authored: Fri Sep 23 11:07:26 2016 +0200
Committer: Anthony Shaw <an...@apache.org>
Committed: Mon Sep 26 14:51:56 2016 +1000
----------------------------------------------------------------------
CHANGES.rst | 3 +++
libcloud/compute/drivers/openstack.py | 32 ++++++++++++++--------------
libcloud/test/compute/test_openstack.py | 8 +++++++
3 files changed, 27 insertions(+), 16 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/libcloud/blob/30965d73/CHANGES.rst
----------------------------------------------------------------------
diff --git a/CHANGES.rst b/CHANGES.rst
index 669c8a0..15cdf78 100644
--- a/CHANGES.rst
+++ b/CHANGES.rst
@@ -16,6 +16,9 @@ Compute
- When fetching the node details of a non-existing node, OpenStack would raise a
`BaseHTTPError` instead of returning `None`, as was intended. Fixed tests and code.
(GITHUB-864)
+
+- Added `ex_stop_node` to the OpenStack driver.
+ (GITHUB-865)
[Allard Hoeve]
Container
http://git-wip-us.apache.org/repos/asf/libcloud/blob/30965d73/libcloud/compute/drivers/openstack.py
----------------------------------------------------------------------
diff --git a/libcloud/compute/drivers/openstack.py b/libcloud/compute/drivers/openstack.py
index 5357cad..d1c3cbd 100644
--- a/libcloud/compute/drivers/openstack.py
+++ b/libcloud/compute/drivers/openstack.py
@@ -2407,29 +2407,29 @@ class OpenStack_1_1_NodeDriver(OpenStackNodeDriver):
return node.extra['metadata']
def ex_pause_node(self, node):
- uri = '/servers/%s/action' % (node.id)
- data = {'pause': None}
- resp = self.connection.request(uri, method='POST', data=data)
- return resp.status == httplib.ACCEPTED
+ return self._post_simple_node_action(node, 'pause')
def ex_unpause_node(self, node):
- uri = '/servers/%s/action' % (node.id)
- data = {'unpause': None}
- resp = self.connection.request(uri, method='POST', data=data)
- return resp.status == httplib.ACCEPTED
+ return self._post_simple_node_action(node, 'unpause')
+
+ def ex_stop_node(self, node):
+ return self._post_simple_node_action(node, 'os-stop')
def ex_suspend_node(self, node):
- uri = '/servers/%s/action' % (node.id)
- data = {'suspend': None}
- resp = self.connection.request(uri, method='POST', data=data)
- return resp.status == httplib.ACCEPTED
+ return self._post_simple_node_action(node, 'suspend')
def ex_resume_node(self, node):
- uri = '/servers/%s/action' % (node.id)
- data = {'resume': None}
- resp = self.connection.request(uri, method='POST', data=data)
- return resp.status == httplib.ACCEPTED
+ return self._post_simple_node_action(node, 'resume')
+ def _post_simple_node_action(self, node, action):
+ """ Post a simple, data-less action to the OS node action endpoint
+ :param `Node` node:
+ :param str action: the action to call
+ :return `bool`: a boolean that indicates success
+ """
+ uri = '/servers/{}/action'.format(node.id)
+ resp = self.connection.request(uri, method='POST', data={action: None})
+ return resp.status == httplib.ACCEPTED
class OpenStack_1_1_FloatingIpPool(object):
"""
http://git-wip-us.apache.org/repos/asf/libcloud/blob/30965d73/libcloud/test/compute/test_openstack.py
----------------------------------------------------------------------
diff --git a/libcloud/test/compute/test_openstack.py b/libcloud/test/compute/test_openstack.py
index cd5a992..ec6a00e 100644
--- a/libcloud/test/compute/test_openstack.py
+++ b/libcloud/test/compute/test_openstack.py
@@ -1437,6 +1437,14 @@ class OpenStack_1_1_Tests(unittest.TestCase, TestCaseMixin):
ret = self.driver.ex_unpause_node(node)
self.assertTrue(ret is True)
+ def test_ex_stop_node(self):
+ node = Node(
+ id='12063', name=None, state=None,
+ public_ips=None, private_ips=None, driver=self.driver,
+ )
+ ret = self.driver.ex_stop_node(node)
+ self.assertTrue(ret is True)
+
def test_ex_suspend_node(self):
node = Node(
id='12063', name=None, state=None,