
    U                        d Z ddlmZ ddlmZ ddlmZ ddlZddl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 ddlmZ ddlmZ ddlZdZ ej<                  d      Z ej@                         Z! G d dejD                        Z#d Z$ ejJ                  ejL                  jN                        ejP                   G d dejR                                      Z* ejJ                  ejL                  jV                         G d de*             Z, ejJ                  ejL                  jZ                         G d de,             Z.y)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                        e Zd Z fdZ xZS )DeprecatedArgumentExceptionc                 L    t         t        |   dj                  ||             y )Nz{0} is deprecated. {1})superr   __init__format)selfargmsg	__class__s      )lib/surface/compute/vpn_tunnels/create.pyr   z$DeprecatedArgumentException.__init__/   s#    	
%t5 ''S13    )__name__
__module____qualname__r   __classcell__)r   s   @r   r   r   -   s    3 3r   r   c                     | st        j                  d      t        j                  t        |       r| S t        j                  d      )aO  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   sL     


$
$8: : XX&8""!	" "r   c                   
   e Zd ZdZ ej
                  d      Z ej                  d      Z	 e
j                  d      Z ej                  d      ZdZdZed        Zed        Zed        Zd Zd	 Zd
 Zd Zd Zd Zd Zy)CreateGAM  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                    t         j                  |       |j                  dd       |j                  dddgt        d       |j                  d	t        d
dt
        z          |j                  dt        j                  d      d
d       y )Nz--descriptionz4An optional, textual description for the VPN tunnel.)helpz--ike-version      z<Internet Key Exchange protocol version number. Default is 2.)choicestyper+   z--shared-secretTzp        Shared secret consisting of printable characters.  Valid
        arguments match the regular expression )r/   r   r+   --ike-networks
