
                         V    S 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S	 rS
 rg)zGValidation of the arguments for the persistent-resources command group.    )util)
exceptions)	constants)
validationc                 J    [         R                  " U [        R                  S9  g)zFValidate whether the given region is allowed for persistent resources.)available_regionsN)r   ValidateRegionr   SUPPORTED_TRAINING_REGIONS)regions    Dlib/googlecloudsdk/command_lib/ai/persistent_resources/validation.pyr	   r	      s    	 D DF    c                 L   U R                   (       a  [        U R                   U5        [        UR                  [        5      (       a  [        UR                  U5        U R                   (       d7  [        UR                  [        5      (       d  [        R                  " SS5      egg)z?Validate the argument values specified in the `create` command.--resource-pool-speczNo resource pools specified. At least one resource pool must be provided via a YAML config file (--config) or via the --resource-pool-spec arg.N)resource_pool_spec_ValidateResourcePoolSpecArgs
isinstanceresourcePoolslist$_ValidateResourcePoolSpecsFromConfigr   InvalidArgumentException)argspersistent_resource_configversions      r   ValidateCreateArgsr      s    	!$"9"97C*88$??("00'; 
!
!
/==t
D
D

-
-	$% % E "r   c                 \    U S   (       d  [         R                  " SS5      e[        X5        g)a  Validates the argument values specified via `--resource-pool-spec` flags.

Args:
  resource_pool_specs: List[dict], a list of resource pool specs specified via
    command line arguments.
  version: str, the API version this command will interact with, either GA or
    BETA.
r   r   zEEmpty value is not allowed for the first `--resource-pool-spec` flag.N)r   r   '_ValidateHardwareInResourcePoolSpecArgs)resource_pool_specsr   s     r   r   r   /   s2     
Q	

-
-OQ Q **=Gr   c                    U  GHs  nU(       d  M  SU;  a  [         R                  " SS5      eSU;   a  SU;  a  [         R                  " SS5      eSU;   a  SU;  a  [         R                  " SS5      eSU;  a  SU;  a  [         R                  " SS	5      eS
U;   SU;   :w  a  [         R                  " SS5      eUR                  SS5      nU(       d  M  [        R                  " SU5      R
                  nUR                  5        Vs/ s H  nUR                  S5      (       d  M  UPM     nnX6;  d  GM2  [         R                  " SSR                  USR                  S [        U5       5       5      S95      e   gs  snf )a  Validates the hardware related fields specified in `--resource-pool-spec` flags.

Args:
  resource_pool_specs: List[dict], a list of resource pool specs specified via
    command line arguments.
  version: str, the API version this command will interact with, either GA or
    BETA.
zmachine-typer   z9Key [machine-type] required in dict arg but not provided.zmin-replica-countzmax-replica-countzVKey [max-replica-count] required in dict arg when key [min-replica-count] is provided.zVKey [min-replica-count] required in dict arg when key [max-replica-count] is provided.zreplica-countz:Key [replica-count] required in dict arg but not provided.zaccelerator-countzaccelerator-typezPKey [accelerator-type] and [accelerator-count] are required to use accelerators.NMachineSpecNVIDIAzWFound invalid value of [accelerator-type]: {actual}. Available values are [{expected}]., c              3   $   #    U  H  ov   M     g 7fN .0vs     r   	<genexpr>:_ValidateHardwareInResourcePoolSpecArgs.<locals>.<genexpr>v   s     %E1DAa1D   actualexpected)r   r   getapi_util
GetMessageAcceleratorTypeValueValuesEnumnames
startswithformatjoinsorted)r   r   specaccelerator_type	type_enumtypevalid_typess          r   r   r   @   s    "dt	t	#11"GI 	I 
%,?t,K11"/0 	0
 
%,?t,K11"/0 	0 
%,?t,K11"HJ 	J 
%+=+E	F11" ! 	!
 "4d;		''7$$B$B 	 '__.
.Tx( . 	 
 .33$45;V* II%E1D%EE 6< 6GH HQ "F
s   E<%E<c                    U (       d  [         R                  " SS5      eU  GH  nUR                  (       d  [         R                  " SS5      eUR                  R                  (       d  [         R                  " SS5      eUR                  (       d(  UR
                  (       d  [         R                  " SS5      eUR
                  (       a2  UR
                  R                  (       d  [         R                  " SS5      eUR
                  (       a2  UR
                  R                  (       d  [         R                  " SS5      eUR                  R                  (       a2  UR                  R                  (       d  [         R                  " SS5      eUR                  (       aM  UR                  R                  (       a2  UR                  R                  (       d  [         R                  " SS	5      eUR                  R                  (       d  GM  [        UR                  R                  R                  5      n[        R                   " S
U5      R"                  nUR%                  5        Vs/ s H  nUR'                  S5      (       d  M  UPM     nnX6;  d  GMp  [         R                  " SSR)                  USR+                  S [-        U5       5       5      S95      e   gs  snf )zJValidate ResourcePoolSpec message instances imported from the config file.z--configzDAt least one [resourcePools] required in but not provided in config.z;Field [machineSpec] required in but not provided in config.z;Field [machineType] required in but not provided in config.z<Field [replicaCount] required in but not provided in config.z7Field [minReplicaCount] required when using autoscalingz7Field [maxReplicaCount] required when using autoscalingzMField [acceleratorType] required as [acceleratorCount] is specifiedin config.zHField [bootDiskType] required as [bootDiskSizeGb] is specifiedin config.r   r    zVFound invalid value of [acceleratorType]: {actual}. Available values are [{expected}].r!   c              3   $   #    U  H  ov   M     g 7fr#   r$   r%   s     r   r(   7_ValidateResourcePoolSpecsFromConfig.<locals>.<genexpr>   s     #C/B!A/Br*   r+   N)r   r   machineSpecmachineTypereplicaCountautoscalingSpecminReplicaCountmaxReplicaCountacceleratorCountacceleratorTypediskSpecbootDiskSizeGbbootDiskTypestrnamer/   r0   r1   r2   r3   r4   r5   r6   )resource_poolsr   r7   r8   r9   r:   r;   s          r   r   r   y   sd   	

-
-NP P d//

GI I ''//

GI I (<(<//

HJ J 	t';';'K'K//

CE E 	t';';'K'K//

CE E 	)),,//
 
 }}$--66"mm88//
 
 '''T--==BBC%%
""@"@  %??,,4__X& ,   
	,112396())#Cvk/B#CC 4: 4EF 	Fc Xs   #KKN)__doc__googlecloudsdk.api_lib.air   r/   googlecloudsdk.callioper   googlecloudsdk.command_lib.air   r   r	   r   r   r   r   r$   r   r   <module>rQ      s7    N 7 . 3 4F%"H"6Hr<Fr   