
    %                         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)zPCommands for interacting with the Cloud NetApp Files Backup Policy 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)BackupPoliciesClientzNWrapper for working with Backup Policies 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BetaBackupPoliciesAdapter_adapterGABackupPoliciesAdapter
ValueErrorformatnetapp_utilVERSION_MAP)selfrelease_tracks     ;lib/googlecloudsdk/api_lib/netapp/backup_policies/client.py__init__zBackupPoliciesClient.__init__!   sg    )).../1dm	$++..	.+-dm9@@

!
!-
02 3 3    c                 .    | j                   j                  S N)r   clientr   s    r   r!   zBackupPoliciesClient.client*   s    ==r   c                 .    | j                   j                  S r    )r   messagesr"   s    r   r$   zBackupPoliciesClient.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.

    Raises:
      waiter.OperationError: if the operation contains an error.

    Returns:
      the 'response' field of the Operation.
    zWaiting for [{0}] to finish)r	   WaitForCloudOperationPollerNoResourcesr!   projects_locations_operationsr   Name)r   operation_refs     r   WaitForOperationz%BackupPoliciesClient.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 Policy.)parentbackupPolicyIdbackupPolicy
collection)r$   2NetappProjectsLocationsBackupPoliciesCreateRequestParentRelativeNamer)   r!   !projects_locations_backupPoliciesCreater   REGISTRYParseRelativeNamenamer   OPERATIONS_COLLECTIONr+   )r   backuppolicy_refasync_backup_policyrequest	create_opr*   s          r   CreateBackupPolicyz'BackupPoliciesClient.CreateBackupPolicyF   s    mmNN&&(557',,." O G
 ==DDWMI&&889#B#B 9 M   //r   Nc                     | j                   j                         }||_        ||_        ||_        ||_        ||_        ||_        ||_        |S )a  Parses the command line arguments for Create Backup Policy into a message.

    Args:
      name: the name of the Backup Policy
      enabled: the Boolean value indicating whether or not backups are made
        automatically according to schedule.
      daily_backup_limit: the number of daily backups to keep.
      weekly_backup_limit: the number of weekly backups to keep.
      monthly_backup_limit: the number of monthly backups to keep.
      description: the description of the Backup Policy.
      labels: the parsed labels value

    Returns:
      The configuration that will be used as the request body for creating a
      Cloud NetApp Backup Policy.
    )	r$   BackupPolicyr9   enableddailyBackupLimitweeklyBackupLimitmonthlyBackupLimitdescriptionlabels)	r   r9   rC   daily_backup_limitweekly_backup_limitmonthly_backup_limitrG   rH   r=   s	            r   ParseBackupPolicyz&BackupPoliciesClient.ParseBackupPolicyU   sT    4 MM..0MM#M%7M"&9M#';M$ +M!Mr   c                 f   | j                   j                  |      }| j                  j                  j	                  |      }|j
                  D ]&  }t        j                  dj                  |             ( t        j                  | j                  j                  |t        j                  |d      S )a  Make API calls to List Cloud NetApp Backup Policies.

    Args:
      location_ref: The parsed location of the listed NetApp Backup Policies.
      limit: The number of Cloud NetApp Backup Policies
        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 Backup Policies.
    )r-   zLocation {} may be unreachable.pageSize)fieldlimitbatch_size_attribute)r$   0NetappProjectsLocationsBackupPoliciesListRequestr!   r5   Listunreachabler   warningr   r   YieldFromListr   BACKUP_POLICY_RESOURCE)r   location_refrP   r>   responselocations         r   ListBackupPoliciesz'BackupPoliciesClient.ListBackupPoliciesy   s     mmLL M G {{<<AA'JH((	kk3::8DE )##55..') )r   c                     | j                   j                  |j                               }| j                  j                  j                  |      S )z+Get Cloud NetApp Backup Policy information.r9   )r$   /NetappProjectsLocationsBackupPoliciesGetRequestr4   r!   r5   Get)r   r;   r>   s      r   GetBackupPolicyz$BackupPoliciesClient.GetBackupPolicy   sC    mmKK**, L .G;;88<<WEEr   c                 z    | j                   j                  |j                               }| j                  ||      S )z/Deletes an existing Cloud NetApp Backup Policy.r]   )r$   2NetappProjectsLocationsBackupPoliciesDeleteRequestr4   _DeleteBackupPolicy)r   r;   r<   r>   s       r   DeleteBackupPolicyz'BackupPoliciesClient.DeleteBackupPolicy   sB     	HH!..0 	I 	
 
 ##FG44r   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   rc   z(BackupPoliciesClient._DeleteBackupPolicy   sb    ==DDWMI&&889#B#B 9 M   //r   c                     | j                   j                  |||      }|r|S t        j                  j	                  |j
                  t        j                        }| j                  |      S )ai  Updates a Backup Policy.

    Args:
      backuppolicy_ref: the reference to the Backup Policy.
      backup_policy: Backup Policy message, the updated Backup Policy.
      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 Policy message.
    r0   )	r   UpdateBackupPolicyr   r7   r8   r9   r   r:   r+   )r   r;   r=   update_maskr<   	update_opr*   s          r   ri   z'BackupPoliciesClient.UpdateBackupPolicy   sg     00-I &&889#B#B 9 M   //r   c           	      F    | j                   j                  |||||||      S )z%Parses updates into an Backup Policy.)r=   rC   rI   rJ   rK   rG   rH   )r   ParseUpdatedBackupPolicy)r   r=   rC   rI   rJ   rK   rG   rH   s           r   rm   z-BackupPoliciesClient.ParseUpdatedBackupPolicy   s5     ==11#-/1 2  r   )NNNNNNNr    NNNNNN)__name__
