Skip to content

Commit

Permalink
Implementing cluster_standalone.Cluster.delete().
Browse files Browse the repository at this point in the history
  • Loading branch information
dhermes committed Jul 25, 2015
1 parent bac2ca0 commit 5fdcd61
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
20 changes: 20 additions & 0 deletions gcloud_bigtable/cluster_standalone.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@
class Cluster(object):
"""Representation of a Google Cloud Bigtable Cluster.
We can use a :class:`Cluster` to:
* :meth:`Cluster.reload` itself
* :meth:`Cluster.delete` itself
:type zone: string
:param zone: The name of the zone where the cluster resides.
Expand Down Expand Up @@ -172,3 +177,18 @@ def reload(self, timeout_seconds=TIMEOUT_SECONDS):
# NOTE: _update_from_pb does not check that the project, zone and
# cluster ID on the response match the request.
self._update_from_pb(cluster_pb)

def delete(self, timeout_seconds=TIMEOUT_SECONDS):
"""Delete this cluster.
:type timeout_seconds: integer
:param timeout_seconds: Number of seconds for request time-out.
If not passed, defaults to ``TIMEOUT_SECONDS``.
"""
request_pb = messages_pb2.DeleteClusterRequest(name=self.name)
stub = make_stub(self.client._credentials, CLUSTER_STUB_FACTORY,
CLUSTER_ADMIN_HOST, CLUSTER_ADMIN_PORT)
with stub:
response = stub.DeleteCluster.async(request_pb, timeout_seconds)
# We expect a `._generated.empty_pb2.Empty`
response.result()
27 changes: 27 additions & 0 deletions gcloud_bigtable/test_cluster_standalone.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,3 +210,30 @@ def result_method(client):
self._grpc_client_test_helper('GetCluster', result_method,
request_pb, response_pb, expected_result,
PROJECT_ID)

def test_delete(self):
from gcloud_bigtable._generated import (
bigtable_cluster_service_messages_pb2 as messages_pb2)
from gcloud_bigtable._generated import empty_pb2

TEST_CASE = self

# Create request_pb
cluster_name = ('projects/' + PROJECT_ID + '/zones/' + ZONE +
'/clusters/' + CLUSTER_ID)
request_pb = messages_pb2.DeleteClusterRequest(name=cluster_name)

# Create response_pb
response_pb = empty_pb2.Empty()

# Create expected_result.
expected_result = None # delete() has no return value.

# We must create the cluster with the client passed in.
def result_method(client):
cluster = TEST_CASE._makeOne(ZONE, CLUSTER_ID, client)
return cluster.delete()

self._grpc_client_test_helper('DeleteCluster', result_method,
request_pb, response_pb, expected_result,
PROJECT_ID)

0 comments on commit 5fdcd61

Please sign in to comment.