def list_operations(self, name, filter_, retry=gapic_v1.method.DEFAULT, timeout=gapic_v1.method.DEFAULT): """ Lists operations that match the specified filter in the request. Example: >>> from google.api.core import operations_v1 >>> api = operations_v1.OperationsClient() >>> name = '' >>> >>> # Iterate over all results >>> for operation in api.list_operations(name): >>> # process operation >>> pass >>> >>> # Or iterate over results one page at a time >>> iter = api.list_operations(name) >>> for page in iter.pages: >>> for operation in page: >>> # process operation >>> pass Args: name (str): The name of the operation collection. filter_ (str): The standard list filter. retry (google.api.core.retry.Retry): The retry strategy to use when invoking the RPC. If unspecified, the default retry from the client configuration will be used. If ``None``, then this method will not retry the RPC at all. timeout (float): The amount of time in seconds to wait for the RPC to complete. Note that if ``retry`` is used, this timeout applies to each individual attempt and the overall time it takes for this method to complete may be longer. If unspecified, the the default timeout in the client configuration is used. If ``None``, then the RPC method will not time out. Returns: google.api.core.page_iterator.Iterator: An iterator that yields :class:`google.longrunning.operations_pb2.Operation` instances. Raises: google.api.core.exceptions.MethodNotImplemented: If the server does not support this method. Services are not required to implement this method. google.api.core.exceptions.GoogleAPICallError: If an error occurred while invoking the RPC, the appropriate ``GoogleAPICallError`` subclass will be raised. """ # Create the request object. request = operations_pb2.ListOperationsRequest(name=name, filter=filter_) return self._list_operations(request, retry=retry, timeout=timeout)
def list_operations(self, name, filter_, page_size=0, options=None): """ Lists operations that match the specified filter in the request. If the server doesn't support this method, it returns ``UNIMPLEMENTED``. NOTE: the ``name`` binding below allows API services to override the binding to use different resource name schemes, such as ``users/*/operations``. Example: >>> from google.gapic.longrunning import operations_client >>> from google.gax import CallOptions, INITIAL_PAGE >>> api = operations_client.OperationsClient() >>> name = '' >>> filter_ = '' >>> >>> # Iterate over all results >>> for element in api.list_operations(name, filter_): >>> # process element >>> pass >>> >>> # Or iterate over results one page at a time >>> for page in api.list_operations(name, filter_, options=CallOptions(page_token=INITIAL_PAGE)): >>> for element in page: >>> # process element >>> pass Args: name (string): The name of the operation collection. filter_ (string): The standard list filter. page_size (int): The maximum number of resources contained in the underlying API response. If page streaming is performed per- resource, this parameter does not affect the return value. If page streaming is performed per-page, this determines the maximum number of resources in a page. options (:class:`google.gax.CallOptions`): Overrides the default settings for this call, e.g, timeout, retries etc. Returns: A :class:`google.gax.PageIterator` instance. By default, this is an iterable of :class:`google.longrunning.operations_pb2.Operation` instances. This object can also be configured to iterate over the pages of the response through the `CallOptions` parameter. Raises: :exc:`google.gax.errors.GaxError` if the RPC is aborted. :exc:`ValueError` if the parameters are invalid. """ # Create the request object. request = operations_pb2.ListOperationsRequest(name=name, filter=filter_, page_size=page_size) return self._list_operations(request, options)
def list_operations( self, name, filter_, retry=gapic_v1.method.DEFAULT, timeout=gapic_v1.method.DEFAULT, metadata=None, ): """ Lists operations that match the specified filter in the request. Example: >>> from google.api_core import operations_v1 >>> api = operations_v1.OperationsClient() >>> name = '' >>> >>> # Iterate over all results >>> for operation in api.list_operations(name): >>> # process operation >>> pass >>> >>> # Or iterate over results one page at a time >>> iter = api.list_operations(name) >>> for page in iter.pages: >>> for operation in page: >>> # process operation >>> pass Args: name (str): The name of the operation collection. filter_ (str): The standard list filter. retry (google.api_core.retry.Retry): The retry strategy to use when invoking the RPC. If unspecified, the default retry from the client configuration will be used. If ``None``, then this method will not retry the RPC at all. timeout (float): The amount of time in seconds to wait for the RPC to complete. Note that if ``retry`` is used, this timeout applies to each individual attempt and the overall time it takes for this method to complete may be longer. If unspecified, the the default timeout in the client configuration is used. If ``None``, then the RPC method will not time out. metadata (Optional[List[Tuple[str, str]]]): Additional gRPC metadata. Returns: google.api_core.page_iterator.Iterator: An iterator that yields :class:`google.longrunning.operations_pb2.Operation` instances. Raises: google.api_core.exceptions.MethodNotImplemented: If the server does not support this method. Services are not required to implement this method. google.api_core.exceptions.GoogleAPICallError: If an error occurred while invoking the RPC, the appropriate ``GoogleAPICallError`` subclass will be raised. """ # Create the request object. request = operations_pb2.ListOperationsRequest(name=name, filter=filter_) # Add routing header metadata = metadata or [] metadata.append( gapic_v1.routing_header.to_grpc_metadata({"name": name})) # Create the method used to fetch pages method = functools.partial(self._list_operations, retry=retry, timeout=timeout, metadata=metadata) iterator = page_iterator.GRPCIterator( client=None, method=method, request=request, items_field="operations", request_token_field="page_token", response_token_field="next_page_token", ) return iterator
def list_operations( self, name: str, filter_: Optional[str] = None, *, page_size: Optional[int] = None, page_token: Optional[str] = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, metadata: Sequence[Tuple[str, str]] = (), ) -> pagers.ListOperationsPager: r"""Lists operations that match the specified filter in the request. If the server doesn't support this method, it returns ``UNIMPLEMENTED``. NOTE: the ``name`` binding allows API services to override the binding to use different resource name schemes, such as ``users/*/operations``. To override the binding, API services can add a binding such as ``"/v1/{name=users/*}/operations"`` to their service configuration. For backwards compatibility, the default name includes the operations collection id, however overriding users must ensure the name binding is the parent resource, without the operations collection id. Args: name (str): The name of the operation's parent resource. filter_ (str): The standard list filter. This corresponds to the ``filter`` field on the ``request`` instance; if ``request`` is provided, this should not be set. retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. metadata (Sequence[Tuple[str, str]]): Strings which should be sent along with the request as metadata. Returns: google.api_core.operations_v1.pagers.ListOperationsPager: The response message for [Operations.ListOperations][google.api_core.operations_v1.Operations.ListOperations]. Iterating over this object will yield results and resolve additional pages automatically. """ # Create a protobuf request object. request = operations_pb2.ListOperationsRequest(name=name, filter=filter_) if page_size is not None: request.page_size = page_size if page_token is not None: request.page_token = page_token # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. rpc = self._transport._wrapped_methods[self._transport.list_operations] # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata or ()) + ( gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) # Send the request. response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) # This method is paged; wrap the response in a pager, which provides # an `__iter__` convenience method. response = pagers.ListOperationsPager( method=rpc, request=request, response=response, metadata=metadata, ) # Done; return the response. return response
def _list_operations( self, request: operations_pb2.ListOperationsRequest, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Optional[float] = None, metadata: Sequence[Tuple[str, str]] = (), ) -> operations_pb2.ListOperationsResponse: r"""Call the list operations method over HTTP. Args: request (~.operations_pb2.ListOperationsRequest): The request object. The request message for [Operations.ListOperations][google.api_core.operations_v1.Operations.ListOperations]. retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. metadata (Sequence[Tuple[str, str]]): Strings which should be sent along with the request as metadata. Returns: ~.operations_pb2.ListOperationsResponse: The response message for [Operations.ListOperations][google.api_core.operations_v1.Operations.ListOperations]. """ http_options = [ { "method": "get", "uri": "/v1/{name=operations}" }, ] if "google.longrunning.Operations.ListOperations" in self._http_options: http_options = self._http_options[ "google.longrunning.Operations.ListOperations"] request_kwargs = json_format.MessageToDict( request, preserving_proto_field_name=True, including_default_value_fields=True, ) transcoded_request = path_template.transcode(http_options, **request_kwargs) uri = transcoded_request["uri"] method = transcoded_request["method"] # Jsonify the query params query_params_request = operations_pb2.ListOperationsRequest() json_format.ParseDict(transcoded_request["query_params"], query_params_request) query_params = json_format.MessageToDict( query_params_request, including_default_value_fields=False, preserving_proto_field_name=False, use_integers_for_enums=False, ) # Send the request headers = dict(metadata) headers["Content-Type"] = "application/json" response = getattr(self._session, method)( "https://{host}{uri}".format(host=self._host, uri=uri), timeout=timeout, headers=headers, params=rest_helpers.flatten_query_params(query_params), ) # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception # subclass. if response.status_code >= 400: raise core_exceptions.from_http_response(response) # Return the response api_response = operations_pb2.ListOperationsResponse() json_format.Parse(response.content, api_response, ignore_unknown_fields=False) return api_response