
    C                     Z    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  G d de	      Z
y	)
z6API utilities for gcloud compute vpn-tunnels commands.    )absolute_import)division)unicode_literals)poller)waiterc                       e Zd ZdZd Zed        Zed        Zed        Z	 	 ddZ		 	 	 ddZ
	 	 	 	 dd	Z	 	 	 	 	 	 dd
Z	 	 	 	 ddZ	 	 	 ddZd Zd Zd Zd ZddZd Zy)VpnTunnelHelperz1Helper for VPN tunnel service in the Compute API.c                 H    |j                   | _        |j                  | _        y)zInitializes the helper for VPN tunnel operations.

    Args:
      holder: Object representing the Compute API holder instance.
    N)client_compute_client	resources
_resources)selfholders     Clib/googlecloudsdk/api_lib/compute/vpn_tunnels/vpn_tunnels_utils.py__init__zVpnTunnelHelper.__init__   s     "==D&&DO    c                 .    | j                   j                  S N)r   apitools_clientr   s    r   _clientzVpnTunnelHelper._client%   s    ///r   c                 .    | j                   j                  S r   )r   messagesr   s    r   	_messageszVpnTunnelHelper._messages)   s    (((r   c                 .    | j                   j                  S r   )r   
vpnTunnelsr   s    r   _servicezVpnTunnelHelper._service-   s    <<"""r   Nc                 h    |||||||||	|
|d}|r|||d<    | j                   j                  di |S )a  Returns the HA VpnTunnel message for an insert request.

    Args:
      name: String representing the name of the VPN tunnel resource.
      description: String representing the description for the VPN tunnel
        resource.
      ike_version: The IKE protocol version for establishing the VPN tunnel.
      peer_ip: String representing the peer IP address for the VPN tunnel.
      shared_secret: String representing the shared secret (IKE pre-shared key).
      vpn_gateway: String representing the VPN Gateway URL the VPN tunnel
        resource should be associated with.
      vpn_gateway_interface: Integer representing the VPN Gateway interface ID
        that VPN tunnel resource should be associated with.
      router: String representing the Router URL the VPN tunnel resource should
        be associated with.
      peer_external_gateway: String representing of the peer side external VPN
        gateway to which the VPN tunnel is connected.
      peer_external_gateway_interface: Interface ID of the External VPN gateway
        to which this VPN tunnel is connected.
      peer_gcp_gateway:  String representing of peer side HA GCP VPN gateway to
        which this VPN tunnel is connected.
      params: Dictionary of params to set on the request.
      support_tagging_at_creation: Boolean representing the support of tagging
        at creation.

    Returns:
      The VpnTunnel message object that can be used in an insert request.
    )namedescription
ikeVersionpeerIpsharedSecret
vpnGatewayvpnGatewayInterfacerouterpeerExternalGatewaypeerExternalGatewayInterfacepeerGcpGatewayparams r   	VpnTunnel)r   r    r!   ike_versionpeer_ipshared_secretvpn_gatewayvpn_gateway_interfacer'   peer_external_gatewaypeer_external_gateway_interfacepeer_gcp_gatewayr+   support_tagging_at_creationvpn_tunnel_argss                  r   %GetHighAvailabilityVpnTunnelForInsertz5VpnTunnelHelper.GetHighAvailabilityVpnTunnelForInsert1   sb    Z "!%!44(G*O 	$(:"(oh#4>>## 
 r   c                 j    |||||||||	|
||d}|r|||d<    | j                   j                  di |S )a  Returns the HA VpnTunnel message for an insert request.

    Args:
      name: String representing the name of the VPN tunnel resource.
      description: String representing the description for the VPN tunnel
        resource.
      ike_version: The IKE protocol version for establishing the VPN tunnel.
      peer_ip: String representing the peer IP address for the VPN tunnel.
      shared_secret: String representing the shared secret (IKE pre-shared key).
      vpn_gateway: String representing the VPN Gateway URL the VPN tunnel
        resource should be associated with.
      vpn_gateway_interface: Integer representing the VPN Gateway interface ID
        that VPN tunnel resource should be associated with.
      router: String representing the Router URL the VPN tunnel resource should
        be associated with.
      peer_external_gateway: String representing of the peer side external VPN
        gateway to which the VPN tunnel is connected.
      peer_external_gateway_interface: Interface ID of the External VPN gateway
        to which this VPN tunnel is connected.
      peer_gcp_gateway:  String representing of peer side HA GCP VPN gateway to
        which this VPN tunnel is connected.
      cipher_suite: String representing the cipher suite to use for the VPN
        tunnel.
      params: Dictionary of params to set on the request.
      support_tagging_at_creation: Boolean representing the support of tagging
        at creation.

    Returns:
      The VpnTunnel message object that can be used in an insert request.
    )r    r!   r"   r#   r$   r%   r&   r'   r(   r)   r*   cipherSuiter+   r,   r-   )r   r    r!   r/   r0   r1   r2   r3   r'   r4   r5   r6   cipher_suiter+   r7   r8   s                   r   4GetHighAvailabilityVpnTunnelForInsertWithCipherSuitezDVpnTunnelHelper.GetHighAvailabilityVpnTunnelForInsertWithCipherSuiteq   se    ` "!%!44(G*#O 	$(:"(oh#4>>## 
 r   c           	      r    |||||||xs g |xs g d}|
r|	|	|d<    | j                   j                  di |S )az  Returns the Classic VpnTunnel message for an insert request.

    Args:
      name: String representing the name of the VPN tunnel resource.
      description: String representing the description for the VPN tunnel
        resource.
      ike_version: The IKE protocol version for establishing the VPN tunnel.
      peer_ip: String representing the peer IP address for the VPN tunnel.
      shared_secret: String representing the shared secret (IKE pre-shared key).
      target_vpn_gateway: String representing the Target VPN Gateway URL the VPN
        tunnel resource should be associated with.
      local_traffic_selector: List of strings representing the local CIDR ranges
        that should be able to send traffic using this VPN tunnel.
      remote_traffic_selector: List of strings representing the remote CIDR
        ranges that should be able to send traffic using this VPN tunnel.
      params: Dictionary of params to set on the request.
      support_tagging_at_creation: Boolean representing the support of tagging
        at creation.

    Returns:
      The VpnTunnel message object that can be used in an insert request.
    )r    r!   r"   r#   r$   targetVpnGatewaylocalTrafficSelectorremoteTrafficSelectorr+   r,   r-   )r   r    r!   r/   r0   r1   target_vpn_gatewaylocal_traffic_selectorremote_traffic_selectorr+   r7   r8   s               r   GetClassicVpnTunnelForInsertz,VpnTunnelHelper.GetClassicVpnTunnelForInsert   sc    D "!%. 6 <"!8!>B	O 	$(:"(oh#4>>## 
 r   c                 v    ||||||||xs g |	xs g |
d
}|r|||d<    | j                   j                  di |S )a*  Returns the Classic VpnTunnel message for an insert request.

    Args:
      name: String representing the name of the VPN tunnel resource.
      description: String representing the description for the VPN tunnel
        resource.
      ike_version: The IKE protocol version for establishing the VPN tunnel.
      peer_ip: String representing the peer IP address for the VPN tunnel.
      shared_secret: String representing the shared secret (IKE pre-shared key).
      target_vpn_gateway: String representing the Target VPN Gateway URL the VPN
        tunnel resource should be associated with.
      router: String representing the Router URL the VPN tunnel resource should
        be associated with.
      local_traffic_selector: List of strings representing the local CIDR ranges
        that should be able to send traffic using this VPN tunnel.
      remote_traffic_selector: List of strings representing the remote CIDR
        ranges that should be able to send traffic using this VPN tunnel.
      cipher_suite: The cipher suite to use during IKE negotiation.
      params: Dictionary of params to set on the request.
      support_tagging_at_creation: Boolean representing the support of tagging
        at creation.

    Returns:
      The VpnTunnel message object that can be used in an insert request.
    )
r    r!   r"   r#   r$   r?   r'   r@   rA   r;   r+   r,   r-   )r   r    r!   r/   r0   r1   rB   r'   rC   rD   r<   r+   r7   r8   s                 r   +GetClassicVpnTunnelForInsertWithCipherSuitez;VpnTunnelHelper.GetClassicVpnTunnelForInsertWithCipherSuite   si    T "!%. 6 <"!8!>B#O 	$(:"(oh#4>>## 
 r   c                     | j                   j                         }|r||_        |r||_        |r||_        |r||_        |s|s|s|r|S y)z?Returns the phase 1 algorithms message object for a VPN tunnel.N)r   VpnTunnelPhase1Algorithmsdh
encryption	integrityprf)r   phase1_encryptionphase1_integrity	phase1_dh
phase1_prfphase1_algorithmss         r   GetVpnTunnelPhase1Algorithmsz,VpnTunnelHelper.GetVpnTunnelPhase1Algorithms#  s[    
 @@B&%6"$4!(&*:jr   c                 ~    | j                   j                         }|r||_        |r||_        |r||_        |s|s|r|S y)z?Returns the phase 2 algorithms message object for a VPN tunnel.N)r   VpnTunnelPhase2AlgorithmsrK   rL   pfs)r   phase2_encryptionphase2_integrity
phase2_pfsphase2_algorithmss        r   GetVpnTunnelPhase2Algorithmsz,VpnTunnelHelper.GetVpnTunnelPhase2Algorithms6  sL     @@B%6"$4!(-r   c                 p    t        j                  | j                  |      }t        j                  |||      S )a  Waits for the specified operation to complete and returns the target.

    Args:
      vpn_tunnel_ref: The VPN tunnel reference object.
      operation_ref: The operation reference object to wait for.
      wait_message: String representing the wait message to display while the
        operation is in progress.

    Returns:
      The resulting resource object after the operation completes.
    )r   Pollerr   r   WaitFor)r   vpn_tunnel_refoperation_refwait_messageoperation_pollers        r   WaitForOperationz VpnTunnelHelper.WaitForOperationF  s-     }}T]]NC>>*M<HHr   c                     | j                   j                  |j                  |j                  |      }| j                  j                  |      }| j                  j                  |j                  d      S )a  Sends an Insert request for a VPN tunnel and returns the operation.

    Args:
      ref: The VPN tunnel reference object.
      vpn_tunnel: The VPN tunnel message object to use in the insert request.

    Returns:
      The operation reference object for the insert request.
    projectregion	vpnTunnelcompute.regionOperations
collection)	r   ComputeVpnTunnelsInsertRequestrf   rg   r   Insertr   ParseselfLink)r   ref
vpn_tunnelrequest	operations        r   CreatezVpnTunnelHelper.CreateU  sk     nn;;CJJ* < FG$$W-I??  'A ! C Cr   c                     | j                   j                  |j                  |j                  |j	                               }| j
                  j                  |      S )zSends a Get request for a VPN tunnel and returns the resource.

    Args:
      ref: The VPN tunnel reference object.

    Returns:
      The VPN tunnel resource object.
    re   )r   ComputeVpnTunnelsGetRequestrf   rg   Namer   Get)r   rp   rr   s      r   DescribezVpnTunnelHelper.Describee  sH     nn88CJJ#((* 9 FG==W%%r   c                    | j                   j                  |j                  |j                  |j	                               }| j
                  j                  |      }| j                  j                  |j                  d      S )zSends a Delete request for a VPN tunnel and returns the operation.

    Args:
      ref: The VPN tunnel reference object.

    Returns:
      The operation reference object for the delete request.
    re   ri   rj   )
r   ComputeVpnTunnelsDeleteRequestrf   rg   rw   r   Deleter   rn   ro   )r   rp   rr   rs   s       r   r|   zVpnTunnelHelper.Deleter  sq     nn;;CJJ#((* < FG$$W-I??  'A ! C Cr   c              #     K   |rj|D ]d  }d}	 | j                   j                  ||||d      }| j                  j                  |      }|j                  }|j
                  D ]  }|  |se` yd}	 | j                   j                  |||d      }| j                  j                  |      }|j                  }|j
                  j                  D ]!  }	|	j                  j                  D ]  }|  # |syw)a9  Yields a VPN tunnel resource from the list of VPN tunnels.

    Sends an AggregatedList request to obtain the list of VPN tunnels and
    yields the next VPN tunnel in this list.

    Sends a List request to obtain the list of VPN tunnels in the specified
    regions and yields the next VPN tunnel in this list.

    Args:
      project: String representing the project to use for the request.
      filter_expr: The expression used to filter the results.
      regions: List of regions to list VPN tunnels from. If not specified,
        aggregated list is used.
    NT)rf   rg   filter	pageTokenreturnPartialSuccess)rf   r~   r   r   )r   ComputeVpnTunnelsListRequestr   ListnextPageTokenitems&ComputeVpnTunnelsAggregatedListRequestAggregatedListadditionalPropertiesvaluer   )
r   rf   filter_exprregionsrg   next_page_tokenrr   responserq   scoped_vpn_tunnelss
             r   r   zVpnTunnelHelper.List  s     &NN?? '#' @ ' ]]''0($22/$NNj +     O
EE+# F %g --g6h ..o ( C C
,22==J
 > !D  s   C4C6c                 B   | j                   j                  ||      }| j                   j                  |j                  |j                  |j                         |      }| j                  j                  |      }| j                  j                  |j                  d      S )aG  Sends a SetLabels request for a VPN tunnel and returns the operation.

    Args:
      ref: The VPN tunnel reference object.
      existing_label_fingerprint: The existing label fingerprint.
      new_labels: List of new label key, value pairs.

    Returns:
      The operation reference object for the SetLabels request.
    )labelFingerprintlabels)rf   rg   resourceregionSetLabelsRequestri   rj   )r   RegionSetLabelsRequest!ComputeVpnTunnelsSetLabelsRequestrf   rg   rw   r   	SetLabelsr   rn   ro   )r   rp   existing_label_fingerprint
new_labelsset_labels_requestrr   rs   s          r   r   zVpnTunnelHelper.SetLabels  s     >>3J ? Hnn>>zz1	 ? 3G
 ''0I??  'A ! C Cr   )NF)NNF)NNNF)NNNNNF)NNNN)NNNr   )__name__
__module____qualname____doc__r   propertyr   r   r   r9   r=   rE   rG   rS   r[   rc   rt   ry   r|   r   r   r,   r   r   r	   r	      s    9' 0 0 ) ) # #  "'>Z "'BV ;?;?*.?D0t !""':x <@48-1.2& <@48.2 IC &C,\Cr   r	   N)r   
__future__r   r   r   )googlecloudsdk.api_lib.compute.operationsr   googlecloudsdk.api_lib.utilr   objectr	   r,   r   r   <module>r      s)    = &  ' < .kCf kCr   