
                         v   S r SSKrSSK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\4S jrSS
\	R                  S\4S jjrS
\	R                  4S jrS
\	R                  S\R(                  4S jrS\S\S\4S jrS\4S jr SS\SS4S jjr " S S\R2                  5      rg)z'Cloud Database Migration API utilities.    N)encoding)apis)waiter)base)log)	resourcesdatamigrationrelease_trackreturnc                 B    U [         R                  R                  :X  a  gg)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                 H    [         R                  " [        [        U 5      US9$ )N)api_nameapi_versionr   )r   GetClientInstance	_API_NAMEr   )r
   r   s     r   r   r   %   s#    			.
 r   c                 F    [         R                  " [        [        U 5      S9$ N)r   r   )r   GetMessagesModuler   r   r   s    r   r   r   -   s     			.
 r   c                 j    [         R                  " 5       nUR                  [        [	        U 5      S9  U$ r   )r   RegistryRegisterApiByNamer   r   )r
   resource_parsers     r   GetResourceParserr"   4   s6    &&(/##. $  
r   projectlocationc                     SU  SU 3$ )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                  >    [        [        R                  " 5       5      $ )ziGenerates 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                    U(       a  [         R                  " U R                  S9nO[        UU R                  S9n [         R                  " U[
        R                  R                  UR                  SS9SUR                   S35        g	! [         R                   a0    [        R                  R                  SUR                   S35         g	f = f)
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                   &    \ rS rSrSrS\4S jrSrg)r6   v   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                     UR                   (       a^  UR                  (       aM  [        R                  " UR                  5      n[        R
                  " S[        R                  " U5      -   5      eUR                   $ )z
Overrides.
)doneerrorr   MessageToDictr   OperationErrorpprintpformat)self	operationop_errors      r   IsDoneCloudDmsOperationPoller.IsDone   sL    ~~)//''	8h!!$)A"ABB>>r   r&   N)__name__
__module____qualname____firstlineno____doc__boolrP   __static_attributes__r&   r   r   r6   r6   v   s     r   r6   )F)rV   rK   r*   apitools.base.pyr   googlecloudsdk.api_lib.utilr   r   googlecloudsdk.callioper   googlecloudsdk.corer   r   r   r   r)   r   rW   r   r   r   r"   r'   r,   rB   CloudOperationPollerr6   r&   r   r   <module>r^      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   