
                             S 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KJr  SSK	J
r
  S	rS
rSrSr " S S\5      r " S S\5      rg)z"Cloud Backup and DR API utilities.    )absolute_import)division)unicode_literalsN)apis)waiter)	resourcesbackupdrv1z;ResponseError: code={status_code}, message={status_message}zMRun [backup-dr operations describe {}] to check the status of this operation.c                   t    \ rS rSrSr\4S jr\S 5       r\S 5       r	S r
S\R                  " SS	94S
 jrSrg)BackupDrClientBase(   z1Base class for Backup and DR API client wrappers.c                     [         R                  " SU5      U l        [         R                  " SU5      U l        S U l        U R                  R                  U l        g )Nr	   )	r   GetClientInstance_clientGetMessagesModule	_messagesserviceclientprojects_locations_operationsoperations_service)selfapi_versions     +lib/googlecloudsdk/api_lib/backupdr/util.py__init__BackupDrClientBase.__init__+   sC    ))*kBDL++JDDNDL"kkGGD    c                     U R                   $ N)r   r   s    r   r   BackupDrClientBase.client1   s    <<r   c                     U R                   $ r   )r   r   s    r   messagesBackupDrClientBase.messages5   s    >>r   c                 n    UR                   c  g[        R                  R                  UR                   SS9$ )zKConverts an Operation to a Resource that can be used with `waiter.WaitFor`.Nonez&backupdr.projects.locations.operations)
collection)namer   REGISTRYParseRelativeName)r   	operations     r   GetOperationRef"BackupDrClientBase.GetOperationRef9   s7    ~~//#K 0  r   Ti  )secondsc                     U(       a,  [         R                  " U R                  U R                  5      nO [         R                  " U R                  5      n[         R
                  " XQX$R                  S-  S9$ )ao  Waits for an operation to complete.

Polls the Backup and DR Operation service until the operation completes,
fails, or
max_wait_seconds elapses.

Args:
  operation_ref: a Resource created by GetOperationRef describing the
    operation.
  message: the message to display to the user while they wait.
  has_result: if True, the function will return the target of the operation
    when it completes. If False, nothing will be returned (useful for Delete
    operations)
  max_wait: The time to wait for the operation to succeed before returning.

Returns:
  if has_result = True, a Backup and DR entity.
  Otherwise, None.
i  )max_wait_ms)r   CloudOperationPollerr   r   CloudOperationPollerNoResourcesWaitForr-   )r   operation_refmessage
has_resultmax_waitpollers         r   WaitForOperation#BackupDrClientBase.WaitForOperationA   s_    4 **
,,//f 55d6M6MNf>>w4D4Dt4K r   )r   r   r   r   N)__name__
__module____qualname____firstlineno____doc__DEFAULT_API_VERSIONr   propertyr   r"   r+   datetime	timedeltar8   __static_attributes__ r   r   r   r   (   sS    9!4 H     !!$/#r   r   c                   H   ^  \ rS rSrSrU 4S jrU 4S jrSU 4S jjrSrU =r	$ )RestrictedDictg   zNRestricted dict only allows specific keys, useful in creating a config object.c                 2   > [         TU ]  " U0 UD6  Xl        g r   )superr   allowed_keys)r   rJ   argskwargs	__class__s       r   r   RestrictedDict.__init__j   s    	Gd%f%$r   c                    > XR                   ;  a+  [        SU SSR                  U R                   5       S35      e[        TU ]  X5        g )Nz	The Key 'z' is not one of  [z, ])rJ   KeyErrorjoinrI   __setitem__)r   keyvaluerM   s      r   rS   RestrictedDict.__setitem__n   sN    
###cU,TYYt7H7H-I,J!
L  
G#r   c                 *  > U(       az  [        U[        5      (       a  UR                  5       OUn[        U5      [        U R                  5      -
  nU(       a+  [        SU SSR                  U R                  5       S35      e[        TU ]   " U40 UD6  g )Nz	The Keys z are not part of  [,rP   )	
isinstancedictkeyssetrJ   rQ   rR   rI   update)r   otherrL   
other_keysinvalid_keysrM   s        r   r]   RestrictedDict.updateu   s    #-eT#:#:5::<j_s4+<+<'==l	~ &$++,-Q0
 	
 
GN5#F#r   )rJ   r   )
r:   r;   r<   r=   r>   r   rS   r]   rC   __classcell__)rM   s   @r   rF   rF   g   s    V%$$ $r   rF   )r>   
__future__r   r   r   rA   googlecloudsdk.api_lib.utilr   r   googlecloudsdk.corer   DEFAULT_API_NAMEr?   HTTP_ERROR_FORMATASYNC_OPERATION_MESSAGEobjectr   rZ   rF   rD   r   r   <module>rj      sY    ) &  '  , . )   B 
. < <~$T $r   