diff --git a/openstack/cluster/v1/_proxy.py b/openstack/cluster/v1/_proxy.py index b3c65123c..98f9b7610 100644 --- a/openstack/cluster/v1/_proxy.py +++ b/openstack/cluster/v1/_proxy.py @@ -191,9 +191,11 @@ class Proxy(proxy.BaseProxy): the cluster could not be found. When set to ``True``, no exception will be raised when attempting to delete a non-existent cluster. - :returns: ``None`` + :returns: The instance of the Cluster which was deleted. + :rtype: :class:`~openstack.cluster.v1.cluster.Cluster`. """ - self._delete(_cluster.Cluster, cluster, ignore_missing=ignore_missing) + return self._delete(_cluster.Cluster, cluster, + ignore_missing=ignore_missing) def find_cluster(self, name_or_id, ignore_missing=True): """Find a single cluster. @@ -427,9 +429,10 @@ class Proxy(proxy.BaseProxy): the node could not be found. When set to ``True``, no exception will be raised when attempting to delete a non-existent node. - :returns: ``None`` + :returns: The instance of the Node which was deleted. + :rtype: :class:`~openstack.cluster.v1.node.Node`. """ - self._delete(_node.Node, node, ignore_missing=ignore_missing) + return self._delete(_node.Node, node, ignore_missing=ignore_missing) def check_node(self, node, **params): """check a node. diff --git a/openstack/cluster/v1/cluster.py b/openstack/cluster/v1/cluster.py index 622697a6f..5fca92e19 100644 --- a/openstack/cluster/v1/cluster.py +++ b/openstack/cluster/v1/cluster.py @@ -149,3 +149,17 @@ class Cluster(resource.Resource): 'recover': params } return self.action(session, body) + + def delete(self, session): + """Delete the remote resource associated with this instance. + + :param session: The session to use for making this request. + :type session: :class:`~openstack.session.Session` + + :returns: The instance of the Cluster which was deleted. + :rtype: :class:`~openstack.cluster.v1.cluster.Cluster`. + """ + url = self._get_url(self, self.id) + resp = session.delete(url, endpoint_filter=self.service) + self.location = resp.headers['location'] + return self diff --git a/openstack/cluster/v1/node.py b/openstack/cluster/v1/node.py index 4106f54ab..de7287ac1 100644 --- a/openstack/cluster/v1/node.py +++ b/openstack/cluster/v1/node.py @@ -99,3 +99,17 @@ class Node(resource.Resource): 'recover': params } return self._action(session, body) + + def delete(self, session): + """Delete the remote resource associated with this instance. + + :param session: The session to use for making this request. + :type session: :class:`~openstack.session.Session` + + :returns: The instance of the Node which was deleted. + :rtype: :class:`~openstack.cluster.v1.node.Node`. + """ + url = self._get_url(self, self.id) + resp = session.delete(url, endpoint_filter=self.service) + self.location = resp.headers['location'] + return self diff --git a/openstack/tests/unit/cluster/v1/test_cluster.py b/openstack/tests/unit/cluster/v1/test_cluster.py index 374bb82d6..dcab3b06c 100644 --- a/openstack/tests/unit/cluster/v1/test_cluster.py +++ b/openstack/tests/unit/cluster/v1/test_cluster.py @@ -248,3 +248,14 @@ class TestCluster(testtools.TestCase): body = {'recover': {}} sess.post.assert_called_once_with(url, endpoint_filter=sot.service, json=body) + + def test_cluster_delete(self): + sot = cluster.Cluster(FAKE) + sot['id'] = 'IDENTIFIER' + url = 'clusters/%s' % sot.id + resp = mock.Mock(headers={'location': 'actions/fake_action'}) + sess = mock.Mock() + sess.delete = mock.Mock(return_value=resp) + clus = sot.delete(sess) + self.assertEqual('actions/fake_action', clus.location) + sess.delete.assert_called_once_with(url, endpoint_filter=sot.service) diff --git a/openstack/tests/unit/cluster/v1/test_node.py b/openstack/tests/unit/cluster/v1/test_node.py index 32a269f2d..88b4695e1 100644 --- a/openstack/tests/unit/cluster/v1/test_node.py +++ b/openstack/tests/unit/cluster/v1/test_node.py @@ -106,3 +106,14 @@ class TestNode(testtools.TestCase): body = {'recover': {}} sess.post.assert_called_once_with(url, endpoint_filter=sot.service, json=body) + + def test_node_delete(self): + sot = node.Node(FAKE) + sot['id'] = 'IDENTIFIER' + url = 'nodes/%s' % sot.id + resp = mock.Mock(headers={'location': 'actions/fake_action'}) + sess = mock.Mock() + sess.delete = mock.Mock(return_value=resp) + nod = sot.delete(sess) + self.assertEqual('actions/fake_action', nod.location) + sess.delete.assert_called_once_with(url, endpoint_filter=sot.service)