
    H                         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)zUCommands for interacting with the Cloud NetApp Files Volume Replication 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d Zd Zd Z	 ddZd Zd Zy)ReplicationsClientzKWrapper for working with Replications 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BETABetaReplicationsAdapter_adapterALPHAAlphaReplicationsAdapterGAReplicationsAdapter
ValueErrorformatnetapp_api_utilVERSION_MAP)selfrelease_tracks     @lib/googlecloudsdk/api_lib/netapp/volumes/replications/client.py__init__zReplicationsClient.__init__!   s    ))...-/dm	$++11	1.0dm	$++..	.)+dm
,
3
3))-8     c                 .    | j                   j                  S N)r   clientr   s    r   r#   zReplicationsClient.client/   s    ==r    c                 .    | j                   j                  S r"   )r   messagesr$   s    r   r&   zReplicationsClient.messages3   s    ==!!!r    c                     t        j                  t        j                  | j                  j                        |dj                  |j                                     S )a  Wait 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#ReplicationsClient.WaitForOperation7   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*Creates a Cloud NetApp Volume Replication.)parentreplicationIdreplication
collection)r&   7NetappProjectsLocationsVolumesReplicationsCreateRequestr+   r#   'projects_locations_volumes_replicationsCreater   REGISTRYParseRelativeNamenamer   OPERATIONS_COLLECTIONr-   )r   replication_ref
volume_refasync_configrequest	create_opr,   s           r   CreateReplicationz$ReplicationsClient.CreateReplicationK   s     	MM)..0 	N 	
  CCJJI &&889#B#B 9 M   //r    Nc                     | j                   j                         }||_        ||_        ||_        ||_        | j                  j                  ||       ||_        |S )a?  Parse the command line arguments for Create Replication into a config.

    Args:
      name: the name of the Replication.
      description: the description of the Replication.
      labels: the parsed labels value.
      replication_schedule: the schedule for Replication.
      destination_volume_parameters: the input parameters used for creating
        destination volume.
      cluster_location: location of the user cluster, optional

    Returns:
      the configuration that will be used as the request body for creating a
      Cloud NetApp Files Replication.
    )	r&   Replicationr9   descriptionlabelsreplicationScheduler    ParseDestinationVolumeParametersclusterLocation)r   r9   rD   rE   replication_scheduledestination_volume_parameterscluster_locationr1   s           r   ParseReplicationConfigz)ReplicationsClient.ParseReplicationConfig^   s^    0 --++-KK)KK&:K#MM222 #3Kr    c                 f   | j                   j                  |      }| j                  j                  j	                  |      }|j
                  D ]&  }t        j                  dj                  |             ( t        j                  | j                  j                  |t        j                  |d      S )a{  List all active Cloud NetApp Volume Replications.

    Args:
      volume_ref: The parent Volume to list NetApp Volume Replications.
      limit: The number of Cloud NetApp Volume Replications 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 Replications.
    )r/   zLocation {} may be unreachable.pageSize)fieldlimitbatch_size_attribute)r&   5NetappProjectsLocationsVolumesReplicationsListRequestr#   r5   Listunreachabler   warningr   r   YieldFromListr   REPLICATION_RESOURCE)r   r<   rP   r?   responselocations         r   ListReplicationsz#ReplicationsClient.ListReplications   s     	KK 	L 	
  {{BBGGPH((	kk3::8DE )##;;,,' r    c                 z    | j                   j                  |j                               }| j                  ||      S )z3Delete an existing Cloud NetApp Volume Replication.r9   )r&   7NetappProjectsLocationsVolumesReplicationsDeleteRequestRelativeName_DeleteReplication)r   r;   r=   r?   s       r   DeleteReplicationz$ReplicationsClient.DeleteReplication   sB     	MM --/ 	N 	
 
 ""6733r    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   r_   z%ReplicationsClient._DeleteReplication   sg    CCJJI &&889#B#B 9 M   //r    c                     | j                   j                  |j                               }| j                  j                  j                  |      S )z5Get information of a Cloud NetApp Volume Replication.r\   )r&   4NetappProjectsLocationsVolumesReplicationsGetRequestr^   r#   r5   Get)r   r;   r?   s      r   GetReplicationz!ReplicationsClient.GetReplication   sJ     	JJ --/ 	K 	
 
 ;;>>BB7KKr    c                 B    | j                   j                  |||||      S )a  Parse updates into a replication config.

    Args:
      replication_config: The replication config to update.
      description: The new description, if any.
      labels: LabelsValue message, the new labels value, if any.
      replication_schedule: The new schedule for Replication, if any.
      cluster_location: location of the user cluster, if any.

    Returns:
      The replication message.
    )rD   rE   rI   rK   )r   ParseUpdatedReplicationConfigr   replication_configrD   rE   rI   rK   s         r   ri   z0ReplicationsClient.ParseUpdatedReplicationConfig   s-      ==66F1) 7  r    c                     | j                   j                  |||      }|r|S t        j                  j	                  |j
                  t        j                        }| j                  |      S )aq  Update a Cloud NetApp Volume Replication.

    Args:
      replication_ref: the reference to the Replication.
      replication_config: Replication config, the updated replication.
      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   UpdateReplicationr   r7   r8   r9   r   r:   r-   )r   r;   rk   update_maskr=   	update_opr,   s          r   rm   z$ReplicationsClient.UpdateReplication   sh     //+[I &&889#B#B 9 M   //r    c                     | j                   j                  |      }|r|S t        j                  j	                  |j
                  t        j                        }| j                  |      S )zResume a Cloud NetApp Volume Replication.

    Args:
      replication_ref: the reference to the Replication.
      async_: bool, if False, wait for the operation to complete.

    Returns:
      an Operation or Volume message.
    r2   )	r   ResumeReplicationr   r7   r8   r9   r   r:   r-   )r   r;   r=   	resume_opr,   s        r   rq   z$ReplicationsClient.ResumeReplication   s^     //@I&&889#B#B 9 M   //r    c                     | j                   j                  |      }|r|S t        j                  j	                  |j
                  t        j                        }| j                  |      S )aY  Reverse the direction of a Cloud NetApp Volume Replication.

    Args:
      replication_ref: the reference to the Replication.
      async_: bool, if False, wait for the operation to complete.

    Returns:
      an Operation if async_ is set to true, or a Replication message if the
      ReverseReplicationDirectionRequest is successful.
    r2   )	r   ReverseReplicationr   r7   r8   r9   r   r:   r-   )r   r;   r=   
