
                             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  G d dej"                        Z G d de
j&                        Zy)z8Base class for gkemulticloud API clients for operations.    )absolute_import)division)unicode_literals)encoding)client)waiter)	constants)log)progress_trackerc                   .     e Zd ZdZ fdZd Zd Z xZS )OperationsClientzClient for managing LROs.c                 p    t        t        | 
  di | | j                  j                  | _        d| _        y )N
operations )superr   __init___clientprojects_locations_operations_service_list_result_field)selfkwargs	__class__s     @lib/googlecloudsdk/api_lib/container/gkemulticloud/operations.pyr   zOperationsClient.__init__   s/    	
D*4V4LL>>DM*D    c                     t        | j                        }t        j                  ||t	        j
                  ||j                  dj                  |            t        j                  t        j                         y)zWaits for an LRO to complete.

    Args:
      operation_ref: object, passed to operation poller poll method.
      message: str, string to display for the progress tracker.
    z Aborting wait for operation {}.
)messagedetail_message_callbackaborted_message)polleroperation_refcustom_trackerwait_ceiling_msmax_wait_msN)_Pollerr   r   WaitForr   ProgressTrackerGetDetailMessageformatr	   MAX_LRO_POLL_INTERVAL_MSMAX_LRO_WAIT_MS)r   r!   r   r    s       r   WaitzOperationsClient.Wait$   sc     T]]#F
NN#'77$*$;$;?FF
 "::--r   c                     | j                   j                  d      }| j                   j                   ||j                                      y)zgCancels an ongoing LRO.

    Args:
      operation_ref: object, operation resource to be canceled.
    CancelnameN)r   GetRequestTyper.   RelativeName)r   r!   request_types      r   r.   zOperationsClient.Cancel:   s8     ==//9LMM=+E+E+GHIr   )__name__
__module____qualname____doc__r   r,   r.   __classcell__)r   s   @r   r   r      s    !+
,Jr   r   c                   "    e Zd ZdZd Zd Zd Zy)r%   zPoller for Anthos Multi-cloud operations.

  The poller stores the status detail from the operation message to update
  the progress tracker.
  c                 .    || _         d| _        d| _        y)See base class.N)operation_servicestatus_detaillast_error_detail)r   r<   s     r   r   z_Poller.__init__K   s    .DD!Dr   c                 v   | j                   j                  d      }| j                   j                   ||j                                     }|j                  at        j                  |j                        }d|v r
|d   | _        d|v r0|d   }|| j                  k7  rt        j                  |       || _        |S )r;   Getr/   statusDetailerrorDetail)r<   r1   r@   r2   metadatar   MessageToPyValuer=   r>   r
   error)r   r!   r3   	operationrC   error_details         r   Pollz_Poller.PollQ   s    ))88?L&&**-4467I %**9+=+=>h	8	#%n5	(	".4111
))L
!!-r   c                     | j                   S )N)r=   )r   s    r   r(   z_Poller.GetDetailMessageb   s    r   N)r4   r5   r6   r7   r   rH   r(   r   r   r   r%   r%   D   s    ""r   r%   N)r7   
__future__r   r   r   apitools.base.pyr   .googlecloudsdk.api_lib.container.gkemulticloudr   googlecloudsdk.api_lib.utilr   2googlecloudsdk.command_lib.container.gkemulticloudr	   googlecloudsdk.corer
   googlecloudsdk.core.consoler   
ClientBaser   CloudOperationPollerNoResourcesr%   r   r   r   <module>rS      sL    ? &  ' % A . H # 8%Jv(( %JPf44 r   