
    D                          d Z ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlm	Z
 ddlmZ dd	lmZ dd
lmZ ddlmZ  G d de      Z G d de      Z G d de      Zy)zJCommands for interacting with the Cloud NetApp Files Backups API resource.    )absolute_import)division)unicode_literals)
list_pager)	constants)util)waiter)base)log)	resourcesc                       e Zd ZdZej
                  j                  fdZed        Z	ed        Z
d Zd Z	 	 	 	 	 ddZdd	Zd
 Zd Zd Zd Z	 	 ddZy)BackupsClientzFWrapper for working with Backups in the Cloud NetApp Files API Client.c                    |t         j                  j                  k(  rt               | _        y |t         j                  j
                  k(  rt               | _        y t        dj                  t        j                  |               )Nz [{}] is not a valid API version.)r
   ReleaseTrackBETABetaBackupsAdapter_adapterGABackupsAdapter
ValueErrorformatnetapp_utilVERSION_MAP)selfrelease_tracks     Alib/googlecloudsdk/api_lib/netapp/backup_vaults/backups/client.py__init__zBackupsClient.__init__!   sg    ))...(*dm	$++..	.$&dm9@@

!
!-
02 3 3    c                 .    | j                   j                  S N)r   clientr   s    r   r!   zBackupsClient.client*   s    ==r   c                 .    | j                   j                  S r    )r   messagesr"   s    r   r$   zBackupsClient.messages.   s    ==!!!r   c                     t        j                  t        j                  | j                  j                        |dj                  |j                                     S )a  Waits on the long-running operation until the done field is True.

    Args:
      operation_ref: The operation reference.

    Returns:
      The 'response' field of the Operation.

    Raises:
      waiter.OperationError: If the operation contains an error.
    zWaiting for [{0}] to finish)r	   WaitForCloudOperationPollerNoResourcesr!   projects_locations_operationsr   Name)r   operation_refs     r   WaitForOperationzBackupsClient.WaitForOperation2   sL     >>..KK55	
 	%,,]-?-?-AB r   c                 x   | j                   j                  |j                         j                         |j	                         |      }| j
                  j                  j                  |      }|r|S t        j                  j                  |j                  t        j                        }| j                  |      S )zCreate a Cloud NetApp Backup.)parentbackupIdbackup
collection)r$   7NetappProjectsLocationsBackupVaultsBackupsCreateRequestParentRelativeNamer)   r!   'projects_locations_backupVaults_backupsCreater   REGISTRYParseRelativeNamenamer   OPERATIONS_COLLECTIONr+   )r   
backup_refasync_r/   request	create_opr*   s          r   CreateBackupzBackupsClient.CreateBackupF   s     	MM$$&335__& 	N 	
  CCJJI &&889#B#B 9 M   //r   Nc                     | j                   j                         }||_        ||_        ||_        ||_        ||_        |S )a  Parses the command line arguments for Create Backup into a message.

    Args:
      name: The name of the Backup.
      source_snapshot: The Source Snapshot of the Backup.
      source_volume: The Source Volume of the Backup.
      description: The description of the Backup.
      labels: The parsed labels value.

    Returns:
      The configuration that will be used ass the request body for creating a
      Cloud NetApp Backup.
    )r$   Backupr9   sourceSnapshotsourceVolumedescriptionlabels)r   r9   source_snapshotsource_volumerD   rE   r/   s          r   ParseBackupzBackupsClient.ParseBackupY   sA    * ]]!!#FFK+F'F$FFMMr   c                 f   | j                   j                  |      }| j                  j                  j	                  |      }|j
                  D ]&  }t        j                  dj                  |             ( t        j                  | j                  j                  |t        j                  |d      S )ac  Make API calls to List Cloud NetApp Backups.

    Args:
      backupvault_ref: The parsed Backup Vault of the listed NetApp Backups.
      limit: The number of Cloud NetApp Backups to limit the results to.
        This limit is passed to the server and the server does the limiting.

    Returns:
      Generator that yields the Cloud NetApp Backups.
    )r-   zLocation {} may be unreachable.pageSize)fieldlimitbatch_size_attribute)r$   5NetappProjectsLocationsBackupVaultsBackupsListRequestr!   r5   Listunreachabler   warningr   r   YieldFromListr   BACKUP_RESOURCE)r   backupvault_refrL   r=   responselocations         r   ListBackupszBackupsClient.ListBackupsv   s     	KK" 	L 	
  {{BBGGPH((	kk3::8DE )##;;''' r   c                     | j                   j                  |j                               }| j                  j                  j                  |      S )z$Get Cloud NetApp Backup information.r9   )r$   4NetappProjectsLocationsBackupVaultsBackupsGetRequestr4   r!   r5   Get)r   r;   r=   s      r   	GetBackupzBackupsClient.GetBackup   sJ     	JJ((* 	K 	
 
 ;;>>BB7KKr   c                 z    | j                   j                  |j                               }| j                  ||      S )z(Deletes an existing Cloud NetApp Backup.rY   )r$   7NetappProjectsLocationsBackupVaultsBackupsDeleteRequestr4   _DeleteBackup)r   r;   r<   r=   s       r   DeleteBackupzBackupsClient.DeleteBackup   sB     	MM((* 	N 	
 
 fg..r   c                     | j                   j                  j                  |      }|r|S t        j                  j                  |j                  t        j                        }| j                  |      S )Nr0   )
