
                          .   S 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	r	SSK
Jr   " S S	\R                  5      r " S
 S\5      r " S S\R                  5      r " S S\5      r " S S\5      r " S S\R                  5      r " S S\5      rg)z&Constructs to poll compute operations.    )
exceptions)utils)waiter)	resourcesN)zipc                       \ rS rSrSrSrg)Error   zErrors raised by this module. N)__name__
__module____qualname____firstlineno____doc____static_attributes__r       7lib/googlecloudsdk/api_lib/compute/operations/poller.pyr	   r	      s    %r   r	   c                   ,   ^  \ rS rSrSrU 4S jrSrU =r$ )OperationErrors   z=Encapsulates multiple errors reported about single operation.c                 f  > SnU H"  n[         R                  " U5      (       d  M   Sn  O   U(       a=  [         R                  " S[         R                  " U5      S9n[        [
        U ]  U5        g U Vs/ s H  o3R                  PM     nn[        [
        U ]  SR                  U5      5        g s  snf )NFT )titleitems, )	r   ShouldUseYamlConstructListParseErrorssuperr   __init__messagejoin)selferrorsuse_construct_listerrorformatted_errorsmessages	__class__s         r   r    OperationErrors.__init__"   s    			U	#	#!  ,,%++F35OT+,<=-34VE--Vh4OT+DIIh,?@ 5s   4B.r   )r   r   r   r   r   r    r   __classcell__)r)   s   @r   r   r      s    EA Ar   r   c                   :    \ rS rSrSrS
S jrS rS rS rS r	S	r
g)Poller1   zCompute operations poller.Nc                     Xl         UR                  U l        U R                  R                  U l        U R                  R                  R
                  U l        X l        X0l        g)a  Initializes poller for compute operations.

Args:
  resource_service: apitools.base.py.base_api.BaseApiService,
      service representing the target of operation.
  target_ref: Resource, optional reference to the expected target of the
      operation. If not provided operation.targetLink will be used instead.
  has_project: If 'projects' token should be in the target link for
      organization operations.
N)	resource_serviceclientMESSAGES_MODULEr(   	OperationStatusValueValuesEnumstatus_enum
target_refhas_project)r#   r0   r6   r7   s       r   r    Poller.__init__4   sK     -"))DKKK//DM}}..DDD O"r   c                     UR                   (       a  [        UR                   R                  5      eUR                  U R                  R
                  :H  $ )
Overrides.)r&   r   r$   statusr5   DONEr#   	operations     r   IsDonePoller.IsDoneF   s;    IOO2233t//4444r   c                 P    [         R                  " UR                  5       5      S:H  $ )Nz$compute.globalOrganizationOperations)six	text_typeGetCollectionInfor#   operation_refs     r   IsGlobalOrganizationOperation$Poller.IsGlobalOrganizationOperationM   s(    ==88: CD Dr   c                 t   U R                  U5      (       a  [        US5      (       ax  SUR                  ;   ah  U R                  R                  nUR                  R                  S5      nSUS   -   nUR                  UR                  S5      " UR                  US95      $ [        US5      (       a  U R                  R                  nO>[        US	5      (       a  U R                  R                  nOU R                  R                  nUR                  UR                  S
5      " S0 UR                  5       D65      $ )r:   r>   org--zorganizations/   Get)r>   parentIdzoneregionWaitr   )rG   hasattrr>   r1   globalOrganizationOperationssplitrM   GetRequestTypezoneOperationsregionOperationsglobalOperationsrQ   AsDict)r#   rF   service
token_list	parent_ids        r   PollPoller.PollQ   s    ))-88W{>$ >$(.-2I2I(I88g **005j"Z]2i[[

 
 
'%//)EF F }f%%**g		)	),,g,,g<<v&@)=)=)?@B Br   c                 R   U R                   R                  S5      nUR                  (       a  SUR                  ;   a  gU R                  =(       d)    [        R
                  R                  UR                  5      nU R                   R                  U" S0 UR                  5       D65      $ )r:   rM   rJ   Nr   )
r0   rU   namer6   r   REGISTRYParse
targetLinkrM   rY   )r#   r>   request_typer6   s       r   	GetResultPoller.GetResultg   s    ((77>L ~~&INN2 //
KY//55i6J6JK   $$\%HJ4E4E4G%HIIr   )r1   r7   r(   r0   r5   r6   )NF)r   r   r   r   r   r    r?   rG   r]   re   r   r   r   r   r-   r-   1   s!    "#$5DB,Jr   r-   c                       \ rS rSrS rSrg)DeletePolleru   c                     g)r:   Nr   r=   s     r   re   DeletePoller.GetResultv   s     r   r   Nr   r   r   r   re   r   r   r   r   rh   rh   u   s    r   rh   c                   <    \ rS rSrSrS rS rS rS rS r	S r
S	rg
)OperationBatch}   z.Wrapper class for a set of batched operations.c                 2    U=(       d    / U l         0 U l        g N_operation_refs
_responses)r#   operation_refss     r   r    OperationBatch.__init__   s    )/RDDOr   c                      X R                   U'   g rq   )rt   )r#   rF   responses      r   SetResponseOperationBatch.SetResponse   s    %-OOM"r   c                 8    U R                   R                  U5      $ rq   )rt   getrE   s     r   GetResponseOperationBatch.GetResponse   s    ??}--r   c              #      #    U R                    H/  nU" U R                  R                  U5      5      (       d  M+  Uv   M1     g 7frq   )rs   rt   r|   )r#   response_funcops      r   GetWithResponseOperationBatch.GetWithResponse   s4     ""	t**2.	/	/ #s
   4A	Ac                 ,    [        U R                  5      $ rq   )iterrs   r#   s    r   __iter__OperationBatch.__iter__   s    $$%%r   c                 d    SR                  SR                  S U R                   5       5      5      $ )Nz[{0}]r   c              3   N   #    U  H  n[         R                  " U5      v   M     g 7frq   )rB   rC   ).0rs     r   	<genexpr>)OperationBatch.__str__.<locals>.<genexpr>   s       $8"6Qa"6s   #%)formatr"   rs   r   s    r   __str__OperationBatch.__str__   s1    >>$)) $8"&"6"6$8 8 9 9r   rr   N)r   r   r   r   r   r    ry   r}   r   r   r   r   r   r   r   rn   rn   }   s#    6..
