
    L=              	          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  ej                  d	d
ddddd      Z ej                  d ej                   d      ddddd      Z G d dej$                        Z G d dej$                        ZdZd(dZd Zd Zd)dZd Zd Zd Zd Zd  Zd)d!Zd)d"Z d)d#Z!d$ Z"d% Z#d& Z$	 d*d'Z%y)+z3Flags and helpers for the compute routers commands.    )absolute_import)division)unicode_literalsN)arg_parsers)flags)	arg_utilsz--nat-external-ip-poolz*External IP Addresses to use for Cloud NATaddresszcompute.addressesTF)name
short_helpresource_nameregional_collectionregion_hiddenpluralrequiredz--nat-external-drain-ip-poolz~       External IP Addresses to be drained

       These IPs must be valid external IPs that have been used as NAT IPs
       )r
   detailed_helpr   r   r   r   r   c                       e Zd ZdZdZdZy)SubnetOptionr         N)__name__
__module____qualname__
ALL_RANGESPRIMARY_RANGESCUSTOM_RANGES     <lib/googlecloudsdk/command_lib/compute/routers/nats/flags.pyr   r   3   s    *.-r   r   c                       e Zd ZdZdZy)SubnetIpv6Optionr   r   N)r   r   r   ALL_IPV6_SUBNETSLIST_OF_IPV6_SUBNETSr   r   r   r    r    9   s    r   r    z    table(
      name,
      natIpAllocateOption,
      sourceSubnetworkIpRangesToNat,
      endpointTypes.list():label=ENDPOINT_TYPES
    )c                 j    dj                  |rdnd|      }d|i}|rd|d<    | j                  di | y)	z,Adds a positional argument for the NAT name.zName of the NAT{} to {}s help+nargsN)r
   )formatadd_argument)parseroperation_typer   	help_textparamss        r   AddNatNameArgr/   G   sD    '..fs"/=?)I&F7O&''r   c                 X    d}ddd}| j                  dt        j                  ||       y)zAdds the --type argument.z=Type of the NAT Gateway. Defaults to PUBLIC if not specified.zbUsed for private-to-public NAT translations. Allows VM instances to communicate with the internet.zXUsed for private-to-private NAT translations. Allows communication between VPC Networks.)PUBLICPRIVATEz--type)typechoicesr&   N)r*   r   ChoiceToEnumNamer+   r-   r4   s      r   
AddTypeArgr7   R   s?    M)."	' 	%%	  r   c                     t        j                  d      }g d}| j                  dt        j                  |      |dd       y)	z"Adds the --endpoint-type argument.a      Endpoint Types supported by the NAT Gateway.

    ENDPOINT_TYPE must be one of:

    ENDPOINT_TYPE_VM
      For VM Endpoints
    ENDPOINT_TYPE_SWG
      For Secure Web Gateway Endpoints
    ENDPOINT_TYPE_MANAGED_PROXY_LB
      For regional Application Load Balancers (internal and external) and regional proxy Network Load Balancers (internal and external) endpoints

  The default is ENDPOINT_TYPE_VM.
  )ENDPOINT_TYPE_VMENDPOINT_TYPE_SWGENDPOINT_TYPE_MANAGED_PROXY_LBz--endpoint-types)r4   ENDPOINT_TYPEF)r3   r&   metavarr   N)textwrapdedentr*   r   ArgListr6   s      r   AddEndpointTypesArgrA   f   sK    oo  )'
 	w/  r   c                    t        |        t        |        t        | |       t        | |       t	        | |       t        | |       t        |        t        |        |st        |        t        |        t        | |       y)z5Adds common arguments for creating and updating NATs.N)_AddAutoNetworkTier_AddIpAllocationArgs_AddSubnetworkArgs_AddSubnetworkNat64Args_AddTimeoutsArgs_AddMinPortsPerVmArg_AddLoggingArgs!_AddEndpointIndependentMappingArg_AddDrainNatIpsArgument_AddRulesArg_AddDynamicPortAllocationArgsr+   
for_creates     r   AddCommonNatArgsrP      sg    fvVZ(&*-6:&vz*&#F+	F#v
3r   c                 R    | j                  dt        j                  d      d       y )Nz--rulesa            Path to YAML file containing NAT Rules applied to the NAT.
          The YAML file format must follow the REST API schema for NAT Rules.
          See [API Discovery docs](https://www.googleapis.com/discovery/v1/apis/compute/alpha/rest)
          for reference.F)r&   r   r*   r>   r?   )r+   s    r   rL   rL      s0     ??  
   	r   c                 ^    ddd}| j                  dt        j                  d      |d       y )NzQHigh quality, Google-grade network tier with support for all networking products.zQPublic internet quality, with only limited support for other networking products.)PREMIUMSTANDARDz--auto-network-tierzBNetwork tier to use when automatically reserving NAT IP addresses.F)r&   r4   r   rR   )r+   r4   s     r   rC   rC      sB    !!' 	??
