
    #                         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 G d de      Zy)zRCommands for interacting with the Cloud NetApp Files Volume Snapshot 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dZd Zy)SnapshotsClientzHWrapper for working with Snapshots in the Cloud NetApp Files API Client.c                 f   |t         j                  j                  k(  rt               | _        y |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ALPHAAlphaSnapshotsAdapter_adapterBETABetaSnapshotsAdapterGASnapshotsAdapter
ValueErrorformatnetapp_api_utilVERSION_MAP)selfrelease_tracks     =lib/googlecloudsdk/api_lib/netapp/volumes/snapshots/client.py__init__zSnapshotsClient.__init__!   s    ))///+-dm	$++00	0*,dm	$++..	.&(dm9@@

%
%m
46 7 7    c                 .    | j                   j                  S N)r   clientr   s    r   r#   zSnapshotsClient.client,   s    ==r    c                 .    | j                   j                  S r"   )r   messagesr$   s    r   r&   zSnapshotsClient.messages0   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 SnapshotsClient.WaitForOperation4   sL     >>..KK55	
 	%,,]-?-?-AB r    c                 @   | j                   j                  ||j                         |      }| j                  j                  j                  |      }|r|S t        j                  j                  |j                  t        j                        }| j                  |      S )z&Create a Cloud NetApp Volume Snapshot.)parent
snapshotIdsnapshot
collection)r&   4NetappProjectsLocationsVolumesSnapshotsCreateRequestr+   r#   $projects_locations_volumes_snapshotsCreater   REGISTRYParseRelativeNamenamer   OPERATIONS_COLLECTIONr-   )r   snapshot_ref
volume_refasync_configrequest	create_opr,   s           r   CreateSnapshotzSnapshotsClient.CreateSnapshotH   s     	JJ,*;*;*= 	K 	
 
 @@GGPI&&889#B#B 9 M   //r    Nc                 d    | j                   j                         }||_        ||_        ||_        |S )aS  Parses the command line arguments for Create Snapshot into a config.

    Args:
      name: the name of the Snapshot.
      description: the description of the Snapshot.
      labels: the parsed labels value.

    Returns:
      the configuration that will be used as the request body for creating a
      Cloud NetApp Files Snapshot.
    )r&   Snapshotr9   descriptionlabels)r   r9   rD   rE   r1   s        r   ParseSnapshotConfigz#SnapshotsClient.ParseSnapshotConfigW   s1     }}%%'HHM&HHOOr    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 active Cloud NetApp Volume Snapshots.

    Args:
      volume_ref: The parent Volume to list NetApp Volume Snapshots.
      limit: The number of Cloud NetApp Volume Snapshots 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 Volume Snapshots.
    )r/   zLocation {} may be unreachable.pageSize)fieldlimitbatch_size_attribute)r&   2NetappProjectsLocationsVolumesSnapshotsListRequestr#   r5   Listunreachabler   warningr   r   YieldFromListr   SNAPSHOT_RESOURCE)r   r<   rJ   r?   responselocations         r   ListSnapshotszSnapshotsClient.ListSnapshotsi   s     mmNN O G {{??DDWMH((	kk3::8DE )##88))' r    c                 z    | j                   j                  |j                               }| j                  ||      S )z1Deletes an existing Cloud NetApp Volume Snapshot.r9   )r&   4NetappProjectsLocationsVolumesSnapshotsDeleteRequestRelativeName_DeleteSnapshot)r   r;   r=   r?   s       r   DeleteSnapshotzSnapshotsClient.DeleteSnapshot   sB     	JJ**, 	K 	
 
 00r    c                     | j                   j                  j                  |      }|r|S t        j                  j                  |j                  t        j                        }| j                  |      S )Nr2   )
