Skip to content

Commit

Permalink
Adding Client.cluster() factory.
Browse files Browse the repository at this point in the history
  • Loading branch information
dhermes committed Jul 27, 2015
1 parent 47ed044 commit 860f833
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
25 changes: 25 additions & 0 deletions gcloud_bigtable/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,31 @@ def project_name(self):
"""
return 'projects/' + self._project_id

def cluster(self, zone, cluster_id, display_name=None, serve_nodes=3):
"""Factory to create a cluster associated with this client.
:type zone: string
:param zone: The name of the zone where the cluster resides.
:type cluster_id: string
:param cluster_id: The ID of the cluster.
:type display_name: string
:param display_name: (Optional) The display name for the cluster in the
Cloud Console UI. (Must be between 4 and 30
characters.) If this value is not set in the
constructor, will fall back to the cluster ID.
:type serve_nodes: integer
:param serve_nodes: (Optional) The number of nodes in the cluster.
Defaults to 3.
:rtype: :class:`.cluster_standalone.Cluster`
:returns: The cluster created owned by this client.
"""
return Cluster(zone, cluster_id, self,
display_name=display_name, serve_nodes=serve_nodes)

def list_zones(self, timeout_seconds=TIMEOUT_SECONDS):
"""Lists zones associated with project.
Expand Down
16 changes: 16 additions & 0 deletions gcloud_bigtable/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,22 @@ def test_project_name_property(self):
client = self._makeOne(credentials, project_id=PROJECT_ID)
self.assertEqual(client.project_name, project_name)

def test_cluster_factory(self):
from gcloud_bigtable._testing import _MockWithAttachedMethods
from gcloud_bigtable.cluster_standalone import Cluster

scoped_creds = object()
credentials = _MockWithAttachedMethods(scoped_creds)
client = self._makeOne(credentials, project_id=PROJECT_ID)

zone = 'zone'
cluster_id = 'cluster-id'
cluster = client.cluster(zone, cluster_id)
self.assertTrue(isinstance(cluster, Cluster))
self.assertTrue(cluster.client is client)
self.assertEqual(cluster.zone, zone)
self.assertEqual(cluster.cluster_id, cluster_id)

def test_list_zones(self):
from gcloud_bigtable._generated import (
bigtable_cluster_data_pb2 as data_pb2)
Expand Down

0 comments on commit 860f833

Please sign in to comment.