
    I                         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S
KJr   " S S\R                   5      r " S S\5      rS rSS jrS rg)z9General utilities using operations in Privateca commands.    )absolute_import)division)unicode_literals)encoding)base)messages)waiter)
exceptions)	resourcesc                       \ rS rSrSrSrg)OperationError   z3Exception for errors encountered from an operation. N__name__
__module____qualname____firstlineno____doc____static_attributes__r       6lib/googlecloudsdk/command_lib/privateca/operations.pyr   r      s    ;r   r   c                       \ rS rSrSrSrg)OperationTimeoutError!   z*Exception for when an operation times out.r   Nr   r   r   r   r   r   !   s    2r   r   c                 V    [         R                  R                  U R                  S5      $ )z5Get a resource reference to a long running operation.z'privateca.projects.locations.operations)r   REGISTRYParseRelativeNamename)	operations    r   GetOperationRefr!   %   s%    				-	-nn?
 r   c                    U R                   (       a<  U R                  (       a  [        U R                  R                  5      eU R                  $ [        U 5      n[        R                  " [        R                  " U5      R                  5      n [        R                  " XCU5      $ ! [        R                   a    [        S5      ef = f)ag  Waits for operation to complete while displaying in-progress indicator.

Args:
  operation: The Operation resource.
  progress_message: The message to display with the in-progress indicator.
  api_version: The API version.

Returns:
  The resource that is the result of the operation.

Raises:
  OperationError: if the operation did not complete successfully
zRequested action timed out. Please run the describe command on your resource to see if changes were successful, or try again in a few minutes.)doneerrorr   messageresponser!   r	   CloudOperationPollerNoResourcesr   GetClientInstanceprojects_locations_operationsWaitForTimeoutErrorr   )r    progress_messageapi_versionoperation_refpollers        r   Awaitr0   ,   s     ^^9??2233!),-11
[)GG&>>&1ABB			 
	 s   B% % Cc                 j    [         R                  " U 5      nSU;   a  US	 [        R                  " X!SS9$ )a  Returns a message from the ResponseValue.

Operations normally return a ResponseValue object in their response field that
is somewhat difficult to use. This functions returns the corresponding
message type to make it easier to parse the response.

Args:
  response: The ResponseValue object that resulted from an Operation.
  message_type: The type of the message that should be returned

Returns:
  An instance of message_type with the values from the response filled in.
z@typeF)throw_on_unexpected_fields)r   MessageToDictmessages_utilDictToMessageWithErrorCheck)r&   message_typemessage_dicts      r   GetMessageFromResponser8   M   s<     ''1,W		2	2U
 r   N)v1)r   
__future__r   r   r   apitools.base.pyr    googlecloudsdk.api_lib.privatecar   googlecloudsdk.api_lib.utilr   r4   r	   googlecloudsdk.corer
   r   Errorr   r   r!   r0   r8   r   r   r   <module>r@      sT    @ &  ' % 1 A . * )<Z%% <3N 3Br   