__module____qualname____doc__r
   r   r   r   propertyr!   r$   r+   r@   rL   r[   r`   rd   rc   ri   rm    r   r   r   r      s    V#'#4#4#9#9 3     " "(0" "H)2F5004 r   r   c                   (    e Zd ZdZd Z	 	 ddZd Zy)r   z>Adapter for the GA Cloud NetApp Files API for Backup Policies.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BackupPoliciesAdapter.__init__   sN    **--D//((DK  11((DMr   Nc                 r    |||_         |||_        |||_        |||_        |||_        |||_        |S )z(Parses updates into a new Backup Policy.)rC   rD   rE   rF   rG   rH   )r   r=   rI   rJ   rK   rC   rG   rH   s           r   rm   z.BackupPoliciesAdapter.ParseUpdatedBackupPolicy   s^    
 %m%'9m$&(;m%')=m&"-m#mr   c                     | j                   j                  ||j                         |      }| j                  j                  j                  |      }|S )z8Send a Patch request for the Cloud NetApp Backup Policy.)r/   r9   
updateMask)r$   1NetappProjectsLocationsBackupPoliciesPatchRequestr4   r!   r5   Patch)r   r;   r=   rj   update_requestrk   s         r   ri   z(BackupPoliciesAdapter.UpdateBackupPolicy   sX     	GG&!..0" 	H 	$ 
 ==CCIr   rn   )ro   rp   rq   rr   r   rm   ri   rt   r   r   r   r      s    F IMHL&	r   r   c                   "     e Zd ZdZ fdZ xZS )r   z@Adapter for the Beta Cloud NetApp Files API for Backup Policies.c                     t         t        |           t        j                  j
                  | _        t        j                  | j                        | _	        t        j                  | j                        | _        y rw   )superr   r   r
   r   r   r   r   rx   r!   ry   r$   )r   	__class__s    r   r   z"BetaBackupPoliciesAdapter.__init__  s]    	
#T35**//D//((DK  11((DMr   )ro   rp   rq   rr   r   __classcell__)r   s   @r   r   r     s    H r   r   N)rr   
__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   rt   r   r   <module>r      sR    W &  ' ' 3 = . ( # )v6 vr(F (V 5 r   