r!   r5   Deleter   r7   r8   r9   r   r:   r+   )r   r<   r=   	delete_opr*   s        r   r_   zBackupsClient._DeleteBackup   sg    CCJJI &&889#B#B 9 M   //r   c                     | j                   j                  |||      }|r|S t        j                  j	                  |j
                  t        j                        }| j                  |      S )a@  Updates a Backup.

    Args:
      backup_ref: The reference to the Backup.
      backup: Backup message, the updated Backup.
      update_mask: str, a comma-separated list of updated fields.
      async_: bool, if False, wait for the operation to complete.

    Returns:
      an Operation or Backup Vault message.
    r0   )	r   UpdateBackupr   r7   r8   r9   r   r:   r+   )r   r;   r/   update_maskr<   	update_opr*   s          r   re   zBackupsClient.UpdateBackup   sg     **FKI &&889#B#B 9 M   //r   c                 >    | j                   j                  |||      S )zParses updates into a Backup.rD   rE   )r   ParseUpdatedBackupr   r/   rD   rE   s       r   rj   z BackupsClient.ParseUpdatedBackup   s)     ==++ ,  r   )NNNNNr    NN)__name__
__module____qualname____doc__r
   r   r   r   propertyr!   r$   r+   r?   rH   rW   r\   r`   r_   re   rj    r   r   r   r      s    N#'#4#4#9#9 3     " "(0* :8L/	006 	r   r   c                   (    e Zd ZdZd Z	 	 ddZd Zy)r   z6Adapter for the GA Cloud NetApp Files API for Backups.c                     t         j                  j                  | _        t	        j
                  | j                        | _        t	        j                  | j                        | _        y N)r   )	r
   r   r   r   r   GetClientInstancer!   GetMessagesModuler$   r"   s    r   r   zBackupsAdapter.__init__   sN    **--D//((DK  11((DMr   Nc                 *    |||_         |||_        |S )z!Parses updates into a new Backup.ri   rk   s       r   rj   z!BackupsAdapter.ParseUpdatedBackup   s$     &ffmMr   c                     | j                   j                  ||j                         |      }| j                  j                  j                  |      }|S )z1Send a Patch request for the Cloud NetApp Backup.)r/   r9   
updateMask)r$   6NetappProjectsLocationsBackupVaultsBackupsPatchRequestr4   r!   r5   Patch)r   r;   r/   rf   update_requestrg   s         r   re   zBackupsAdapter.UpdateBackup   sX     	LL((*" 	M 	$ 
 CCIIIr   rl   )rm   rn   ro   rp   r   rj   re   rr   r   r   r   r      s    > 		r   r   c                   "     e Zd ZdZ fdZ xZS )r   z8Adapter for the Beta Cloud NetApp Files API for Backups.c                     t         t        |           t        j                  j
                  | _        t        j                  | j                        | _	        t        j                  | j                        | _        y ru   )superr   r   r
   r   r   r   r   rv   r!   rw   r$   )r   	__class__s    r   r   zBetaBackupsAdapter.__init__   s]    	
d,.**//D//((DK  11((DMr   )rm   rn   ro   rp   r   __classcell__)r   s   @r   r   r      s    @ r   r   N)rp   
__future__r   r   r   apitools.base.pyr   googlecloudsdk.api_lib.netappr   r   r   googlecloudsdk.api_lib.utilr	   googlecloudsdk.callioper
   googlecloudsdk.corer   r   objectr   r   r   rr   r   r   <module>r      sQ    Q &  ' ' 3 = . ( # )tF tn"V "J r   