
    }%                         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	\R                  4S jrS	 rS
 rS r     SS jr       SS jrSS jrS rg)z$Utilities for validating parameters.    )absolute_import)division)unicode_literals)
exceptions)	constantsc                 H    U b  U (       d  [         R                  " SS5      egg)zValidates the display name.Nz--display-namezDisplay name can not be empty.r   InvalidArgumentException)display_names    /lib/googlecloudsdk/command_lib/ai/validation.pyValidateDisplayNamer      s+    l

-
-:  '3    c                 z    X;  a6  [         R                  " SSR                  SR                  U5      U 5      5      eg)z=Validates whether a given region is among the available ones.regionz*Available values are [{}], but found [{}]., N)r   r
   formatjoin)r   available_regionss     r   ValidateRegionr   !   s@    $

-
-4;;II'(&	
  %r   c                    [        U R                  S5      (       am  U R                  R                  R                  5       nU(       a  UR	                  5       $ S H+  n[        XS5      (       d  M  [        R                  " SS5      e   gg)zFParse CMEK resource arg, and check if the arg was partially specified.kms_key)r   kms_keyringkms_locationkms_projectNz	--kms-keyz#Encryption key not fully specified.)hasattrCONCEPTSr   ParseRelativeNamegetattrr   r
   )argskms_refkeywords      r   GetAndValidateKmsKeyr#   ,   ss    T]]I&&mm##))+G!!##N'4$''33@  O 'r   c                    U c  gU R                  5        H  u  pU[        R                  ;  az  [        R                  " SSR                  SR                  [        [        R                  R                  5       5       Vs/ s H  nSR                  U5      PM     sn5      5      5      eUS:X  a  US::  a  [        R                  " SS5      eM  US::  d  US	:  d  M  [        R                  " SS
R                  X!5      5      e   gs  snf )zDValue validation for autoscaling metric specs target name and value.N--autoscaling-metric-specsz=Autoscaling metric name can only be one of the following: {}.r   z'{}'zrequest-counts-per-minuter   zEMetric target for request-counts-per-minute must be a positive value.d   z7Metric target value {} for {} is not between 0 and 100.)	itemsr   !OP_AUTOSCALING_METRIC_NAME_MAPPERr   r
   r   r   sortedkeys)specskeyvaluecs       r   ValidateAutoscalingMetricSpecsr/   :   s   
]
KKMjc
)===//
&
M
T
Tii!AAFFHa --" 
 
 ))	!11(
 	
 
 
!us{//
&
C
J
J - "
s   >Dc                 Z    U b(  U=(       d    SnX:  a  [         R                  " SS5      egg)z,Value validation for required replica count.N   --required-replica-countz6Value must be less than or equal to min-replica-count.r	   )required_replica_countmin_replica_counts     r   ValidateRequiredReplicaCountr5   ]   s<    ').Q1//
$
B  2 (r   Nc                    UbV  U c  [         R                  " SS5      eU S:  a  [         R                  " SS5      eUb  X!:  a  [         R                  " SS5      eUb7  U c  [         R                  " SS5      eU S:  a  [         R                  " SS	5      eUb8  U c  [         R                  " S
S5      eU S:  a  [         R                  " S
S5      egg)z(Value validation for scale-to-zero args.Nz--initial-replica-countzuCannot set initial-replica-count without explicitly setting
          min-replica-count to 0 to enable scale-to-zero.r   zkCannot set initial-replica-count when min-replica-count > 0 as
          scale-to-zero will not be enabled.z=Initial-replica-count must be smaller than max replica count.z--min-scaleup-periodzrCannot set min-scaleup-period without explicitly setting
          min-replica-count to 0 to enable scale-to-zero.zhCannot set min-scaleup-period when min-replica-count > 0 as
          scale-to-zero will not be enabled.z--idle-scaledown-periodzuCannot set idle-scaledown-period without explicitly setting
          min-replica-count to 0 to enable scale-to-zero.zkCannot set idle-scaledown-period when min-replica-count > 0 as
          scale-to-zero will not be enabled.r	   )r4   initial_replica_countmax_replica_countmin_scaleup_periodidle_scaledown_periods        r   ValidateScaleToZeroArgsr;   h   s    & //
#= 
 1//
#0  	%5//
#
M  # //
 = 
 1//
 0 
 & //
#= 
 1//
#0   'r   c                 D   U c  gUb  [         R                  " SS5      eUb  [         R                  " SS5      eUb  [         R                  " SS5      eUb  [         R                  " SS	5      eUb  [         R                  " S
S5      eUb  [         R                  " SS5      eg)a  Value validation for dedicated resource args while making a shared resource command call.

Args:
    shared_resources_ref: str or None, the shared deployment resource pool
      full name the model should use, formatted as the full URI
    machine_type: str or None, the type of the machine to serve the model.
    accelerator_dict: dict or None, the accelerator attached to the deployed
      model from args.
    min_replica_count: int or None, the minimum number of replicas the
      deployed model will be always deployed on.
    max_replica_count: int or None, the maximum number of replicas the
      deployed model may be deployed on.
    required_replica_count: int or None, the required number of replicas the
      deployed model will be considered successfully deployed.
    autoscaling_metric_specs: dict or None, the metric specification that
      defines the target resource utilization for calculating the desired
      replica count.
Nz--machine-typezECannot use
    machine type and shared resources in the same command.z--acceleratorzDCannot
    use accelerator and shared resources in the same command.z--min-replica-countzJCannot
    use min replica count and shared resources in the same command.z--max-replica-countzJCannot
    use max replica count and shared resources in the same command.r2   zOCannot
    use required replica count and shared resources in the same command.r%   zUCannot use autoscaling metric specs
        and shared resources in the same command.r	   )shared_resources_refmachine_typeaccelerator_dictr4   r8   r3   autoscaling_metric_specss          r   ValidateSharedResourceArgsrA      s    6 !


-
-	> 
 !

-
-	A 
 "

-
-	G 
 "

-
-	G 
 '

-
-"	L 
 )

-
-$	5  *r   c                 H    U b  U(       a  [         R                  " SS5      egg)z2Validates the network and public_endpoint_enabled.NzRPlease either set --network for private endpoint, or set --public-endpoint-enabledzfor public enpdoint.r	   )networkpublic_endpoint_enableds     r   ValidateEndpointArgsrE      s.    4

-
-	%  5r   c                 `   U R                   b(  U R                   (       d  [        R                  " SS5      e[        U R                   R	                  S5      5      S:w  d:  [        U R                   R	                  S5      S   R	                  S5      5      S:  a  [        R                  " SS5      eg)	z&Validates the model garden model args.Nz--modelzModel name should not be empty./   r1   @a4  Model name should be in the format of Model Garden, e.g. `{publisher_name}/{model_name}@{model_version_name}, e.g. `google/gemma2@gemma-2-2b` or in the format of Hugging Face convention, e.g. `meta-llama/Meta-Llama-3-8B`. You can use the `gcloud ai model-garden models list` command to find supported models.)modelr   r
   lensplit)r    s    r   ValidateModelGardenModelArgsrM      s    	ZZDJJ

-
-)  
$**

3
 A%	TZZc"1%++C0	1A	5

-
-	  
6r   )NNNNN)NNNNNNN)NN)__doc__
__future__r   r   r   googlecloudsdk.callioper   googlecloudsdk.command_lib.air   r   SUPPORTED_REGIONr   r#   r/   r5   r;   rA   rE   rM    r   r   <module>rT      s}    + &  ' . 3 .7-G-G  F 9z !AHr   