コード例 #1
0
    def test_constructor(self):
        from gcloud.bigtable.client import Client
        from gcloud.bigtable.client import DATA_SCOPE
        PROJECT = 'PROJECT'
        USER_AGENT = 'USER_AGENT'

        credentials = _Credentials()
        client = Client(project=PROJECT, credentials=credentials,
                        user_agent=USER_AGENT)
        transformer = self._makeOne(client)
        self.assertTrue(transformer._credentials is credentials)
        self.assertEqual(transformer._user_agent, USER_AGENT)
        self.assertEqual(credentials.scopes, [DATA_SCOPE])
コード例 #2
0
ファイル: bigtable.py プロジェクト: vmarkovtsev/gcloud-python
def setUpModule():
    _helpers.PROJECT = TESTS_PROJECT
    Config.CLIENT = Client(admin=True)
    Config.INSTANCE = Config.CLIENT.instance(INSTANCE_ID, LOCATION_ID)
    Config.CLIENT.start()
    instances, failed_locations = _retry_backoff(Config.CLIENT.list_instances)

    if len(failed_locations) != 0:
        raise ValueError('List instances failed in module set up.')

    EXISTING_INSTANCES[:] = instances

    # After listing, create the test instance.
    created_op = Config.INSTANCE.create()
    if not _operation_wait(created_op):
        raise RuntimeError('Instance creation exceed 5 seconds.')
コード例 #3
0
ファイル: bigtable.py プロジェクト: vkaya/gcloud-python
def setUpModule():
    Config.CLIENT = Client(admin=True)
    Config.CLUSTER = Config.CLIENT.cluster(CENTRAL_1C_ZONE, CLUSTER_ID,
                                           display_name=CLUSTER_ID)
    Config.CLIENT.start()
    clusters, failed_zones = Config.CLIENT.list_clusters()

    if len(failed_zones) != 0:
        raise ValueError('List clusters failed in module set up.')

    EXISTING_CLUSTERS[:] = clusters

    # After listing, create the test cluster.
    created_op = Config.CLUSTER.create()
    if not _operation_wait(created_op):
        raise RuntimeError('Cluster creation exceed 5 seconds.')
コード例 #4
0
def setUpModule():
    from grpc._channel import _Rendezvous
    _helpers.PROJECT = TESTS_PROJECT
    Config.CLIENT = Client(admin=True)
    Config.INSTANCE = Config.CLIENT.instance(INSTANCE_ID, LOCATION_ID)
    retry = RetryErrors(_Rendezvous, error_predicate=_retry_on_unavailable)
    instances, failed_locations = retry(Config.CLIENT.list_instances)()

    if len(failed_locations) != 0:
        raise ValueError('List instances failed in module set up.')

    EXISTING_INSTANCES[:] = instances

    # After listing, create the test instance.
    created_op = Config.INSTANCE.create()
    if not _wait_until_complete(created_op):
        raise RuntimeError('Instance creation exceed 5 seconds.')
コード例 #5
0
    def test___call__(self):
        from gcloud.bigtable.client import Client
        from gcloud.bigtable.client import DATA_SCOPE
        from gcloud.bigtable.client import DEFAULT_USER_AGENT

        access_token_expected = 'FOOBARBAZ'
        credentials = _Credentials(access_token=access_token_expected)
        project = 'PROJECT'
        client = Client(project=project, credentials=credentials)

        transformer = self._makeOne(client)
        result = transformer(None)
        self.assertEqual(result, [
            ('Authorization', 'Bearer ' + access_token_expected),
            ('User-agent', DEFAULT_USER_AGENT),
        ])
        self.assertEqual(credentials._scopes, [DATA_SCOPE])
        self.assertEqual(len(credentials._tokens), 1)