N   r   c                     | j                  d      }|j                  dddd       t        j                  | |d       y	)
zAAdds a mutually exclusive group to specify IP allocation options.Fr   z --auto-allocate-nat-external-ipsz:Automatically allocate external IP addresses for Cloud NAT
store_true)r&   actiondefault
IP_ADDRESS)mutex_groupcust_metavarN)add_mutually_exclusive_groupr*   IP_ADDRESSES_ARGAddArgument)r+   ip_allocations     r   rD   rD      sS     55u5E-(G	  
 -l  Dr   c                    d}|r|dz  }| j                  d|      }|j                  dt        j                  d      ddt        j
                  t        j                  	       |j                  d
t        j                  d      ddt        j                  t        j                  	       d}|j                  dd|t        j                  d             |s*|j                  dt        j                  d      ddd       yy):Adds a mutually exclusive group to specify subnet options.z#Options for IPv4 subnetwork ranges.zR If not specified, one of the options for IPv6 subnetwork ranges must be provided.F)r   r&   z--nat-all-subnet-ip-rangesz            Allow all IP ranges of all subnetworks in the region, including
            primary and secondary ranges, to use NAT.store_constsubnet_optionr&   rY   destconstrZ   z--nat-primary-subnet-ip-rangesza            Allow only primary IP ranges of all subnetworks in the region to use
            NAT.a      List of subnetwork primary and secondary IP ranges to be allowed to
    use NAT.

    * `SUBNETWORK:ALL` - specifying a subnetwork name with ALL includes the
    primary range and all secondary ranges of the subnet.
    * `SUBNETWORK` - including a subnetwork name includes only the primary
    subnet range of the subnetwork.
    * `SUBNETWORK:RANGE_NAME` - specifying a subnetwork and secondary range
    name includes only that secondary range. It does not include the
    primary range of the subnet.
    z--nat-custom-subnet-ip-rangeszSUBNETWORK[:RANGE_NAME|:ALL]r   
min_lengthr=   r&   r3   z--clear-nat-subnet-ip-rangesz)            Clear IPv4 subnetwork ranges.rX   clear_nat_subnet_ip_rangesr&   rY   rZ   rg   N)
r^   r*   r>   r?   r   r   r   r   r   r@   r+   rO   group_help_text
subnetworkcustom_subnet_help_texts        r   rE   rE      s)   9/	O 22? 3 * "?? 9 : ##((  	 &??   ''((  	 %,"!,	   
&__ - .)   
r   c                 t   d}|r|dz  }| j                  |      }|j                  dt        j                  d      ddt        j
                  t        j                         d	}|j                  d
d|t        j                  d             |s*|j                  dt        j                  d      ddd       yy)rc   z#Options for IPv6 subnetwork ranges.zR If not specified, one of the options for IPv4 subnetwork ranges must be provided.)r&   z--nat64-all-v6-subnet-ip-rangeszF            Allow all IPv6 subnetwork ranges in the region to use NAT.rd   subnet_ipv6_optionrf   zG    List of subnetworks with IPv6 ranges to be allowed to use NAT.
    z"--nat64-custom-v6-subnet-ip-ranges
SUBNETWORKr   ri   rk   z--clear-nat64-subnet-ip-rangesz)            Clear IPv6 subnetwork ranges.rX   Fclear_nat64_subnet_ip_rangesrm   N)	r^   r*   r>   r?   r    r!   r"   r   r@   rn   s        r   rF   rF     s    9/	O 22 3 * '?? J K--33   *"!,	   
(__ - .+   
r   c           	         t        | |dt        j                         t        j                  d      d       t        | |dt        j                         t        j                  d      d       t        | |dt        j                         t        j                  d      d	       t        | |d
t        j                         t        j                  d      d       t        | |dt        j                         t        j                  d      d       y)z.Adds arguments to specify connection timeouts.zudp-idle-timeoutz         Timeout for UDP connections. See
         https://cloud.google.com/sdk/gcloud/reference/topic/datetimes for
         information on duration formats.z!Clear timeout for UDP connectionszicmp-idle-timeoutz         Timeout for ICMP connections. See
         https://cloud.google.com/sdk/gcloud/reference/topic/datetimes for
         information on duration formats.z"Clear timeout for ICMP connectionsztcp-established-idle-timeoutz         Timeout for TCP established connections. See
         https://cloud.google.com/sdk/gcloud/reference/topic/datetimes for
         information on duration formats.z-Clear timeout for TCP established connectionsztcp-transitory-idle-timeoutz         Timeout for TCP transitory connections. See
         https://cloud.google.com/sdk/gcloud/reference/topic/datetimes for
         information on duration formats.z,Clear timeout for TCP transitory connectionsztcp-time-wait-timeoutz         Timeout for TCP connections in the TIME_WAIT state. See
         https://cloud.google.com/sdk/gcloud/reference/topic/datetimes for
         information on duration formats.z8Clear timeout for TCP connections in the TIME_WAIT stateN)_AddClearableArgumentr   Durationr>   r?   rN   s     r   rG   rG   *  s   j,k.B.B.Doo - . *+ j-{/C/C/Eoo - . +, j8oo - . 67 j79M9M9Ooo - . 56 j1;3G3G3Ioo - . ABr   c                 v    t        j                  d      }t        | |dt        j                  d      |d       y)zGAdds an argument to specify the minimum number of ports per VM for NAT.z  Minimum ports to be allocated to a VM.

  If Dynamic Port Allocation is disabled, this defaults to 64.

  If Dynamic Port Allocation is enabled, this defaults to 32 and must be set
  to a power of 2 that is at least 32 and lower than maxPortsPerVm.
  zmin-ports-per-vmr   )lower_boundz+Clear minimum ports to be allocated to a VMN)r>   r?   rw   r   
