Beispiel #1
0
    def list_instance_configs(self, page_size=None, page_token=None):
        """List available instance configurations for the client's project.

        .. _RPC docs: https://cloud.google.com/spanner/docs/reference/rpc/\
                      google.spanner.admin.instance.v1#google.spanner.admin.\
                      instance.v1.InstanceAdmin.ListInstanceConfigs

        See `RPC docs`_.

        :type page_size: int
        :param page_size: (Optional) Maximum number of results to return.

        :type page_token: str
        :param page_token: (Optional) Token for fetching next page of results.

        :rtype: :class:`~google.api.core.page_iterator.Iterator`
        :returns:
            Iterator of
            :class:`~google.cloud.spanner_v1.instance.InstanceConfig`
            resources within the client's project.
        """
        if page_token is None:
            page_token = INITIAL_PAGE
        options = _options_with_prefix(self.project_name,
                                       page_token=page_token)
        path = 'projects/%s' % (self.project, )
        page_iter = self.instance_admin_api.list_instance_configs(
            path, page_size=page_size, options=options)
        return page_iterator._GAXIterator(self, page_iter,
                                          _item_to_instance_config)
Beispiel #2
0
    def list_instances(self, filter_='', page_size=None, page_token=None):
        """List instances for the client's project.

        See
        https://cloud.google.com/spanner/reference/rpc/google.spanner.admin.database.v1#google.spanner.admin.database.v1.InstanceAdmin.ListInstances

        :type filter_: string
        :param filter_: (Optional) Filter to select instances listed.  See
                        the ``ListInstancesRequest`` docs above for examples.

        :type page_size: int
        :param page_size: (Optional) Maximum number of results to return.

        :type page_token: str
        :param page_token: (Optional) Token for fetching next page of results.

        :rtype: :class:`~google.api.core.page_iterator.Iterator`
        :returns:
            Iterator of :class:`~google.cloud.spanner_v1.instance.Instance`
            resources within the client's project.
        """
        if page_token is None:
            page_token = INITIAL_PAGE
        options = _options_with_prefix(self.project_name,
                                       page_token=page_token)
        path = 'projects/%s' % (self.project, )
        page_iter = self.instance_admin_api.list_instances(path,
                                                           filter_=filter_,
                                                           page_size=page_size,
                                                           options=options)
        return page_iterator._GAXIterator(self, page_iter, _item_to_instance)
    def list_metrics(self, project, page_size=0, page_token=None):
        """List metrics for the project associated with this client.

        :type project: str
        :param project: ID of the project whose metrics are to be listed.

        :type page_size: int
        :param page_size: maximum number of metrics to return, If not passed,
                          defaults to a value set by the API.

        :type page_token: str
        :param page_token: opaque marker for the next "page" of metrics. If not
                           passed, the API will return the first page of
                           metrics.

        :rtype: :class:`~google.api.core.page_iterator.Iterator`
        :returns: Iterator of
                  :class:`~google.cloud.logging.metric.Metric`
                  accessible to the current API.
        """
        if page_token is None:
            page_token = INITIAL_PAGE
        options = CallOptions(page_token=page_token)
        path = 'projects/%s' % (project, )
        page_iter = self._gax_api.list_log_metrics(path,
                                                   page_size=page_size,
                                                   options=options)
        return page_iterator._GAXIterator(self._client, page_iter,
                                          _item_to_metric)
Beispiel #4
0
    def list_databases(self, page_size=None, page_token=None):
        """List databases for the instance.

        See
        https://cloud.google.com/spanner/reference/rpc/google.spanner.admin.database.v1#google.spanner.admin.database.v1.DatabaseAdmin.ListDatabases

        :type page_size: int
        :param page_size: (Optional) Maximum number of results to return.

        :type page_token: str
        :param page_token: (Optional) Token for fetching next page of results.

        :rtype: :class:`~google.api.core.page_iterator.Iterator`
        :returns:
            Iterator of :class:`~google.cloud.spanner_v1.database.Database`
            resources within the current instance.
        """
        if page_token is None:
            page_token = INITIAL_PAGE
        options = _options_with_prefix(self.name, page_token=page_token)
        page_iter = self._client.database_admin_api.list_databases(
            self.name, page_size=page_size, options=options)
        iterator = page_iterator._GAXIterator(self._client, page_iter,
                                              _item_to_database)
        iterator.instance = self
        return iterator
    def list_sinks(self, project, page_size=0, page_token=None):
        """List sinks for the project associated with this client.

        :type project: str
        :param project: ID of the project whose sinks are to be listed.

        :type page_size: int
        :param page_size: maximum number of sinks to return, If not passed,
                          defaults to a value set by the API.

        :type page_token: str
        :param page_token: opaque marker for the next "page" of sinks. If not
                           passed, the API will return the first page of
                           sinks.

        :rtype: tuple, (list, str)
        :returns: list of mappings, plus a "next page token" string:
                  if not None, indicates that more sinks can be retrieved
                  with another call (pass that value as ``page_token``).
        """
        if page_token is None:
            page_token = INITIAL_PAGE
        options = CallOptions(page_token=page_token)
        path = 'projects/%s' % (project, )
        page_iter = self._gax_api.list_sinks(path,
                                             page_size=page_size,
                                             options=options)
        return page_iterator._GAXIterator(self._client, page_iter,
                                          _item_to_sink)
