
                             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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.    )absolute_import)division)unicode_literals)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+   2   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?   6   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_coderD   content)urlrD   bodyresponses       r"   _DoHttpPostrL   h   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)rA   rB   T)rC   rD   streamN)r   rE   rF   
iter_lines)rI   rD   rJ   resplines        r"   _DoStreamHttpPostrR   p   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)r1   r   r6   )selfendpoint_refendpointendpoint_resources       r"   _CheckIsGdcGgsModelrZ   y   sc    XXl#(//9t# 1
*
*1
%k2
21 K
(
0	r$   c                   D   \ 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 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)rV   r   rc   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)rc   %GoogleCloudAiplatformV1EncryptionSpecapi_util
GetMessager   
GA_VERSION#predictRequestResponseLoggingConfig1AiplatformProjectsLocationsEndpointsCreateRequestr5   r   projects_locations_endpointsCreate)rV   location_refdisplay_namerm   rl   rn   endpoint_idencryption_kms_key_namerequest_response_logging_tablerequest_response_logging_rateencryption_specrX   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.
Nrh   )rU   rj   )rk   rl   rm   rn   ro   
gdceConfigrT   rp   Trq   rr   rs   ru   )ry   rz   $googleCloudAiplatformV1beta1Endpoint)rc   *GoogleCloudAiplatformV1beta1EncryptionSpec&GoogleCloudAiplatformV1beta1GdceConfig%GoogleCloudAiplatformV1beta1GdcConfigr}   r~   r   BETA_VERSIONr   r   r5   r   r   r   )rV   r   r   rm   rl   rn   r   r   	gdce_zonegdc_zoner   r   r   gdce_config
gdc_configrX   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)rc   1AiplatformProjectsLocationsEndpointsDeleteRequestr5   r   r   DeleterV   rW   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   )rc   .AiplatformProjectsLocationsEndpointsGetRequestr5   r   r   r1   r   s      r"   r1   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.)ry   filtergdcZone	endpointspageSize)fieldbatch_size_attribute)rc   /AiplatformProjectsLocationsEndpointsListRequestr5   r	   YieldFromListr   r   )rV   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.
rj   rm   Nr   keyvalueadditionalPropertiestraffic_splitrl   rp   Trr   rs   'predict_request_response_logging_configFNo updates requested.,)r   r{   
updateMask)r}   r~   r   r   needs_updaterm   appendrk   sorteditemsTrafficSplitValueAdditionalPropertytrafficSplitrl   r1   r   rv   rx   rw   r   NoFieldsSpecifiedErrorrc   0AiplatformProjectsLocationsEndpointsPatchRequestr5   joinr   r   PatchrV   rW   labels_updater   rl   r   clear_traffic_splitr   r    disable_request_response_loggingrX   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.
rm   Nr   r   r   r   rl   rp   Trr   rs   r   Fr   r   )r   r   r   )rc   $GoogleCloudAiplatformV1beta1Endpointr   rm   r   rk   r   r   r   r   r   rl   r1   r   r}   r~   r   r   rv   rx   rw   r   r   r   r5   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)rX   %googleCloudAiplatformV1PredictRequest)rc   %GoogleCloudAiplatformV1PredictRequestr+   r   	JsonValuer   r'   r   2AiplatformProjectsLocationsEndpointsPredictRequestr5   r   r   PredictrV   rW   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   )rX   *googleCloudAiplatformV1beta1PredictRequest)rc   *GoogleCloudAiplatformV1beta1PredictRequestr+   r   r   r   r'   r   r   r5   r   r   r   r   s        r"   PredictBetaEndpointsClient.PredictBeta7  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:
)r7   r   rI   getattrr5   rL   r   OKcore_exceptionsErrordecode)rV   rW   rD   rF   rI   statusresponse_headersrK   s           r"   
RawPredictEndpointsClient.RawPredictI  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)r7   r   rI   r   r5   rR   )rV   rW   rD   rF   rI   rP   s         r"   StreamRawPredict EndpointsClient.StreamRawPredictY  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   )rX   +googleCloudAiplatformV1DirectPredictRequest)rc   +GoogleCloudAiplatformV1DirectPredictRequestr+   GoogleCloudAiplatformV1Tensorr   r'   r   8AiplatformProjectsLocationsEndpointsDirectPredictRequestr5   r   r   DirectPredictrV   rW   inputs_jsondirect_predict_requestr   s        r"   r   EndpointsClient.DirectPredictd  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   )rX   0googleCloudAiplatformV1beta1DirectPredictRequest)rc   0GoogleCloudAiplatformV1beta1DirectPredictRequestr+   "GoogleCloudAiplatformV1beta1Tensorr   r'   r   r   r5   r   r   r   r   s        r"   DirectPredictBeta!EndpointsClient.DirectPredictBeta{  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  )rX   .googleCloudAiplatformV1DirectRawPredictRequest)	rc   .GoogleCloudAiplatformV1DirectRawPredictRequestbytesget;AiplatformProjectsLocationsEndpointsDirectRawPredictRequestr5   r   r   DirectRawPredictrV   rW   
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
  )rX   3googleCloudAiplatformV1beta1DirectRawPredictRequest)	rc   3GoogleCloudAiplatformV1beta1DirectRawPredictRequestr  r  r  r5   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   )rX   %googleCloudAiplatformV1ExplainRequest)rc   %GoogleCloudAiplatformV1ExplainRequestr+   r   r   r   r'   r   deployed_model_iddeployedModelId2AiplatformProjectsLocationsEndpointsExplainRequestr5   r   r   ExplainrV   rW   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)rX   *googleCloudAiplatformV1beta1ExplainRequest)rc   *GoogleCloudAiplatformV1beta1ExplainRequestr+   r   r   r   r'   r   3GoogleCloudAiplatformV1beta1ExplanationSpecOverrideexplanationSpecOverrider  r  r   r5   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 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                  R/                  [        R0                  U   US95        MB     UUl        U R                  R5                  UUUR7                  5       S9nOWU R                  R9                  5       nU	b  U	Ul        U
b  U
Ul        U R                  R5                  UUUR7                  5       S9nUUl        UUl        Ub  UUl        Ub  UUl         U R                  RC                  US9nUbf  / n[)        UR+                  5       5       H3  u  n n!UR-                  URE                  5       RG                  U U!S95        M5     URE                  US	9Ul$        U R                  RK                  UR7                  5       US
9n"U R                  RL                  RO                  U"5      $ )a#  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.

