
    U                        S r SSKJr  SSKJr  SSKJr  SSKrSSKrSSKJr  SSK	J
r
  SSKJr  SS	KJr  SS
KJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKrSr\R<                  " SS9r\R@                  " 5       r! " S S\RD                  5      r#S r$\RJ                  " \RL                  RN                  5      \RP                   " S S\RR                  5      5       5       r*\RJ                  " \RL                  RV                  5       " S S\*5      5       r,\RJ                  " \RL                  RZ                  5       " S S\,5      5       r.g)z!Command for creating VPN tunnels.    )absolute_import)division)unicode_literalsN)base_classes)vpn_tunnels_utils)arg_parsers)base)
exceptions)flags)resource_manager_tags_utilsz[ -~]+Frequiredc                   (   ^  \ rS rSrU 4S jrSrU =r$ )DeprecatedArgumentException-   c                 J   > [         [        U ]  SR                  X5      5        g )Nz{0} is deprecated. {1})superr   __init__format)selfargmsg	__class__s      )lib/surface/compute/vpn_tunnels/create.pyr   $DeprecatedArgumentException.__init__/   s!    	
%t5 ''13     )__name__
__module____qualname____firstlineno__r   __static_attributes____classcell__)r   s   @r   r   r   -   s    3 3r   r   c                     U (       d  [         R                  " S5      e[        R                  " [        U 5      (       a  U $ [         R                  " S5      e)a?  ValidateSimpleSharedSecret checks its argument is a vpn shared secret.

ValidateSimpleSharedSecret(v) returns v iff v matches [ -~]+.

Args:
  possible_secret: str, The data to validate as a shared secret.

Returns:
  The argument, if valid.

Raises:
  ArgumentTypeError: The argument is not a valid vpn shared secret.
z.--shared-secret requires a non-empty argument.zQThe argument to --shared-secret is not valid it contains non-printable charcters.)argparseArgumentTypeErrorrematch_PRINTABLE_CHARS_PATTERN)possible_secrets    r   ValidateSimpleSharedSecretr+   4   sO     


$
$8: : XX&88""!	" "r   c                       \ rS rSrSr\R                  " SS9r\R                  " SS9r
\R                  " SS9r\R                  " SS9rSrSr\S 5       r\S 5       r\S 5       rS	 rS
 rS rS rS rS rS rSrg)CreateGAO   A  Create a VPN tunnel.

  *{command}* is used to create a Classic VPN tunnel between a target VPN
gateway in Google Cloud Platform and a peer address; or create Highly
Available VPN tunnel between HA VPN gateway and another HA VPN gateway, or
Highly Available VPN tunnel between HA VPN gateway and an external VPN
gateway.
Fr   Tc                     [         R                  U5        UR                  SSS9  UR                  SSS/[        SS9  UR                  S	[        S
S[
        -   S9  UR                  S[        R                  " SS9S
SS9  g )Nz--descriptionz4An optional, textual description for the VPN tunnel.)helpz--ike-version      z<Internet Key Exchange protocol version number. Default is 2.)choicestyper1   z--shared-secretTzp        Shared secret consisting of printable characters.  Valid
        arguments match the regular expression )r5   r   r1   --ike-networks
min_lengthzTHIS ARGUMENT NEEDS HELP TEXT.)r5   hiddenr1   )_ROUTER_ARGAddArgumentadd_argumentintr+   r)   r   ArgListclsparsers     r   _AddCommonFlagsCreateGA._AddCommonFlagsl   s    F#
C  E AK	  M '35MN	  O   A.-	  /r   c                    UR                  SS[        R                  " SS9SS9  UR                  SS[        R                  " SS9SS9  UR                  S	S
[        R                  " SS9SS9  UR                  SS[        R                  " SS9SS9  UR                  SS[        R                  " SS9SS9  UR                  SS[        R                  " SS9SS9  UR                  SS[        R                  " SS9SS9  g )Nz--phase1-encryption
ALGORITHMSr2   r7   zPhase 1 encryption algorithms.)metavarr5   r1   z--phase1-integrityzPhase 1 integrity algorithms.z--phase1-prfzPSEUDORANDOM FUNCTIONSzPhase 1 pseudorandom functions.z--phase1-dhGROUPSzPhase 1 Diffie-Hellman groups.z--phase2-encryptionzPhase 2 encryption algorithms.z--phase2-integrityzPhase 2 integrity algorithms.z--phase2-pfsz,Phase 2 perfect forward secerecy algorithms.)r<   r   r>   r?   s     r   _AddCipherSuiteFlagsCreateGA._AddCipherSuiteFlags   s3   
- ,(00A>=  ? , ,(00A><  >  8(00A>>  @  ((00A>=  ? - ,(00A>=  ? , ,(00A><  >  ,(00A>K  Mr   c                    UR                   R                  [        R                  5        [        R                  USS9  UR                  SS9nU R                  R                  U5        U R                  R                  U5        UR                  SS9nU R                  R                  U5        U R                  R                  U5        UR                  SSSS9  U R                  U5        UR                  S	[        R                  " S
S9SSS9  UR                  S[        R                  " S
S9SSS9  UR                  SSS
/[        SSS9  UR                  S/ SQ[        SSS9  U R                   (       a  U R#                  U5        U R$                  (       a%  UR                  S[        R&                  " 5       SSS9  UR                   R)                  [        R*                  5        g)z&Adds arguments to the supplied parser.create)operation_typeTr   --peer-addressFzValid IPV4 address representing the remote tunnel endpoint, the peer address must be specified when creating Classic VPN tunnels from Classic Target VPN gateway)r   r1   --local-traffic-selectorr2   r7   CIDRa          Traffic selector is an agreement between IKE peers to permit traffic
        through a tunnel if the traffic matches a specified pair of local and
        remote addresses.

        --local-traffic-selector allows to configure the local addresses that are
        permitted. The value should be a comma separated list of CIDR formatted
        strings. Example: 192.168.0.0/16,10.0.0.0/24.

        Local traffic selector must be specified only for VPN tunnels that
        do not use dynamic routing with a Cloud Router. Omit this flag when
        creating a tunnel using dynamic routing, including a tunnel for a
        Highly Available VPN gateway.)r5   rF   r1   --remote-traffic-selectora          Traffic selector is an agreement between IKE peers to permit traffic
        through a tunnel if the traffic matches a specified pair of local and
        remote addresses.

        --remote-traffic-selector allows to configure the remote addresses that
        are permitted. The value should be a comma separated list of CIDR
        formatted strings. Example: 192.168.0.0/16,10.0.0.0/24.

        Remote traffic selector must be specified for VPN tunnels that do
        not use dynamic routing with a Cloud Router. Omit this flag when
        creating a tunnel using dynamic routing, including a tunnel for a
        Highly Available VPN gateway.--interfacer   ao          Numeric interface ID of the VPN gateway with which this VPN tunnel
        is associated. This flag is required if the tunnel is being attached
        to a Highly Available VPN gateway. This option is only available
        for use with Highly Available VPN gateway and must be omitted if the
        tunnel is going to be connected to a Classic VPN gateway.)r4   r5   r   r1   !--peer-external-gateway-interface)r   r2   r3      z        Interface ID of the external VPN gateway to which this VPN tunnel
        is connected to.
        This flag is required if the tunnel is being created from
        a Highly Available VPN gateway to an External Vpn Gateway.z--resource-manager-tagsz	KEY=VALUEz`            A comma-separated list of Resource Manager tags to apply to the VPN tunnel.
        N)display_info	AddFormatr   HA_VPN_LIST_FORMAT_VPN_TUNNEL_ARGr;   add_mutually_exclusive_group_TARGET_VPN_GATEWAY_ARG_VPN_GATEWAY_ARG_EXTERNAL_VPN_GATEWAY_ARG_PEER_GCP_GATEWAY_ARGr<   rB   r   r>   r=   _support_cipher_suiterH   _support_tagging_at_creationArgDictAddCacheUpdaterVpnTunnelsCompleter)r@   rA   vpn_gateway_group_parserpeer_vpn_gateway_group_parsers       r   ArgsCreateGA.Args   s    !!%":":;x@%BB  C  ++,DE$$%=>$*$G$G %H %!!!--.KL))*GH!..2 / 3 
"  A.)	  +$ #  A.)	  +$ AE  
F +F  	G   	v&
''
#""$	   ''(A(ABr   c                    UR                  S5      (       Gah  UR                  S5      (       d  [        R                  " SS5      eUR                  S5      (       d  [        R                  " SS5      eUR                  S5      (       d-  UR                  S	5      (       d  [        R                  " S
S5      eUR                  S	5      (       a-  UR                  S5      (       d  [        R                  " SS5      eUR                  S5      (       a  [        R                  " SS5      eUR                  S5      (       a  [        R                  " SS5      eUR                  S5      (       a  [        R                  " SS5      eg g )Nvpn_gateway	interfacerQ   zsWhen creating Highly Available VPN tunnels, the VPN gateway interface must be specified using the --interface flag.router--routerzeWhen creating Highly Available VPN tunnels, a Cloud Router must be specified using the --router flag.peer_gcp_gatewaypeer_external_gatewayz--peer-gcp-gatewayzsWhen creating Highly Available VPN tunnels, either --peer-gcp-gateway or --peer-external-gateway must be specified.peer_external_gateway_interfacerR   z`The flag --peer-external-gateway-interface must be specified along with --peer-external-gateway.local_traffic_selectorrN   zHCannot specify local traffic selector with Highly Available VPN tunnels.remote_traffic_selectorrP   zICannot specify remote traffic selector with Highly Available VPN tunnels.peer_addressrM   zGCannot specify the flag peer address with Highly Available VPN tunnels.IsSpecifiedr
   InvalidArgumentExceptionr   argss     r    _ValidateHighAvailabilityVpnArgs)CreateGA._ValidateHighAvailabilityVpnArgs
  s   &&k**11FG 	G h''119: 	: 011$:J:J
!;# ;#11 OP 	P 
		1	2	24;K;K
+<- <-11/-. 	. 
		2	3	311& 	 
		3	4	411' 	 
		.	)	)11 	 
*C 'r   c                     UR                  S5      (       a[  UR                  S5      (       d  [        R                  " SS5      eUR                  S5      (       a  [        R                  " SS5      eg g )Ntarget_vpn_gatewayrp   rM   zFWhen creating Classic VPN tunnels, the peer address must be specified.ri   rj   z/Cannot specify router with Classic VPN tunnels.rq   rt   s     r   _ValidateClassicVpnArgs CreateGA._ValidateClassicVpnArgs2  sv    ,--n--11!" 	" 
		(	#	#11=
 	
 
$ .r   c                     UR                  S5      (       a+  U R                  R                  X!5      R                  5       nU$ g )Nrk   )rr   r\   ResolveAsResourceSelfLink)r   api_resource_registryru   rk   s       r   _GetPeerGcpGatewayCreateGA._GetPeerGcpGateway?  s@    *++33EE
''/xz r   c                     UR                  S5      (       a+  U R                  R                  X!5      R                  5       nU$ g )Nrl   )rr   r[   r}   r~   )r   r   ru   rl   s       r   _GetPeerExternalGateway CreateGA._GetPeerExternalGatewayF  s@    /00"<<NN
''/xz ""r   c                    [         R                  " U R                  5       5      nUR                  n[        R
                  " U5      nUR                  b  [        SS5      e[        R                  UUR                  [        R                  " U5      S9nS nUR                  S5      (       a@  UR                  Ul        [         R                  XR                  5      nUR#                  5       nS n	S n
S nS nS nS nS nU(       a  UR                  S5      (       a  U R%                  U5        UR                  Ul        U R(                  R                  XR                  5      R#                  5       n
UR*                  nU R-                  UR                  U5      nUR.                  nU R1                  UR                  U5      nOUU R3                  U5        UR                  Ul        U R6                  R                  XR                  5      R#                  5       n	U R8                  (       a3  UR:                  b&  U R=                  UR>                  UR:                  5      nU	(       Ga  U R@                  (       Ga2  URC                  URD                  URF                  URH                  URJ                  S9nURM                  URN                  URP                  URR                  S9nUR>                  RU                  5       nU(       a  UUl+        U(       a  UUl,        URV                  (       d  URX                  (       d  S nUR[                  UR]                  5       UR^                  UR`                  URb                  URd                  U	URf                  URh                  UUU R8                  S9nGOURk                  UR]                  5       UR^                  UR`                  URb                  URd                  U	URf                  URh                  UU R8                  S	9
nGOU R@                  (       Ga   URC                  URD                  URF                  URH                  URJ                  S9nURM                  URN                  URP                  URR                  S9nUR>                  RU                  5       nU(       a  UUl+        U(       a  UUl,        URV                  (       d  URX                  (       d  S nURm                  UR]                  5       UR^                  UR`                  URb                  URd                  U
UUUUUUUU R8                  S
9nO[URo                  UR]                  5       UR^                  UR`                  URb                  URd                  U
UUUUUUU R8                  S9nURq                  UU5      nURs                  UUS5      $ )Nr6   z0It has been renamed to --local-traffic-selector.)scope_listerri   rg   )phase1_encryptionphase1_integrity	phase1_dh
phase1_prf)phase2_encryptionphase2_integrity
phase2_pfs)namedescriptionike_versionpeer_ipshared_secretry   rn   ro   cipher_suiteparamssupport_tagging_at_creation)
r   r   r   r   r   ry   rn   ro   r   r   )r   r   r   r   r   rg   vpn_gateway_interfaceri   rl   rm   rk   r   r   r   )r   r   r   r   r   rg   r   ri   rl   rm   rk   r   r   zCreating VPN tunnel):r   ComputeApiHolderReleaseTrackclientr   VpnTunnelHelperike_networksr   rW   r}   	resourcescompute_flagsGetDefaultScopeListerrr   regionrouter_regionr:   r~   rv   vpn_gateway_regionrZ   rh   r   rm   r   rz   target_vpn_gateway_regionrY   r^   resource_manager_tags_CreateVpnTunnelParamsmessagesr]   GetVpnTunnelPhase1Algorithmsr   r   r   r   GetVpnTunnelPhase2Algorithmsr   r   r   VpnTunnelCipherSuitephase1phase2+GetClassicVpnTunnelForInsertWithCipherSuiteNamer   r   rp   r   rn   ro   GetClassicVpnTunnelForInsert4GetHighAvailabilityVpnTunnelForInsertWithCipherSuite%GetHighAvailabilityVpnTunnelForInsertCreateWaitForOperation)r   ru   is_vpn_gateway_supportedholderr   helpervpn_tunnel_refrouter_link
router_refry   rg   r   rl   rm   rk   r   phase1_algophase2_algor   vpn_tunnel_to_insertoperation_refs                        r   _RunCreateGA._RunM  s\   **4+<+<+>?F]]F..v6F $'

<> > %66"88@ 7 BN
 K!!)00d007G7GHj'')kK  &*# D$4$4]$C$C
++D1 . 5 5d));;
  
  #nn"::


