
    }                         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  G d	 d
e
j                        Z G d dej                        Zd Zd Zd Zy)zCRM operations utilities.    )absolute_import)division)unicode_literals)tags)waiter)
exceptions)	resourcesc                       e Zd Zy)OperationErrorN)__name__
__module____qualname__     =lib/googlecloudsdk/command_lib/resource_manager/operations.pyr   r      s    r   r   c                       e Zd ZdZd Zd Zy)ReturnOperationPollerzPolls for operations that retrieve the operation rather than the resource.

  This is needed for Delete operations, where the response is Empty. It is also
  needed for services that do not have a Get* method, such as TagBindings.
  c                     || _         y)zSets up poller for polling operations.

    Args:
      operation_service: apitools.base.py.base_api.BaseApiService, api service
        for retrieving information about ongoing operation.
    N)operation_service)selfr   s     r   __init__zReturnOperationPoller.__init__&   s     /Dr   c                     |S )aN  Overrides.

    Response for Deletion Operation is of type google.protobuf.Empty and hence
    we can return the operation itself as the result. For operations without a
    Get[Resource] method, we have no choice but to return the operation.

    Args:
      operation: api_name_messages.Operation.

    Returns:
      operation
    r   )r   	operations     r   	GetResultzReturnOperationPoller.GetResult/   s
     r   N)r   r   r   __doc__r   r   r   r   r   r   r      s    /r   r   c                 V    t        t        j                               }t        | ||      S )a  Waits for the given google.longrunning.Operation to complete.

  Args:
    operation: The operation to poll.
    message: String to display for default progress_tracker.

  Raises:
    apitools.base.py.HttpError: if the request returns an HTTP error

  Returns:
    operation
  )r   r   OperationsService_WaitForOperation)r   messagepollers      r   WaitForReturnOperationr!   ?   s&     !!7!7!9:&	9gv	66r   c                 l    t        j                  |t        j                               }t	        | ||      S )a  Waits for the given google.longrunning.Operation to complete.

  Args:
    operation: The operation to poll.
    message: String to display for default progress_tracker.
    service: The service to get the resource after the long running operation
      completes.

  Raises:
    apitools.base.py.HttpError: if the request returns an HTTP error

  Returns:
    The TagKey or TagValue resource.
  )r   CloudOperationPollerr   r   r   )r   r   servicer    s       r   WaitForOperationr%   P   s.     &&w0F0F0HI&	9gv	66r   c                     |j                  |       r|j                  |       S t        j                  j	                  | j
                  d      }t        j                  |||      S )Nzcloudresourcemanager.operations)
collection)IsDoner   r	   REGISTRYParsenamer   WaitFor)r   r   r    operation_refs       r   r   r   c   sZ    ]]9 I&&$$**nn!B + D-	w	77r   N)r   
__future__r   r   r   'googlecloudsdk.api_lib.resource_managerr   googlecloudsdk.api_lib.utilr   googlecloudsdk.corer   r	   Errorr   r#   r   r!   r%   r   r   r   r   <module>r3      sS      &  ' 8 . * )Z%% F77 @7"7&8r   