
                           S r SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  SSK	J
r  SSKJr  SS	KJr  SS
KJr  SSKJr  SSKJr  SSKJ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S jrS r S r!S r" " S S\#5      r$g)z5Utilities for dealing with AI Platform endpoints API.    )annotations)encoding)
exceptions)extra_types)
list_pager)utilclient)apis)	constants)errors)flags)
properties)	resources)requests)http_clientc                    [         R                  R                  U U[        R                  R
                  R                  R                  S.SS9$ )z/Parses a model ID into a model resource object.)locationsId
projectsIdz$aiplatform.projects.locations.models)params
collection)r   REGISTRYParser   VALUEScoreproject	GetOrFail)model_idlocation_ids     1lib/googlecloudsdk/api_lib/ai/endpoints/client.py_ParseModelr!   $   sK    				!	!$"))..66@@ 8 
" 
     c                Z    U Vs/ s H  n[         R                  " X5      PM     sn$ s  snf N)r   PyValueToMessage)message_typevaluesvs      r    _ConvertPyListToMessageListr)   0   s%    >D	Ef(
#
#L
4f	EE	Es    (Nc                    [         R                  " US9R                  U 5      n[        R                  " U5      nUS   nUb:  SU;  a3  [
        R                  " SR                  U R                  5       5      5      eg UR                  S5        US   $ ! [        R                   a(    [
        R                  " SU R                  5       -  5      ef = f! [         a    US   S   s $ f = f)a  Gets the deployment resource type of a model.

Args:
  model_ref: a model resource object.
  client: an apis.GetClientInstance object.
  shared_resources_ref: str, the shared deployment resource pool the model
    should use, formatted as the full URI

Returns:
  A string which value must be 'DEDICATED_RESOURCES', 'AUTOMATIC_RESOURCES'
  or 'SHARED_RESOURCES'

Raises:
  ArgumentError: if the model resource object is not found.
r	   z\There is an error while getting the model information. Please make sure the model %r exists.!supportedDeploymentResourcesTypesSHARED_RESOURCESz,Shared resources not supported for model {}.r   )model_clientModelsClientGetapitools_exceptions	HttpErrorr   ArgumentErrorRelativeNamer   MessageToPyValueformatremove
ValueError)	model_refr
   shared_resources_ref	model_msgmodel_resource$supported_deployment_resources_typess         r    _GetModelDeploymentResourceTyper=   4   s
   $))8<<YGI ,,Y7. *8)*& %!EE  
8
?
?$$&   B(//0BC/22/ 
	&	& 


	0

 
 
"	# 4 
 B=>qAABs   #B >C <CC('C(c                    [         R                  " 5       R                  SXUS9nUR                  UR                  UR
                  4$ )Makes an http POST request.POST)dataheaders)r   
GetSessionrequeststatus_coderB   content)urlrB   bodyresponses       r    _DoHttpPostrJ   f   sH      "**cg + ( 
		x//1A1A	AAr"   c              #     #    [         R                  " 5       R                  SXUSS9 nUR                  5        H  nUv   M	     SSS5        g! , (       d  f       g= f7f)r?   r@   T)rA   rB   streamN)r   rC   rD   