reverse_opr,   s        r   rt   z%ReplicationsClient.ReverseReplication   s^     11/BJ&&88I$C$C 9 M   //r    c                     | j                   j                  ||      }|r|S t        j                  j	                  |j
                  t        j                        }| j                  |      S )aB  Stop a Cloud NetApp Volume Replication.

    Args:
      replication_ref: the reference to the Replication.
      async_: bool, if False, wait for the operation to complete.
      force: bool, if True, call stop Replication with force parameter set to
        True.

    Returns:
      an Operation or Volume message.
    r2   )	r   StopReplicationr   r7   r8   r9   r   r:   r-   )r   r;   r=   forcestop_opr,   s         r   rw   z"ReplicationsClient.StopReplication  s_     mm++OUCGn&&88!@!@ 9 M   //r    c                 >    | j                   j                  ||||      S )a  Parse the command line arguments for Establish Peering into a config.

    Args:
      peer_cluster_name: the name of the peer cluster.
      peer_svm_name: the name of the peer svm.
      peer_volume_name: the name of the peer volume.
      peer_ip_addresses: the ip addresses of the peer cluster.

    Returns:
      the configuration that will be used as the request body for establishing
      peering for Hybrid Replication.
    )r   "ParseEstablishPeeringRequestConfig)r   peer_cluster_namepeer_svm_namepeer_volume_namepeer_ip_addressess        r   r{   z5ReplicationsClient.ParseEstablishPeeringRequestConfig%  s&    & ==;;=*:<M r    c                     | j                   j                  ||      }|r|S t        j                  j	                  |j
                  t        j                        }| j                  |      S )aY  Establish a peering for a Cloud NetApp Volume Replication.

    Args:
      replication_ref: the reference to the Replication.
      establish_peering_request_config: the request configuration to establish
        peering.
      async_: bool, if False, wait for the operation to complete.

    Returns:
      an Operation or Volume message.
    r2   )	r   EstablishPeeringr   r7   r8   r9   r   r:   r-   )r   r;    establish_peering_request_configr=   establish_opr,   s         r   r   z#ReplicationsClient.EstablishPeering<  sh     ==119L &&88i&E&E 9 M   //r    c                     | j                   j                  |      }|r|S t        j                  j	                  |j
                  t        j                        }| j                  |      S )zSync a Cloud NetApp Volume Replication.

    Args:
      replication_ref: the reference to the Replication.
      async_: bool, if False, wait for the operation to complete.

    Returns:
      an Operation or Volume message.
    r2   )	r   SyncReplicationr   r7   r8   r9   r   r:   r-   )r   r;   r=   sync_opr,   s        r   r   z"ReplicationsClient.SyncReplicationT  s]     mm++O<Gn&&88!@!@ 9 M   //r    )NNNNNNr"   NNNN)__name__
