Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding list clusters request to Bigtable client. #1244

Merged
merged 1 commit into from
Nov 25, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions gcloud/bigtable/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -400,3 +400,23 @@ def list_zones(self):
zone.display_name,))
result.append(zone.display_name)
return result

def list_clusters(self):
"""Lists clusters owned by the project.

:rtype: tuple
:returns: A pair of results, the first is a list of :class:`.Cluster` s
returned and the second is a list of strings (the failed
zones in the request).
"""
request_pb = messages_pb2.ListClustersRequest(name=self.project_name)
response = self._cluster_stub.ListClusters.async(request_pb,
self.timeout_seconds)
# We expect a `.messages_pb2.ListClustersResponse`
list_clusters_response = response.result()

failed_zones = [zone.display_name
for zone in list_clusters_response.failed_zones]
clusters = [Cluster.from_pb(cluster_pb, self)
for cluster_pb in list_clusters_response.clusters]
return clusters, failed_zones
64 changes: 64 additions & 0 deletions gcloud/bigtable/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -547,6 +547,70 @@ def test_list_zones_failure(self):
with self.assertRaises(ValueError):
self._list_zones_helper(data_pb2.Zone.EMERGENCY_MAINENANCE)

def test_list_clusters(self):
from gcloud.bigtable._generated import (
bigtable_cluster_data_pb2 as data_pb2)
from gcloud.bigtable._generated import (
bigtable_cluster_service_messages_pb2 as messages_pb2)

credentials = _Credentials()
project = 'PROJECT'
timeout_seconds = 8004
client = self._makeOne(project=project, credentials=credentials,
admin=True, timeout_seconds=timeout_seconds)

# Create request_pb
request_pb = messages_pb2.ListClustersRequest(
name='projects/' + project,
)

# Create response_pb
zone = 'foo'
failed_zone = 'bar'
cluster_id1 = 'cluster-id1'
cluster_id2 = 'cluster-id2'
cluster_name1 = ('projects/' + project + '/zones/' + zone +
'/clusters/' + cluster_id1)
cluster_name2 = ('projects/' + project + '/zones/' + zone +
'/clusters/' + cluster_id2)
response_pb = messages_pb2.ListClustersResponse(
failed_zones=[
data_pb2.Zone(display_name=failed_zone),
],
clusters=[
data_pb2.Cluster(
name=cluster_name1,
display_name=cluster_name1,
serve_nodes=3,
),
data_pb2.Cluster(
name=cluster_name2,
display_name=cluster_name2,
serve_nodes=3,
),
],
)

# Patch the stub used by the API method.
client._cluster_stub_internal = stub = _FakeStub(response_pb)

# Create expected_result.
failed_zones = [failed_zone]
clusters = [
client.cluster(zone, cluster_id1),
client.cluster(zone, cluster_id2),
]
expected_result = (clusters, failed_zones)

# Perform the method and check the result.
result = client.list_clusters()
self.assertEqual(result, expected_result)
self.assertEqual(stub.method_calls, [(
'ListClusters',
(request_pb, timeout_seconds),
{},
)])


class _Credentials(object):

Expand Down