示例#1
0
    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)
示例#2
0
    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)
示例#3
0
    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)
示例#4
0
    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)
示例#5
0
    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)
示例#6
0
    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)