
                             d Z ddlmZ ddlmZ ddlmZ ddlmZ d Zd Z	 	 	 	 dd	Z		 	 	 	 dd
Z
	 	 	 	 	 	 	 ddZ	 	 	 	 	 	 ddZy)zBigtable clusters API helper.    )absolute_import)division)unicode_literals)utilc                     t        j                         }t        j                         }|j                  | j	                               }|j
                  j                  |       y)z]Delete a cluster.

  Args:
    cluster_ref: A resource reference to the cluster to delete.
  )nameN)r   GetAdminClientGetAdminMessages3BigtableadminProjectsInstancesClustersDeleteRequestRelativeNameprojects_instances_clustersDelete)cluster_refclientmsgsmsgs       /lib/googlecloudsdk/api_lib/bigtable/clusters.pyr   r      sV      &				 $@@##% 	A 	'#$$++C0    c                    t        j                         }t        j                         }|j                  || j	                         | j                         j                               }|j                  j                  |      S )zCreate a cluster.

  Args:
    cluster_ref: A resource reference to the cluster to create.
    cluster: A Cluster msg object to create.

  Returns:
    Long running operation.
  )cluster	clusterIdparent)	r   r	   r
   3BigtableadminProjectsInstancesClustersCreateRequestNameParentr   r   Create)r   r   r   r   r   s        r   r   r   %   ss      &				 $@@  "!..0 	A 	2# 
	+	+	2	23	77r   Nc                     t        j                         }|j                  | |      }|j                  ||      }|j	                  ||      S )z'Build a ClusterAutoscalingConfig field.)minServeNodesmaxServeNodes)cpuUtilizationPercentstorageUtilizationGibPerNode)autoscalingLimitsautoscalingTargets)r   r
   AutoscalingLimitsAutoscalingTargetsClusterAutoscalingConfig)	min_nodes	max_nodes
cpu_targetstorage_targetr   limitstargetss          r   BuildClusterAutoscalingConfigr-   8   sf    
 
			 $!!Y " 8&##&#1 $ 3' 
	&	&7 
' 
< <r   c                 h    t        j                         }|j                  t        | |||            S )zBuild a ClusterConfig field.)r'   r(   r)   r*   )clusterAutoscalingConfig)r   r
   ClusterConfigr-   )autoscaling_minautoscaling_maxautoscaling_cpu_targetautoscaling_storage_targetr   s        r   BuildClusterConfigr5   G   s>    
 
			 $			<##+3	 5 
 
6 6r   c                     | j                  ||      }||||t        ||||      |_        | j                  |||      S )z$Build a PartialUpdateClusterRequest.)r   
serveNodes)r1   r2   r3   r4   )r   r   
updateMask)Clusterr5   clusterConfigABigtableadminProjectsInstancesClustersPartialUpdateClusterRequest)	r   r   nodesr1   r2   r3   r4   update_maskr   s	            r    BuildPartialUpdateClusterRequestr>   U   sh     LLduL5'!_%@( ,.''5#=	?G 
	O	OD[ 
P 
: :r   c                 @   t        j                         }t        j                         }|rI||||t        d      |j                  j                  t        || j                         |d            S g }	||	j                  d       ||	j                  d       ||	j                  d       ||	j                  d       ||	j                  d       d	j                  |	      }
|j                  j                  t        || j                         ||||||

            S )a  Partially update a cluster.

  Args:
    cluster_ref: A resource reference to the cluster to update.
    nodes: int, the number of nodes in this cluster.
    autoscaling_min: int, the minimum number of nodes for autoscaling.
    autoscaling_max: int, the maximum number of nodes for autoscaling.
    autoscaling_cpu_target: int, the target CPU utilization percent for
      autoscaling.
    autoscaling_storage_target: int, the target storage utilization gibibytes
      per node for autoscaling.
    disable_autoscaling: bool, True means disable autoscaling if it is currently
      enabled. False means change nothing whether it is currently enabled or
      not.

  Returns:
    Long running operation.
  zEautoscaling arguments cannot be set together with disable_autoscalingz5serve_nodes,cluster_config.cluster_autoscaling_config)r   r   r<   r=   serve_nodeszLcluster_config.cluster_autoscaling_config.autoscaling_limits.min_serve_nodeszLcluster_config.cluster_autoscaling_config.autoscaling_limits.max_serve_nodeszUcluster_config.cluster_autoscaling_config.autoscaling_targets.cpu_utilization_percentz^cluster_config.cluster_autoscaling_config.autoscaling_targets.storage_utilization_gib_per_node,)r   r   r<   r1   r2   r3   r4   r=   )
r   r	   r
   
ValueErrorr   PartialUpdateClusterr>   r   appendjoin)r   r<   r1   r2   r3   r4   disable_autoscalingr   r   changed_fieldsr=   s              r   PartialUpdaterH   m   sS   2  &				 $#'B*". - . .--BB 	)))+O		
  .
-( V  V '_  +h (+		+	+	@	@&'')))!7%?!#	
$ 	$r   )NNNN)NNNNNNN)NNNNNF)__doc__
__future__r   r   r   googlecloudsdk.api_lib.bigtabler   r   r   r-   r5   r>   rH    r   r   <module>rM      s|    $ &  ' 0
18& -1,0-115< (,'+.2266 +/+/5959<@@D15:2 "&"&)--1&+J$r   