Beispiel #6
0
    def list_topics(self, project, page_size=0, page_token=None):
        """List topics for the project associated with this API.

        See
        https://cloud.google.com/pubsub/docs/reference/rest/v1/projects.topics/list

        :type project: str
        :param project: project ID

        :type page_size: int
        :param page_size: maximum number of topics to return, If not passed,
                          defaults to a value set by the API.

        :type page_token: str
        :param page_token: opaque marker for the next "page" of topics. If not
                           passed, the API will return the first page of
                           topics.

        :rtype: :class:`~google.api.core.page_iterator.Iterator`
        :returns: Iterator of :class:`~google.cloud.pubsub.topic.Topic`
                  accessible to the current API.
        """
        if page_token is None:
            page_token = INITIAL_PAGE
        options = CallOptions(page_token=page_token)
        path = 'projects/%s' % (project, )
        page_iter = self._gax_api.list_topics(path,
                                              page_size=page_size,
                                              options=options)
        return page_iterator._GAXIterator(self._client, page_iter,
                                          _item_to_topic)
    def list_entries(self,
                     projects,
                     filter_='',
                     order_by='',
                     page_size=0,
                     page_token=None):
        """Return a page of log entry resources.

        :type projects: list of strings
        :param projects: project IDs to include. If not passed,
                         defaults to the project bound to the API's client.

        :type filter_: str
        :param filter_:
            a filter expression. See
            https://cloud.google.com/logging/docs/view/advanced_filters

        :type order_by: str
        :param order_by: One of :data:`~google.cloud.logging.ASCENDING`
                         or :data:`~google.cloud.logging.DESCENDING`.

        :type page_size: int
        :param page_size: maximum number of entries to return, If not passed,
                          defaults to a value set by the API.

        :type page_token: str
        :param page_token: opaque marker for the next "page" of entries. If not
                           passed, the API will return the first page of
                           entries.

        :rtype: :class:`~google.api.core.page_iterator.Iterator`
        :returns: Iterator of :class:`~google.cloud.logging.entries._BaseEntry`
                  accessible to the current API.
        """
        if page_token is None:
            page_token = INITIAL_PAGE
        options = CallOptions(page_token=page_token)
        page_iter = self._gax_api.list_log_entries([],
                                                   project_ids=projects,
                                                   filter_=filter_,
                                                   order_by=order_by,
                                                   page_size=page_size,
                                                   options=options)

        # We attach a mutable loggers dictionary so that as Logger
        # objects are created by entry_from_resource, they can be
        # re-used by other log entries from the same logger.
        loggers = {}
        item_to_value = functools.partial(_item_to_entry, loggers=loggers)
        return page_iterator._GAXIterator(self._client, page_iter,
                                          item_to_value)
Beispiel #8
0
    def test__next_page(self):
        page_items = (29, 31)
        page_token = '2sde98ds2s0hh'
        page_iter = GAXPageIterator([page_items], page_token=page_token)
        iterator = page_iterator._GAXIterator(
            mock.sentinel.client, page_iter,
            page_iterator._item_to_value_identity)

        page = iterator._next_page()

        assert iterator.next_page_token == page_token
        assert isinstance(page, page_iterator.Page)
        assert list(page) == list(page_items)

        next_page = iterator._next_page()

        assert next_page is None
Beispiel #9
0
    def test_constructor(self):
        client = mock.sentinel.client
        token = 'zzzyy78kl'
        page_iter = GAXPageIterator((), page_token=token)
        item_to_value = page_iterator._item_to_value_identity
        max_results = 1337
        iterator = page_iterator._GAXIterator(client,
                                              page_iter,
                                              item_to_value,
                                              max_results=max_results)

        assert not iterator._started
        assert iterator.client is client
        assert iterator._item_to_value is item_to_value
        assert iterator.max_results == max_results
        assert iterator._gax_page_iter is page_iter
        # Changing attributes.
        assert iterator.page_number == 0
        assert iterator.next_page_token == token
        assert iterator.num_results == 0
