
                         t    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Z
dd
ZddZddZddZy	)z-Utils for common operations API interactions.    )absolute_import)division)unicode_literals)apis)waiter)	resourcesz/transferappliance.projects.locations.operationsNc                    |t        j                  dd      }|j                  }|t        j                  |      }nW|dk(  r!t        j
                  |j                  |      }n1|dk(  r!t        j
                  |j                  |      }nt        d      t        j                  j                  | j                  t              }t        j                  ||dj                  |            S )aP  Blocks execution until an operation completes and handles the result.

  Args:
    operation (messages.Operation): The operation to wait on.
    verb (str): The verb to use in messages, such as "delete order".
    result_type (str|none): Type of result for retrieving once operation
        completes. Will skip returning result if None.
    client (apitools.base.py.base_api.BaseApiService): API client for loading
        the results and operations clients.

  Returns:
    poller.GetResult(operation).
  Raises:
    InternalError if provided `result_type` is not `appliance` or `order`.
  transferappliancev1alpha1	applianceorderz7The `result_type` must be `order`, `appliance` or None.)
collectionz$Waiting for {} operation to complete)r   GetClientInstanceprojects_locations_operationsr   CloudOperationPollerNoResourcesCloudOperationPollerprojects_locations_appliancesprojects_locations_orders
ValueErrorr   REGISTRYParsename
COLLECTIONWaitForformat)	operationverbresult_typeclientoperations_servicepolleroperation_refs          Alib/googlecloudsdk/api_lib/transfer/appliances/operations_util.py_wait_for_operationr$      s      ^##$7DF;;334FGFk!((,,.@BFg((((*<>F N
OO$$**nn + --	mCJJ4P
     c                      t        | |d|      S )a  Blocks execution until an operation completes and does not yield a result.

  Args:
    operation (messages.Operation): The operation to wait on.
    verb (str): The verb to use in messages, such as "delete order".
    client (apitools.base.py.base_api.BaseApiService): API client for loading
        the results and operations clients.

  Returns:
    poller.GetResult(operation).
  N)r   r   r$   r   r   r   s      r#   wait_then_yield_nothingr)   A   s     
Y$v	NNr%   c                 *    |dz  }t        | |d|      S )a|  Blocks execution until an operation completes and returns an appliance.

  Args:
    operation (messages.Operation): The operation to wait on.
    verb (str): The verb to use in messages, such as "create".
    client (apitools.base.py.base_api.BaseApiService|None): API client for
        loading the results and operations clients.

  Returns:
    poller.GetResult(operation).
  z
 appliancer   r   r'   r(   s      r#   wait_then_yield_appliancer,   P   s     ,$	Yk&	IIr%   c                 *    |dz  }t        | |d|      S )ax  Blocks execution until an operation completes and returns an order.

  Args:
    operation (messages.Operation): The operation to wait on.
    verb (str): The verb to use in messages, such as "create".
    client (apitools.base.py.base_api.BaseApiService|None): API client for
        loading the results and operations clients.

  Returns:
    poller.GetResult(operation).
  z orderr   r+   r'   r(   s      r#   wait_then_yield_orderr.   `   s     ($	Ygf	EEr%   )NN)N)__doc__
__future__r   r   r   googlecloudsdk.api_lib.utilr   r   googlecloudsdk.corer   r   r$   r)   r,   r.    r%   r#   <module>r4      s;    4 &  ' , . ) ?
!HOJ Fr%   