
    T                         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 dd
lmZ ddlmZ d Z G d de      Zy)z;Utilities for dealing with AI Platform index endpoints API.    )absolute_import)division)unicode_literals)
list_pager)apis)	constants)errors)labels_util)
properties)	resourcesc                     t         j                  j                  | |t        j                  j
                  j                  j                  dd      S )z/Parses a index ID into a index resource object.)locationsId
projectsIdz%aiplatform.projects.locations.indexes)params
collection)r   REGISTRYParser   VALUEScoreproject	GetOrFail)index_idlocation_ids     7lib/googlecloudsdk/api_lib/ai/index_endpoints/client.py_ParseIndexr      sK    				!	!$"))..66@@ 9 
" 
: :    c                       e Zd ZdZddej
                  fdZd Zd Zd Z	d Z
d Zd	 Zd
 Zd Zd Zd Zd ZddZd Zd Zd Zd Zd Zy)IndexEndpointsClientz>High-level client for the AI Platform index endpoints surface.Nc                     |xs5 t        j                  t        j                  t        j                  |         | _        |xs | j
                  j                  | _        | j
                  j                  | _	        y N)
r   GetClientInstancer   AI_PLATFORM_API_NAMEAI_PLATFORM_API_VERSIONclientMESSAGES_MODULEmessages!projects_locations_indexEndpoints_service)selfr$   r&   versions       r   __init__zIndexEndpointsClient.__init__,   s[     4D22&&))'24DK ; ; ;DMKKAADMr   c                    t        j                  || j                  j                  j                        }d}|j
                  &| j                  j                  |j
                        }d}|j                  r| j                  j                  |j                  |j                  r|j                  ng       }| j                  j                  |j                         | j                  j                  |j                  |j                  |j                  |||            }n|j                  h| j                  j                  |j                         | j                  j                  |j                  |j                  |j                  ||            }n^| j                  j                  |j                         | j                  j                  |j                  |j                  d|||            }| j                   j#                  |      S )zCreate a new index endpoint.N
kmsKeyNameenablePrivateServiceConnectprojectAllowlistdisplayNamedescriptionpublicEndpointEnabledlabelsencryptionSpecprivateServiceConnectConfig)parent)googleCloudAiplatformV1beta1IndexEndpointr3   r4   networkr6   r7   T)r
   ParseCreateArgsr&   )GoogleCloudAiplatformV1beta1IndexEndpointLabelsValueencryption_kms_key_name*GoogleCloudAiplatformV1beta1EncryptionSpecenable_private_service_connect7GoogleCloudAiplatformV1beta1PrivateServiceConnectConfigproject_allowlist6AiplatformProjectsLocationsIndexEndpointsCreateRequestRelativeNamedisplay_namer4   public_endpoint_enabledr<   r(   Creater)   location_refargsr6   encryption_specprivate_service_connect_configreqs          r   
CreateBetazIndexEndpointsClient.CreateBeta3   s   ((??KKMF O##/
--
B
B55 C 7  &*"**
--
O
O*.*M*M#'#9#9 !% 6 6?A P  % MMPP**,48MM4k4k++**$($@$@,*H 5l 5 Q 
c 
	!MMPP**,48MM4k4k++**ll, 5l 5 Q 	c MMPP**,48MM4k4k++**$(,*H 5l 5 Q 
c ==$$r   c                    t        j                  || j                  j                  j                        }d}|j
                  &| j                  j                  |j
                        }d}|j                  r| j                  j                  |j                  |j                  r|j                  ng       }| j                  j                  |j                         | j                  j                  |j                  |j                  |j                  |||            }n|j                  h| j                  j                  |j                         | j                  j                  |j                  |j                  |j                  ||            }n^| j                  j                  |j                         | j                  j                  |j                  |j                  d|||            }| j                   j#                  |      S )zCreate a new v1 index endpoint.Nr-   r/   r2   )r9   $googleCloudAiplatformV1IndexEndpointr;   T)r
   r=   r&   $GoogleCloudAiplatformV1IndexEndpointr?   r@   %GoogleCloudAiplatformV1EncryptionSpecrB   2GoogleCloudAiplatformV1PrivateServiceConnectConfigrD   rE   rF   rG   r4   rH   r<   r(   rI   rJ   s          r   rI   zIndexEndpointsClient.Createn   s   ((dmm@@LLNF O##/
--
=
=55 > 7  &*"**
--
J
J*.*M*M#'#9#9 !% 6 6?A K  % MMPP**,/3}}/a/a++**$($@$@,*H 0b 0 Q 
c 
	!MMPP**,/3}}/a/a++**ll, 0b 0 Q 	c MMPP**,/3}}/a/a++**$(,*H 0b 0 Q 
c ==$$r   c                      j                   j                         }g }|j                  "|j                  |_        |j	                  d       |j
                  "|j
                  |_        |j	                  d        fd}t        j                  | j                   j                  j                  |      }|j                  r"|j                  |_
        |j	                  d       |st        j                  d       j                   j                  j                         |dj                  |            } j                   j#                  |      S )zUpdate an index endpoint.rG   r4   c                  :    j                         j                  S r    Getr6   index_endpoint_refr)   s   r   	GetLabelsz1IndexEndpointsClient.PatchBeta.<locals>.GetLabels       XX()000r   r6   No updates requested.,)namer:   