コード例 #6
0
def _get_instance(timeout=None):
    """Gets instance for the default project.

    Creates a client with the inferred credentials and project ID from
    the local environment. Then uses
    :meth:`.bigtable.client.Client.list_instances` to
    get the unique instance owned by the project.

    If the request fails for any reason, or if there isn't exactly one instance
    owned by the project, then this function will fail.

    :type timeout: int
    :param timeout: (Optional) The socket timeout in milliseconds.

    :rtype: :class:`gcloud.bigtable.instance.Instance`
    :returns: The unique instance owned by the project inferred from
              the environment.
    :raises ValueError: if there is a failed location or any number of
                        instances other than one.
    """
    client_kwargs = {'admin': True}
    if timeout is not None:
        client_kwargs['timeout_seconds'] = timeout / 1000.0
    client = Client(**client_kwargs)
    try:
        client.start()
        instances, failed_locations = client.list_instances()
    finally:
        client.stop()

    if len(failed_locations) != 0:
        raise ValueError('Determining instance via ListInstances encountered '
                         'failed locations.')
    if len(instances) == 0:
        raise ValueError('This client doesn\'t have access to any instances.')
    if len(instances) > 1:
        raise ValueError('This client has access to more than one instance. '
                         'Please directly pass the instance you\'d '
                         'like to use.')
    return instances[0]
コード例 #7
0
ファイル: connection.py プロジェクト: E-LLP/gcloud-python
def _get_instance(timeout=None):
    """Gets instance for the default project.

    Creates a client with the inferred credentials and project ID from
    the local environment. Then uses
    :meth:`.bigtable.client.Client.list_instances` to
    get the unique instance owned by the project.

    If the request fails for any reason, or if there isn't exactly one instance
    owned by the project, then this function will fail.

    :type timeout: int
    :param timeout: (Optional) The socket timeout in milliseconds.

    :rtype: :class:`gcloud.bigtable.instance.Instance`
    :returns: The unique instance owned by the project inferred from
              the environment.
    :raises ValueError: if there is a failed location or any number of
                        instances other than one.
    """
    client_kwargs = {'admin': True}
    if timeout is not None:
        client_kwargs['timeout_seconds'] = timeout / 1000.0
    client = Client(**client_kwargs)
    try:
        client.start()
        instances, failed_locations = client.list_instances()
    finally:
        client.stop()

    if len(failed_locations) != 0:
        raise ValueError('Determining instance via ListInstances encountered '
                         'failed locations.')
    if len(instances) == 0:
        raise ValueError('This client doesn\'t have access to any instances.')
    if len(instances) > 1:
        raise ValueError('This client has access to more than one instance. '
                         'Please directly pass the instance you\'d '
                         'like to use.')
    return instances[0]
コード例 #8
0
def _get_cluster(timeout=None):
    """Gets cluster for the default project.

    Creates a client with the inferred credentials and project ID from
    the local environment. Then uses
    :meth:`.bigtable.client.Client.list_clusters` to
    get the unique cluster owned by the project.

    If the request fails for any reason, or if there isn't exactly one cluster
    owned by the project, then this function will fail.

    :type timeout: int
    :param timeout: (Optional) The socket timeout in milliseconds.

    :rtype: :class:`gcloud.bigtable.cluster.Cluster`
    :returns: The unique cluster owned by the project inferred from
              the environment.
    :raises: :class:`ValueError <exceptions.ValueError>` if there is a failed
             zone or any number of clusters other than one.
    """
    client_kwargs = {"admin": True}
    if timeout is not None:
        client_kwargs["timeout_seconds"] = timeout / 1000.0
    client = Client(**client_kwargs)
    try:
        client.start()
        clusters, failed_zones = client.list_clusters()
    finally:
        client.stop()

    if len(failed_zones) != 0:
        raise ValueError("Determining cluster via ListClusters encountered " "failed zones.")
    if len(clusters) == 0:
        raise ValueError("This client doesn't have access to any clusters.")
    if len(clusters) > 1:
        raise ValueError(
            "This client has access to more than one cluster. " "Please directly pass the cluster you'd " "like to use."
        )
    return clusters[0]