def cluster(self, zone, cluster_id, display_name=None, serve_nodes=3): """Factory to create a cluster associated with this client. :type zone: str :param zone: The name of the zone where the cluster resides. :type cluster_id: str :param cluster_id: The ID of the cluster. :type display_name: str :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: int :param serve_nodes: (Optional) The number of nodes in the cluster. Defaults to 3. :rtype: :class:`.Cluster` :returns: The cluster owned by this client. """ return Cluster(zone, cluster_id, self, display_name=display_name, serve_nodes=serve_nodes)
def test_it(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) from gcloud.bigtable.cluster import Cluster project = 'PROJECT' zone = 'zone' cluster_id = 'cluster-id' display_name = u'DISPLAY_NAME' serve_nodes = 8 client = _Client(project) cluster = Cluster(zone, cluster_id, client, display_name=display_name, serve_nodes=serve_nodes) request_pb = self._callFUT(cluster) self.assertTrue( isinstance(request_pb, messages_pb2.CreateClusterRequest)) self.assertEqual(request_pb.cluster_id, cluster_id) self.assertEqual(request_pb.name, 'projects/' + project + '/zones/' + zone) self.assertTrue(isinstance(request_pb.cluster, data_pb2.Cluster)) self.assertEqual(request_pb.cluster.display_name, display_name) self.assertEqual(request_pb.cluster.serve_nodes, serve_nodes)
def cluster(self, cluster_id, serve_nodes=3): """Factory to create a cluster associated with this client. :type cluster_id: str :param cluster_id: The ID of the cluster. :type serve_nodes: int :param serve_nodes: (Optional) The number of nodes in the cluster. Defaults to 3. :rtype: :class:`.Cluster` :returns: The cluster owned by this client. """ return Cluster(cluster_id, self, serve_nodes=serve_nodes)
def _finished_helper(self, done): import datetime from gcloud.bigtable._generated import operations_pb2 from gcloud.bigtable._testing import _FakeStub from gcloud.bigtable.cluster import Cluster project = 'PROJECT' zone = 'zone' cluster_id = 'cluster-id' op_type = 'fake-op' op_id = 789 begin = datetime.datetime(2015, 10, 22, 1, 1) timeout_seconds = 1 client = _Client(project, timeout_seconds=timeout_seconds) cluster = Cluster(zone, cluster_id, client) operation = self._makeOne(op_type, op_id, begin, cluster=cluster) # Create request_pb op_name = ('operations/projects/' + project + '/zones/' + zone + '/clusters/' + cluster_id + '/operations/%d' % (op_id,)) request_pb = operations_pb2.GetOperationRequest(name=op_name) # Create response_pb response_pb = operations_pb2.Operation(done=done) # Patch the stub used by the API method. client._operations_stub = stub = _FakeStub(response_pb) # Create expected_result. expected_result = done # Perform the method and check the result. result = operation.finished() self.assertEqual(result, expected_result) self.assertEqual(stub.method_calls, [( 'GetOperation', (request_pb, timeout_seconds), {}, )]) if done: self.assertTrue(operation._complete) else: self.assertFalse(operation._complete)
def _finished_helper(self, done): from google.longrunning import operations_pb2 from gcloud.bigtable._testing import _FakeStub from gcloud.bigtable.cluster import Cluster PROJECT = 'PROJECT' INSTANCE_ID = 'instance-id' CLUSTER_ID = 'cluster-id' OP_TYPE = 'fake-op' OP_ID = 789 timeout_seconds = 1 client = _Client(PROJECT, timeout_seconds=timeout_seconds) instance = _Instance(INSTANCE_ID, client) cluster = Cluster(CLUSTER_ID, instance) operation = self._makeOne(OP_TYPE, OP_ID, cluster=cluster) # Create request_pb op_name = ('operations/projects/' + PROJECT + '/instances/' + INSTANCE_ID + '/clusters/' + CLUSTER_ID + '/operations/%d' % (OP_ID,)) request_pb = operations_pb2.GetOperationRequest(name=op_name) # Create response_pb response_pb = operations_pb2.Operation(done=done) # Patch the stub used by the API method. client._operations_stub = stub = _FakeStub(response_pb) # Create expected_result. expected_result = done # Perform the method and check the result. result = operation.finished() self.assertEqual(result, expected_result) self.assertEqual(stub.method_calls, [( 'GetOperation', (request_pb, timeout_seconds), {}, )]) if done: self.assertTrue(operation._complete) else: self.assertFalse(operation._complete)
def test_it(self): from gcloud.bigtable.cluster import Cluster PROJECT = 'PROJECT' INSTANCE_ID = 'instance-id' CLUSTER_ID = 'cluster-id' SERVE_NODES = 8 client = _Client(PROJECT) instance = _Instance(INSTANCE_ID, client) cluster = Cluster(CLUSTER_ID, instance, serve_nodes=SERVE_NODES) request_pb = self._callFUT(cluster) self.assertEqual(request_pb.cluster_id, CLUSTER_ID) self.assertEqual(request_pb.parent, instance.name) self.assertEqual(request_pb.cluster.serve_nodes, SERVE_NODES)
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) # We expect a `.messages_pb2.ListClustersResponse` list_clusters_response = self._cluster_stub.ListClusters( request_pb, self.timeout_seconds) 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
def list_clusters(self): """Lists clusters in this instance. :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 locations in the request). """ request_pb = messages_v2_pb2.ListClustersRequest(parent=self.name) # We expect a `.cluster_messages_v1_pb2.ListClustersResponse` list_clusters_response = self._client._instance_stub.ListClusters( request_pb, self._client.timeout_seconds) failed_locations = [ location for location in list_clusters_response.failed_locations] clusters = [Cluster.from_pb(cluster_pb, self) for cluster_pb in list_clusters_response.clusters] return clusters, failed_locations
def list_clusters(self): """Lists clusters in this instance. :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 locations in the request). """ request_pb = messages_v2_pb2.ListClustersRequest(parent=self.name) # We expect a `.cluster_messages_v1_pb2.ListClustersResponse` list_clusters_response = self._client._instance_stub.ListClusters( request_pb, self._client.timeout_seconds) failed_locations = [ location for location in list_clusters_response.failed_locations ] clusters = [ Cluster.from_pb(cluster_pb, self) for cluster_pb in list_clusters_response.clusters ] return clusters, failed_locations