
                         d   d Z ddlZddl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
e	j                  defdZdd
e	j                  defdZd
e	j                  fdZd
e	j                  dej(                  fdZdededefdZdefdZ	 ddeddfdZ G d dej2                        Zy)z'Cloud Database Migration API utilities.    N)encoding)apis)waiter)base)log)	resourcesdatamigrationrelease_trackreturnc                 @    | t         j                  j                  k(  ryy)z3Returns the API version based on the release track.v1alpha2v1)r   ReleaseTrackALPHAr
   s    9lib/googlecloudsdk/api_lib/database_migration/api_util.pyGetApiVersionr      s    d''---	    no_httpc                 L    t        j                  t        t        |       |      S )N)api_nameapi_versionr   )r   GetClientInstance	_API_NAMEr   )r
   r   s     r   r   r   %   s#    			.
 r   c                 J    t        j                  t        t        |             S N)r   r   )r   GetMessagesModuler   r   r   s    r   r   r   -   s     			.
 r   c                 n    t        j                         }|j                  t        t	        |              |S r   )r   RegistryRegisterApiByNamer   r   )r
   resource_parsers     r   GetResourceParserr"   4   s6    &&(/##. $  
r   projectlocationc                     d|  d| S )a  Get the resource name of the parent collection.

  Args:
    project: the project of the parent collection.
    location: the GCP region of the membership.

  Returns:
    the resource name of the parent collection in the format of
    `projects/{project}/locations/{location}`.
  z	projects/z/locations/ )r#   r$   s     r   	ParentRefr'   =   s     WI[
	33r   c                  <    t        t        j                               S )zoGenerates a UUID to use as the request ID.

  Returns:
    string, the 40-character UUID for the request ID.
  )struuiduuid4r&   r   r   GenerateRequestIdr,   K   s     
TZZ\	r   no_resourcec                    |r!t        j                  | j                        }nt        || j                        }	 t        j                  |t
        j                  j                  |j                  d      d|j                   d       y	# t         j                  $ r0 t        j                  j                  d|j                   d       Y y	w xY w)
z<Uses the waiter library to handle LRO synchronous execution.)operation_service)result_servicer/   z+datamigration.projects.locations.operations)relative_name
collectionzWaiting for operation [z] to completezThe operations may still be underway remotely and may still succeed. You may check the operation status for the following operation []N)r   CloudOperationPollerNoResourcesprojects_locations_operationsCloudDmsOperationPollerWaitForr   REGISTRYParseRelativeNamenameTimeoutErrorr   statusPrint)clientresult_operationservicer-   pollers        r   	HandleLROrB   T   s     33 >>F % >>F

NN,,*//D 	- 	
 ""2"7"7!8F 
		 JJ	""#1	&s   AB A CCc                       e Zd ZdZdefdZy)r6   zManages a longrunning Operations for cloud DMS.

  It is needed since we want to return the entire error rather than just the
  error message as the base class does.

  See https://cloud.google.com/speech/reference/rpc/google.longrunning
  r   c                     |j                   rV|j                  rJt        j                  |j                        }t	        j
                  dt        j                  |      z         |j                   S )z
Overrides.
)doneerrorr   MessageToDictr   OperationErrorpprintpformat)self	operationop_errors      r   IsDonezCloudDmsOperationPoller.IsDone   sL    ~~)//''	8h!!$)A"ABB>>r   N)__name__
__module____qualname____doc__boolrO   r&   r   r   r6   r6   v   s     r   r6   )F)rS   rJ   r*   apitools.base.pyr   googlecloudsdk.api_lib.utilr   r   googlecloudsdk.callioper   googlecloudsdk.corer   r   r   r   r)   r   rT   r   r   r   r"   r'   r,   rB   CloudOperationPollerr6   r&   r   r   <module>rZ      s    .   % , . ( # )	!2!2 s T%6%6  T%6%6 T%6%6 9;M;M 4s 4c 4c 43  	 	
 
Df99 r   