iter_lines)rG   rB   rH   resplines        r    _DoStreamHttpPostrP   n   sR     $$cgd % !j "  s   &AA	A
AAc                    U R                  U5      n[        R                  " U5      nUSL=(       a#    SU;   =(       a    SUS   ;   =(       a    US   S   $ )z2GDC GGS model is only supported for GDC endpoints.N	gdcConfigzone)r/   r   r4   )selfendpoint_refendpointendpoint_resources       r    _CheckIsGdcGgsModelrX   w   sc    XXl#(//9t# 1
*
*1
%k2
21 K
(
0	r"   c                  T   \ rS rSrSrSS jr      SS jr        SS jrS rS r	SS	 jr
       S S
 jr       S S jrS rS rS rS rS rS rS rS rS rS r                S!S jr                S!SSSSSS. S"S jjjrS#S jr S#S jrSrg)$EndpointsClient   z8High-level client for the AI Platform endpoints surface.Nc                    U=(       d6    [         R                  " [        R                  [        R                  U   5      U l        U=(       d    U R
                  R                  U l        g r$   )r   GetClientInstancer   AI_PLATFORM_API_NAMEAI_PLATFORM_API_VERSIONr
   MESSAGES_MODULEmessages)rT   r
   ra   versions       r    __init__EndpointsClient.__init__   sJ     D22&&))'2DK ; ; ;DMr"   c
                   Sn
U(       a  U R                   R                  US9n
[        R                  " S[        R
                  5      " UUUUU
S9nUb`  [        R                  " S[        R
                  5      " SU	(       a  U	OS[        R                  " S[        R
                  5      " US	9S
9Ul        U R                   R                  UR                  5       UUS9nU R                  R                  R                  U5      $ )a0  Creates a new endpoint using v1 API.

Args:
  location_ref: Resource, the parsed location to create an endpoint.
  display_name: str, the display name of the new endpoint.
  labels: list, the labels to organize the new endpoint.
  description: str or None, the description of the new endpoint.
  network: str, the full name of the Google Compute Engine network.
  endpoint_id: str or None, the id of the new endpoint.
  encryption_kms_key_name: str or None, the Cloud KMS resource identifier of
    the customer managed encryption key used to protect a resource.
  request_response_logging_table: str or None, the BigQuery table uri for
    request-response logging.
  request_response_logging_rate: float or None, the sampling rate for
    request-response logging.

Returns:
  A long-running operation for Create.
N
kmsKeyNameEndpoint)displayNamedescriptionlabelsnetworkencryptionSpec#PredictRequestResponseLoggingConfigT        BigQueryDestination	outputUrienabledsamplingRatebigqueryDestination)parent
endpointIdgoogleCloudAiplatformV1Endpoint)ra   %GoogleCloudAiplatformV1EncryptionSpecapi_util
GetMessager   
GA_VERSION#predictRequestResponseLoggingConfig1AiplatformProjectsLocationsEndpointsCreateRequestr3   r
   projects_locations_endpointsCreate)rT   location_refdisplay_namerk   rj   rl   endpoint_idencryption_kms_key_namerequest_response_logging_tablerequest_response_logging_rateencryption_specrV   reqs                r    r   EndpointsClient.Create   s    > OKK, L o "":y/C/CD &H &15=5H5H
/1E1E6 * 5&11#Y%9%946
6h2 --
I
I((*(0 J C
 ;;33::3??r"   c           
        SnU(       a  U R                   R                  US9nSnU(       a  U R                   R                  US9nSnU	(       a  U R                   R                  U	S9n[        R
                  " S[        R                  5      " UUUUUUUS9nU
b`  [        R
                  " S[        R                  5      " SU(       a  UOS[        R
                  " S	[        R                  5      " U
S
9S9Ul        U R                   R                  UR                  5       UUS9nU R                  R                  R                  U5      $ )a  Creates a new endpoint using v1beta1 API.

Args:
  location_ref: Resource, the parsed location to create an endpoint.
  display_name: str, the display name of the new endpoint.
  labels: list, the labels to organize the new endpoint.
  description: str or None, the description of the new endpoint.
  network: str, the full name of the Google Compute Engine network.
  endpoint_id: str or None, the id of the new endpoint.
  encryption_kms_key_name: str or None, the Cloud KMS resource identifier of
    the customer managed encryption key used to protect a resource.
  gdce_zone: str or None, the name of the GDCE zone.
  gdc_zone: str or None, the name of the GDC zone.
  request_response_logging_table: str or None, the BigQuery table uri for
    request-response logging.
  request_response_logging_rate: float or None, the sampling rate for
    request-response logging.

Returns:
  A long-running operation for Create.
Nrf   )rS   rh   )ri   rj   rk   rl   rm   
gdceConfigrR   rn   Tro   rp   rq   rs   )rw   rx   $googleCloudAiplatformV1beta1Endpoint)ra   *GoogleCloudAiplatformV1beta1EncryptionSpec&GoogleCloudAiplatformV1beta1GdceConfig%GoogleCloudAiplatformV1beta1GdcConfigr{   r|   r   BETA_VERSIONr~   r   r3   r
   r   r   )rT   r   r   rk   rj   rl   r   r   	gdce_zonegdc_zoner   r   r   gdce_config
gdc_configrV   r   s                    r    
CreateBetaEndpointsClient.CreateBeta   sV   F O
--
B
B0 C   KMMHH I k J==FF G j "":y/E/EF &H &15=5H5H
/1G1G6 * 5&11#Y%;%;46
6h2 --
I
I((*-5 J C
 ;;33::3??r"   c                    U R                   R                  UR                  5       S9nU R                  R                  R                  U5      $ )zDeletes an existing endpoint.name)ra   1AiplatformProjectsLocationsEndpointsDeleteRequestr3   r
   r   DeleterT   rU   r   s      r    r   EndpointsClient.Delete  sE    
--
I
I&&( J C ;;33::3??r"   c                    U R                   R                  UR                  5       S9nU R                  R                  R                  U5      $ )zGets details about an endpoint.r   )ra   .AiplatformProjectsLocationsEndpointsGetRequestr3   r
   r   r/   r   s      r    r/   EndpointsClient.Get&  sE    
--
F
F&&( G C ;;3377<<r"   c                    U R                   R                  UR                  5       UUS9n[        R                  " U R
                  R                  USSS9$ )zLists endpoints in the project.)rw   filtergdcZone	endpointspageSize)fieldbatch_size_attribute)ra   /AiplatformProjectsLocationsEndpointsListRequestr3   r   YieldFromListr
   r   )rT   r   
