
                         t    S 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 rS	 rS
 rS rS rS rS rS rg)zUtilities for HA controllers.    )poller)waiter)
exceptions)logc                 H    U(       d  [        XU 5      $ [        [        XUSS9$ )zInserts an HA Controller.creationoperation_type)_Insert_ExecuteAsyncOperation_InsertAsyncholderha_controllerha_controller_refasync_s       :lib/googlecloudsdk/api_lib/compute/ha_controllers/utils.pyInsertr      s*    	=V<<	F+<
     c                 H    U(       d  [        XU 5      $ [        [        XUSS9$ )zPatches an HA Controller.updater	   )_Patchr   _PatchAsyncr   s       r   Patchr   !   s*    	-F;;	6*;
 r   c                 `    U R                   R                  UUR                  UR                  S9$ )N)haControllerprojectregion)messages!ComputeHaControllersInsertRequestr   r   )clientr   r   s      r   _CreateInsertRequestr"   +   s3    		:	: ''%% 
; 
 r   c           	         [        UR                  X5      nUR                  R                  R                  R	                  U5      nUR
                  R                  UR                  5      n[        R                  " [        R                  " UR                  R                  R                  5      USR                  U R                  UR                  5       5      S9$ )Nz/HA controller creation in progress for [{}]: {}message)r"   r!   apitools_clienthaControllersr   	resourcesParseselfLinkr   WaitForr   PollerformatnameSelfLinkr   r   r   requestresponseoperation_refs         r   r   r   3   s     mm]' ]]**88??H(""(():):;-	mmFMM11??@
;
B
B  -"8"8":	
 r   c                 t    [        XU5      nU R                  U R                  R                  SU4/U5      S   $ )Nr   r   )r"   AsyncRequestsr&   r'   r!   r   r   errors_to_collectr1   s        r   r   r   D   sH     8IJ'			,,h@A
 
 r   c           	         UR                   R                  R                  UR                  5       U UR                  UR
                  S9nUR                   R                  R                  R                  U5      nUR                  R                  UR                  5      n[        R                  " [        R                  " UR                   R                  R                  5      USR!                  U R"                  UR%                  5       5      S9$ )Nr   haControllerResourcer   r   z-HA controller update in progress for [{}]: {}r$   )r!   r    ComputeHaControllersPatchRequestNamer   r   r&   r'   r   r(   r)   r*   r   r+   r   r,   r-   r.   r/   r0   s         r   r   r   L   s    MM""CC$))+(''%%	 D ' ]]**88>>wG(""(():):;-	mmFMM11??@
9
@
@  -"8"8":	
 r   c                     U R                   R                  UR                  5       UUR                  UR                  S9nU R                  U R                  R                  SU4/U5      S   $ )Nr9   r   r   )r   r;   r<   r   r   r5   r&   r'   r6   s        r   r   r   `   sw    OO<<$))+(''%%	 = ' 
		,,gw?@
 
 r   c                     U R                   R                  R                  U R                  R                  " S0 UR                  5       D65      $ )zSend HA Controller get request. )r&   r'   Getr   ComputeHaControllersGetRequestAsDict)r!   r   s     r   r@   r@   m   sD    				-	-	1	1oo44 $$&
 r   c                    [        U SS5      nU(       a5  [        R                  " [        R                  " UR
                  5      /5      eUR                  R                  U R                  5      n[        R                  R                  SR                  X2UR                  5       5      5        [        R                  R                  S5        U $ )zBHandles the response from an asynchronous HA Controller operation.errorNz)HA Controller {} in progress for [{}]: {}zZUse [gcloud compute operations describe URI] command to check the status of the operation.)getattrcore_exceptions
MultiErrorr   OperationErrorserrorsr(   r)   r*   r   statusPrintr-   r/   )r2   r   ha_controller_namer
   errr3   s         r   _HandleAsyncResponserN   v   s    '4(#

$
$f&<&<SZZ&H%I
JJ""(():):;-**188
m.D.D.F
 **. 
/r   c                     / nU " UR                   X#U5      nU(       a  [        R                  " U5      e[        XaUR                  U5      $ )z1Executes an asynchronous HA Controller operation.)r!   rF   rG   rN   r.   )async_methodr   r   r   r
   r7   r2   s          r   r   r      sQ     mm]7H( 

$
$%6
77	**N
 r   N)__doc__)googlecloudsdk.api_lib.compute.operationsr   googlecloudsdk.api_lib.utilr   googlecloudsdk.corer   rF   r   r   r   r"   r   r   r   r   r@   rN   r   r?   r   r   <module>rU      sH    $ < . = #"(
(r   