D )-(L(L%001A1A4H
""4('5'<'<d$77II
  
  ((		#	#	/ $ ; ;OOT77!
 		#	#	#99"44!22nn	 : 
 99"44!22 : 

 ;;= +,
 +,
""<+>+>,>>#((* ,, ,,))"00#5'+'B'B(,(D(D),,0,M,M ?  	   &BB$$&((((%%,,1#'#>#>$($@$@((,(I(I  C  
 
	#	#	#99"44!22nn	 : 
 99"44!22 : 

 ;;= +,
 +,
""<+>+>,GG#((* ,, ,,))"00'&;"&;0O!1),,0,M,M H  	&  &KK$$&(((( %%,,#"7"7,K-((,(I(I!  L  
& MM.2FGM"">=#8: :r   c                 "    U R                  USS9$ )z-Issues API requests to construct VPN Tunnels.T)r   )r   rt   s     r   RunCreateGA.Run  s    99TD999r   c           	         [         R                  " U5      nUR                  n[        [        R
                  " U5      5       VVs/ s H  u  pVUR                  R                  XVS9PM      nnnU" UR                  US9S9$ s  snnf )N)keyvalue)additionalProperties)resourceManagerTags)r   GetResourceManagerTagsVpnTunnelParamssortedsix	iteritemsResourceManagerTagsValueAdditionalProperty)r   r   r   resource_manager_tags_mapr   r   r   additional_propertiess           r   r   CreateGA._CreateVpnTunnelParams  s    #::!	
 
 %%F !/H!IJJJC 	''::s:PJ   ";;!6 < 
 	s   %B r   N)r   r   r    r!   __doc__target_vpn_gateway_flags$TargetVpnGatewayArgumentForVpnTunnelrY   vpn_gateway_flags%GetVpnGatewayArgumentForOtherResourcerZ   external_vpn_gateway_flags&ExternalVpnGatewayArgumentForVpnTunnelr[   )GetPeerVpnGatewayArgumentForOtherResourcer\   r]   r^   classmethodrB   rH   rd   rv   rz   r   r   r   r   r   r"   r   r   r   r-   r-   O   s     CC  ==uM  !GG 
 AA  !&/ /6 M M< `C `CD&P