filter_strr   r   s        r    ListEndpointsClient.List-  sY    
--
G
G((* H C
 ##00'	 r"   c
                2   [         R                  " S[        R                  5      " 5       n
/ nUR                  (       a"  UR
                  U
l        UR                  S5        Ub  X:l        UR                  S5        Ubu  / n[        UR                  5       5       H1  u  pUR                  U
R                  5       R                  XS95        M3     U
R                  US9U
l        UR                  S5        U(       a  SU
l        UR                  S5        Ub  XJl        UR                  S5        Uc  Ub  U R                  U5      R                  nU(       d*  [         R                  " S	[        R                  5      " 5       nS
Ul        Ub.  [         R                  " S[        R                  5      " US9Ul        Ub  UUl        UU
l        UR                  S5        U	(       aA  U R                  U5      R                  nU(       a  SUl        UU
l        UR                  S5        U(       d  [&        R(                  " S5      eU R*                  R-                  UR/                  5       U
SR1                  U5      S9nU R2                  R4                  R7                  U5      $ )a  Updates an endpoint using v1 API.

Args:
  endpoint_ref: Resource, the parsed endpoint to be updated.
  labels_update: UpdateResult, the result of applying the label diff
    constructed from args.
  display_name: str or None, the new display name of the endpoint.
  description: str or None, the new description of the endpoint.
  traffic_split: dict or None, the new traffic split of the endpoint.
  clear_traffic_split: bool, whether or not clear traffic split of the
    endpoint.
  request_response_logging_table: str or None, the BigQuery table uri for
    request-response logging.
  request_response_logging_rate: float or None, the sampling rate for
    request-response logging.
  disable_request_response_logging: bool, whether or not disable
    request-response logging of the endpoint.

Returns:
  The response message of Patch.

Raises:
  NoFieldsSpecifiedError: An error if no updates requested.
rh   rk   Nr   keyvalueadditionalPropertiestraffic_splitrj   rn   Trp   rq   'predict_request_response_logging_configFNo updates requested.,)r   ry   
updateMask)r{   r|   r   r}   needs_updaterk   appendri   sorteditemsTrafficSplitValueAdditionalPropertytrafficSplitrj   r/   r~   rt   rv   ru   r   NoFieldsSpecifiedErrorra   0AiplatformProjectsLocationsEndpointsPatchRequestr3   joinr
   r   PatchrT   rU   labels_updater   rj   r   clear_traffic_splitr   r    disable_request_response_loggingrV   update_maskadditional_propertiesr   r   request_response_logging_configr   s                    r    r   EndpointsClient.Patch;  s{   H "":y/C/CDFHK!!%,,ho")(  }2245*#$$&&(;; < 	
 6 '884 9 h )"h)(' 	'2(4(,
)++ & -*2*=*=193G3G+
 +' 15%-	'	3 5y7K7KL8 	(;
 
'	2) 	(4 * 2 BC'(,
)++ & 
)27'/
) 2 BC))*ABB
--
H
H&&((088K( I C
 ;;3399#>>r"   c
                   U R                   R                  5       n
/ nUR                  (       a"  UR                  U
l        UR	                  S5        Ub  X:l        UR	                  S5        Ubu  / n[        UR                  5       5       H1  u  pUR	                  U
R                  5       R                  XS95        M3     U
R                  US9U
l
        UR	                  S5        U(       a  SU
l
        UR	                  S5        Ub  XJl        UR	                  S5        Uc  Ub  U R                  U5      R                  nU(       d*  [        R                  " S[         R"                  5      " 5       nS	Ul        Ub.  [        R                  " S
[         R"                  5      " US9Ul        Ub  UUl        UU
l        UR	                  S5        U	(       aA  U R                  U5      R                  nU(       a  SUl        UU
l        UR	                  S5        U(       d  [*        R,                  " S5      eU R                   R/                  UR1                  5       U
SR3                  U5      S9nU R4                  R6                  R9                  U5      $ )a  Updates an endpoint using v1beta1 API.

Args:
  endpoint_ref: Resource, the parsed endpoint to be updated.
  labels_update: UpdateResult, the result of applying the label diff
    constructed from args.
  display_name: str or None, the new display name of the endpoint.
  description: str or None, the new description of the endpoint.
  traffic_split: dict or None, the new traffic split of the endpoint.
  clear_traffic_split: bool, whether or not clear traffic split of the
    endpoint.
  request_response_logging_table: str or None, the BigQuery table uri for
    request-response logging.
  request_response_logging_rate: float or None, the sampling rate for
    request-response logging.
  disable_request_response_logging: bool, whether or not disable
    request-response logging of the endpoint.

Returns:
  The response message of Patch.

Raises:
  NoFieldsSpecifiedError: An error if no updates requested.
rk   Nr   r   r   r   rj   rn   Trp   rq   r   Fr   r   )r   r   r   )ra   $GoogleCloudAiplatformV1beta1Endpointr   rk   r   ri   r   r   r   r   r   rj   r/   r~   r{   r|   r   r   rt   rv   ru   r   r   r   r3   r   r
   r   r   r   s                    r    	PatchBetaEndpointsClient.PatchBeta  sr   H }}AACHK!!%,,ho")(  }2245*#$$&&(;; < 	
 6 '884 9 h )"h)(' 	'2(4(,
)++ & -*2*=*=193I3I+
 +' 15%-	'	3 5y7M7MN8 	(;
 
'	2) 	(4 * 2 BC'(,
)++ & 
)27'/
) 2 BC))*ABB
--
H
H&&(-588K( I C
 ;;3399#>>r"   c                j   U R                   R                  [        [        R                  US   5      S9nSU;   a-  [
        R                  " [        R                  US   5      Ul        U R                   R                  UR                  5       US9nU R                  R                  R                  U5      $ )z<Sends online prediction request to an endpoint using v1 API.	instancesr   
parameters)rV   %googleCloudAiplatformV1PredictRequest)ra   %GoogleCloudAiplatformV1PredictRequestr)   r   	JsonValuer   r%   r   2AiplatformProjectsLocationsEndpointsPredictRequestr3   r
   r   PredictrT   rU   instances_jsonpredict_requestr   s        r    r   EndpointsClient.Predict#  s    mmII-!!>+#>
 J O
 ~%#+#<#<


!=$o  --
J
J**,.= K C ;;33;;C@@r"   c                j   U R                   R                  [        [        R                  US   5      S9nSU;   a-  [
        R                  " [        R                  US   5      Ul        U R                   R                  UR                  5       US9nU R                  R                  R                  U5      $ )zASends online prediction request to an endpoint using v1beta1 API.r   r   r   )rV   *googleCloudAiplatformV1beta1PredictRequest)ra   *GoogleCloudAiplatformV1beta1PredictRequestr)   r   r   r   r%   r   r   r3   r
   r   r   r   s        r    PredictBetaEndpointsClient.PredictBeta5  s    mmNN-!!>+#>
 O O
 ~%#+#<#<


!=$o  --
J
J**,3B K C ;;33;;C@@r"   c                .   SR                  U R                  R                  [        U R                  S5      UR	                  5       5      n[        XBU5      u  pVnU[        R                  :w  a'  [        R                  " SUR                  5       -   5      eXg4$ )3Sends online raw prediction request to an endpoint.z{}{}/{}:rawPredict_VERSIONzHTTP request failed. Response:
)r5   r
   rG   getattrr3   rJ   r   OKcore_exceptionsErrordecode)rT   rU   rB   rD   rG   statusresponse_headersrI   s           r    
RawPredictEndpointsClient.RawPredictG  s    

%
%Z(!!#C *5S7)K&Fh!!
,x/@
@  %%r"   c              #     #    SR                  U R                  R                  [        U R                  S5      UR	                  5       5      n[        XBU5       H  nUv   M	     g7f)r   z{}{}/{}:streamRawPredictr   N)r5   r
   rG   r   r3   rP   )rT   rU   rB   rD   rG   rN   s         r    StreamRawPredict EndpointsClient.StreamRawPredictW  sR     
$
+
+Z(!!#C "#8j 9s   A"A$c                   U R                   R                  [        U R                   R                  US   5      S9nSU;   a3  [        R
                  " U R                   R                  US   5      Ul        U R                   R                  UR                  5       US9nU R                  R                  R                  U5      $ )zCSends online direct prediction request to an endpoint using v1 API.inputsr   r   )rV   +googleCloudAiplatformV1DirectPredictRequest)ra   +GoogleCloudAiplatformV1DirectPredictRequestr)   GoogleCloudAiplatformV1Tensorr   r%   r   8AiplatformProjectsLocationsEndpointsDirectPredictRequestr3   r
   r   DirectPredictrT   rU   inputs_jsondirect_predict_requestr   s        r    r   EndpointsClient.DirectPredictb  s     	AA.;;H% 	B 	
  {"*2*C*C
--
5
5{<7P+'
 	NN!..08N 	O 	
  ;;33AA#FFr"   c                   U R                   R                  [        U R                   R                  US   5      S9nSU;   a3  [        R
                  " U R                   R                  US   5      Ul        U R                   R                  UR                  5       US9nU R                  R                  R                  U5      $ )zHSends online direct prediction request to an endpoint using v1beta1 API.r   r   r   )rV   0googleCloudAiplatformV1beta1DirectPredictRequest)ra   0GoogleCloudAiplatformV1beta1DirectPredictRequestr)   "GoogleCloudAiplatformV1beta1Tensorr   r%   r   r   r3   r
   r   r   r   s        r    DirectPredictBeta!EndpointsClient.DirectPredictBetay  s     	FF.@@H% 	G 	
  {"*2*C*C
--
:
:
l
#+'
 --
P
P**,9O Q C ;;33AA#FFr"   c           	     (   U R                   R                  [        US   S5      UR                  SUR                  S5      5      S9nU R                   R	                  UR                  5       US9nU R                  R                  R                  U5      $ )zGSends online direct raw prediction request to an endpoint using v1 API.inpututf-8
methodNamemethod_namer  r  )rV   .googleCloudAiplatformV1DirectRawPredictRequest)	ra   .GoogleCloudAiplatformV1DirectRawPredictRequestbytesget;AiplatformProjectsLocationsEndpointsDirectRawPredictRequestr3   r
   r   DirectRawPredictrT   rU   
input_jsondirect_raw_predict_requestr   s        r    r   EndpointsClient.DirectRawPredict  s    !%!]!]Jw'1>>,
}0MN "^ " --
S
S**,7Q T C ;;33DDSIIr"   c           	     (   U R                   R                  [        US   S5      UR                  SUR                  S5      5      S9nU R                   R	                  UR                  5       US9nU R                  R                  R                  U5      $ )zLSends online direct raw prediction request to an endpoint using v1beta1 API.r  r  r  r  r  )rV   3googleCloudAiplatformV1beta1DirectRawPredictRequest)	ra   3GoogleCloudAiplatformV1beta1DirectRawPredictRequestr  r  r  r3   r
   r   r  r  s        r    DirectRawPredictBeta$EndpointsClient.DirectRawPredictBeta  s    !%!b!bJw'1>>,
}0MN "c " --
S
S**,<V T C ;;33DDSIIr"   c                   U R                   R                  [        [        R                  US   5      S9nSU;   a-  [
        R                  " [        R                  US   5      Ul        UR                  b  UR                  Ul	        U R                   R                  UR                  5       US9nU R                  R                  R                  U5      $ )BSends online explanation request to an endpoint using v1beta1 API.r   r   r   )rV   %googleCloudAiplatformV1ExplainRequest)ra   %GoogleCloudAiplatformV1ExplainRequestr)   r   r   r   r%   r   deployed_model_iddeployedModelId2AiplatformProjectsLocationsEndpointsExplainRequestr3   r
   r   ExplainrT   rU   r   argsexplain_requestr   s         r    r  EndpointsClient.Explain  s    mmII-!!>+#>
 J O
 ~%#+#<#<


!=$o  )(,(>(>o%
--
J
J**,.= K C ;;33;;C@@r"   c                   U R                   R                  [        [        R                  US   5      S9nSU;   a-  [
        R                  " [        R                  US   5      Ul        SU;   a3  [
        R                  " U R                   R                  US   5      Ul	        UR                  b  UR                  Ul        U R                   R                  UR                  5       US9nU R                  R                  R!                  U5      $ )r  r   r   r   explanation_spec_override)rV   *googleCloudAiplatformV1beta1ExplainRequest)ra   *GoogleCloudAiplatformV1beta1ExplainRequestr)   r   r   r   r%   r   3GoogleCloudAiplatformV1beta1ExplanationSpecOverrideexplanationSpecOverrider  r  r  r3   r
   r   r  r   s         r    ExplainBetaEndpointsClient.ExplainBeta  s    mmNN-!!>+#>
 O O
 ~%#+#<#<


!=$o  #n4080I0I
--
K
K
4
51o- )(,(>(>o%
--
J
J**,3B K C ;;33;;C@@r"   c                   [        X#5      n[        UU R                  5      nUS:X  Ga  U R                  R	                  5       nUb  UUl        Ub  UUl        Ub  UUl        [        R                  " U[        R                  5      nUb"  UR                  Ul        UR                  Ul        Ub*  [        R                  " U[        R                  5      Ul        Ub  UUl        U R                  R#                  UUS9nU	=(       d    SUl        U
b  U
Ul        Ub  UUl        Ubf  / n[+        UR-                  5       5       H@  u  nnUR/                  U R                  R1                  [        R2                  U   US95        MB     UUl        U R                  R7                  UUUR9                  5       S9nOWU R                  R;                  5       nU	b  U	Ul        U
b  U
Ul        U R                  R7                  UUUR9                  5       S9nUUl        UUl        Ub  UUl         Ub  UUl!        U R                  RE                  US9nUbf  / n [+        UR-                  5       5       H3  u  n!n"U R/                  URG                  5       RI                  U!U"S95        M5     URG                  U S	9Ul%        U R                  RM                  UR9                  5       US
9n#U R                  RN                  RQ                  U#5      $ )au  Deploys a model to an existing endpoint using v1 API.

Args:
  endpoint_ref: Resource, the parsed endpoint that the model is deployed to.
  model: str, Id of the uploaded model to be deployed.
  region: str, the location of the endpoint and the model.
  display_name: str, the display name of the new deployed model.
  machine_type: str or None, the type of the machine to serve the model.
  tpu_topology: str or None, the topology of the TPU to serve the model.
  multihost_gpu_node_count: int or None, the number of nodes per replica for
    multihost GPU deployments.
  accelerator_dict: dict or None, the accelerator attached to the deployed
    model from args.
  min_replica_count: int or None, the minimum number of replicas the
    deployed model will be always deployed on.
  max_replica_count: int or None, the maximum number of replicas the
    deployed model may be deployed on.
  required_replica_count: int or None, the required number of replicas the
    deployed model will be considered successfully deployed.
  reservation_affinity: dict or None, the reservation affinity of the
    deployed model which specifies which reservations the deployed model can
    use.
  autoscaling_metric_specs: dict or None, the metric specification that
    defines the target resource utilization for calculating the desired
    replica count.
  spot: bool, whether or not deploy the model on spot resources.
  enable_access_logging: bool, whether or not enable access logs.
  disable_container_logging: bool, whether or not disable container logging.
  service_account: str or None, the service account that the deployed model
    runs as.
  traffic_split: dict or None, the new traffic split of the endpoint.
  deployed_model_id: str or None, id of the deployed model.
  gpu_partition_size: str or None, the partition size of the GPU
    accelerator.

Returns:
  A long-running operation for DeployModel.
DEDICATED_RESOURCESmachineSpecspot   
metricNametargetdedicatedResourcesri   modelautomaticResourcesri   r7  deployedModelr   r   )rV   )googleCloudAiplatformV1DeployModelRequest))r!   r=   r
   ra   "GoogleCloudAiplatformV1MachineSpecmachineTypetpuTopologymultihostGpuNodeCountr   ParseAcceleratorFlagr   r}   acceleratorTypeacceleratorCountParseReservationAffinityFlagreservationAffinitygpuPartitionSize)GoogleCloudAiplatformV1DedicatedResourcesminReplicaCountmaxReplicaCountrequiredReplicaCountr   r   r   ,GoogleCloudAiplatformV1AutoscalingMetricSpec!OP_AUTOSCALING_METRIC_NAME_MAPPERautoscalingMetricSpecs$GoogleCloudAiplatformV1DeployedModelr3   )GoogleCloudAiplatformV1AutomaticResourcesenableAccessLoggingdisableContainerLoggingserviceAccountid)GoogleCloudAiplatformV1DeployModelRequestr   r   r   6AiplatformProjectsLocationsEndpointsDeployModelRequestr   DeployModel)$rT   rU   r7  regionr   machine_typetpu_topologymultihost_gpu_node_countaccelerator_dictmin_replica_countmax_replica_countrequired_replica_countreservation_affinityautoscaling_metric_specsr0  enable_access_loggingdisable_container_loggingservice_accountr   r  gpu_partition_sizer8   resource_typemachine_specaccelerator	dedicatedautoscaling_metric_specs_listr   r4  deployed_model	automaticdeployed_model_reqr   r   r   r   s$                                       r    rV  EndpointsClient.DeployModel  s&   z E*I3It{{KM--]]EEGl		!#/ 		!#/ 	!	--E*..
I00k 
	 '2'B'B$(3(D(D%		)+0+M+M )"6"6,
( 
	'(:%--II" J i
 #4"8qi		&$5	!		+)?	&	!	-(*%"#;#A#A#CDLD&
'
.
.mmHH&HHN I  E ,I	(}}II&"&&( J n --IIKi		&$5	!		&$5	!}}II&"&&( J n *?N&-FN*"&5n#$+n 	??( 	@ 	
    }2245*#u$$002EEu F 	
 6 );(L(L4 )M )% --
N
N**,2D O C ;;33??DDr"   )min_scaleup_periodidle_scaledown_periodinitial_replica_countrd  min_gpu_driver_versionc                  [        X5      nU(       a{  U R                  R                  SU R                  R                  R                  R                  SS9nU R                  R                  USSS9nU R                  R                  UUUS9nGO[        X#5      n[        UU R                  U5      nUS:X  Ga0  U R                  R                  5       nUb  UUl
        Ub  UUl        Ub  UUl        [        R                  " U[        R                   5      n U b"  U R"                  Ul        U R$                  Ul        Ub*  [        R&                  " U[        R                   5      Ul        Ub  UUl        Ub  UUl        U R                  R                  UUS9nU	c  SOU	Ul        U
c  UR.                  S:X  a  SUl        O
U
b  U
Ul        Ub  UUl        Uc  UR.                  S:X  a  SUl        O
Ub  UUl        Ubf  / n![7        UR9                  5       5       H@  u  n"n#U!R;                  U R                  R=                  [        R>                  U"   U#S	95        MB     U!Ul         U R                  RC                  5       n$S
n%Ub  SRE                  U5      U$l#        Sn%Ub  SRE                  U5      U$l$        Sn%U%(       a  U$Ul%        U R                  R                  UUURM                  5       S9nOUS:X  aX  U R                  RO                  5       n&U	b  U	U&l        U
b  U
U&l        U R                  R                  U&UURM                  5       S9nO7U R                  R                  UURM                  5       URM                  5       S9nUUl(        UUl)        Ub  UUl*        Ub  UUl+        U R                  RY                  US9n'Ubf  / n([7        UR9                  5       5       H3  u  n)n*U(R;                  U'R[                  5       R]                  U)U*S95        M5     U'R[                  U(S9U'l/        U R                  Ra                  URM                  5       U'S9n+U R                  Rb                  Re                  U+5      $ )a
  Deploys a model to an existing endpoint using v1beta1 API.

Args:
  endpoint_ref: Resource, the parsed endpoint that the model is deployed to.
  model: str, Id of the uploaded model to be deployed.
  region: str, the location of the endpoint and the model.
  display_name: str, the display name of the new deployed model.
  machine_type: str or None, the type of the machine to serve the model.
  tpu_topology: str or None, the topology of the TPU to serve the model.
  multihost_gpu_node_count: int or None, the number of nodes per replica for
    multihost GPU deployments.
  accelerator_dict: dict or None, the accelerator attached to the deployed
    model from args.
  min_replica_count: int or None, the minimum number of replicas the
    deployed model will be always deployed on.
  max_replica_count: int or None, the maximum number of replicas the
    deployed model may be deployed on.
  required_replica_count: int or None, the required number of replicas the
    deployed model will be considered successfully deployed.
  reservation_affinity: dict or None, the reservation affinity of the
    deployed model which specifies which reservations the deployed model can
    use.
  autoscaling_metric_specs: dict or None, the metric specification that
    defines the target resource utilization for calculating the desired
    replica count.
  spot: bool, whether or not deploy the model on spot resources.
  enable_access_logging: bool, whether or not enable access logs.
  enable_container_logging: bool, whether or not enable container logging.
  service_account: str or None, the service account that the deployed model
    runs as.
  traffic_split: dict or None, the new traffic split of the endpoint.
  deployed_model_id: str or None, id of the deployed model.
  shared_resources_ref: str or None, the shared deployment resource pool the
    model should use
  min_scaleup_period: str or None, the minimum duration (in seconds) that a
    deployment will be scaled up before traffic is evaluated for potential
    scale-down. Defaults to 1 hour if min replica count is 0.
  idle_scaledown_period: str or None, the duration after which the
    deployment is scaled down if no traffic is received. This only applies
    to deployments enrolled in scale-to-zero.
  initial_replica_count: int or None, the initial number of replicas the
    deployment will be scaled up to. This only applies to deployments
    enrolled in scale-to-zero.
  gpu_partition_size: str or None, the partition size of the GPU
    accelerator.
  min_gpu_driver_version: str or None, the minimum GPU driver version that
    this machine requires.

Returns:
  A long-running operation for DeployModel.
zn1-standard-2r1  )r>  rB  rC  )r/  rH  rI  )r6  ri   gdcConnectedModelr-  r.  r   r2  Fz{}sTr5  AUTOMATIC_RESOURCESr8  )ri   r7  sharedResourcesr:  r   r   )rV   .googleCloudAiplatformV1beta1DeployModelRequest)3rX   ra   'GoogleCloudAiplatformV1beta1MachineSpecAcceleratorTypeValueValuesEnumNVIDIA_TESLA_T4.GoogleCloudAiplatformV1beta1DedicatedResources)GoogleCloudAiplatformV1beta1DeployedModelr!   r=   r
   r>  r?  r@  r   rA  r   r   rB  rC  rD  rE  rF  minGpuDriverVersionrH  rI  rJ  initialReplicaCountr   r   r   1GoogleCloudAiplatformV1beta1AutoscalingMetricSpecrL  rM  =GoogleCloudAiplatformV1beta1DedicatedResourcesScaleToZeroSpecr5   minScaleupPeriodidleScaledownPeriodscaleToZeroSpecr3   .GoogleCloudAiplatformV1beta1AutomaticResourcesrP  enableContainerLoggingrR  rS  .GoogleCloudAiplatformV1beta1DeployModelRequestr   r   r   rU  r   rV  ),rT   rU   r7  rW  r   rX  rY  rZ  r[  r\  r]  r^  r_  r`  r0  ra  enable_container_loggingrc  r   r  r9   rn  ro  rp  rd  rq  is_gdc_ggs_modelrf  rh  rj  r8   re  rg  ri  r   r4  stz_specstz_spec_modifiedrk  rl  r   r   r   r   s,                                               r    DeployModelBetaEndpointsClient.DeployModelBetax  s   ` +4>]]JJ%--OOnn~~ K l
 --NN"Aq O i }}NN&"! O n e,i5
T[["6m 
/	/}}LLN#%1,
"#%1,
"#//G,
,00i44
 ")4)D)D,
&*5*F*F,
'+-2-O-O"I$:$:.,
* )*<,
'!--C,
* MMHH(t I  	 #*A0A 	!
 $)B)Ba)G&')
#*(9I%!-+A)
( !(Y-F-F!-K*+)
'".,AI)#/*,
'$%=%C%C%EFldF)00OO(JJ  "	 P  G .K)
* MMWWY 	 ")&+ll3E&F(
#"
 ,).6K)L(
&"
&.)
# MMCC#,(,,. D  	 11 MMHHJ 	 (&7)
#(&7)
# MMCC#,(,,. D  	 MMCC(,,. 4 A A C D  	 *?N&,DN)"&5n#$+n 	DD( 	E 	
    }2245*#u$$002EEu F 	
 6 );(L(L4 )M )% --
