
    N!                     R   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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.    )absolute_import)division)unicode_literals)
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)Poller4   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&   r3   r9   r:   s       r   r#   Poller.__init__7   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'   statusr8   DONEr&   	operations     r   IsDonePoller.IsDoneI   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.IsGlobalOrganizationOperationP   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=   rA   org--zorganizations/   Get)rA   parentIdzoneregionWaitr   )rJ   hasattrrA   r4   globalOrganizationOperationssplitrP   GetRequestTypezoneOperationsregionOperationsglobalOperationsrT   AsDict)r&   rI   service
token_list	parent_ids        r   PollPoller.PollT   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=   rP   rM   Nr   )
r3   rX   namer9   r	   REGISTRYParse
targetLinkrP   r\   )r&   rA   request_typer9   s       r   	GetResultPoller.GetResultj   s    ((77>L ~~&INN2 //
KY//55i6J6JK   $$\%HJ4E4E4G%HIIr   )r4   r:   r+   r3   r8   r9   )NF)r   r   r   r   r   r#   rB   rJ   r`   rh   r   r   r   r   r0   r0   4   s!    "#$5DB,Jr   r0   c                       \ rS rSrS rSrg)DeletePollerx   c                     g)r=   Nr   r@   s     r   rh   DeletePoller.GetResulty   s     r   r   Nr   r   r   r   rh   r   r   r   r   rk   rk   x   s    r   rk   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 rt   )rw   )r&   rI   responses      r   SetResponseOperationBatch.SetResponse   s    %-OOM"r   c                 8    U R                   R                  U5      $ rt   )rw   getrH   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rt   )rv   rw   r   )r&   response_funcops      r   GetWithResponseOperationBatch.GetWithResponse   s4     ""	t**2.	/	/ #s
   4A	Ac                 ,    [        U R                  5      $ rt   )iterrv   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rt   )rE   rF   ).0rs     r   	<genexpr>)OperationBatch.__str__.<locals>.<genexpr>   s       $8"6Qa"6s   #%)formatr%   rv   r   s    r   __str__OperationBatch.__str__   s1    >>$)) $8"&"6"6$8 8 9 9r   ru   N)r   r   r   r   r   r#   r|   r   r   r   r   r   r   r   r   rq   rq      s#    6..
&9r   rq   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+   	_messagesr6   r7   _status_enum_target_refs)r&   compute_adapterr3   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_donerI   r{   s        r   rB   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  $ rt   )r>   r   r?   )r   r&   s    r   <lambda>"BatchPoller.Poll.<locals>.<lambda>   s&    !t)Aqxx4+<+<+A+AAAr   rR   rS   rT   r   )listr   rU   r   rY   rZ   r[   rX   appendr\   r   AsyncRequestsr
   r|   r)   r   r'   core_exceptions
MultiError)
r&   r   requestsnot_donerI   r]   rg   errors_to_collect	responsesr{   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=   rP   r   )r   rX   r   r	   rd   re   r   rf   r   r\   r   r   r   r   )	r&   r   r   rg   rI   r   r9   r   r   s	            r   rh   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   rt   )
r   r   r   r   r   r#   rB   r`   rh   r   r   r   r   r   r      s    ($$:r   r   c                       \ rS rSrS rSrg)DeleteBatchPoller   c                     g rt   r   )r&   r   s     r   rh   DeleteBatchPoller.GetResult   s     r   r   Nro   r   r   r   r   r      s    r   r   )r   
__future__r   r   r   googlecloudsdk.api_lib.computer   r   googlecloudsdk.api_lib.utilr   googlecloudsdk.corer   r	   rE   	six.movesr
   r   r   OperationPollerr0   rk   objectrq   r   r   r   r   r   <module>r      s    - &  ' 5 0 . = ) 
 &J &Ae A$AJV## AJH6 9V 94N&(( Nb r   