
    .                         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 Zd	 Zdd
Z	 	 	 	 	 	 ddZ	 	 	 	 	 	 	 	 	 	 ddZ	 	 	 	 	 	 	 	 	 	 ddZy)z!Bigtable app-profiles API helper.    )absolute_import)division)unicode_literals)
list_pager)util)
exceptionsc                     t        j                         }t        j                         j                  | j	                               }|j
                  j                  |      S )zDescribe an app profile.

  Args:
    app_profile_ref: A resource reference to the app profile to describe.

  Returns:
    App profile resource object.
  )name)r   GetAdminClientGetAdminMessages3BigtableadminProjectsInstancesAppProfilesGetRequestRelativeNameprojects_instances_appProfilesGet)app_profile_refclientmsgs      3lib/googlecloudsdk/api_lib/bigtable/app_profiles.pyDescriber      sV      &SS'') 	T 	# 
	.	.	2	23	77    c                     t        j                         }t        j                         j                  | j	                               }t        j                  |j                  |dd      S )zList app profiles.

  Args:
    instance_ref: A resource reference of the instance to list app profiles for.

  Returns:
    Generator of app profile resource objects.
  )parentappProfilesN)fieldbatch_size_attribute)r   r   r   4BigtableadminProjectsInstancesAppProfilesListRequestr   r   YieldFromListr   )instance_refr   r   s      r   Listr   *   sd      &TT&&( 	U 	# 
	!	!++		
 r   c                     t        j                         }t        j                         j                  | j	                         |      }|j
                  j                  |      S )zDelete an app profile.

  Args:
    app_profile_ref: A resource reference to the app profile to delete.
    force: bool, Whether to ignore API warnings and delete forcibly.

  Returns:
    Empty response.
  )r
   ignoreWarnings)r   r   r   6BigtableadminProjectsInstancesAppProfilesDeleteRequestr   r   Delete)r   forcer   r   s       r   r#   r#   ?   sX      &VV'')% 	W 	# 
	.	.	5	5c	::r   Nc                 v   |r| rt        j                  dd      |s| st        j                  ddgd      |r|rt        j                  dd      | r|rt        j                  dd      | r|rt        j                  dd      |r|rt        j                  dd      |r|rt        j                  dd      yy)	a  Create an app profile.

  Args:
    cluster: string, The cluster id for the new app profile to route to using
      single cluster routing.
    multi_cluster: bool, Whether this app profile should route to multiple
      clusters, instead of single cluster.
    restrict_to: list[string] The list of cluster ids for the new app profile to
      route to using multi cluster routing.
    transactional_writes: bool, Whether this app profile has transactional
      writes enabled. This is only possible when using single cluster routing.
    row_affinity: bool, Whether to use row affinity sticky routing.
    data_boost: bool, If the app profile should use Data Boost Read-only
      Isolation.

  Raises:
    ConflictingArgumentsException:
        If both cluster and multi_cluster are present.
        If both multi_cluster and transactional_writes are present.
        If both cluster and row_affinity are present.
        If both cluster and restrict_to are present.
        If both multi_cluster and data_boost are present.
        If both transactional_writes and data_boost are present.

    OneOfArgumentsRequiredException: If neither cluster or multi_cluster are
        present.
  z
--route-toz--route-anyz3Either --route-to or --route-any must be specified.z--transactional-writesz--row-affinityz--restrict-toz--data-boostN)r   ConflictingArgumentsExceptionOneOfArgumentsRequiredExceptionclustermulti_clusterrestrict_totransactional_writesrow_affinity
data_boosts         r   _AppProfileChecksr/   P   s    F w

2
2<
OO	w

4
4	}%= 
 +

2
2/  

2
2&  

2
2o 
 z

2
2~  j

