
                         ~    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dl	m
Z
 ddlmZ dd	lmZ  G d
 de      Zy)z6Utilities for querying Vertex AI Persistent Resources.    )absolute_import)division)unicode_literals)
list_pager)apis)	constants)util)
console_ioc                   n    e Zd ZdZej
                  fdZd Zd Z	 	 	 	 	 	 ddZ	ddZ
d Zd	 Zd
 Zd Zy)PersistentResourcesClientzAClient used for interacting with the PersistentResource endpoint.c                     t        j                  t        j                  t        j                  |         }|j
                  | _        || _        |j                  | _	        t        j                  |   | _        y )N)r   GetClientInstancer   AI_PLATFORM_API_NAMEAI_PLATFORM_API_VERSIONMESSAGES_MODULE	_messages_version&projects_locations_persistentResources_serviceAI_PLATFORM_MESSAGE_PREFIX_message_prefix)selfversionclients      <lib/googlecloudsdk/api_lib/ai/persistent_resources/client.py__init__z"PersistentResourcesClient.__init__   s]    ##I$B$B$-$E$Eg$NPF++DNDMAADM$??HD    c                 f    t        | j                  dj                  | j                  |      d      S )z&Returns the API message class by name.z{prefix}{name})prefixnameN)getattrr   formatr   )r   message_names     r   
GetMessagez$PersistentResourcesClient.GetMessage'   s9     t';';%1 	  	348: :r   c                 $    | j                  d      S )z'Returns the PersistentResource message.PersistentResource)r$   )r   s    r   PersistentResourceMessagez3PersistentResourcesClient.PersistentResourceMessage/   s     ??/00r   Nc
                     | j                         ||      }
| | j                  d      |      |
_        |r||
_        |r||
_        |r4 | j                  d       | j                  d      d|	            |
_        | j                  t        j                  k(  r7| j                  j                  | j                  j                  ||
|	            S | j                  j                  | j                  j                  ||
|
            S )a  Constructs a request and sends it to the endpoint to create a persistent resource.

    Args:
      parent: str, The project resource path of the persistent resource to
      create.
      resource_pools: The PersistentResource message instance for the
      creation request.
      persistent_resource_id: The PersistentResource id for the creation
      request.
      display_name: str, The display name of the persistent resource to create.
      kms_key_name: A customer-managed encryption key to use for the persistent
      resource.
      labels: LabelValues, map-like user-defined metadata to organize the
      resource.
      network: Network to peer with the PersistentResource
      enable_custom_service_account: Whether or not to enable this Persistent
        Resource to use a custom service account.
      service_account: A service account (email address string) to use for
        creating the Persistent Resource.

    Returns:
      A PersistentResource message instance created.
    )displayNameresourcePoolsEncryptionSpec)
kmsKeyNameResourceRuntimeSpecServiceAccountSpecT)enableCustomServiceAccountserviceAccount)serviceAccountSpec)parent)googleCloudAiplatformV1PersistentResourcepersistentResourceId)r2   .googleCloudAiplatformV1beta1PersistentResourcer4   )r'   r$   encryptionSpeclabelsnetworkresourceRuntimeSpecr   r   
GA_VERSIONr   Creater   ;AiplatformProjectsLocationsPersistentResourcesCreateRequest)r   r2   resource_poolspersistent_resource_iddisplay_namekms_key_namer7   r8   enable_custom_service_accountservice_accountpersistent_resources              r   r;   z PersistentResourcesClient.Create4   s   B ;$88: @ +L4??;K+L!,#( #) $+!$
0$///
0!F1E!F-1!0"23 - }}	,,,]]!!
..
T
T8K#9 U   ==RR;N!7 	S 	
 r   c                 ~    t        j                  | j                  | j                  j	                  |      dd|      S )a  Constructs a list request and sends it to the Persistent Resources endpoint.

    Args:
      limit: How many items to return in the list
      region: Which region to list resources from

    Returns:
      A Persistent Resource list response message.

    )r2   persistentResourcespageSize)fieldbatch_size_attributelimit)r   YieldFromListr   r   9AiplatformProjectsLocationsPersistentResourcesListRequest)r   rI   regions      r   ListzPersistentResourcesClient.Listy   sD     ##PP 	Q 	
 $' r   c                 p    | j                   j                  |      }| j                  j                  |      S N)r    )r   8AiplatformProjectsLocationsPersistentResourcesGetRequestr   Getr   r    requests      r   rQ   zPersistentResourcesClient.Get   s9    ~~HH I   ==W%%r   c                 p    | j                   j                  |      }| j                  j                  |      S rO   )r   ;AiplatformProjectsLocationsPersistentResourcesDeleteRequestr   DeleterR   s      r   rV   z PersistentResourcesClient.Delete   6    nnXX Y G ==((r   c                 p    | j                   j                  |      }| j                  j                  |      S rO   )r   ;AiplatformProjectsLocationsPersistentResourcesRebootRequestr   RebootrR   s      r   rZ   z PersistentResourcesClient.Reboot   rW   r   c                     t        j                  |d      }| j                  |      }t        j                  ||      S )z@Import a messages class instance typed by name from a YAML file.F)binary)message_typestream)r
   ReadFromFileOrStdinr$   export_utilImport)r   	yaml_filer#   datar]   s        r   ImportResourceMessagez/PersistentResourcesClient.ImportResourceMessage   s5    )))EBD??<0L<EEr   )NNNNFN)NN)__name__
__module____qualname____doc__r   r:   r   r$   r'   r;   rM   rQ   rV   rZ   rd    r   r   r   r      sS    I&11 I:1 +0!CJ*&))Fr   r   N)rh   
__future__r   r   r   apitools.base.pyr   googlecloudsdk.api_lib.utilr   googlecloudsdk.command_lib.air   !googlecloudsdk.command_lib.exportr	   r`   googlecloudsdk.core.consoler
   objectr   ri   r   r   <module>rq      s2    = &  ' ' , 3 A 2HF HFr   