Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 94AC0200B9C for ; Mon, 26 Sep 2016 06:52:21 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 93277160ACE; Mon, 26 Sep 2016 04:52:21 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id D601D160AE3 for ; Mon, 26 Sep 2016 06:52:20 +0200 (CEST) Received: (qmail 71331 invoked by uid 500); 26 Sep 2016 04:52:20 -0000 Mailing-List: contact notifications-help@libcloud.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@libcloud.apache.org Delivered-To: mailing list notifications@libcloud.apache.org Received: (qmail 71318 invoked by uid 500); 26 Sep 2016 04:52:19 -0000 Delivered-To: apmail-libcloud-commits@libcloud.apache.org Received: (qmail 71314 invoked by uid 99); 26 Sep 2016 04:52:19 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 26 Sep 2016 04:52:19 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 94ADEE1075; Mon, 26 Sep 2016 04:52:19 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: anthonyshaw@apache.org To: commits@libcloud.apache.org Date: Mon, 26 Sep 2016 04:52:20 -0000 Message-Id: <903711da9932448298aaf15c8a032213@git.apache.org> In-Reply-To: References: X-Mailer: ASF-Git Admin Mailer Subject: [2/3] libcloud git commit: Add ex_stop_node to OS driver archived-at: Mon, 26 Sep 2016 04:52:21 -0000 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 Authored: Fri Sep 23 11:07:26 2016 +0200 Committer: Anthony Shaw 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,