__module____qualname____doc__r
   r   r   r   propertyr#   r&   r-   rA   rL   rZ   r`   r_   rg   ri   rm   rq   rt   rw   r{   r   r    r    r   r   r      s    S#'#4#4#9#9      " "(0* $(!F84	0L :>26,000(0*02 .000r    r   c                   R    e Zd ZdZd Zd Zd Z	 	 ddZd Zd Z	d	 Z
d
 Zd Zd Zy)r   z<Adapter for the Cloud NetApp Files API Replication 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ReplicationsAdapter.__init__j  sN    **--D!33((DK $55((DMr    c                    |sy| j                   j                         }|j                         D ]  \  }}|dk(  r||_        |dk(  r||_         |dk(  r||_        -|dk(  r||_        :|dk(  r)| j                   j                  |d   |d   	      |_        ht        j                  d
j                  |              ||_        y)aO  Parses Destination Volume Parameters for Replication into a config.

    Args:
      replication: The Cloud Netapp Volumes Replication object.
      destination_volume_parameters: The Destination Volume Parameters message
        object.

    Returns:
      Replication message populated with Destination Volume Parameters values.
    Nstorage_pool	volume_id
share_namerD   tiering_policyztier-actionzcooling-threshold-days)
tierActioncoolingThresholdDaysz#The attribute {} is not recognized.)r&   DestinationVolumeParametersitemsstoragePoolvolumeId	shareNamerD   TieringPolicytieringPolicyr   rU   r   destinationVolumeParameters)r   r1   rJ   
parameterskeyvals         r   rG   z4ReplicationsAdapter.ParseDestinationVolumeParameterss  s     )::<J1779S		!$
+!
,"
-!$
""#'==#>#>=)!$%=!> $? $

 
 	9@@EF :  /9K+r    c                     | j                   j                  ||j                         |      }| j                  j                  j                  |      }|S )z=Send a Patch request for the Cloud NetApp Volume Replication.)r1   r9   
