
    (                     Z    d 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		 	 dd
Z
d Zy	)z7Utilities for AI Platform persistent resource commands.    )absolute_import)division)unicode_literals)	arg_utilsz1aiplatform.projects.locations.persistentResourcesc                     | j                  d             }| j                  d      } ||j                  d            }|j                  d      }|rEt        j                  ||j                        |_        t        |j                  dd            |_        ||_        |j                  d      }|rt        |      |_	        |j                  d	      }|j                  d
      }|s|r= | j                  d             }	t        |      |	_
        t        |      |	_        |	|_        |j                  d      }
|j                  d      }|
r"| j                  d      } ||
|      }||_        |S )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,      s_    ?#..~>@-&11-@!dhh~.FG,XX01#,#9#9*II$KL $'1Da(H$IL!*-((?+-!$]!3Mhh23hh23+C$$%BCE '*+<'=$'*+<'=$$4M!hh{#)hh{#)%00<M9YOI&M	    c                     g }|D ]F  }|r|j                  t        | |fi |       "|j                   | j                  d                    H |S )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   sc     d  
*+<d
Mf
MO   
:

&
&'9
:
<>  
r-   Nc                 z    g }t        |j                  t              r|j                  }|r|t        | |fi |z   }|S )aY  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                 B    | |v xr t        |j                  |             S )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-   