
    }%                         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	ej                  fdZd	 Zd
 Zd Z	 	 	 	 	 ddZ	 	 	 	 	 	 	 ddZddZd Zy)z$Utilities for validating parameters.    )absolute_import)division)unicode_literals)
exceptions)	constantsc                 :    | | st        j                  dd      yy)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                 v    | |vr5t        j                  ddj                  dj                  |      |             y)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   !   sC    $$

-
-4;;II'(&	
  %r   c                     t        | j                  d      ra| j                  j                  j                         }|r|j	                         S dD ]%  }t        | |d      st        j                  dd       yy)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#   ,   so    T]]I&mm##))+G!!##N'4$'33@  O 'r   c                    | y| j                         D ]  \  }}|t        j                  vrvt        j                  ddj                  dj                  t        t        j                  j                               D cg c]  }dj                  |       c}                  |dk(  r|dk  st        j                  dd      |dk  s|d	kD  st        j                  dd
j                  ||             yc c}w )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   
]
KKMjc5
)===//
&
M
T
Tii!AAFFHa --" 
 
 ))	!11(
 	

 
!us{//
&
C
J
JS - "
s   ;C6c                 L    | "|xs d}| |kD  rt        j                  dd      yy)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1//
$
B  2 (r   Nc                 ~   |P| t        j                  dd      | dkD  rt        j                  dd      |||k  rt        j                  dd      |3| t        j                  dd      | dkD  rt        j                  dd	      |4| t        j                  d
d      | dkD  rt        j                  d
d      yy)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5//
#
M  # //
 = 
 1//
 0 
 & //
#= 
 1//
#0   'r   c                 *   | y|t        j                  dd      |t        j                  dd      |t        j                  dd      |t        j                  dd	      |t        j                  d
d      |t        j                  dd      y)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                 :    | |rt        j                  dd      yy)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                 L   | j                   "| j                   st        j                  dd      t        | j                   j	                  d            dk7  s9t        | j                   j	                  d      d   j	                  d            dkD  rt        j                  dd      y)	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   