
                         D   S r SSKJr  SSKJr  SSKJ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
rSr1 SkrSSSS.r\R$                  " S\R&                  5      r\R$                  " S\R&                  5      r " S S\
R,                  5      rSS jrSS jrS rS rS rg)zAFlags and helpers for the compute external-vpn-gateways commands.    )absolute_import)division)unicode_literalsN)arg_parsers)
completers)
exceptions)flagsz1    table(
      name,
      redundancyType
    )zID=IP_ADDRESS>   r            SINGLE_IP_INTERNALLY_REDUNDANTTWO_IPS_REDUNDANCYFOUR_IPS_REDUNDANCY)r
   r      a  

    (?P<id>[0-3]) # The id group.

    (=(?P<ipAddress>(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)))
                                  # The ip_address group.

    $                             # End of input marker.
    aQ  

    (?P<id>[0-3]) # The id group.

    (=(?P<ipv6Address>(
    (([0-9a-fA-F]{1,4}(:[0-9a-fA-F]{1,4}){0,6})?::(([0-9a-fA-F]{1,4}:){0,6}[0-9a-fA-F]{1,4})?)
    |
    (([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4})
    )))
                                  # The ipv6_address group.

    $                             # End of input marker.
    c                   (   ^  \ rS rSrU 4S jrSrU =r$ )ExternalVpnGatewaysCompleterL   c                 4   > [         [        U ]
  " SSSS.UD6  g )Ncompute.externalVpnGatewaysz.alpha compute external-vpn-gateways list --uri)
collectionlist_command )superr   __init__)selfkwargs	__class__s     Elib/googlecloudsdk/command_lib/compute/external_vpn_gateways/flags.pyr   %ExternalVpnGatewaysCompleter.__init__N   s(    	
&6 0E     r   )__name__
__module____qualname____firstlineno__r   __static_attributes____classcell__)r   s   @r   r   r   L   s     r    r   c                 :    [         R                  " S[        UU SS9$ )Nexternal VPN gatewayr   )resource_name	completerpluralrequiredglobal_collectioncompute_flagsResourceArgumentr   )r,   r+   s     r   ExternalVpnGatewayArgumentr1   V   s$    		'	'*,5
 r    c           	      <    [         R                  " SS[        U SSS9$ )Nz--peer-external-gatewayr(   a'  Peer side external VPN gateway representing the remote tunnel endpoint, this flag is used when creating HA VPN tunnels from Google Cloud to your external VPN gateway.Either --peer-external-gateway or --peer-gcp-gateway must be specified when creating VPN tunnels from High Available VPN gateway.r   )namer)   r*   r,   
short_helpr-   r.   )r,   s    r   &ExternalVpnGatewayArgumentForVpnTunnelr5   `   s+    		'	'$*, 6
 r    c           
      x    U R                  SSS9  U R                  SS[        [        R                  " SSS9S	S
9  g)z9Adds common arguments for creating external VPN gateways.z--descriptionz0Textual description of the External VPN Gateway.)helpz--interfacesTr   r   )
min_length
max_lengtha1        Map of interfaces from interface ID to interface IP address for the External VPN Gateway.

      There can be one, two, or four interfaces in the map.

      For example, to create an external VPN gateway with one interface:

        $ {command} MY-EXTERNAL-GATEWAY --interfaces 0=192.0.2.0

      To create an external VPN gateway with two interfaces:
        $ {command} MY-EXTERNAL-GATEWAY --interfaces 0=192.0.2.0,1=192.0.2.1

      To create an external VPN gateway with four interfaces:
        $ {command} MY-EXTERNAL-GATEWAY --interfaces 0=192.0.2.0,1=192.0.2.1,2=192.0.2.3,3=192.0.2.4

      To create an external VPN gateway with IPv6 addresses on four interfaces:
        $ {command} MY-EXTERNAL-GATEWAY --interfaces 0=2001:db8::1,1=2001:db8::2,2=2001:db8::3,3=2001:db8::4

      Note that the redundancy type of the gateway will be automatically inferred based on the number
      of interfaces provided:

        1 interface: `SINGLE_IP_INTERNALLY_REDUNDANT`

        2 interfaces: `TWO_IPS_REDUNDANCY`

        4 interfaces: `FOUR_IPS_REDUNDANCY`
      )r,   metavartyper7   N)add_argumentALLOWED_METAVARr   ArgList)parsers    r   AddCreateExternalVpnGatewayArgsr@   r   sP     	N   	!:
   r    c                    [        U 5      S:w  aL  [        U 5      S:w  a=  [        U 5      S:w  a.  [        R                  " SR                  [        U 5      5      5      e/ nU =(       d    /  GH  n[        R                  U5      nU(       aN  UR                  S5      nUR                  S5      nUR                  [        U5      US9nUR                  U5        Mn  [        R                  U5      nU(       aN  UR                  S5      nUR                  S5      n	UR                  [        U5      U	S	9nUR                  U5        M  U(       a  M  U(       a  M  [        R                  " S
R                  [        U5      5      e   U$ )z=Parses id=ip_address mappings from --interfaces command line.r
   r   r   zSNumber of interfaces must be either one, two, or four; received [{0}] interface(s).id	ipAddress)rB   rC   ipv6Address)rB   rD   zInterfaces must be of the form {0}, ID must be an integer value in [0,1,2,3], IP_ADDRESS must be a valid IP address; received [{1}].)lenr   ArgumentErrorformatLEGAL_SPECSmatchgroupExternalVpnGatewayInterfaceintappendLEGAL_IPV6_SPECSr=   )

interfacesmessage_classesinterface_listspec
match_ipv4interface_id
ip_address	interface
match_ipv6ipv6_addresss
             r   ParseInterfacesrY      sc   _c*o2s:!7K

"
"	s:/ 
 .Bd""4(J%%d+l##K0j!==* > i I&!''-J%%d+l%%m4l!==L > i I&:jj$$N6/4( - 8 
r    c                     U b  [         [        U 5         c  gUR                  R                  [         [        U 5         5      $ )zConverts the interconnect type flag to a message enum.

Args:
  interfaces: List of the interfaces provided by user.
  messages: The API messages holder.

Returns:
  An InterconnectTypeValueValuesEnum of the flag value, or None if absent.
N)EXTERNAL_VPN_GATEWAY_TYPE__MAPrE   ExternalVpnGatewayRedundancyTypeValueValuesEnum)rO   messagess     r   InferAndGetRedundancyTyper_      sA     	'J	8	@&&DD&s:7 r    )TF)F)__doc__
__future__r   r   r   regooglecloudsdk.callioper   "googlecloudsdk.command_lib.computer   compute_completersr   r	   r/   DEFAULT_LIST_FORMATr=   ALLOWED_INTERFACE_IDSr[   compileVERBOSErH   rN   ListCommandCompleterr   r1   r5   r@   rY   r_   r   r    r   <module>rk      s    H &  ' 	 / O 9 E	  "$  ("  jj JJ :: JJ $#5#J#J $'T%Pr    