min_lengthzTHIS ARGUMENT NEEDS HELP TEXT.)r/   hiddenr+   )_ROUTER_ARGAddArgumentadd_argumentintr&   r$   r   ArgListclsparsers     r   _AddCommonFlagszCreateGA._AddCommonFlagsl   s    F#
C  E AK	  M '35MN	  O   A.-	  /r   c                 B   |j                  ddt        j                  d      d       |j                  ddt        j                  d      d       |j                  d	d
t        j                  d      d       |j                  ddt        j                  d      d       |j                  ddt        j                  d      d       |j                  ddt        j                  d      d       |j                  ddt        j                  d      d       y )Nz--phase1-encryption
ALGORITHMSr,   r1   zPhase 1 encryption algorithms.)metavarr/   r+   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.)r6   r   r8   r9   s     r   _AddCipherSuiteFlagszCreateGA._AddCipherSuiteFlags   s3   
- ,(00A>=  ? , ,(00A><  >  8(00A>>  @  ((00A>=  ? - ,(00A>=  ? , ,(00A><  >  ,(00A>K  Mr   c                    |j                   j                  t        j                         t        j                  |d       |j                  d      }| j                  j                  |       | j                  j                  |       |j                  d      }| j                  j                  |       | j                  j                  |       |j                  ddd       | j                  |       |j                  d	t        j                  d
      dd       |j                  dt        j                  d
      dd       |j                  ddd
gt        dd       |j                  dg dt        dd       | j                   r| j#                  |       | j$                  r'|j                  dt        j&                         dd       |j                   j)                  t        j*                         y)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   r+   --local-traffic-selectorr,   r1   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.)r/   r?   r+   --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.)r.   r/   r   r+   !--peer-external-gateway-interface)r   r,   r-      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_ARGr5   add_mutually_exclusive_group_TARGET_VPN_GATEWAY_ARG_VPN_GATEWAY_ARG_EXTERNAL_VPN_GATEWAY_ARG_PEER_GCP_GATEWAY_ARGr6   r<   r   r8   r7   _support_cipher_suiterA   _support_tagging_at_creationArgDictAddCacheUpdaterVpnTunnelsCompleter)r:   r;   vpn_gateway_group_parserpeer_vpn_gateway_group_parsers       r   Argsz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                    |j                  d      r4|j                  d      st        j                  dd      |j                  d      st        j                  dd      |j                  d      s'|j                  d	      st        j                  d
d      |j                  d	      r'|j                  d      st        j                  dd      |j                  d      rt        j                  dd      |j                  d      rt        j                  dd      |j                  d      rt        j                  dd      y y )Nvpn_gateway	interfacerI   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_interfacerJ   z`The flag --peer-external-gateway-interface must be specified along with --peer-external-gateway.local_traffic_selectorrF   zHCannot specify local traffic selector with Highly Available VPN tunnels.remote_traffic_selectorrH   zICannot specify remote traffic selector with Highly Available VPN tunnels.peer_addressrE   zGCannot specify the flag peer address with Highly Available VPN tunnels.IsSpecifiedr
   InvalidArgumentExceptionr   argss     r    _ValidateHighAvailabilityVpnArgsz)CreateGA._ValidateHighAvailabilityVpnArgs
  sp   &k*11FG 	G h'119: 	: 01$:J:J
!;#11 OP 	P 
		1	24;K;K
+<-11/-. 	. 
		2	311& 	 
		3	411' 	 
		.	)11 	 
*C 'r   c                     |j                  d      rO|j                  d      st        j                  dd      |j                  d      rt        j                  dd      y y )Ntarget_vpn_gatewayrg   rE   zFWhen creating Classic VPN tunnels, the peer address must be specified.r`   ra   z/Cannot specify router with Classic VPN tunnels.rh   rk   s     r   _ValidateClassicVpnArgsz CreateGA._ValidateClassicVpnArgs2  sm    ,-n-11!" 	" 
		(	#11=
 	
 
$ .r   c                 ~    |j                  d      r,| j                  j                  ||      j                         }|S y )Nrb   )ri   rT   ResolveAsResourceSelfLink)r   api_resource_registryrl   rb   s       r   _GetPeerGcpGatewayzCreateGA._GetPeerGcpGateway?  s@    *+33EE
%''/xz r   c                 ~    |j                  d      r,| j                  j                  ||      j                         }|S y )Nrc   )ri   rS   rr   rs   )r   rt   rl   rc   s       r   _GetPeerExternalGatewayz CreateGA._GetPeerExternalGatewayF  s@    /0"<<NN
%''/xz ""r   c                    t        j                  | j                               }|j                  }t	        j
                  |      }|j                  t        dd      t        j                  ||j                  t        j                  |            }d }|j                  d      rA|j                  |_        t         j                  ||j                        }|j#                         }d }	d }
d }d }d }d }d }|r|j                  d      r| j%                  |       |j                  |_        | j(                  j                  ||j                        j#                         }
|j*                  }| j-                  |j                  |      }|j.                  }| j1                  |j                  |      }nV| j3                  |       |j                  |_        | j6                  j                  ||j                        j#                         }	| j8                  r2|j:                  &| j=                  |j>                  |j:                        }|	r| j@                  r'|jC                  |jD                  |jF                  |jH                  |jJ                        }|jM                  |jN                  |jP                  |jR                        }|j>                  jU                         }|r||_+        |r||_,        |jV                  s|jX                  sd }|j[                  |j]                         |j^                  |j`                  |jb                  |jd                  |	|jf                  |jh                  ||| j8                        }n|jk                  |j]                         |j^                  |j`                  |jb                  |jd                  |	|jf                  |jh                  || j8                  	
      }n| j@                  r|jC                  |jD                  |jF                  |jH                  |jJ                        }|jM                  |jN                  |jP                  |jR                        }|j>                  jU                         }|r||_+        |r||_,        |jV                  s|jX                  sd }|jm                  |j]                         |j^                  |j`                  |jb                  |jd                  |
|||||||| j8                  
      }n^|jo                  |j]                         |j^                  |j`                  |jb                  |jd                  |