c:J:r   r-   c                        \ rS rSrSrSrSrSrg)
CreateBetai  r/   TFr   Nr   r   r    r!   r   r]   r^   r"   r   r   r   r   r     s     !&r   r   c                        \ rS rSrSrSrSrSrg)CreateAlphai  r/   Tr   Nr   r   r   r   r   r     s     !%r   r   )/r   
__future__r   r   r   r%   r'   googlecloudsdk.api_lib.computer   *googlecloudsdk.api_lib.compute.vpn_tunnelsr   googlecloudsdk.callioper   r	   r
   "googlecloudsdk.command_lib.computer   r   r   8googlecloudsdk.command_lib.compute.external_vpn_gatewaysr   *googlecloudsdk.command_lib.compute.routersrouter_flags6googlecloudsdk.command_lib.compute.target_vpn_gatewaysr   /googlecloudsdk.command_lib.compute.vpn_gatewaysr   .googlecloudsdk.command_lib.compute.vpn_tunnelsr   r)   RouterArgumentForVpnTunnelr:   VpnTunnelArgumentrW   ToolExceptionr   r+   ReleaseTracksr   GAUniverseCompatibleCreateCommandr-   BETAr   ALPHAr   r   r   r   <module>r      s+   ( &  '  	 7 H / ( . E J h L d V @ 
 % 55uE))+3*":": 3"6 D%%(()tt!! t  *tn D%%**+' ' ,' D%%++,
&* 
& -
&r   