
                             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 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 G d de
j2                        ZddZddZddZy)z1Utilities Anthos GKE On-Prem resource operations.    )absolute_import)division)unicode_literals)	Generator)
list_pager)client)waiter)parser_extensions)flags)log)	resources)gkeonprem_v1_messagesi'  i m c                        e Zd ZdZ fdZ	 ddej                  fdZdej                  de
ej                  ddf   fdZ xZS )	OperationsClientz:Client for operations in Anthos GKE On-Prem API resources.c                 b    t        t        | 
  di | | j                  j                  | _        y )N )superr   __init___clientprojects_locations_operations_service)selfkwargs	__class__s     <lib/googlecloudsdk/api_lib/container/gkeonprem/operations.pyr   zOperationsClient.__init__(   s'    	
D*4V4LL>>DM    Nreturnc                 &   |r+t         j                  j                  |j                  d      }||dz  nt        }t        j                  t        j                  | j                        |dj                  |j                               t        |      S )a  Waits for an LRO to complete.

    Args:
      operation: object, operation to wait for.
      operation_ref: operation resource argument reference.
      timeout: int, time in seconds to wait for the operation to complete.

    Returns:
      A completed long-running operation.
    z'gkeonprem.projects.locations.operations)
collectioni  z&Waiting for operation [{}] to complete)wait_ceiling_msmax_wait_ms)r   REGISTRYParseRelativeNamenameMAX_LRO_WAIT_MSr	   WaitForCloudOperationPollerNoResourcesr   formatRelativeNameMAX_LRO_POLL_INTERVAL_MS)r   	operationoperation_reftimeoutr!   s        r   WaitzOperationsClient.Wait,   s     ((::
..> ; m
 %,$7'D._K>>..t}}=077&&(	
 1 r   argsc           
          t        j                  | j                  |            }t        j                  | j
                  |dt        j                  |d      t        j                  |d      d      S )zList operations.)r$   
operations	page_sizelimitpageSize)field
batch_sizer3   batch_size_attribute)messages/GkeonpremProjectsLocationsOperationsListRequest_location_namer   YieldFromListr   r   Get)r   r/   list_reqs      r   ListzOperationsClient.ListJ   sc     GG  &H ##99T;/iig&' r   )NNN)__name__
__module____qualname____doc__r   r8   	Operationr.   r
   	Namespacer   r>   __classcell__)r   s   @r   r   r   %   sP    B?
 9=<#--##T4/0r   r   c                 H    t        j                  t        | dd|             y )NEnrollEnrolledis_asyncr   Printlog_operationresource_refrJ   s     r   
log_enrollrP   [   s    ))L(JJr   c                 H    t        j                  t        | dd|             y )NUnenroll
UnenrolledrI   rK   rN   s     r   log_unenrollrT   a   s    ))L*lXNr   c           	          | j                         }|j                  d      d   }ddddddd	d
d}|j                  |d      }| j                         }|rdj	                  |||      S dj	                  |||      S )a0  Logs the long running operation of a resource.

  Args:
    resource_ref: A resource argument.
    action: str, present tense of the operation.
    past_tense: str, past tense of the operation.
    is_async: bool, if async operation is enabled.

  Returns:
    A string that logs the operation status.
  .z user cluster in Anthos on VMwarez/node pool of a user cluster in Anthos on VMwarez!admin cluster in Anthos on VMwarez$user cluster in Anthos on bare metalz3node pool of a user cluster in Anthos on bare metalz%admin cluster in Anthos on bare metalz*standalone cluster in Anthos on bare metalz9node pool of a standalone cluster in Anthos on bare metal)vmwareClustersvmwareNodePoolsvmwareAdminClustersbareMetalClustersbareMetalNodePoolsbareMetalAdminClustersbareMetalStandaloneClustersbareMetalStandaloneNodePoolszunknown resourcez7{action} in progress for {resource_name} [{self_link}].)actionresource_name	self_linkz+{past_tense} {resource_name} [{self_link}].)
past_tensera   rb   )
CollectionsplitgetSelfLinkr(   )	rO   r`   rc   rJ   resource_collectionresource_typeresource_type_to_namera   rb   s	            r   rM   rM   g   s     %//1%++C04- ;J@A
? G
6 F  (++M;MN-##%)DKK# L   9??# @  r   N)F)rB   
__future__r   r   r   typingr   apitools.base.pyr   *googlecloudsdk.api_lib.container.gkeonpremr   googlecloudsdk.api_lib.utilr	   googlecloudsdk.callioper
   +googlecloudsdk.command_lib.container.vmwarer   googlecloudsdk.corer   r   2googlecloudsdk.generated_clients.apis.gkeonprem.v1r   r8   r*   r%   
ClientBaser   rP   rT   rM   r   r   r   <module>ru      s[    8 &  '  ' = . 5 = # ) `  3v(( 3l.r   