
    E-                     \   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r
SrS	r\	R                  R                  S
\	R                  R                  S\	R                  R                   S0rSS\	R                  4S jjrS rS rS rS rS r\	R                  R                  4S\	R                  4S jjr\	R                  R                  4S\	R                  4S jjr\	R                  R                  4S\	R                  4S jjr\	R                  R                  4S\	R                  4S jjrg)z/Utilities for Cloud Quotas API QuotaPreference.    )
list_pager)message_util)apis)common_args)based   z%s/locations/globalzreconciling:truev1alphav1betav1release_trackc                 V    [         R                  U 5      n[        R                  " SX!S9$ )Ncloudquotas)no_http)VERSION_MAPgetr   GetClientInstance)r   r   api_versions      5lib/googlecloudsdk/api_lib/quotas/quota_preference.py_GetClientInstancer   "   s#    .+			{	LL    c                     Uc  g U S-   U-   $ )Nz/quotaPreferences/ )request_parentpreference_ids     r   _GetPreferenceNamer   '   s    	.	.	>>r   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)keyvalue)additionalProperties)QuotaPreferenceDimensionsValuesortedkeysAdditionalProperty)messages
dimensionsdimensions_valuelocations       r   _GetDimensionsr)   -   st    --==	
 !!23	 4h 
-
-X"6 .  4	
 s   Ac                 >    U b  Ub
  SU < SU< 3$ U c  U$ Uc  SU -  $ g )Nzemail: z. z
email: %s.r   )emailjustifications     r   _GetJustificationr-   <   s7    
=4#]33
]%	r   c                     / nU R                   (       a%  UR                  UR                  R                  5        U R                  (       a%  UR                  UR                  R
                  5        U$ )N) allow_quota_decrease_below_usageappend!IgnoreSafetyChecksValueValuesEnumQUOTA_DECREASE_BELOW_USAGE$allow_high_percentage_quota_decrease"QUOTA_DECREASE_PERCENTAGE_TOO_HIGH)argsrequestignore_safety_checkss      r   _GetIgnoreSafetyChecksr8   F   s^    	**11LL 