updateMask)r&   r>   rG   r3   appendr4   r
   ProcessUpdateArgsLazyr?   needs_updater6   r	   NoFieldsSpecifiedError5AiplatformProjectsLocationsIndexEndpointsPatchRequestrF   joinr(   Patchr)   r[   rL   index_endpointupdate_maskr\   labels_updaterequests   ``      r   	PatchBetazIndexEndpointsClient.PatchBeta   s"   ]]LLNNK$#'#4#4n (##'#3#3n '1  55??KKM !!+22n"))*ABBmmQQ,,.2@88K( R *G ==w''r   c                      j                   j                         }g }|j                  "|j                  |_        |j	                  d       |j
                  "|j
                  |_        |j	                  d        fd}t        j                  | j                   j                  j                  |      }|j                  r"|j                  |_
        |j	                  d       |st        j                  d       j                   j                  j                         |dj                  |            } j                   j#                  |      S )zUpdate an v1 index endpoint.rG   r4   c                  :    j                         j                  S r    rX   rZ   s   r   r\   z-IndexEndpointsClient.Patch.<locals>.GetLabels   r]   r   r6   r^   r_   )r`   rR   ra   )r&   rS   rG   r3   rb   r4   r
   rc   r?   rd   r6   r	   re   rf   rF   rg   r(   rh   ri   s   ``      r   rh   zIndexEndpointsClient.Patch   s!   ]]GGINK$#'#4#4n (##'#3#3n '1  55dmm@@LLM !!+22n"))*ABBmmQQ,,.-;88K( R *G ==w''r   c                 r   t        |j                  |j                        }| j                  j	                  |j
                  |j                  |j                               }|j                  %|j                  j                  |j                         |j                  |j                  |_        |j                  |j                  |_        |j                  |j                   | j                  j#                         }|j                  j                  |j                         |j$                  j                  |j                          | j                  j'                  |      |_        |j*                  | j                  j-                         }| j                  j/                  |j*                        |_        |j2                  |j2                  |_        |j6                  |j6                  |_        ||_        n[| j                  j=                         }|j2                  |j2                  |_        |j6                  |j6                  |_        ||_        | j                  jA                  |      }| j                  jC                  |j                         |      }	| jD                  jG                  |	      S )z%Deploy an index to an index endpoint.)r3   idindexauthProvidermachineTypedeployedIndex)indexEndpoint.googleCloudAiplatformV1beta1DeployIndexRequest)$r   rs   regionr&   )GoogleCloudAiplatformV1beta1DeployedIndexrG   deployed_index_idrF   reserved_ip_rangesreservedIpRangesextenddeployment_groupdeploymentGroupenable_access_loggingenableAccessLogging	audiencesallowed_issuers?GoogleCloudAiplatformV1beta1DeployedIndexAuthConfigAuthProviderallowedIssuers3GoogleCloudAiplatformV1beta1DeployedIndexAuthConfigdeployedIndexAuthConfigmachine_type.GoogleCloudAiplatformV1beta1DedicatedResources'GoogleCloudAiplatformV1beta1MachineSpecmachineSpecmin_replica_countminReplicaCountmax_replica_countmaxReplicaCountdedicatedResources.GoogleCloudAiplatformV1beta1AutomaticResourcesautomaticResources.GoogleCloudAiplatformV1beta1DeployIndexRequest;AiplatformProjectsLocationsIndexEndpointsDeployIndexRequestr(   DeployIndex)
