
    E-                     H   d Z ddlmZ ddlmZ ddlmZ ddlmZ ddlm	Z	 dZ
dZd	Ze	j                  j                  d
e	j                  j                  de	j                  j                   diZdde	j                  fdZd Zd Zd Zd Zd Ze	j                  j                  fde	j                  fdZe	j                  j                  fde	j                  fdZe	j                  j                  fde	j                  fdZe	j                  j                  fde	j                  fdZy)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                 \    t         j                  |       }t        j                  d||      S )Ncloudquotas)no_http)VERSION_MAPgetr   GetClientInstance)r   r   api_versions      5lib/googlecloudsdk/api_lib/quotas/quota_preference.py_GetClientInstancer   "   s%    .+			{G	LL    c                     |y | dz   |z   S )Nz/quotaPreferences/ )request_parentpreference_ids     r   _GetPreferenceNamer   '   s    	.	.	>>r   c           
          |y | j                   j                  } |t        |j                               D cg c]  }|j	                  |||          c}      S c c}w )N)keyvalue)additionalProperties)QuotaPreferenceDimensionsValuesortedkeysAdditionalProperty)messages
dimensionsdimensions_valuelocations       r   _GetDimensionsr)   -   sv    --==	
 !!23	 4h 
-
-*X"6 .  4	
 s   Ac                 2    | 
|d| d|S | |S |d| z  S y )Nzemail: z. z
email: %s.r   )emailjustifications     r   _GetJustificationr-   <   s7    
=4#]33
]%	r   c                     g }| j                   r%|j                  |j                  j                         | j                  r%|j                  |j                  j
                         |S )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                 <    | |r| dz   t         z   S |rt         S | | S y )Nz AND )_RECONCILING_ONLY_FILTER)custom_filterreconciling_onlys     r   
_GetFilterr=   S   s4    #37"%===##	r   c                    t        j                  | j                  | j                  | j                        }t        |      }|j                  }t        |z  }|j                  t        || j                        t        || j                        |j                  t        | j                              | j                   | j"                  t%        | j&                  | j(                        | j&                        }| j                  rN|j+                  || j                  |t-        | |j*                              }|j.                  j1                  |      S | j                  rN|j3                  || j                  |t-        | |j2                              }|j4                  j1                  |      S | j                  rN|j7                  || j                  |t-        | |j6                              }|j8                  j1                  |      S y)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&--fd&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   t        j                  | j                  | j                  | j                        }t        |      }|j                  }t        t        |z  | j                        }|j                  |t        || j                        |j                  t        | j                              | j                   | j"                  t%        | j&                  | j(                        | j&                        }| j                  rY|j+                  ||| j,                  | j.                  t1        | |j*                              }|j2                  j5                  |      S | j                  rY|j7                  ||| j,                  | j.                  t1        | |j6                              }|j8                  j5                  |      S | j                  rY|j;                  ||| j,                  | j.                  t1        | |j:                              }|j<                  j5                  |      S y)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                 $   t        j                  | j                  | j                  | j                        }t        |      }|j                  }t        |z  d| j                  z  z   }| j                  r-|j                  |      }|j                  j                  |      S | j                  r-|j                  |      }|j                  j                  |      S | j                  r-|j                  |      }|j                  j                  |      S y)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                    t        j                  | j                  | j                  | j                        }t        |      }|j                  }t        |z  }t        | j                         | j                  r|j                  || j                  t        | j                  | j                        t        j                  | j                               }t#        j$                  |j&                  |d| j                  | j                  nt(        d| j*                        S | j                  r|j-                  || j                  t        | j                  | j                        t        j                  | j                               }t#        j$                  |j.                  |d| j                  | j                  nt(        d| j*                        S | j                  r|j1                  || j                  t        | j                  | j                        t        j                  | j                               }t#        j$                  |j2                  |d| j                  | j                  nt(        d| j*                        S y)a  Lists 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   