..11TT 
r   c                 T    U b  U(       a  U S-   [         -   $ U(       a  [         $ U b  U $ g )Nz AND )_RECONCILING_ONLY_FILTER)custom_filterreconciling_onlys     r   
_GetFilterr=   S   s4    #37"%===##	r   c                    [         R                  " U R                  U R                  U R                  5      n[        U5      nUR                  n[        U-  nUR                  [        XPR                  5      [        X@R                  5      UR                  [        U R                  5      S9U R                   U R"                  [%        U R&                  U R(                  5      U R&                  S9nU R                  (       aK  UR+                  UU R                  U[-        U UR*                  5      S9nUR.                  R1                  U5      $ U R                  (       aK  UR3                  UU R                  U[-        U UR2                  5      S9nUR4                  R1                  U5      $ U R                  (       aK  UR7                  UU R                  U[-        U UR6                  5      S9nUR8                  R1                  U5      $ g)a  Creates a new QuotaPreference that declares the desired value for a quota.

Args:
  args: argparse.Namespace, The arguments that this command was invoked with.
  release_track: base.ReleaseTrack, The release track to use.

Returns:
  The created QuotaPreference
preferredValuenamer&   quotaConfigservicequotaIdr,   contactEmail)parentquotaPreferenceIdquotaPreferenceignoreSafetyChecksN)r   CreateConsumerprojectfolderorganizationr   MESSAGES_MODULE_CONSUMER_LOCATION_RESOURCEr    r   r   r)   r&   QuotaConfigintpreferred_valuerD   quota_idr-   r+   r,   9CloudquotasProjectsLocationsQuotaPreferencesCreateRequestr8   #projects_locations_quotaPreferencesCreate8CloudquotasFoldersLocationsQuotaPreferencesCreateRequest"folders_locations_quotaPreferences>CloudquotasOrganizationsLocationsQuotaPreferencesCreateRequest(organizations_locations_quotaPreferences)r5   r   consumerclientr%   rG   quota_preferencer6   s           r   CreateQuotaPreferencer_   ]   s    ((
llDKK!2!2( m,&##(&(3&--f&8&89//:&&T112 '  llmm%djj$2D2DE:: . 
 
\\PP,,(1NN
	 Q G 55<<WEE	[[OO,,(1MM
	 P G 44;;GDD	UU,,(1SS
	 V G ::AA'JJ r   c                 J   [         R                  " U R                  U R                  U R                  5      n[        U5      nUR                  n[        [        U-  U R                  5      nUR                  U[        X@R                  5      UR                  [        U R                  5      S9U R                   U R"                  [%        U R&                  U R(                  5      U R&                  S9nU R                  (       aV  UR+                  UUU R,                  U R.                  [1        U UR*                  5      S9nUR2                  R5                  U5      $ U R                  (       aV  UR7                  UUU R,                  U R.                  [1        U UR6                  5      S9nUR8                  R5                  U5      $ U R                  (       aV  UR;                  UUU R,                  U R.                  [1        U UR:                  5      S9nUR<                  R5                  U5      $ g)zUpdates the parameters of a single QuotaPreference.

Args:
  args: argparse.Namespace, The arguments that this command was invoked with.
  release_track: base.ReleaseTrack, The release track to use.

Returns:
  The updated QuotaPreference.
r?   rA   )rB   rI   allowMissingvalidateOnlyrJ   N)r   rK   rL   rM   rN   r   rO   r   rP   PREFERENCE_IDr    r)   r&   rQ   rR   rS   rD   rT   r-   r+   r,   8CloudquotasProjectsLocationsQuotaPreferencesPatchRequestallow_missingvalidate_onlyr8   rV   Patch7CloudquotasFoldersLocationsQuotaPreferencesPatchRequestrY   =CloudquotasOrganizationsLocationsQuotaPreferencesPatchRequestr[   )r5   r   r\   r]   r%   preference_namer^   r6   s           r   UpdateQuotaPreferencerk      s    ((
llDKK!2!2( m,&##(&!X.0B0B/ --//:&&T112 '  llmm%djj$2D2DE:: . 
 
\\OO(''''1MM
 P 	G 55;;GDD	[[NN(''''1LL
 O 	G 44::7CC	TT(''''1RR
 U 	G ::@@II r   c                 2   [         R                  " U R                  U R                  U R                  5      n[        U5      nUR                  n[        U-  SU R                  -  -   nU R                  (       a*  UR                  US9nUR                  R                  U5      $ U R                  (       a*  UR                  US9nUR                  R                  U5      $ U R                  (       a*  UR                  US9nUR                  R                  U5      $ g)a   Retrieve the QuotaPreference for a project, folder or organization.

Args:
  args: argparse.Namespace, The arguments that this command was invoked with.
  release_track: base.ReleaseTrack, The release track to use.

Returns:
  The request QuotaPreference.
z/quotaPreferences/%s)rB   N)r   rK   rL   rM   rN   r   rO   rP   rc   6CloudquotasProjectsLocationsQuotaPreferencesGetRequestrV   Get5CloudquotasFoldersLocationsQuotaPreferencesGetRequestrY   ;CloudquotasOrganizationsLocationsQuotaPreferencesGetRequestr[   )r5   r   r\   r]   r%   rB   r6   s          r   GetQuotaPreferencerq      s    ((
llDKK!2!2( m,&##(!X.!3!334 
 
\\MM N G 5599'BB	[[LL M G 4488AA	LL 	M 	
 
 ::>>wGG r   c           	         [         R                  " U R                  U R                  U R                  5      n[        U5      nUR                  n[        U-  n[        U R                  5        U R                  (       a  UR                  UU R                  [        U R                  U R                  5      [        R                  " U R                   5      S9n["        R$                  " UR&                  USU R                  b  U R                  O[(        SU R*                  S9$ U R                  (       a  UR-                  UU R                  [        U R                  U R                  5      [        R                  " U R                   5      S9n["        R$                  " UR.                  USU R                  b  U R                  O[(        SU R*                  S9$ U R                  (       a  UR1                  UU R                  [        U R                  U R                  5      [        R                  " U R                   5      S9n["        R$                  " UR2                  USU R                  b  U R                  O[(        SU R*                  S9$ g)zLists QuotaPreferences in a given project, folder or organization.

Args:
  args: argparse.Namespace, The arguments that this command was invoked with.
  release_track: base.ReleaseTrack, The release track to use.

Returns:
  List of QuotaPreferences.
)rG   pageSizefilterorderByrs   NquotaPreferences)batch_size_attribute
batch_sizefieldlimit)r   rK   rL   rM   rN   r   rO   rP   print	page_size7CloudquotasProjectsLocationsQuotaPreferencesListRequestr=   rt   r<   r   ParseSortByArgsort_byr   YieldFromListrV   	PAGE_SIZErz   6CloudquotasFoldersLocationsQuotaPreferencesListRequestrY   <CloudquotasOrganizationsLocationsQuotaPreferencesListRequestr[   )r5   r   r\   r]   r%   rG   r6   s          r   ListQuotaPreferencesr     s    ((
llDKK!2!2( m,&##(&1&	\\NN$++t'<'<=**4<<8	 O G ##22'%)^^%?4>>Y jj  
[[MM$++t'<'<=**4<<8	 N G ##11'%)^^%?4>>Y jj  
MM^^dkk4+@+@A..t||<	 	N 	
  ##77'%)^^%?4>>Y jj  r   N)F)__doc__apitools.base.pyr   googlecloudsdk.api_lib.quotasr   googlecloudsdk.api_lib.utilr   r   googlecloudsdk.callioper   r   rP   r:   ReleaseTrackALPHABETAGAr   r   r   r)   r-   r8   r=   r_   rk   rq   r   r   r   r   <module>r      s2   6 ' 6 , 3 (	3 -  	YH$Md&7&7 M
?
 .2->->-D-DAK**AKJ .2->->-D-DFJ**FJT .2->->-D-D(H**(HX .2->->-D-DD**Dr   