BoundedInt)r+   rO   r-   s      r   rH   rH   R  s:    oo  ) 
,>#..1=yEGr   c           	          t        j                  d      }t        | |dt        j                  dd      |d       t        j                  d      }| j                  dt        j                  |	       y
)zaAdds arguments for Dynamic Port Allocation to specify the maximum number of ports per VM for NAT.z  Maximum ports to be allocated to a VM.

  This field can only be set when Dynamic Port Allocation is enabled and
  defaults to 65536. It must be set to a power of 2 that is greater than
  minPortsPerVm and at most 65536.
  zmax-ports-per-vm@   i   )rz   upper_boundz+Clear maximum ports to be allocated to a VMzi  Enable dynamic port allocation.

  If not specified, Dynamic Port Allocation is disabled by default.
  z --enable-dynamic-port-allocation)rY   r&   N)r>   r?   rw   r   r{   r*   StoreTrueFalseAction)r+   rO   max_ports_help_textdpa_help_texts       r   rM   rM   a  sz     ! )  ?3 // # -
 	(--  r   c                     t        j                  d      }t        j                  d      }dddd}| j                  ddd	|
       | j                  d||       y	)z(Adds arguments to configure NAT logging.z    Enable logging for the NAT. Logs will be exported to Stackdriver. NAT
    logging is disabled by default.
    To disable logging for the NAT, use
    $ {parent_command} update MY-NAT --no-enable-logging --router ROUTER
      --region REGIONz    Filter for logs exported to stackdriver.

    The default is ALL.

    If logging is not enabled, filter settings will be persisted but will have
    no effect.

    Use --[no-]enable-logging to enable and disable logging.
z4Export logs for all connections handled by this NAT.z)Export logs for connection failures only.z,Export logs for successful connections only.)ALLERRORS_ONLYTRANSLATIONS_ONLYz--enable-loggingrX   NrY   rZ   r&   z--log-filter)r&   r4   r>   r?   r*   )r+   enable_logging_help_textlog_filter_help_textfilter_choicess       r   rI   rI   ~  s~    %__ .  " 	* 	 D@I.
 	#	  %
 	/  Ir   c                     | j                  d      }t        j                  | |       |j                  dddd       y )NFrW   )r\   z"--clear-nat-external-drain-ip-poolrX   zClear the drained NAT IPsr   )r^   DRAIN_NAT_IP_ADDRESSES_ARGr`   r*   )r+   drain_ips_groups     r   rK   rK     sG    777G/((_(M*&	  (r   c                 X    t        j                  d      }| j                  ddd |       y )Nz  Enable endpoint-independent mapping for the NAT (as defined in RFC 5128).

  If not specified, NATs have endpoint-independent mapping disabled by default.

  Use `--no-enable-endpoint-independent-mapping` to disable endpoint-independent
  mapping.
  z%--enable-endpoint-independent-mappingrX   r   r   )r+   r-   s     r   rJ   rJ     s6    oo  ) 	-	  r   c                    |r%| j                  dj                  |      |||       y| j                  d      }|j                  dj                  |      |||       |j                  dj                  |      dd|       y)	z>Adds an argument for a field that can be cleared in an update.z--{})r3   r&   r4   FrW   z
--clear-{}rX   r   N)r*   r)   r^   )r+   rO   arg_namearg_typearg_help
clear_helpr4   mutexs           r   rw   rw     s     
hhXw  P ///?E	hhXw  P	H%	  r   )z
operate onF)F)N)&__doc__
__future__r   r   r   enumr>   googlecloudsdk.callioper   "googlecloudsdk.command_lib.computer   compute_flags$googlecloudsdk.command_lib.util.apisr   ResourceArgumentr_   r?   r   Enumr   r    DEFAULT_LIST_FORMATr/   r7   rA   rP   rL   rC   rD   rE   rF   rG   rH   rM   rI   rK   rJ   rw   r   r   r   <module>r      s   : &  '   / E :1=11	!;+  <];;	'!(// # 
 + 499 tyy 
	 ((<4$
&D 9x%P%BPG:I@(, #'r   