
                          r    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  G d	 d
e      Zy)zEUtilities for dealing with AI Platform deployment resource pools API.    )absolute_import)division)unicode_literals)
list_pager)apis)	constants)flagsc                   L    e Zd ZdZd	dZ	 	 	 	 	 	 	 	 	 	 d
dZd Zd Zd Zd Z	y)DeploymentResourcePoolsClientzHHigh-level client for the AI Platform deployment resource pools surface.Nc                     |xs5 t        j                  t        j                  t        j                  |         | _        |xs | j
                  j                  | _        y )N)r   GetClientInstancer   AI_PLATFORM_API_NAMEAI_PLATFORM_API_VERSIONclientMESSAGES_MODULEmessages)selfr   r   versions       Alib/googlecloudsdk/api_lib/ai/deployment_resource_pools/client.py__init__z&DeploymentResourcePoolsClient.__init__   sJ     D22&&))'2DK ; ; ;DM    c                    | j                   j                         }|||_        |||_        |	|	|_        t        j                  |t        j                        }|"|j                  |_	        |j                  |_
        |
)t        j                  |
t        j                        |_        | j                   j                  ||      }|xs d|_        |||_        |||_        |gg }t#        |j%                               D ]B  \  }}|j'                  | j                   j)                  t        j*                  |   |             D ||_        | j                   j/                  |      }| j                   j1                  ||      }| j                   j3                  |j5                         |      }| j6                  j8                  j;                  |      }|S )a*  Creates a new deployment resource pool using v1beta1 API.

    Args:
      location_ref: Resource, the parsed location to create a deployment
        resource pool.
      deployment_resource_pool_id: str, The ID to use for the
        DeploymentResourcePool, which will become the final component of the
        DeploymentResourcePool's resource name.
      autoscaling_metric_specs: dict or None, the metric specification that
        defines the target resource utilization for calculating the desired
        replica count.
      accelerator_dict: dict or None, the accelerator attached to the deployment
        resource pool from args.
      min_replica_count: int or None, The minimum number of machine replicas
        this deployment resource pool will be always deployed on. This value
        must be greater than or equal to 1.
      max_replica_count: int or None, The maximum number of replicas this
        deployment resource pool may be deployed on when the traffic against it
        increases.
      machine_type: str or None, Immutable. The type of the machine.
      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.
      reservation_affinity: dict or None, the reservation affinity of the
        deployed model which specifies which reservations the deployed model can
        use.
      spot: bool, whether or not deploy the model on spot resources.
      required_replica_count: int or None, The required number of replicas this
        deployment resource pool will be considered successfully deployed. This
        value must be greater than or equal to 1 and less than or equal to
        min_replica_count.

    Returns:
      A long-running operation for Create.
    )machineSpecspot   )
metricNametarget)dedicatedResources)deploymentResourcePooldeploymentResourcePoolId)parent?googleCloudAiplatformV1beta1CreateDeploymentResourcePoolRequest)r   'GoogleCloudAiplatformV1beta1MachineSpecmachineTypetpuTopologymultihostGpuNodeCountr	   ParseAcceleratorFlagr   BETA_VERSIONacceleratorTypeacceleratorCountParseReservationAffinityFlagreservationAffinity.GoogleCloudAiplatformV1beta1DedicatedResourcesminReplicaCountmaxReplicaCountrequiredReplicaCountsorteditemsappend1GoogleCloudAiplatformV1beta1AutoscalingMetricSpec!OP_AUTOSCALING_METRIC_NAME_MAPPERautoscalingMetricSpecs2GoogleCloudAiplatformV1beta1DeploymentResourcePool?GoogleCloudAiplatformV1beta1CreateDeploymentResourcePoolRequest?AiplatformProjectsLocationsDeploymentResourcePoolsCreateRequestRelativeNamer   *projects_locations_deploymentResourcePoolsCreate)r   location_refdeployment_resource_pool_idautoscaling_metric_specsaccelerator_dictmin_replica_countmax_replica_countmachine_typetpu_topologymultihost_gpu_node_countreservation_affinityr   required_replica_countmachine_specaccelerator	dedicatedautoscaling_metric_specs_listnamer   poolpool_requestreq	operations                          r   
CreateBetaz(DeploymentResourcePoolsClient.CreateBeta%   s   f ==HHJL!-l!-l++Cl(,,)00K %0%@%@l"&1&B&Bl#').)K)K
	 6 6*l& LL t M I !2 6QI$"3i)'=i$+&(# !9!?!?!AB,$%,,MMKK$FFtL L 	
 C *Gi&==KK$ L D ==``#!< a L
 --
W
W((*HT X C
 FFMMI r   c                     | j                   j                  |j                               }| j                  j                  j                  |      }|S )zDeletes a deployment resource pool using v1beta1 API.

    Args:
      deployment_resource_pool_ref: str, The deployment resource pool to delete.

    Returns:
      A GoogleProtobufEmpty response message for delete.
    rL   )r   ?AiplatformProjectsLocationsDeploymentResourcePoolsDeleteRequestr:   r   r;   Delete)r   deployment_resource_pool_refrO   rP   s       r   
DeleteBetaz(DeploymentResourcePoolsClient.DeleteBeta   sQ     --
W
W)668 X C FFMMI r   c                     | j                   j                  |j                               }| j                  j                  j                  |      }|S )zDescribes a deployment resource pool using v1beta1 API.

    Args:
      deployment_resource_pool_ref: str, Deployment resource pool to describe.

    Returns:
      GoogleCloudAiplatformV1beta1DeploymentResourcePool response message.
    rS   )r   <AiplatformProjectsLocationsDeploymentResourcePoolsGetRequestr:   r   r;   Getr   rV   rO   responses       r   DescribeBetaz*DeploymentResourcePoolsClient.DescribeBeta   sK     --
T
T)668 U C {{EEII#NHOr   c                     | j                   j                  |j                               }t        j                  | j
                  j                  |dd      S )zLists deployment resource pools using v1beta1 API.

    Args:
      location_ref: Resource, the parsed location to list deployment resource
        pools.

    Returns:
      Nested attribute containing list of deployment resource pools.
    )r!   deploymentResourcePoolspageSize)fieldbatch_size_attribute)r   =AiplatformProjectsLocationsDeploymentResourcePoolsListRequestr:   r   YieldFromListr   r;   )r   r=   rO   s      r   ListBetaz&DeploymentResourcePoolsClient.ListBeta   sU     --
U
U((* V C ##>>''	 r   c                     | j                   j                  |j                               }| j                  j                  j                  |      }|S )a  Queries deployed models sharing a specified deployment resource pool using v1beta1 API.

    Args:
      deployment_resource_pool_ref: str, Deployment resource pool to query.

    Returns:
      GoogleCloudAiplatformV1beta1QueryDeployedModelsResponse message.
    )r   )r   LAiplatformProjectsLocationsDeploymentResourcePoolsQueryDeployedModelsRequestr:   r   r;   QueryDeployedModelsr[   s       r   QueryDeployedModelsBetaz5DeploymentResourcePoolsClient.QueryDeployedModelsBeta   sP     --
d
d;HHJ e C {{EEYYH Or   )NNN)
NNNNNNNNFN)
__name__
__module____qualname____doc__r   rQ   rW   r]   re   ri    r   r   r   r      sE    P<  $#!l\("*r   r   N)rm   
__future__r   r   r   apitools.base.pyr   googlecloudsdk.api_lib.utilr   googlecloudsdk.command_lib.air   r	   objectr   rn   r   r   <module>rt      s.    L &  ' ' , 3 /CF Cr   