r)   r[   rL   	index_refdeployed_indexauth_providerdedicated_resourcesautomatic_resourcesdeploy_index_reqrm   s
             r   DeployIndexBetaz$IndexEndpointsClient.DeployIndexBeta   sj   DJJ4I]]LL%%!!$$& M N *%%,,T-D-DE('+'<'<n$!!-+/+E+En(~~!d&:&:&Fmmccem$$T^^4""))$*>*>?
--
K
K( L * , $
--
F
F
H  --
?
?++ @  %
 
			+.2.D.D+				+.2.D.D+*=n' --
F
F
H  
			+.2.D.D+				+.2.D.D+*=n'}}SS$ T &mmWW(5577G X IG ==$$W--r   c                    t        |j                  |j                        }| j                  j	                  |j
                  |j                  |j                         |j                        }|j                  %|j                  j                  |j                         |j                  |j                  |_        |j                  |j                  | j                  j!                         }|j                  j                  |j                         |j"                  j                  |j                         | j                  j%                  |      |_        |j(                  Tg |_        |j(                  D ]>  }|j*                  j-                  | j                  j/                  |d   |d                @ |j0                  | j                  j3                         }| j                  j5                  |j0                        |_        |j8                  |j8                  |_        |j<                  |j<                  |_        ||_         n[| j                  jC                         }|j8                  |j8                  |_        |j<                  |j<                  |_        ||_"        | j                  jG                  |      }	| j                  jI                  |j                         |	      }
| jJ                  jM                  |
      S )	z(Deploy an v1 index to an index endpoint.)r3   rr   rs   r   rt   z
