
    	                     z    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	Zd
 Zd Zd ZddZy)z%Common utility functions for Updater.    )absolute_import)division)unicode_literals)apis)	time_util)progress_tracker)resource_printerz;ResponseError: code={status_code}, message={status_message}c                  .    t        j                  dd      S Nreplicapoolupdaterv1beta1)	core_apisGetClientInstance     :lib/googlecloudsdk/api_lib/compute/rolling_updates_util.pyGetApiClientInstancer          		$	$%99	EEr   c                  .    t        j                  dd      S r   )r   GetMessagesModuler   r   r   GetApiMessagesr   #   r   r   c                    t        j                  |d      5 }	 | j                  j                  | j                  j                  |j                  |j                  |j                              }|j                  r
	 ddd       y|j                  dk(  r
	 ddd       y|j                          t        j                  d       # 1 sw Y   yxY w)aC  Waits until the given operation finishes.

  Wait loop terminates when the operation's status becomes 'DONE'.

  Args:
    client: interface to the Cloud Updater API
    operation_ref: operation to poll
    message: message to be displayed by progress tracker

  Returns:
    True iff the operation finishes with success
  F)autotickT)projectzone	operationNDONE   )r   ProgressTrackerzoneOperationsGetMESSAGES_MODULE*ReplicapoolupdaterZoneOperationsGetRequestr   r   r   errorstatusTickr   Sleep)clientoperation_refmessageptr   s        r   WaitForOperationr,   '   s     ''%@B
''++

 
 
K
K#++ %%%// L 12i
 
 A@ 
		V	# A@ 	ggiooa  A@s   A$CC&CCc                 4    t        j                  | g|       y)zPrints the given resource.)	resourcesprint_formatN)r	   Print)resourcer/   s     r   PrettyPrintr2   C   s    H:LIr   N)json)__doc__
__future__r   r   r   googlecloudsdk.api_lib.utilr   r   googlecloudsdk.command_lib.utilr   googlecloudsdk.core.consoler   googlecloudsdk.core.resourcer	   HTTP_ERROR_FORMATr   r   r,   r2   r   r   r   <module>r;      sA    , &  ' 9 5 8 9 B FF8Jr   