예제 #1
0
def test_instance_from_pb_bad_instance_name():
    from google.cloud.bigtable_admin_v2.types import instance as data_v2_pb2
    from google.cloud.bigtable.instance import Instance

    instance_name = "INCORRECT_FORMAT"
    instance_pb = data_v2_pb2.Instance(name=instance_name)

    with pytest.raises(ValueError):
        Instance.from_pb(instance_pb, None)
예제 #2
0
def test_instance_from_pb_project_mistmatch():
    from google.cloud.bigtable_admin_v2.types import instance as data_v2_pb2
    from google.cloud.bigtable.instance import Instance

    ALT_PROJECT = "ALT_PROJECT"
    credentials = _make_credentials()
    client = _make_client(project=ALT_PROJECT,
                          credentials=credentials,
                          admin=True)

    instance_pb = data_v2_pb2.Instance(name=INSTANCE_NAME)

    with pytest.raises(ValueError):
        Instance.from_pb(instance_pb, client)
예제 #3
0
def test_instance_from_pb_success():
    from google.cloud.bigtable_admin_v2.types import instance as data_v2_pb2
    from google.cloud.bigtable import enums
    from google.cloud.bigtable.instance import Instance

    credentials = _make_credentials()
    client = _make_client(project=PROJECT, credentials=credentials, admin=True)
    instance_type = enums.Instance.Type.PRODUCTION
    state = enums.Instance.State.READY
    instance_pb = data_v2_pb2.Instance(
        name=INSTANCE_NAME,
        display_name=INSTANCE_ID,
        type_=instance_type,
        labels=LABELS,
        state=state,
    )

    instance = Instance.from_pb(instance_pb, client)

    assert isinstance(instance, Instance)
    assert instance._client == client
    assert instance.instance_id == INSTANCE_ID
    assert instance.display_name == INSTANCE_ID
    assert instance.type_ == instance_type
    assert instance.labels == LABELS
    assert instance._state == state
예제 #4
0
    def list_instances(self):
        """List instances owned by the project.

        :rtype: tuple
        :returns:
            (instances, failed_locations), where 'instances' is list of
            :class:`google.cloud.bigtable.instance.Instance`, and
            'failed_locations' is a list of locations which could not
            be resolved.
        """
        resp = self.instance_admin_client.list_instances(self.project_path)
        instances = [
            Instance.from_pb(instance, self) for instance in resp.instances]
        return instances, resp.failed_locations
예제 #5
0
    def list_instances(self):
        """List instances owned by the project.

        :rtype: tuple
        :returns:
            (instances, failed_locations), where 'instances' is list of
            :class:`google.cloud.bigtable.instance.Instance`, and
            'failed_locations' is a list of locations which could not
            be resolved.
        """
        resp = self.instance_admin_client.list_instances(self.project_path)
        instances = [
            Instance.from_pb(instance, self) for instance in resp.instances
        ]
        return instances, resp.failed_locations
예제 #6
0
    def list_instances(self):
        """List instances owned by the project.

        :rtype: tuple
        :returns: A pair of results, the first is a list of
                  :class:`.Instance` objects returned and the second is a
                  list of strings (the failed locations in the request).
        """
        request_pb = bigtable_instance_admin_pb2.ListInstancesRequest(
            parent=self.project_name)

        response = self._instance_stub.ListInstances(request_pb)

        instances = [Instance.from_pb(instance_pb, self)
                     for instance_pb in response.instances]
        return instances, response.failed_locations
예제 #7
0
    def list_instances(self):
        """List instances owned by the project.

        :rtype: tuple
        :returns: A pair of results, the first is a list of
                  :class:`~google.cloud.bigtable.instance.Instance` objects
                  returned and the second is a list of strings (the failed
                  locations in the request).
        """
        request_pb = bigtable_instance_admin_pb2.ListInstancesRequest(
            parent=self.project_name)

        response = self._instance_stub.ListInstances(request_pb)

        instances = [Instance.from_pb(instance_pb, self)
                     for instance_pb in response.instances]
        return instances, response.failed_locations
예제 #8
0
    def list_instances(self):
        """List instances owned by the project.

        For example:

        .. literalinclude:: snippets.py
            :start-after: [START bigtable_list_instances]
            :end-before: [END bigtable_list_instances]

        :rtype: tuple
        :returns:
            (instances, failed_locations), where 'instances' is list of
            :class:`google.cloud.bigtable.instance.Instance`, and
            'failed_locations' is a list of locations which could not
            be resolved.
        """
        resp = self.instance_admin_client.list_instances(self.project_path)
        instances = [Instance.from_pb(instance, self) for instance in resp.instances]
        return instances, resp.failed_locations
예제 #9
0
    def list_instances(self):
        """List instances owned by the project.

        For example:

        .. literalinclude:: snippets.py
            :start-after: [START bigtable_list_instances]
            :end-before: [END bigtable_list_instances]

        :rtype: tuple
        :returns:
            (instances, failed_locations), where 'instances' is list of
            :class:`google.cloud.bigtable.instance.Instance`, and
            'failed_locations' is a list of locations which could not
            be resolved.
        """
        resp = self.instance_admin_client.list_instances(self.project_path)
        instances = [Instance.from_pb(instance, self) for instance in resp.instances]
        return instances, resp.failed_locations