
                            d Z ddlmZ ddlmZ ddlmZ ddl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 ddlmZ ddlmZ ddlmZ dZdZ e	j2                  e	j4                  j6                         G d de	j8                               Z e	j2                  e	j4                  j<                  e	j4                  j>                         G d de             Z y)z5Command to create a Persistent Resource in Vertex AI.    )absolute_import)division)unicode_literalsN)client)base)	constants)endpoint_util)
validation)flags)persistent_resource_util)labels_util)log)
propertieszFprojects/{project_number}/locations/{region}/operations/{operation_id}zOperation to create PersistentResource [{display_name}] is submitted successfully.

You may view the status of your PersistentResource create operation with the command

  $ {command_prefix} ai operations describe {operation_resource_name}
c                   J    e Zd ZdZej
                  Zed        Zd Z	d Z
d Zy)CreateGA  Create a new persistent resource.

  This command will create a persistent resource on the users project to use
  with Vertex AI custom training jobs. Persistent resources remain active until
  they are deleted by the user.

  ## EXAMPLES

  To create a PersistentResource under project ``example'' in region
  ``us-central1'', run:

    $ {command} --region=us-central1 --project=example
    --resource-pool-spec=replica-count=1,machine-type='n1-standard-4'
    --display-name=example-resource
  c                 .    t        j                  |        y )N)r    AddCreatePersistentResourceFlags)parsers    -lib/surface/ai/persistent_resources/create.pyArgszCreateGA.ArgsC   s    	**62    c                    d}| j                         j                  r |d| j                         j                  z   z  }t        j                  d|j                        j                  d      d   }t        j                  |||      }t        j                  j                  t        j                  |j                  ||             y )Ngcloud zoperations\/(\d+)r   )project_numberregionoperation_id)display_namecommand_prefixoperation_resource_name)ReleaseTrackprefixresearchnamegroups!_OPERATION_RESOURCE_NAME_TEMPLATEformatr   statusPrint6_PERSISTENT_RESOURCE_CREATION_DISPLAY_MESSAGE_TEMPLATE)selfresponser   r   
cmd_prefixr   r!   s          r   _DisplayResultzCreateGA._DisplayResultG   s    J!!C$++-4444j9918==AHHKANL?FF%! G  JJ>EE!%$; 	F 	
r   c                    |j                   r|j                  |j                   d      n|j                         }t        j                  ||| j
                         t        |j                  xs g       }t        j                  |||      }|S )NPersistentResource)persistent_resource_configresource_pool_specs)
configImportResourceMessagePersistentResourceMessager
   ValidateCreateArgs_versionlistresource_pool_specr   ConstructResourcePools)r-   args
api_clientr3   r4   persistent_resource_specs         r   _PrepareResourcePoolszCreateGA._PrepareResourcePools[   s     ;; 	((6JK113  !!($-- t66<"=7NN#=/ 
 $#r   c                    t         j                  j                  j                  j	                         }|j
                  j                  j                         }|j                         d   }t        j                  |       t        j                  | j                  |      5  t        j                  | j                        }| j!                  ||      }t#        j$                  ||j'                         j(                        }|j+                  |j-                         |j.                  ||j0                  t3        j4                  |      ||j6                  |j8                        }| j;                  |||       |cd d d        S # 1 sw Y   y xY w)NlocationsId)versionr   )rC   )parentr   resource_poolspersistent_resource_idkms_key_namelabelsnetworkenable_custom_service_account)r   VALUEScoreproject	GetOrFailCONCEPTSr   ParseAsDictr
   ValidateRegionr	   AiplatformEndpointOverridesr9   r   PersistentResourcesClientr@   r   ParseCreateArgsr7   LabelsValueCreateRelativeNamer   rF   common_validationGetAndValidateKmsKeyrI   rJ   r0   )	r-   r=   rM   
region_refr   r>   rE   rH   r.   s	            r   RunzCreateGA.Runm   sC   $$,,668G%%++-J /Ff%		2	2f
 33DMMJj11

n **

446BBf ""((*(('!%!<!<(==dC,,(,(J(J # h (GV41
 
 
s    CFF
N)__name__
__module____qualname____doc__r   
GA_VERSIONr9   staticmethodr   r0   r@   r\    r   r   r   r   /   s5      !!(3 3($$r   r   c                   (    e Zd ZdZej
                  Zy)CreatePreGAr   N)r]   r^   r_   r`   r   BETA_VERSIONr9   rc   r   r   re   re      s      ##(r   re   )!r`   
__future__r   r   r   r$   .googlecloudsdk.api_lib.ai.persistent_resourcesr   googlecloudsdk.callioper   googlecloudsdk.command_lib.air   r	   r
   rY   2googlecloudsdk.command_lib.ai.persistent_resourcesr   r   $googlecloudsdk.command_lib.util.argsr   googlecloudsdk.corer   r   r(   r,   ReleaseTracksr"   GACreateCommandr   ALPHABETAre   rc   r   r   <module>rs      s    < &  ' 	 A ( 3 7 I D W I < # * M ": 6 D%%(()[t!! [ *[| D%%++T->->-C-CD$( $ E$r   