
    (                     \    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S
 jr
S rg	)z7Utilities for AI Platform persistent resource commands.    )absolute_import)division)unicode_literals)	arg_utilsz1aiplatform.projects.locations.persistentResourcesc                    U R                  S5      " 5       nU R                  S5      nU" UR                  S5      S9nUR                  S5      nU(       aE  [        R                  " XSR                  5      Ul        [        UR                  SS5      5      Ul        XBl        UR                  S5      nU(       a  [        U5      Ul	        UR                  S	5      nUR                  S
5      nU(       d  U(       a<  U R                  S5      " 5       n	[        U5      U	l
        [        U5      U	l        Xl        UR                  S5      n
UR                  S5      nU
(       a  U R                  S5      nU" XS9nXl        U$ )a  Constructs a single resource pool spec.

Args:
  aiplatform_client: The AI Platform API client used.
  spec: A dict whose fields represent a resource pool spec.

Returns:
  A ResourcePoolSpec message instance for setting a resource pool in a
  Persistent Resource
ResourcePoolMachineSpeczmachine-type)machineTypezaccelerator-typezaccelerator-count   zreplica-countzmin-replica-countzmax-replica-countResourcePoolAutoscalingSpecz	disk-typez	disk-sizeDiskSpec)bootDiskTypebootDiskSizeGb)
GetMessagegetr   ChoiceToEnumAcceleratorTypeValueValuesEnumacceleratorTypeintacceleratorCountmachineSpecreplicaCountminReplicaCountmaxReplicaCountautoscalingSpecdiskSpec)aiplatform_clientspecresource_poolmachine_spec_msgmachine_specaccelerator_typereplica_countmin_replica_countmax_replica_countautoscaling_spec	disk_type	disk_sizedisk_spec_msg	disk_specs                 Rlib/googlecloudsdk/command_lib/ai/persistent_resources/persistent_resource_util.py _ConstructSingleResourcePoolSpecr,      sN    $..~>@-&11-@!dhh~.FG,XX01#,#9#9II$KL $'1Da(H$IL!*((?+-!$]!3Mhh23hh23+$$%BCE '*+<'=$'*+<'=$$4!hh{#)hh{#)%00<M9OI&	    c                     / nU HL  nU(       a  UR                  [        X40 UD65        M'  UR                  U R                  S5      " 5       5        MN     U$ )a  Constructs the resource pool specs for a persistent resource.

Args:
  aiplatform_client: The AI Platform API client used.
  specs: A list of dict of resource pool specs, supposedly derived from
    the gcloud command flags.
  **kwargs: The keyword args to pass down to construct each worker pool spec.

Returns:
  A list of ResourcePool message instances for creating a Persistent Resource.
ResourcePoolSpec)appendr,   r   )r   specskwargsresource_pool_specsr   s        r+   _ConstructResourcePoolSpecsr4   G   s^     d  
*+<
Mf
MO   

&
&'9
:
<>  
r-   Nc                     / n[        UR                  [        5      (       a  UR                  nU(       a  U[        X40 UD6-   nU$ )aC  Constructs the resource pools to be used to create a Persistent Resource.

Resource pools from the config file and arguments will be combined.

Args:
  aiplatform_client: The AI Platform API client used.
  persistent_resource_config: A Persistent Resource configuration imported
    from a YAML config.
  resource_pool_specs: A dict of worker pool specification, usually derived
    from the gcloud command argument values.
  **kwargs: The keyword args to pass to construct the worker pool specs.

Returns:
  An array of ResourcePool messages for creating a Persistent Resource.
)
isinstanceresourcePoolslistr4   )r   persistent_resource_configr3   r2   resource_poolss        r+   ConstructResourcePoolsr;   `   sP    , .*88$??/==N#&A':28': :N 
r-   c                 L    X;   =(       a    [        UR                  U 5      5      $ )N)boolr   )keyr2   s     r+   _IsKwargsDefinedr?      s    		04

300r-   )NN)__doc__
__future__r   r   r   $googlecloudsdk.command_lib.util.apisr   PERSISTENT_RESOURCE_COLLECTIONr,   r4   r;   r?    r-   r+   <module>rE      s:    > &  ' :!T *Z6  $@1r-   