N
N**,7I O C ;;33??DDr"   c                   U R                   R                  US9nUbd  / n[        UR                  5       5       H1  u  pgUR	                  UR                  5       R                  XgS95        M3     UR                  US9Ul        U R                   R                  UR                  5       US9nU R                  R                  R                  U5      $ )aP  Undeploys a model from an endpoint using v1 API.

Args:
  endpoint_ref: Resource, the parsed endpoint that the model is undeployed
    from.
  deployed_model_id: str, Id of the deployed model to be undeployed.
  traffic_split: dict or None, the new traffic split of the endpoint.

Returns:
  A long-running operation for UndeployModel.
r  r   r   )rV   +googleCloudAiplatformV1UndeployModelRequest)ra   +GoogleCloudAiplatformV1UndeployModelRequestr   r   r   r   r   r   8AiplatformProjectsLocationsEndpointsUndeployModelRequestr3   r
   r   UndeployModel	rT   rU   r  r   undeployed_model_reqr   r   r   r   s	            r    r  EndpointsClient.UndeployModelo  s     	AA- 	B 	
    }2245*#$$ 224GG H 	
 6 
0
0#8 1  ' 	NN!..08L 	O 	
  ;;33AA#FFr"   c                   U R                   R                  US9nUbd  / n[        UR                  5       5       H1  u  pgUR	                  UR                  5       R                  XgS95        M3     UR                  US9Ul        U R                   R                  UR                  5       US9nU R                  R                  R                  U5      $ )aU  Undeploys a model from an endpoint using v1beta1 API.

