
                             S r SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKJ	r
  SSKJr  SS	KJr  S
rSrSS jrSS jr " S S\R"                  5      r " S S\5      rg)z"Utilities for the clouddeploy API.    )absolute_import)division)unicode_literals)apis)waiter)
exceptions)log)	resourcesclouddeployv1Nc                 @    U =(       d
    [        5       n U R                  $ )zReturns the messages module for Cloud Deploy.

Args:
  client: base_api.BaseApiClient, the client class for Cloud Deploy.

Returns:
  Module containing the definitions of messages for Cloud Deploy.
)GetClientInstanceMESSAGES_MODULEclients    5lib/googlecloudsdk/api_lib/clouddeploy/client_util.pyGetMessagesModuler      s     (&(&			    c                 H    [         R                  " [        [        U (       + S9$ )zReturns an instance of the Cloud Deploy client.

Args:
  use_http: bool, True to create an http object for this client.

Returns:
  base_api.BaseApiClient, An instance of the Cloud Deploy client.
)no_http)r   r   	_API_NAME_API_VERSION)use_https    r   r   r   ,   s     
			<h,	PPr   c                   8   ^  \ rS rSrSrU 4S jrS rS rSrU =r	$ )DeployOperationPoller8   zPoller for Cloud Deploy operations API.

This is necessary because the core operations library doesn't directly support
simple_uri.
c                    > Xl         [        [        U ]  U R                   R                   R                  U R                   R                   R                  5        g)ztInitiates a DeployOperationPoller.

Args:
  client: base_api.BaseApiClient, An instance of the Cloud Deploy client.
N)r   superr   __init__projects_locations_operations)selfr   	__class__s     r   r   DeployOperationPoller.__init__?   sD     K	

++II++IIKr   c                 8    U R                   R                  U5      $ N)r   Getr!   operation_refs     r   PollDeployOperationPoller.PollJ   s    ;;??=))r   c                     U$ r%    )r!   	operations     r   	GetResultDeployOperationPoller.GetResultM   s    r   r   )
__name__
__module____qualname____firstlineno____doc__r   r)   r.   __static_attributes____classcell__)r"   s   @r   r   r   8   s    	K* r   r   c                   8    \ rS rSrSrS	S jrS rS
S jrS rSr	g)OperationsClientQ   z:High-level client for the cloud deploy operations surface.Nc                 |    U=(       d
    [        5       U l        U=(       d    U R                  R                  U l        g)zInitiates an OperationsClient.

Args:
  client:  base_api.BaseApiClient, An instance of the Cloud Deploy client.
  messages: messages module for Cloud Deploy.
N)r   r   r   messages)r!   r   r;   s      r   r   OperationsClient.__init__T   s*     /-/DK; ; ;DMr   c                     U R                   R                  R                  U R                  R	                  UR                  5       S95      $ )N)name)r   r    r&   r;   0ClouddeployProjectsLocationsOperationsGetRequestRelativeNamer'   s     r   r&   OperationsClient.Get^   sC    ;;4488FF++- 	G 	/0 0r   c                     [        U 5      nUR                  U5      (       a  U$ Uc  SR                  UR                  5       5      n[        R
                  " XBU5      $ )a  Wait until the operation is complete or times out.

Args:
  operation: The operation resource to wait on
  operation_ref: The operation reference to the operation resource. It's the
    result by calling resources.REGISTRY.Parse
  message: str, the message to print while waiting.

Returns:
  The operation resource when it has completed

Raises:
  OperationTimeoutError: when the operation polling times out
  OperationError: when the operation completed with an error
zWaiting for operation [{}])r   IsDoneformatNamer   WaitFor)r!   r-   r(   messagepollers        r   WaitForOperation!OperationsClient.WaitForOperationc   sR      #4(F}}Y,33M4F4F4HIg>>&99r   c                    UR                  5        H  u  p4U(       a  UR                  (       d  M   [        R                  R	                  UR                  SS9nU R                  XESR                  U5      5      R                  n[        R                  R                  UR                  U5      5        M     g! [        R                   a9  n[        R                  R                  SR                  U5      5         SnAM  SnAff = f)aB  Checks operations status.

Only logs the errors instead of re-throwing them.

Args:
 operation_dict: dict[str, oOptional[clouddeploy_messages.Operation],
   dictionary of resource name and clouddeploy_messages.Operation. The
   operation can be None if the operation isn't executed.
 msg_template: output string template.
z)clouddeploy.projects.locations.operations)
collectionz(Waiting for the operation on resource {}zOperation failed: {}N)itemsr>   r
   REGISTRYParseRelativeNamerI   rD   responser	   statusPrintcore_exceptionsError)r!   operation_dictmsg_templateresource_namer-   r(   _es           r   CheckOperationStatus%OperationsClient.CheckOperationStatus{   s     %3$8$8$: inn;!**<<NNB = D !!6==  !) 	

 	

,,];< %; "" ;

/66q9::;s   BB77D.C??D)r   r;   )NNr%   )
r0   r1   r2   r3   r4   r   r&   rI   rZ   r5   r,   r   r   r8   r8   Q   s    B<0
:0;r   r8   r%   )T)r4   
__future__r   r   r   googlecloudsdk.api_lib.utilr   r   googlecloudsdk.corer   rS   r	   r
   r   r   r   r   CloudOperationPollerr   objectr8   r,   r   r   <module>ra      sW    ) &  ' , . = # )	
 	QF77 2D;v D;r   