
                             S r SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  SSK	Jr  SSK
Jr  SrS	r1 S
krSS jr SS jr SS jrS rS rS rS rS rg)z1Service Consumer Management API helper functions.    )absolute_import)division)unicode_literals)
exceptions)
list_pager)apiszservices/%s/%sz%s/producerOverrides/%s>   folders/	projects/organizations/Nc           	          [        U5        [        5       nUR                  nUR                  [        X4-  S9n[
        R                  " UR                  UUSUSS9$ )a  List service quota metrics for a consumer.

Args:
  service: The service to list metrics for.
  consumer: The consumer to list metrics for, e.g. "projects/123".
  page_size: The page size to list.
  limit: The max number of metrics to return.

Raises:
  exceptions.PermissionDeniedException: when listing metrics fails.
  apitools_exceptions.HttpError: Another miscellaneous error with the service.

Returns:
  The list of quota metrics
)parentpageSizemetrics)limitbatch_size_attribute
batch_sizefield)_ValidateConsumer_GetClientInstanceMESSAGES_MODULE@ServiceconsumermanagementServicesConsumerQuotaMetricsListRequest_SERVICE_CONSUMER_RESOURCEr   YieldFromListservices_consumerQuotaMetrics)serviceconsumer	page_sizer   clientmessagesrequests          *lib/googlecloudsdk/api_lib/services/scm.pyListQuotaMetricsr"      sk      H&##(UU'7*== V ?'		!	!**%
     c                    [        U5        [        5       nUR                  n[        X5      n	UR	                  [
        X4-  UR                  UR                  UR                  UUUU	S9/S9US9S9n
 UR                  R                  U
5      $ ! [        R                  [        R                  4 a/  n[        R                  " U[        R                   5         SnAgSnAff = f)a  Update a quota override.

Args:
  service: The service to update a quota override for.
  consumer: The consumer to update a quota override for, e.g. "projects/123".
  metric: The quota metric name.
  unit: The unit of quota metric.
  dimensions: The dimensions of the override in dictionary format. It can be
    None.
  value: The override integer value.
  force: Force override update even if the change results in a substantial
    decrease in available quota.

Raises:
  exceptions.UpdateQuotaOverridePermissionDeniedException: when updating an
  override fails.
  apitools_exceptions.HttpError: Another miscellaneous error with the service.

Returns:
  The quota override operation.
)metricunitoverrideValue
dimensions)	overrides)inlineSourceforce)r   %v1Beta1ImportProducerOverridesRequestN)r   r   r   _GetDimensionsSServiceconsumermanagementServicesConsumerQuotaMetricsImportProducerOverridesRequestr   %V1Beta1ImportProducerOverridesRequestV1Beta1OverrideInlineSourceV1Beta1QuotaOverrider   ImportProducerOverridesapitools_exceptionsHttpForbiddenErrorHttpNotFoundErrorr   ReraiseError,UpdateQuotaOverridePermissionDeniedException)r   r   r%   r&   r(   valuer+   r   r   dimensions_messager    es               r!   UpdateQuotaOverrideCallr;   >   s    8 H&##(%h;hh'7*==,4,,;;//#$)!3	 0 5 <   - 	 i 'D//GGPP

0
0

/
/
1 D	:BBD DDs   2B $C 1%CC c                 t   [        U5        [        5       nUR                  n[        XX#5      n[        X4-  n	UR                  U	US9n
 UR                  R                  U
5      $ ! [        R                  [        R                  4 a/  n[        R                  " U[        R                  5         SnAgSnAff = f)aW  Delete a quota override.

Args:
  service: The service to delete a quota aoverride for.
  consumer: The consumer to delete a quota override for, e.g. "projects/123".
  metric: The quota metric name.
  unit: The unit of quota metric.
  override_id: The override ID.
  force: Force override deletion even if the change results in a substantial
    decrease in available quota.

Raises:
  exceptions.DeleteQuotaOverridePermissionDeniedException: when deleting an
  override fails.
  apitools_exceptions.HttpError: Another miscellaneous error with the service.

Returns:
  The quota override operation.
)namer+   N)r   r   r   _GetMetricResourceName_LIMIT_OVERRIDE_RESOURCEYServiceconsumermanagementServicesConsumerQuotaMetricsLimitsProducerOverridesDeleteRequest6services_consumerQuotaMetrics_limits_producerOverridesDeleter3   r4   r5   r   r6   ,DeleteQuotaOverridePermissionDeniedException)r   r   r%   r&   override_idr+   r   r   r   r=   r    r:   s               r!   DeleteQuotaOverrideCallrE   u   s    2 H&##(!'VB&	!V$9	9$nn o 'DHHOO 

0
0

/
/
1 D	:BBD DDs   	A$ $$B7%B22B7c           
          Uc  g U R                   R                  nU" [        UR                  5       5       Vs/ s H  nUR	                  X1U   S9PM     snS9$ s  snf )N)keyr8   )additionalProperties)r1   DimensionsValuesortedkeysAdditionalProperty)r   r(   dtks       r!   r-   r-      si    $$44"	 *//+,,a 

A]

;,

 
s   Ac                     [        X5      nU HH  nUR                  U:X  d  M  UR                   H#  nUR                  U:X  d  M  UR                  s  s  $    MJ     [
        R                  " SU< SU< S35      e)a|  Get the metric resource name from metric name and unit.

Args:
  service: The service to manage an override for.
  consumer: The consumer to manage an override for, e.g. "projects/123".
  metric: The quota metric name.
  unit: The unit of quota metric.

Raises:
  exceptions.Error: when the limit with given metric and unit is not found.

Returns:
  The quota override operation.
zlimit not found with name "z" and unit "z".)r"   r%   consumerQuotaLimitsr&   r=   r   Error)r   r   r%   r&   r   mqs          r!   r>   r>      sg     W/'axx6$$!66T>- % 
 	 $( 	) )r#   c                 0   [        5       nUR                  nUR                  U S9n UR                  R	                  U5      $ ! [
        R                  [
        R                  4 a/  n[        R                  " U[        R                  5         SnAgSnAff = f)a  Make API call to get an operation.

Args:
  name: The name of the operation.

Raises:
  exceptions.OperationErrorException: when the getting operation API fails.
  apitools_exceptions.HttpError: Another miscellaneous error with the service.

Returns:
  The result of the operation
)r=   N)r   r   -ServiceconsumermanagementOperationsGetRequest
operationsGetr3   r4   r5   r   r6   OperationErrorException)r=   r   r   r    r:   s        r!   GetOperationrY      s     &##(BBBM'C  ))

0
0

/
/
1 CAzAABBCs   A $B&%BBc                 ~    [          H  nU R                  U5      (       d  M    g    [        R                  " SU -  5      e)Nzinvalid consumer format "%s".)_VALID_CONSUMER_PREFIX
startswithr   rQ   )r   prefixs     r!   r   r      s9    &f6"" ' 	88CDDr#   c                  0    [         R                  " SS5      $ )Nserviceconsumermanagementv1beta1)r   GetClientInstance r#   r!   r   r      s    			 ;Y	GGr#   )NN)F)__doc__
__future__r   r   r   apitools.base.pyr   r3   r   googlecloudsdk.api_lib.servicesgooglecloudsdk.api_lib.utilr   r   r?   r[   r"   r;   rE   r-   r>   rY   r   r   rb   r#   r!   <module>rh      sk    8 &  ' > ' 6 ,- 4 D J #(4Dx #()DX	
)2C.EHr#   