Beispiel #10
0
    def topic_list_subscriptions(self, topic, page_size=0, page_token=None):
        """API call:  list subscriptions bound to a topic

        See
        https://cloud.google.com/pubsub/docs/reference/rest/v1/projects.topics.subscriptions/list

        :type topic: :class:`~google.cloud.pubsub.topic.Topic`
        :param topic: The topic that owns the subscriptions.

        :type page_size: int
        :param page_size: maximum number of subscriptions to return, If not
                          passed, defaults to a value set by the API.

        :type page_token: str
        :param page_token: opaque marker for the next "page" of subscriptions.
                           If not passed, the API will return the first page
                           of subscriptions.

        :rtype: :class:`~google.api.core.page_iterator.Iterator`
        :returns: Iterator of
                  :class:`~google.cloud.pubsub.subscription.Subscription`
                  accessible to the current API.
        :raises: :exc:`~google.cloud.exceptions.NotFound` if the topic does
                  not exist.
        """
        if page_token is None:
            page_token = INITIAL_PAGE
        options = CallOptions(page_token=page_token)
        topic_path = topic.full_name
        try:
            page_iter = self._gax_api.list_topic_subscriptions(
                topic_path, page_size=page_size, options=options)
        except GaxError as exc:
            if exc_to_code(exc.cause) == StatusCode.NOT_FOUND:
                raise NotFound(topic_path)
            raise

        iterator = page_iterator._GAXIterator(self._client, page_iter,
                                              _item_to_subscription_for_topic)
        iterator.topic = topic
        return iterator
Beispiel #11
0
    def list_subscriptions(self, project, page_size=0, page_token=None):
        """List subscriptions for the project associated with this API.

        See
        https://cloud.google.com/pubsub/docs/reference/rest/v1/projects.subscriptions/list

        :type project: str
        :param project: project ID

        :type page_size: int
        :param page_size: maximum number of subscriptions to return, If not
                          passed, defaults to a value set by the API.

        :type page_token: str
        :param page_token: opaque marker for the next "page" of subscriptions.
                           If not passed, the API will return the first page
                           of subscriptions.

        :rtype: :class:`~google.api.core.page_iterator.Iterator`
        :returns: Iterator of
                  :class:`~google.cloud.pubsub.subscription.Subscription`
                  accessible to the current API.
        """
        if page_token is None:
            page_token = INITIAL_PAGE
        options = CallOptions(page_token=page_token)
        path = 'projects/%s' % (project, )
        page_iter = self._gax_api.list_subscriptions(path,
                                                     page_size=page_size,
                                                     options=options)

        # We attach a mutable topics dictionary so that as topic
        # objects are created by Subscription.from_api_repr, they
        # can be re-used by other subscriptions from the same topic.
        topics = {}
        item_to_value = functools.partial(_item_to_sub_for_client,
                                          topics=topics)
        return page_iterator._GAXIterator(self._client, page_iter,
                                          item_to_value)
    def list_traces(self,
                    project_id,
                    view=None,
                    page_size=None,
                    start_time=None,
                    end_time=None,
                    filter_=None,
                    order_by=None,
                    page_token=None):
        """Returns of a list of traces that match the specified filter
        conditions.

        :type project_id: str
        :param project_id: ID of the Cloud project where the trace data is
                           stored.

        :type view: :class:`google.cloud.gapic.trace.v1.enums.
                           ListTracesRequest.ViewType`
        :param view: (Optional) Type of data returned for traces in the list.
                     Default is ``MINIMAL``.

        :type page_size: int
        :param page_size: (Optional) Maximum number of traces to return.
                          If not specified or <= 0, the implementation selects
                          a reasonable value. The implementation may return
                          fewer traces than the requested page size.

        :type start_time: :class:`google.protobuf.timestamp_pb2.Timestamp`
        :param start_time: (Optional) Start of the time interval (inclusive)
                           during which the trace data was collected from the
                           application.

        :type end_time: :class:`google.protobuf.timestamp_pb2.Timestamp`
        :param end_time: (Optional) End of the time interval (inclusive)
                         during which the trace data was collected from the
                         application.

        :type filter_: str
        :param filter_: (Optional) An optional filter for the request.

        :type order_by: str
        :param order_by: (Optional) Field used to sort the returned traces.

        :type page_token: str
        :param page_token: opaque marker for the next "page" of entries. If not
                           passed, the API will return the first page of
                           entries.

        :rtype: :class:`~google.api.core.page_iterator.Iterator`
        :returns: Traces that match the specified filter conditions.
        """
        if page_token is None:
            page_token = INITIAL_PAGE
        options = CallOptions(page_token=page_token)
        page_iter = self._gax_api.list_traces(project_id=project_id,
                                              view=view,
                                              page_size=page_size,
                                              start_time=start_time,
                                              end_time=end_time,
                                              filter_=filter_,
                                              order_by=order_by,
                                              options=options)
        item_to_value = _item_to_mapping
        return page_iterator._GAXIterator(self.client, page_iter,
                                          item_to_value)