Returns:
  A long-running operation for DeployModel.
DEDICATED_RESOURCESmachineSpecspot   
metricNametargetdedicatedResourcesrk   modelautomaticResourcesrk   r9  deployedModelr   r   )rX   )googleCloudAiplatformV1DeployModelRequest)(r#   r?   r   rc   "GoogleCloudAiplatformV1MachineSpecmachineTypetpuTopologymultihostGpuNodeCountr   ParseAcceleratorFlagr   r   acceleratorTypeacceleratorCountParseReservationAffinityFlagreservationAffinity)GoogleCloudAiplatformV1DedicatedResourcesminReplicaCountmaxReplicaCountrequiredReplicaCountr   r   r   ,GoogleCloudAiplatformV1AutoscalingMetricSpec!OP_AUTOSCALING_METRIC_NAME_MAPPERautoscalingMetricSpecs$GoogleCloudAiplatformV1DeployedModelr5   )GoogleCloudAiplatformV1AutomaticResourcesenableAccessLoggingdisableContainerLoggingserviceAccountid)GoogleCloudAiplatformV1DeployModelRequestr   r   r   6AiplatformProjectsLocationsEndpointsDeployModelRequestr   DeployModel)#rV   rW   r9  regionr   machine_typetpu_topologymultihost_gpu_node_countaccelerator_dictmin_replica_countmax_replica_countrequired_replica_countreservation_affinityautoscaling_metric_specsr2  enable_access_loggingdisable_container_loggingservice_accountr   r  r:   resource_typemachine_specaccelerator	dedicatedautoscaling_metric_specs_listr   r6  deployed_model	automaticdeployed_model_reqr   r   r   r   s#                                      r"   rW  EndpointsClient.DeployModel  s   t 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$   c                    [        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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	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 [5        UR7                  5       5       H@  u  n!n"U R9                  U R                  R;                  [        R<                  U!   U"S	95        MB     U Ul        U R                  RA                  5       n#S
n$Ub  SRC                  U5      U#l"        Sn$Ub  SRC                  U5      U#l#        Sn$U$(       a  U#Ul$        U R                  R                  UUURK                  5       S9nOUS:X  aX  U R                  RM                  5       n%U	b  U	U%l        U
b  U
U%l        U R                  R                  U%UURK                  5       S9nO7U R                  R                  UURK                  5       URK                  5       S9nUUl'        UUl(        Ub  UUl)        Ub  UUl*        U R                  RW                  US9n&Ubf  / n'[5        UR7                  5       5       H3  u  n(n)U'R9                  U&RY                  5       R[                  U(U)S95        M5     U&RY                  U'S9U&l.        U R                  R_                  URK                  5       U&S9n*U R                  R`                  Rc                  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.

Returns:
  A long-running operation for DeployModel.
zn1-standard-2r3  )r@  rD  rE  )r1  rI  rJ  )r8  rk   gdcConnectedModelr/  r0  r   r4  Fz{}sTr7  AUTOMATIC_RESOURCESr:  )rk   r9  sharedResourcesr<  r   r   )rX   .googleCloudAiplatformV1beta1DeployModelRequest)2rZ   rc   'GoogleCloudAiplatformV1beta1MachineSpecAcceleratorTypeValueValuesEnumNVIDIA_TESLA_T4.GoogleCloudAiplatformV1beta1DedicatedResources)GoogleCloudAiplatformV1beta1DeployedModelr#   r?   r   r@  rA  rB  r   rC  r   r   rD  rE  rF  rG  gpuPartitionSizerI  rJ  rK  initialReplicaCountr   r   r   1GoogleCloudAiplatformV1beta1AutoscalingMetricSpecrM  rN  =GoogleCloudAiplatformV1beta1DedicatedResourcesScaleToZeroSpecr7   minScaleupPeriodidleScaledownPeriodscaleToZeroSpecr5   .GoogleCloudAiplatformV1beta1AutomaticResourcesrQ  enableContainerLoggingrS  rT  .GoogleCloudAiplatformV1beta1DeployModelRequestr   r   r   rV  r   rW  )+rV   rW   r9  rX  r   rY  rZ  r[  r\  r]  r^  r_  r`  ra  r2  rb  enable_container_loggingrd  r   r  r;   min_scaleup_periodidle_scaledown_periodinitial_replica_countgpu_partition_sizeis_gdc_ggs_modelrf  rh  rj  r:   re  rg  ri  r   r6  stz_specstz_spec_modifiedrk  rl  r   r   r   r   s+                                              r"   DeployModelBetaEndpointsClient.DeployModelBetau  s   X +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$:$:.,
* )*<,
' 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   )rX   +googleCloudAiplatformV1UndeployModelRequest)rc   +GoogleCloudAiplatformV1UndeployModelRequestr   r   r   r   r   r   8AiplatformProjectsLocationsEndpointsUndeployModelRequestr5   r   r   UndeployModel	rV   rW   r  r   undeployed_model_reqr   r   r   r   s	            r"   r  EndpointsClient.UndeployModelf  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   )rX   0googleCloudAiplatformV1beta1UndeployModelRequest)rc   0GoogleCloudAiplatformV1beta1UndeployModelRequestr   r   r   r   r   r   r  r5   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   rc   )NNN)NNNNNN)NNNNNNNN)NN)NNNFNNF)NNNNNNNNNFFFNNN)NNNNNNNNNFFFNNNNNNNNr&   )__name__
__module____qualname____firstlineno____doc__re   r   r   r   r1   r   r   r   r   r   r   r   r   r  r  r  r!  r,  rW  r  r  r  __static_attributes__ r$   r"   r\   r\      s]   @< "%)$(=@H "%)$(Q@f@=$ %)$(',r?p %)$(',r?hA$A$& 	G.G,JJA(A> #!#! %)YEB #!#!$  3oEb&GR <@&Gr$   r\   r&   )'r  
__future__r   r   r   apitools.base.pyr   r   r2   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?   rL   rR   rZ   objectr\   r  r$   r"   <module>r     sw    < &  ' % > ( ' 6 C , 3 0 / = * ) 4 !	F
 -1/BdB	oGf oGr$   