Args:
  endpoint_ref: Resource, the parsed endpoint that the model is undeployed
    from.
  deployed_model_id: str, Id of the deployed model to be undeployed.
  traffic_split: dict or None, the new traffic split of the endpoint.

Returns:
  A long-running operation for UndeployModel.
r  r   r   )rV   0googleCloudAiplatformV1beta1UndeployModelRequest)ra   0GoogleCloudAiplatformV1beta1UndeployModelRequestr   r   r   r   r   r   r  r3   r
   r   r  r  s	            r    UndeployModelBeta!EndpointsClient.UndeployModelBeta  s     	FF- 	G 	
    }2245*#$$ 224GG H 	
 6 
0
0#8 1  ' --
P
P**,9M Q C ;;33AA#FFr"   )r
   ra   )NNN)NNNNNN)NNNNNNNN)NN)NNNFNNF)NNNNNNNNNFFFNNNN)rq  z
str | Noner$   )__name__
__module____qualname____firstlineno____doc__rc   r   r   r   r/   r   r   r   r   r   r   r   r   r  r  r  r  r*  rV  r  r  r  __static_attributes__ r"   r    rZ   rZ      sx   @< "%)$(=@H "%)$(Q@f@=$ %)$(',r?p %)$(',r?hA$A$& 	G.G,JJA(A> #!#! %+^EL #!#!$+uE.   +/7uE6 )7uEn&GR <@&Gr"   rZ   r$   )%r  
__future__r   apitools.base.pyr   r   r0   r   r   googlecloudsdk.api_lib.air   r{    googlecloudsdk.api_lib.ai.modelsr
   r-   googlecloudsdk.api_lib.utilr   googlecloudsdk.command_lib.air   r   r   googlecloudsdk.corer   r   r   googlecloudsdk.core.credentialsr   	six.movesr   r!   r)   r=   rJ   rP   rX   objectrZ   r  r"   r    <module>r     sq    < " % > ( ' 6 C , 3 0 / = * ) 4 !	F
 -1/BdB	zGf zGr"   