project-idr<   )	projectIdr<   rv   rx   )rz   )googleCloudAiplatformV1DeployIndexRequest)'r   rs   r|   r&   $GoogleCloudAiplatformV1DeployedIndexrG   r~   rF   r   r   r   r   r   r   r   r   :GoogleCloudAiplatformV1DeployedIndexAuthConfigAuthProviderr   .GoogleCloudAiplatformV1DeployedIndexAuthConfigr   psc_automation_configspscAutomationConfigsrb   *GoogleCloudAiplatformV1PSCAutomationConfigr   )GoogleCloudAiplatformV1DedicatedResources"GoogleCloudAiplatformV1MachineSpecr   r   r   r   r   r   )GoogleCloudAiplatformV1AutomaticResourcesr   )GoogleCloudAiplatformV1DeployIndexRequestr   r(   r   )r)   r[   rL   r   r   r   psc_automation_configr   r   r   rm   s              r   r   z IndexEndpointsClient.DeployIndex"  s   DJJ4I]]GG%%!!$$& 66	 H N *%%,,T-D-DE('+'<'<n$ ~~!d&:&:&Fmm^^`m$$T^^4""))$*>*>?
--
F
F( G * ,
 "".,.n)#'#>#>
++22MMDD/=-i8 E 	
 $? $
--
A
A
C  --
:
:++ ;  %
 
			+.2.D.D+				+.2.D.D+*=n' --
A
A
C  
			+.2.D.D+				+.2.D.D+*=n'}}NN$ O &mmWW(5572B X DG ==$$W--r   c                     | j                   j                  |j                        }| j                   j                  |j	                         |      }| j
                  j                  |      S )z'Undeploy an index to an index endpoint.deployedIndexId)rz   0googleCloudAiplatformV1beta1UndeployIndexRequest)r&   0GoogleCloudAiplatformV1beta1UndeployIndexRequestr~   =AiplatformProjectsLocationsIndexEndpointsUndeployIndexRequestrF   r(   UndeployIndexr)   r[   rL   undeploy_index_reqrm   s        r   UndeployIndexBetaz&IndexEndpointsClient.UndeployIndexBetae  sg    WW.. X 0mmYY(5579K Z MG ==&&w//r   c                     | j                   j                  |j                        }| j                   j                  |j	                         |      }| j
                  j                  |      S )z*Undeploy an v1 index to an index endpoint.r   )rz   +googleCloudAiplatformV1UndeployIndexRequest)r&   +GoogleCloudAiplatformV1UndeployIndexRequestr~   r   rF   r(   r   r   s        r   r   z"IndexEndpointsClient.UndeployIndexn  sg    RR.. S 0mmYY(5574F Z HG ==&&w//r   c                 8   | j                   j                  |j                  |j                        }|j                  | j                  |      |_        n| j                  |      |_        |j                  %|j                  j                  |j                         |j                  |j                  |_        |j                  |j                  | j                   j!                         }|j                  j                  |j                         |j"                  j                  |j                         | j                   j%                  |      |_        | j                   j)                  |j+                         |      }| j,                  j/                  |      S )/Mutate a deployed index from an index endpoint.rr   r   rt   )rz   )googleCloudAiplatformV1beta1DeployedIndex)r&   r}   r~   r   r   _GetDedicatedResourcesBetar   _GetAutomaticResourcesBetar   r   r   r   r   r   r   r   r   r   r   r   CAiplatformProjectsLocationsIndexEndpointsMutateDeployedIndexRequestrF   r(   MutateDeployedIndexr)   r[   rL   r   r   rm   s         r   MutateDeployedIndexBetaz,IndexEndpointsClient.MutateDeployedIndexBetaw  sc    ]]LL!! 66 M N
 $*.*I*I$*On'*.*I*I$*On'*%%,,T-D-DE('+'<'<n$~~!d&:&:&Fmmccem$$T^^4""))$*>*>?
--
K
K( L * , mm__(5572@ ` BG ==,,W55r   c                 8   | j                   j                  |j                  |j                        }|j                  | j                  |      |_        n| j                  |      |_        |j                  %|j                  j                  |j                         |j                  |j                  |_        |j                  |j                  | j                   j!                         }|j                  j                  |j                         |j"                  j                  |j                         | j                   j%                  |      |_        | j                   j)                  |j+                         |      }| j,                  j/                  |      S )r   r   rt   )rz   $googleCloudAiplatformV1DeployedIndex)r&   r   r~   r   r   _GetDedicatedResourcesr   _GetAutomaticResourcesr   r   r   r   r   r   r   r   r   r   r   r   r   rF   r(   r   r   s         r   r   z(IndexEndpointsClient.MutateDeployedIndex  sb    ]]GG!! 66 H N
 $*.*E*Ed*Kn'*.*E*Ed*Kn'*%%,,T-D-DE('+'<'<n$~~!d&:&:&Fmm^^`m$$T^^4""))$*>*>?
--
F
F( G * , mm__(557-; ` =G ==,,W55r   c                     | j                   j                  |j                               }| j                  j	                  |      S N)r`   )r&   3AiplatformProjectsLocationsIndexEndpointsGetRequestrF   r(   rY   r)   r[   rm   s      r   rY   zIndexEndpointsClient.Get  s=    mmOO,,. P 0G==W%%r   c                     t        j                  | j                  | j                  j	                  |j                               dd|      S )N)r9   indexEndpointspageSize)fieldbatch_size_attributelimit)r   YieldFromListr(   r&   4AiplatformProjectsLocationsIndexEndpointsListRequestrF   )r)   r   
region_refs      r   ListzIndexEndpointsClient.List  sI    ##JJ**, 	K 	.' r   c                     | j                   j                  |j                               }| j                  j	                  |      S r   )r&   6AiplatformProjectsLocationsIndexEndpointsDeleteRequestrF   r(   Deleter   s      r   r   zIndexEndpointsClient.Delete  s=    mmRR,,. S 0G==((r   c                    | j                   j                         }| j                   j                  |j                        |_        |j
                  |j
                  |_        |j                  |j                  |_        |S )z+Construct dedicated resources for beta API.rv   )	r&   r   r   r   r   r   r   r   r   r)   rL   r   s      r   r   z/IndexEndpointsClient._GetDedicatedResourcesBeta  s     	DDF  	==)) 	> 	
 #
 ),0,B,B)),0,B,B)r   c                     | j                   j                         }|j                  |j                  |_        |j                  |j                  |_        |S )z+Construct automatic resources for beta API.)r&   r   r   r   r   r   r)   rL   r   s      r   r   z/IndexEndpointsClient._GetAutomaticResourcesBeta  sW     	DDF  ),0,B,B)),0,B,B)r   c                    | j                   j                         }| j                   j                  |j                        |_        |j
                  |j
                  |_        |j                  |j                  |_        |S )z)Construct dedicated resources for GA API.rv   )	r&   r   r   r   r   r   r   r   r   r   s      r   r   z+IndexEndpointsClient._GetDedicatedResources  s     	??A  	88)) 	9 	
 #
 ),0,B,B)),0,B,B)r   c                     | j                   j                         }|j                  |j                  |_        |j                  |j                  |_        |S )z)Construct automatic resources for GA API.)r&   r   r   r   r   r   r   s      r   r   z+IndexEndpointsClient._GetAutomaticResources  sW     	??A  ),0,B,B)),0,B,B)r   )NN)__name__
__module____qualname____doc__r   
GA_VERSIONr+   rP   rI   rn   rh   r   r   r   r   r   r   rY   r   r   r   r   r   r    r   r   r   r   )   sv    F 49M9M B9%v8%t(B(@7.rA.F006@6@&
)
 	 	r   r   N)r   
__future__r   r   r   apitools.base.pyr   googlecloudsdk.api_lib.utilr   googlecloudsdk.command_lib.air   r	   $googlecloudsdk.command_lib.util.argsr
   googlecloudsdk.corer   r   r   objectr   r   r   r   <module>r      s<    B &  ' ' , 3 0 < * ):U6 Ur   