Пример #1
0
    def update_budget(
            self,
            request: budget_service.UpdateBudgetRequest = None,
            *,
            budget: budget_model.Budget = None,
            update_mask: field_mask_pb2.FieldMask = None,
            retry: retries.Retry = gapic_v1.method.DEFAULT,
            timeout: float = None,
            metadata: Sequence[Tuple[str, str]] = (),
    ) -> budget_model.Budget:
        r"""Updates a budget and returns the updated budget.
        WARNING: There are some fields exposed on the Google
        Cloud Console that aren't available on this API. Budget
        fields that are not exposed in this API will not be
        changed by this method.

        Args:
            request (google.cloud.billing.budgets_v1.types.UpdateBudgetRequest):
                The request object. Request for UpdateBudget
            budget (google.cloud.billing.budgets_v1.types.Budget):
                Required. The updated budget object.
                The budget to update is specified by the
                budget name in the budget.

                This corresponds to the ``budget`` field
                on the ``request`` instance; if ``request`` is provided, this
                should not be set.
            update_mask (google.protobuf.field_mask_pb2.FieldMask):
                Optional. Indicates which fields in the provided budget
                to update. Read-only fields (such as ``name``) cannot be
                changed. If this is not provided, then only fields with
                non-default values from the request are updated. See
                https://developers.google.com/protocol-buffers/docs/proto3#default
                for more details about default values.

                This corresponds to the ``update_mask`` 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.cloud.billing.budgets_v1.types.Budget:
                A budget is a plan that describes
                what you expect to spend on Cloud
                projects, plus the rules to execute as
                spend is tracked against that plan, (for
                example, send an alert when 90% of the
                target spend is met). The budget time
                period is configurable, with options
                such as month (default), quarter, year,
                or custom time period.

        """
        # Create or coerce a protobuf request object.
        # Sanity check: If we got a request object, we should *not* have
        # gotten any keyword arguments that map to the request.
        has_flattened_params = any([budget, update_mask])
        if request is not None and has_flattened_params:
            raise ValueError('If the `request` argument is set, then none of '
                             'the individual field arguments should be set.')

        # Minor optimization to avoid making a copy if the user passes
        # in a budget_service.UpdateBudgetRequest.
        # There's no risk of modifying the input as we've already verified
        # there are no flattened fields.
        if not isinstance(request, budget_service.UpdateBudgetRequest):
            request = budget_service.UpdateBudgetRequest(request)
            # If we have keyword arguments corresponding to fields on the
            # request, apply these.
            if budget is not None:
                request.budget = budget
            if update_mask is not None:
                request.update_mask = update_mask

        # Wrap the RPC method; this adds retry and timeout information,
        # and friendly error handling.
        rpc = self._transport._wrapped_methods[self._transport.update_budget]

        # Certain fields should be provided within the metadata header;
        # add these here.
        metadata = tuple(metadata) + (gapic_v1.routing_header.to_grpc_metadata(
            (("budget.name", request.budget.name), )), )

        # Send the request.
        response = rpc(
            request,
            retry=retry,
            timeout=timeout,
            metadata=metadata,
        )

        # Done; return the response.
        return response
Пример #2
0
    async def update_budget(
        self,
        request: budget_service.UpdateBudgetRequest = None,
        *,
        budget: budget_model.Budget = None,
        update_mask: field_mask.FieldMask = None,
        retry: retries.Retry = gapic_v1.method.DEFAULT,
        timeout: float = None,
        metadata: Sequence[Tuple[str, str]] = (),
    ) -> budget_model.Budget:
        r"""Updates a budget and returns the updated budget.
        WARNING: There are some fields exposed on the Google
        Cloud Console that aren't available on this API. Budget
        fields that are not exposed in this API will not be
        changed by this method.

        Args:
            request (:class:`google.cloud.billing.budgets_v1.types.UpdateBudgetRequest`):
                The request object. Request for UpdateBudget
            budget (:class:`google.cloud.billing.budgets_v1.types.Budget`):
                Required. The updated budget object.
                The budget to update is specified by the
                budget name in the budget.

                This corresponds to the ``budget`` field
                on the ``request`` instance; if ``request`` is provided, this
                should not be set.
            update_mask (:class:`google.protobuf.field_mask_pb2.FieldMask`):
                Optional. Indicates which fields in the provided budget
                to update. Read-only fields (such as ``name``) cannot be
                changed. If this is not provided, then only fields with
                non-default values from the request are updated. See
                https://developers.google.com/protocol-buffers/docs/proto3#default
                for more details about default values.

                This corresponds to the ``update_mask`` 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.cloud.billing.budgets_v1.types.Budget:
                A budget is a plan that describes
                what you expect to spend on Cloud
                projects, plus the rules to execute as
                spend is tracked against that plan, (for
                example, send an alert when 90% of the
                target spend is met). Currently all
                plans are monthly budgets so the usage
                period(s) tracked are implied (calendar
                months of usage back-to-back).

        """
        # Create or coerce a protobuf request object.
        # Sanity check: If we got a request object, we should *not* have
        # gotten any keyword arguments that map to the request.
        has_flattened_params = any([budget, update_mask])
        if request is not None and has_flattened_params:
            raise ValueError(
                "If the `request` argument is set, then none of "
                "the individual field arguments should be set."
            )

        request = budget_service.UpdateBudgetRequest(request)

        # If we have keyword arguments corresponding to fields on the
        # request, apply these.

        if budget is not None:
            request.budget = budget
        if update_mask is not None:
            request.update_mask = update_mask

        # Wrap the RPC method; this adds retry and timeout information,
        # and friendly error handling.
        rpc = gapic_v1.method_async.wrap_method(
            self._client._transport.update_budget,
            default_retry=retries.Retry(
                initial=0.1,
                maximum=60.0,
                multiplier=1.3,
                predicate=retries.if_exception_type(
                    exceptions.DeadlineExceeded, exceptions.ServiceUnavailable,
                ),
                deadline=60.0,
            ),
            default_timeout=60.0,
            client_info=DEFAULT_CLIENT_INFO,
        )

        # Certain fields should be provided within the metadata header;
        # add these here.
        metadata = tuple(metadata) + (
            gapic_v1.routing_header.to_grpc_metadata(
                (("budget.name", request.budget.name),)
            ),
        )

        # Send the request.
        response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,)

        # Done; return the response.
        return response