2
2 .  )r   c           	         t        ||||||       t        j                         }t        j                         }| j	                         }d}d}|r*|j                  |xs g |r|j                         nd      }n|r|j                  ||      }d}d}|r.|j                  j                  |      }|j                  |      }n/|r-|j                  j                  |	      }|j                  |      }|j                  |j                  |||||      | j                         |j                         |
      }|j                   j#                  |      S )	a  Create an app profile.

  Args:
    app_profile_ref: A resource reference of the new app profile.
    cluster: string, The cluster id for the new app profile to route to using
      single cluster routing.
    description: string, A description of the new app profile.
    multi_cluster: bool, Whether this app profile should route to multiple
      clusters, instead of single cluster.
    restrict_to: list[string] The list of cluster ids for the new app profile to
      route to using multi cluster routing.
    transactional_writes: bool, Whether this app profile has transactional
      writes enabled. This is only possible when using single cluster routing.
    row_affinity: bool, Whether to use row affinity sticky routing.
    priority: string, The request priority of the new app profile.
    data_boost: bool, If the app profile should use Standard Isolation.
    data_boost_compute_billing_owner: string, The compute billing owner for Data
      Boost.
    force: bool, Whether to ignore API warnings and create forcibly.

  Raises:
    ConflictingArgumentsException,
    OneOfArgumentsRequiredException:
      See _AppProfileChecks(...)

  Returns:
    Created app profile resource object.
  r(   N
clusterIdsrowAffinity	clusterIdallowTransactionalWritesprioritycomputeBillingOwner)descriptionmultiClusterRoutingUseAnysingleClusterRoutingstandardIsolationdataBoostIsolationReadOnly)
appProfileappProfileIdr   r!   )r/   r   r   r   ParentMultiClusterRoutingUseAnyRowAffinitySingleClusterRoutingStandardIsolationPriorityValueValuesEnumDataBoostIsolationReadOnly"ComputeBillingOwnerValueValuesEnum6BigtableadminProjectsInstancesAppProfilesCreateRequest
AppProfileNamer   r   Create)r   r)   r;   r*   r+   r,   r-   r8   r.    data_boost_compute_billing_ownerr$   r   msgsr   multi_cluster_routingsingle_cluster_routingstandard_isolationdata_boost_isolationpriority_enumdata_boost_enumr   s                        r   rM   rM      s   R !/  &				 $ ''), ::$"*6D$$&D ;  !66!5 7 
 **BB8LM///G''JJ,	
 
  ::+ ;  	CC!$95.%9 !  #'')&&( 	D 	# 
	.	.	5	5c	::r   c                    t        ||||||       t        j                         }t        j                         }g }|j	                         }|r=|j                  d       ||j                  d       |j                  ||      |_        n|r|r|j                  d       ||j                  d       |j                  |xs g |r|j                         nd      |_
        |j                  |j                         k(  r|j                  d	       |r|j                  d
       ||_        |rD|j                  j                  |      }|j                  d       |j                  |      |_        nE|rC|j                  j!                  |	      }|j                  d       |j                  |      |_        |j%                  || j'                         dj)                  |      |
      }|j*                  j-                  |      S )a  Update an app profile.

  Args:
    app_profile_ref: A resource reference of the app profile to update.
    cluster: string, The cluster id for the app profile to route to using single
      cluster routing.
    description: string, A description of the app profile.
    multi_cluster: bool, Whether this app profile should route to multiple
      clusters, instead of single cluster.
    restrict_to: list[string] The list of cluster IDs for the app profile to
      route to using multi cluster routing.
    transactional_writes: bool, Whether this app profile has transactional
      writes enabled. This is only possible when using single cluster routing.
    row_affinity: bool, Whether to use row affinity sticky routing. If None,
      then no change should be made.
    priority: string, The request priority of the new app profile.
    data_boost: bool, If the app profile should use Standard Isolation.
    data_boost_compute_billing_owner: string, The compute billing owner for Data
      Boost.
    force: bool, Whether to ignore API warnings and create forcibly.

  Raises:
    ConflictingArgumentsException,
    OneOfArgumentsRequiredException:
      See _AppProfileChecks(...)

  Returns:
    Long running operation.
  r(   zsingleClusterRouting.clusterIdNz-singleClusterRouting.allowTransactionalWritesr4   z$multiClusterRoutingUseAny.clusterIdsz%multiClusterRoutingUseAny.rowAffinityr1   r<   r;   zstandardIsolation.priorityr7   r?   r9   ,)r@   r
   
updateMaskr!   )r/   r   r   r   rK   appendrE   r=   rC   rD   r<   r;   rF   rG   r>   rH   rI   r?   5BigtableadminProjectsInstancesAppProfilesPatchRequestr   joinr   Patch)r   r)   r;   r*   r+   r,   r-   r8   r.   rN   r$   r   rO   changed_fieldsapp_profilerT   rU   r   s                     r   Updater_      s   T !/  &				 $.!+:;'KL'+'@'@!5 (A (K$ BCCD,0,J,J$"*6D$$&D -K -K) 	--))+	, 78-()K**BB8LM67$($:$: %; %K! ''JJ,	
 
 67-1-L-L+ .M .K* 	BB'').)	 	C 	# 
	.	.	4	4S	99r   )F)NFNNFF)
N FNNFNFNF)
Nr`   FNNNNFNF)__doc__
__future__r   r   r   apitools.base.pyr   googlecloudsdk.api_lib.bigtabler   googlecloudsdk.callioper   r   r   r#   r/   rM   r_    r   r   <module>rg      s    ( &  ' ' 0 .8 *;$ @J %)
_;H %)
n:r   