
                             d Z ddlmZ ddlmZ ddlmZ ddlZddlmZ ddlmZ ddl	m
Z
 d	Zd
ZdZdZ G d de      Z G d de      Zy)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                   n    e Zd ZdZefdZed        Zed        Zd Z	d e
j                  d      fd	Zy
)BackupDrClientBasez1Base class for Backup and DR API client wrappers.c                     t        j                  d|      | _        t        j                  d|      | _        d | _        | j                  j                  | _        y )Nr	   )	r   GetClientInstance_clientGetMessagesModule	_messagesserviceclientprojects_locations_operationsoperations_service)selfapi_versions     +lib/googlecloudsdk/api_lib/backupdr/util.py__init__zBackupDrClientBase.__init__+   sC    ))*kBDL++JDDNDL"kkGGD    c                     | j                   S N)r   r   s    r   r   zBackupDrClientBase.client1   s    <<r   c                     | j                   S r   )r   r   s    r   messageszBackupDrClientBase.messages5   s    >>r   c                 r    |j                   yt        j                  j                  |j                   d      S )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   GetOperationRefz"BackupDrClientBase.GetOperationRef9   s7    ~~//#K 0  r   Ti  )secondsc                     |r+t        j                  | j                  | j                        }nt        j                  | j                        }t        j
                  ||||j                  dz        S )a  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   WaitForOperationz#BackupDrClientBase.WaitForOperationA   sc    4 **
,,//f 55d6M6MNf>>wH4D4Dt4K r   N)__name__
__module____qualname____doc__DEFAULT_API_VERSIONr   propertyr   r   r'   datetime	timedeltar3    r   r   r   r   (   sU    9!4 H     !x!!$/#r   r   c                   8     e Zd ZdZ fdZ fdZd fd	Z xZS )RestrictedDictzNRestricted dict only allows specific keys, useful in creating a config object.c                 2    t        |   |i | || _        y r   )superr   allowed_keys)r   rA   argskwargs	__class__s       r   r   zRestrictedDict.__init__j   s    	Gd%f%$Dr   c                     || j                   vr+t        d| ddj                  | j                          d      t        |   ||       y )Nz	The Key 'z' is not one of  [z, ])rA   KeyErrorjoinr@   __setitem__)r   keyvaluerD   s      r   rI   zRestrictedDict.__setitem__n   sR    
$###cU,TYYt7H7H-I,J!
L  
GU#r   c                 
   |rpt        |t              r|j                         n|}t        |      t        | j                        z
  }|r+t        d| ddj                  | j                         d      t        |    |fi | y )Nz	The Keys z are not part of  [,rF   )	
isinstancedictkeyssetrA   rG   rH   r@   update)r   otherrC   
other_keysinvalid_keysrD   s        r   rR   zRestrictedDict.updateu   s    #-eT#:5::<j_s4+<+<'==l	~ &$++,-Q0
 	
 
GN5#F#r   r   )r4   r5   r6   r7   r   rI   rR   __classcell__)rD   s   @r   r>   r>   g   s    V%$$ $r   r>   )r7   
__future__r   r   r   r:   googlecloudsdk.api_lib.utilr   r   googlecloudsdk.corer   DEFAULT_API_NAMEr8   HTTP_ERROR_FORMATASYNC_OPERATION_MESSAGEobjectr   rO   r>   r<   r   r   <module>r^      sY    ) &  '  , . )   B 
. < <~$T $r   