r#   r5   Deleter   r7   r8   r9   r   r:   r-   )r   r=   r?   	delete_opr,   s        r   rY   zSnapshotsClient._DeleteSnapshot   sa    @@GGPI&&889#B#B 9 DM  //r    c                     | j                   j                  |j                               }| j                  j                  j                  |      S )z&Get Cloud NetApp Snapshot information.rV   )r&   1NetappProjectsLocationsVolumesSnapshotsGetRequestrX   r#   r5   Get)r   r;   r?   s      r   GetSnapshotzSnapshotsClient.GetSnapshot   sC    mmMM&&( N *G;;;;??HHr    c                 >    | j                   j                  |||      S )a
  Parses updates into a snapshot config.

    Args:
      snapshot_config: The snapshot config to update.
      description: str, a new description, if any.
      labels: LabelsValue message, the new labels value, if any.

    Returns:
      The snapshot message.
    rD   rE   )r   ParseUpdatedSnapshotConfigr   snapshot_configrD   rE   s       r   rd   z*SnapshotsClient.ParseUpdatedSnapshotConfig   s)     ==33 4  r    c                     | j                   j                  |||      }|r|S t        j                  j	                  |j
                  t        j                        }| j                  |      S )aY  Updates a Cloud NetApp Snapshot.

    Args:
      snapshot_ref: the reference to the Snapshot.
      snapshot_config: Snapshot config, the updated snapshot.
      update_mask: str, a comma-separated list of updated fields.
      async_: bool, if False, wait for the operation to complete.

    Returns:
      an Operation or Volume message.
    r2   )	r   UpdateSnapshotr   r7   r8   r9   r   r:   r-   )r   r;   rf   update_maskr=   	update_opr,   s          r   rh   zSnapshotsClient.UpdateSnapshot   sd     ,,\?-8:I&&889#B#B 9 DM  //r    )NNNr"   NN)__name__
__module____qualname____doc__r
   r   r   r   propertyr#   r&   r-   rA   rF   rT   rZ   rY   ra   rd   rh    r    r   r   r      sw    P#'#4#4#:#: 	7     " "(0$210I .2(,&0r    r   c                   (    e Zd ZdZd Zd Z	 	 ddZy)r   z9Adapter for the Cloud NetApp Files API Snapshot resource.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SnapshotsAdapter.__init__   sN    **--D!33((DK $55((DMr    c                     | j                   j                  ||j                         |      }| j                  j                  j                  |      }|S )z3Send a Patch request for the Cloud NetApp Snapshot.)r1   r9   
updateMask)r&   3NetappProjectsLocationsVolumesSnapshotsPatchRequestrX   r#   r5   Patch)r   r;   rf   ri   update_requestrj   s         r   rh   zSnapshotsAdapter.UpdateSnapshot   sX     	II$**," 	J 	$ 
 @@FFIr    Nc                 *    |||_         |||_        |S )z:Parse update information into an updated Snapshot message.rc   re   s       r   rd   z+SnapshotsAdapter.ParseUpdatedSnapshotConfig   s&    
 $/o!%or    rk   )rl   rm   rn   ro   r   rh   rd   rq   r    r   r   r      s    A	 .2(,	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 Snapshot resource.c                     t         t        |           t        j                  j
                  | _        t        j                  | j                        | _	        t        j                  | j                        | _        y rt   )superr   r   r
   r   r   r   r   ru   r#   rv   r&   r   	__class__s    r   r   zBetaSnapshotsAdapter.__init__   s]    	
.0**//D!33((DK $55((DMr    rl   rm   rn   ro   r   __classcell__r   s   @r   r   r      s    F r    r   c                   "     e Zd ZdZ fdZ xZS )r   z?Adapter for the Alpha Cloud NetApp Files API Snapshot resource.c                     t         t        |           t        j                  j
                  | _        t        j                  | j                        | _	        t        j                  | j                        | _        y rt   )r   r   r   r
   r   r   r   r   ru   r#   rv   r&   r   s    r   r   zAlphaSnapshotsAdapter.__init__   s]    	
/1**00D!33((DK $55((DMr    r   r   s   @r   r   r      s    G r    r   N)ro   
__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   r   rq   r    r   <module>r      s_    Y &  ' ' 3 A . ( # )`0f `0F v  F+ 0 r    