updateMask)r&   6NetappProjectsLocationsVolumesReplicationsPatchRequestr^   r#   r5   Patch)r   r;   rk   rn   update_requestro   s         r   rm   z%ReplicationsAdapter.UpdateReplication  sZ     	LL* --/" 	M 	
  CCIII r    Nc                 N    |||_         |||_        |||_        |||_        |S )z=Parse update information into an updated Replication message.)rD   rE   rF   rH   rj   s         r   ri   z1ReplicationsAdapter.ParseUpdatedReplicationConfig  sF    
 '2$"('/C,#+;(r    c                     | j                   j                  |j                               }| j                  j                  j                  |      S )z>Send a resume request for the Cloud NetApp Volume Replication.r\   )r&   7NetappProjectsLocationsVolumesReplicationsResumeRequestr^   r#   r5   Resume)r   r;   resume_requests      r   rq   z%ReplicationsAdapter.ResumeReplication  sO     	MM --/ 	N 	
 
 ;;>>EE r    c                     | j                   j                  |j                               }| j                  j                  j                  |      S )z?Send a reverse request for the Cloud NetApp Volume Replication.r\   )r&   ANetappProjectsLocationsVolumesReplicationsReverseDirectionRequestr^   r#   r5   ReverseDirection)r   r;   reverse_requests      r   rt   z&ReplicationsAdapter.ReverseReplication  sO     	WW --/ 	X 	
 
 ;;>>OO r    c                     | j                   j                  |j                         | j                   j                  |            }| j                  j
                  j                  |      S )z<Send a stop request for the Cloud NetApp Volume Replication.)rx   )r9   stopReplicationRequest)r&   5NetappProjectsLocationsVolumesReplicationsStopRequestr^   StopReplicationRequestr#   r5   Stop)r   r;   rx   stop_requests       r   rw   z#ReplicationsAdapter.StopReplication  sj     	KK --/#'==#G#G $H $ 	L 	
  ;;>>CC r    c                 L    | j                   j                  ||||r|ng       }|S )zHParse establish peering request for the Cloud NetApp Volume Replication.)peerClusterNamepeerSvmNamepeerVolumeNamepeerIpAddresses)r&   EstablishPeeringRequest)r   r|   r}   r~   r   establish_peering_requests         r   r{   z6ReplicationsAdapter.ParseEstablishPeeringRequestConfig  s8     !% E E)!'->)B	 !F ! %$r    c                     | j                   j                  |j                         |      }| j                  j                  j                  |      S )zISend a establish peering request for the Cloud NetApp Volume Replication.)r9   establishPeeringRequest)r&   ANetappProjectsLocationsVolumesReplicationsEstablishPeeringRequestr^   r#   r5   r   )r   r;   r   r   s       r   r   z$ReplicationsAdapter.EstablishPeering  sR     	WW --/$D 	X 	
  ;;>>OO! r    c                     | j                   j                  |j                               }| j                  j                  j                  |      S )z<Send a sync request for the Cloud NetApp Volume Replication.r\   )r&   5NetappProjectsLocationsVolumesReplicationsSyncRequestr^   r#   r5   Sync)r   r;   sync_requests      r   r   z#ReplicationsAdapter.SyncReplication  sO     	KK --/ 	L 	
 
 ;;>>CC r    r   )r   r   r   r   r   rG   rm   ri   rq   rt   rw   r{   r   r   r   r    r   r   r   g  s@    D 9D :>26		% 
	r    r   c                   "     e Zd ZdZ fdZ xZS )r   zAAdapter for the Beta Cloud NetApp Files API Replication resource.c                     t         t        |           t        j                  j
                  | _        t        j                  | j                        | _	        t        j                  | j                        | _        y r   )superr   r   r
   r   r   r   r   r   r#   r   r&   r   	__class__s    r   r   z BetaReplicationsAdapter.__init__  s]    	
!413**//D!33((DK $55((DMr    r   r   r   r   r   __classcell__r   s   @r   r   r     s    I r    r   c                   "     e Zd ZdZ fdZ xZS )r   zBAdapter for the Alpha Cloud NetApp Files API Replication resource.c                     t         t        |           t        j                  j
                  | _        t        j                  | j                        | _	        t        j                  | j                        | _        y r   )r   r   r   r
   r   r   r   r   r   r#   r   r&   r   s    r   r   z!AlphaReplicationsAdapter.__init__  s]    	
"D24**00D!33((DK $55((DMr    r   r   s   @r   r   r     s    J r    r   N)r   
__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   r   r    r   <module>r      sa    \ &  ' ' 3 A . ( # )F0 F0R
T& Tn1 6 r    