||||||| j8                        }|jq                  ||      }|js                  ||d      S )Nr0   z0It has been renamed to --local-traffic-selector.)scope_listerr`   r^   )phase1_encryptionphase1_integrity	phase1_dh
phase1_prf)phase2_encryptionphase2_integrity
phase2_pfs)namedescriptionike_versionpeer_ipshared_secretro   re   rf   cipher_suiteparamssupport_tagging_at_creation)
r   r   r   r   r   ro   re   rf   r   r   )r   r   r   r   r   r^   vpn_gateway_interfacer`   rc   rd   rb   r   r   r   )r   r   r   r   r   r^   r   r`   rc   rd   rb   r   r   zCreating VPN tunnel):r   ComputeApiHolderReleaseTrackclientr   VpnTunnelHelperike_networksr   rO   rr   	resourcescompute_flagsGetDefaultScopeListerri   regionrouter_regionr4   rs   rm   vpn_gateway_regionrR   r_   rw   rd   ru   rp   target_vpn_gateway_regionrQ   rV   resource_manager_tags_CreateVpnTunnelParamsmessagesrU   GetVpnTunnelPhase1Algorithmsrz   r{   r|   r}   GetVpnTunnelPhase2Algorithmsr~   r   r   VpnTunnelCipherSuitephase1phase2+GetClassicVpnTunnelForInsertWithCipherSuiteNamer   r   rg   r   re   rf   GetClassicVpnTunnelForInsert4GetHighAvailabilityVpnTunnelForInsertWithCipherSuite%GetHighAvailabilityVpnTunnelForInsertCreateWaitForOperation)r   rl   is_vpn_gateway_supportedholderr   helpervpn_tunnel_refrouter_link
router_refro   r^   r   rc   rd   rb   r   phase1_algophase2_algor   vpn_tunnel_to_insertoperation_refs                        r   _RunzCreateGA._RunM  sV   **4+<+<+>?F]]F..v6F $'

<> > %66"88@ 7 BN
 K!)00d00v7G7GHj'')kK  &*# D$4$4]$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                 (    | j                  |d      S )z-Issues API requests to construct VPN Tunnels.T)r   )r   rk   s     r   RunzCreateGA.Run  s    99TD999r   c                    t        j                  |      }|j                  }t        t	        j
                  |            D cg c]"  \  }}|j                  j                  ||      $ }}} ||j                  |            S c c}}w )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   zCreateGA._CreateVpnTunnelParams  s    #::!	
 
 %%F !/H!IJJJC 	''::s%:PJ   ";;!6 < 
 	s   'BN)r   r   r   __doc__target_vpn_gateway_flags$TargetVpnGatewayArgumentForVpnTunnelrQ   vpn_gateway_flags%GetVpnGatewayArgumentForOtherResourcerR   external_vpn_gateway_flags&ExternalVpnGatewayArgumentForVpnTunnelrS   )GetPeerVpnGatewayArgumentForOtherResourcerT   rU   rV   classmethodr<   rA   r\   rm   rp   ru   rw   r   r   r    r   r   r(   r(   O   s     DCC  >==uM  H GG 
 BAA  !&/ /6 M M< `C `CD&P
c:J:r   r(   c                       e Zd ZdZdZdZy)
CreateBetar)   TFNr   r   r   r   rU   rV   r   r   r   r   r     s     !&r   r   c                       e Zd ZdZdZdZy)CreateAlphar)   TNr   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$   RouterArgumentForVpnTunnelr4   VpnTunnelArgumentrO   ToolExceptionr   r&   ReleaseTracksr   GAUniverseCompatibleCreateCommandr(   BETAr   ALPHAr   r   r   r   <module>r      s5   ( &  '  	 7 H / ( . E J h L d V @ 
 % 5l55uE)%))+3*":": 3"6 D%%(()tt!! t  *tn D%%**+' ' ,' D%%++,
&* 
& -
&r   