&9r   rn   c                   4    \ rS rSrSrS	S jrS rS rS rSr	g)
BatchPoller   z Compute operations batch poller.Nc                     Xl         X l        UR                  U l        UR                  U l        U R
                  R                  R                  U l        X0l	        g)a  Initializes poller for compute operations.

Args:
  compute_adapter: googlecloudsdk.api_lib.compute.client_adapter
      .ClientAdapter.
  resource_service: apitools.base.py.base_api.BaseApiService,
      service representing the target of operation.
  target_refs: Resources, optional references to the expected targets of the
      operations. If not provided operation.targetLink will be used instead.
N)
_compute_adapter_resource_serviceapitools_client_clientr(   	_messagesr3   r4   _status_enum_target_refs)r#   compute_adapterr0   target_refss       r   r    BatchPoller.__init__   sH     ,-"22DL$--DN00FFD#r   c                     SnU H@  nUR                  U5      nU=(       a#    UR                  U R                  R                  :H  nMB     U$ )r:   T)r}   r;   r   r<   )r#   operation_batchis_donerF   rx   s        r   r?   BatchPoller.IsDone   sG    G( ,,];hEHOOt/@/@/E/EEg ) Nr   c                   ^  / n[        UR                  U 4S j5      5      nU H  n[        US5      (       a  T R                  R                  nO>[        US5      (       a  T R                  R
                  nOT R                  R                  nUR                  S5      nUR                  USU" S0 UR                  5       D645        M     / nT R                  R                  X'5      n[        X5       H\  u  pUR                  XI5        U	c  M  U	R                  (       d  M.  UR                  [        U	R                  R                   5      5        M^     U(       a  ["        R$                  " U5      eU$ )r:   c                 `   > U S L =(       d#    U R                   TR                  R                  :g  $ rq   )r;   r   r<   )r   r#   s    r   <lambda>"BatchPoller.Poll.<locals>.<lambda>   s&    !t)Aqxx4+<+<+A+AAAr   rO   rP   rQ   r   )listr   rR   r   rV   rW   rX   rU   appendrY   r   AsyncRequestsr   ry   r&   r   r$   core_exceptions
MultiError)
r#   r   requestsnot_donerF   rZ   rd   errors_to_collect	responsesrx   s
   `         r   r]   BatchPoller.Poll   s/   HO33AC DH!		'	',,--=(++,,//,,//++F3loow(N}7K7K7M(NOP " %%33HPI#&y#;!!-:		(...  1F1F!GH $<
 &&'899r   c                    / nU R                   R                  S5      nU R                  =(       dI    U Vs/ s H;  n[        R                  R                  UR                  U5      R                  5      PM=     snnU H5  nUR                  U R                   SU" S0 UR                  5       D645        M7     / nU R                  R                  X'5      nU(       a  [        R                  " U5      eU$ s  snf )r:   rM   r   )r   rU   r   r   ra   rb   r}   rc   r   rY   r   r   r   r   )	r#   r   r   rd   rF   r   r6   r   r   s	            r   re   BatchPoller.GetResult   s    H))88?L 	/ .	/-] 
			!	!''6AA
C-	/  "
oo

 
 


-**,
-/ 0 " %%33HPI&&'899	/s   AC1)r   r   r   r   r   r   rq   )
r   r   r   r   r   r    r?   r]   re   r   r   r   r   r   r      s    ($$:r   r   c                       \ rS rSrS rSrg)DeleteBatchPoller   c                     g rq   r   )r#   r   s     r   re   DeleteBatchPoller.GetResult   s     r   r   Nrl   r   r   r   r   r      s    r   r   )r   googlecloudsdk.api_lib.computer   r   googlecloudsdk.api_lib.utilr   googlecloudsdk.corer   r   rB   	six.movesr   r	   r   OperationPollerr-   rh   objectrn   r   r   r   r   r   <module>r      s    - 6 0 . = ) 
 &J &Ae A$AJV## AJH6 9V 94N&(( Nb r   