
    o[                     F   S 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Jr  SSKJr  SSKrS rS rS rS rS rS r\R>                  \R@                  " \RB                  RD                  5       " S S\RF                  5      5       5       r$\R@                  " \RB                  RJ                  5       " S S\$5      5       r&\R@                  " \RB                  RN                  5       " S S\&5      5       r(g)z!Command for creating subnetworks.    )absolute_import)division)unicode_literals)base_classes)subnets_utils)utils)apis)arg_parsers)base)flags)resource_manager_tags_utils)	arg_utilsNc                      SSSS.$ )Nz4Define a subnet for a network in custom subnet mode.z      *{command}* define a subnetwork for a network in custom subnet mode.
      Subnets must be uniquely named per region.
      z        To create the subnetwork ``subnet-1'' with address range ``10.10.0.0/24'' in the network ``network-0'', run:

        $ {command} subnet-1 --network=network-0 --range=10.10.0.0/24 --region=us-central1
      )briefDESCRIPTIONEXAMPLES r       .lib/surface/compute/networks/subnets/create.py_DetailedHelpr   #   s     A



 r   c                 <   U R                   R                  [        R                  5        [        R                  " 5       R                  U SS9  [        R                  " S5      R                  U 5        [        R                  " S[        R                  5      nU R                  SSS9  U R                  SS	S9  U R                  S
SSSS9  U R                  S[        R                  " SS9SSSS9  U R                  SSSSS9  [        R                  " X5        U R                  S[        R                   " SSS9SS9  U R                  SS S9  [        R"                  " X5        U R                  S![        R$                  " 5       S"SS#S$9  U(       au  [        R                  " S[        R&                  5      n[        R(                  " X5        U R                  S%[        R                   " SSS9S&S9  [        R*                  " X5        S'S(S)S*S+S,S-S..n	U(       a  S/U	S0'   U(       a  S1U	S2'   U(       a  S-U	S3'   U R                  S4U	[,        R.                  S5S69  U R                  S7S8S9S:.S; S<S69  [        R                  " SU5      n[1        U5      R2                  R5                  U 5        S=S>S?S@.n
U R                  SAU
[,        R.                  SBS69  SCSDSE.nU R                  SFU[,        R.                  SGS69  U R                   R7                  [        R8                  5        U(       a7  U R;                  SHS9nUR                  SISSJSKSL9  UR                  SM[<        SNSOSP9  U R                  SQSRS9  U R                  SS[        R                  " SS9SSTSUS9  U R                  SVSWS9  U R                  SXSYS9  U R                  SZ[        R                  " 5       S[S\SP9  U(       a%  S]S^S_.nU R                  S`U[,        R.                  SaS69  [        R>                  " 5       R                  U 5        g)bz*Add subnetwork create arguments to parser.create)operation_type,The network to which the subnetwork belongs.computez--descriptionz+An optional description of this subnetwork.)helpz--rangez9The IP space allocated to this subnetwork in CIDR format.z!--enable-private-ip-google-access
store_trueFzfEnable/disable access to Google Cloud APIs from this subnet for instances without a public ip address.)actiondefaultr   z--secondary-range   )
min_lengthappendzPROPERTY=VALUEa0        Adds a secondary IP range to the subnetwork for use in IP aliasing.

      For example, `--secondary-range range1=192.168.64.0/24` adds
      a secondary range 192.168.64.0/24 with name range1.

      * `RANGE_NAME` - Name of the secondary range.
      * `RANGE` - `IP range in CIDR format.`
      )typer   metavarr   z--enable-flow-logsNzEnable/disable VPC Flow Logs for this subnet. More information for VPC Flow Logs can be found at https://cloud.google.com/vpc/docs/using-flow-logs.z--logging-flow-samplingg        g      ?)lower_boundupper_boundaj        Can only be specified if VPC Flow Logs for this subnetwork is
      enabled. The value of the field must be in [0, 1]. Set the sampling rate
      of VPC flow logs within the subnetwork where 1.0 means all collected
      logs are reported and 0.0 means no logs are reported. Default is 0.5
      which means half of all collected logs are reported.
      )r#   r   z--logging-filter-exprz        Can only be specified if VPC Flow Logs for this subnetwork is enabled.
        Export filter used to define which logs should be generated.
        z--logging-metadata-fieldsMETADATA_FIELDz      Can only be specified if VPC Flow Logs for this subnetwork is enabled
      and "metadata" is set to CUSTOM_METADATA. The comma-separated list of
      metadata fields that should be added to reported logs.
      )r#   r$   r   r   z--flow-samplingay          Can only be specified if VPC flow logging for this subnetwork is
        enabled. The value of the field must be in [0, 1]. Set the sampling rate
        of VPC flow logs within the subnetwork where 1.0 means all collected
        logs are reported and 0.0 means no logs are reported. Default is 0.5
        which means half of all collected logs are reported.
        z5Regular user created or automatically created subnet.z-Reserved for Internal HTTP(S) Load Balancing.z1Reserved for Regional Envoy-based Load Balancing.z0Reserved for Global Envoy-based  Load Balancing.z=Reserved for Private Service Connect Internal Load Balancing.z1Reserved for use as source range for Private NAT.z2Reserved for subnet migration between peered VPCs.)PRIVATEINTERNAL_HTTPS_LOAD_BALANCERREGIONAL_MANAGED_PROXYGLOBAL_MANAGED_PROXYPRIVATE_SERVICE_CONNECTPRIVATE_NATPEER_MIGRATIONzGReserved for Aggregate Ranges used for aggregating private subnetworks.	AGGREGATEz"Reserved for Custom Hardware Link.CUSTOM_HARDWARE_LINKr.   z	--purposezThe purpose of this subnetwork.)choicesr#   r   z--rolez)The ACTIVE subnet that is currently used.z3The BACKUP subnet that could be promoted to ACTIVE.)ACTIVEBACKUPc                 B    U R                  SS5      R                  5       $ )N-_)replaceupper)xs    r   <lambda>_AddArgs.<locals>.<lambda>   s    QYYsC(..0r   zThe role of subnetwork. This field is required when the purpose is set to GLOBAL_MANAGED_PROXY, REGIONAL_MANAGED_PROXY or INTERNAL_HTTPS_LOAD_BALANCER.z;New VMs in this subnet will only be assigned IPv4 addressesz<New VMs in this subnet can have both IPv4 and IPv6 addressesz;New VMs in this subnet will only be assigned IPv6 addresses)	IPV4_ONLY	IPV4_IPV6	IPV6_ONLYz--stack-typezuThe stack type for this subnet. Determines if IPv6 is enabled on the subnet. If not specified IPV4_ONLY will be used.z*VMs in this subnet can have external IPv6.z*VMs in this subnet can have internal IPv6.)EXTERNALINTERNALz--ipv6-access-typezIPv6 access type can be specified only when the subnet is created, or when the subnet is first updated to have a stack type of IPV4_IPV6. Once set, the access type is immutable.zL2 networking specifications.z--enable-l2TzP        If set to true, enables l2 networking capability on subnetwork.
        )r   requiredr   z--vlanVLANz@        Specifies ID of the vlan to tag the subnetwork.
        )r#   r$   r   z--reserved-internal-rangea  
      If set, the primary IP range of the subnetwork will be
      associated with the given internal range resource.
      If --range is set, the subnetwork will only use the given IP range,
      which must be contained by the IP range defined by the internal range resource.
      For example,
      --range=10.0.0.0/24
      --reserved-internal-range //networkconnectivity.googleapis.com/projects/PROJECT/locations/global/internalRanges/RANGE
      If --range is not set, the subnetwork will use the entire IP range
      defined by the internal range resource.
      For example, `--reserved-internal-range //networkconnectivity.googleapis.com/projects/PROJECT/locations/global/internalRanges/RANGE`
      z.--secondary-range-with-reserved-internal-rangezRANGE_NAME=INTERNAL_RANGE_URLa         Adds secondary IP ranges that are associated with internal range
       resources.
       For example, `--secondary-range-with-reserved-internal-range
       range1=//networkconnectivity.googleapis.com/projects/PROJECT/locations/global/internalRanges/RANGE`
       adds a secondary range with the reserved internal range resource.
       * `RANGE_NAME` - Name of the secondary range.
       * `INTERNAL_RANGE_URL` - `URL of an internal range resource.`
      z--external-ipv6-prefixa  
      The /64 external IPv6 CIDR range to assign to this subnet. The range must
      be associated with an IPv6 BYOIP sub-prefix that is defined by the
      --ip-collection flag. If you specify --ip-collection but not
      --external-ipv6-prefix, a random /64 range is allocated from
      the sub-prefix.

      For example, `--external-ipv6-prefix=2600:1901:0:0:0:0:0:0/64`
      z--internal-ipv6-prefixa  
      The /64 internal IPv6 CIDR range to assign to this subnet. The range must
      be associated with an IPv6 BYOIP sub-prefix that is defined by the
      --ip-collection flag. If you specify --ip-collection but not
      --internal-ipv6-prefix, a random /64 range is allocated from the
      sub-prefix.

      For example, `--internal-ipv6-prefix 2600:1901:0:0:0:0:0:0/64`
      z--resource-manager-tagsz	KEY=VALUEz\          A comma-separated list of Resource Manager tags to apply to the subnetwork.
      z
        VMs connected to this subnet receive ARP responses for IPv4
        addresses from any ranges of the subnet that are assigned to the VM's
        NIC. The DHCP responses contain the netmask of the subnet, instead of
        /32.
        z
        VMs connected to this subnet receive ARP responses only for IP
        addresses in the primary IPv4 range of the subnet. DHCP responses
        contain the netmask of the subnet, instead of /32.
        )ARP_ALL_RANGESARP_PRIMARY_RANGEz--resolve-subnet-maskz;Resolve subnet mask can only be set when subnet is created.) display_info	AddFormatr   #DEFAULT_LIST_FORMAT_WITH_IPV6_FIELDSubnetworkArgumentAddArgumentnetwork_flagsNetworkArgumentForOtherResourcer	   GetMessagesModulecompute_apiCOMPUTE_GA_API_VERSIONadd_argumentr
   ArgDictAddLoggingAggregationIntervalBoundedFloatAddLoggingMetadataArgListCOMPUTE_ALPHA_API_VERSION'AddLoggingAggregationIntervalDeprecatedAddLoggingMetadataDeprecatedr   ChoiceToEnumName(GetPrivateIpv6GoogleAccessTypeFlagMapper
choice_argAddToParserAddCacheUpdaterNetworksCompleter	add_groupintIpCollectionArgument)parserinclude_alpha_logginginclude_aggregate_purpose
include_l2include_custom_hardware_linkapi_versioninclude_peer_migration_purposeinclude_resolve_subnet_maskmessagespurpose_choicesstack_type_choicesipv6_access_type_choicesl2_argsresolve_subnet_mask_choicess                 r   _AddArgsro   5   s    	 I IJ(((I//466Ak&6I##I$/$F$FH( 	I  K 	F  H 	)5	  7 	!,
   	A	  C %%f7##E
  	 	   6,! 
  	 %%i&1&K&KMH	11&C
%%#3G  	 
&&v8 I
9 > = JHL/$ 	 K 
 ", *+ $< $% 	%%,	  . 	?I 1+   ##I{;(*84??KK
 H I H
 	 %%D   ?> 	&%%G  	 	%%m&E&EF$CDG	   	   	!
   	6!,-
    	
   	
   	 
	   !# +''J	   **62r   c                 `    [         R                  " SU R                  R                  SSSS.SS9$ )Nz!--private-ipv6-google-access-typedisablezenable-bidirectional-accesszenable-outbound-vm-access)DISABLE_GOOGLE_ACCESS%ENABLE_BIDIRECTIONAL_ACCESS_TO_GOOGLE#ENABLE_OUTBOUND_VM_ACCESS_TO_GOOGLEz?The private IPv6 google access type for the VMs in this subnet.)custom_mappingshelp_str)r   ChoiceEnumMapper
Subnetwork&PrivateIpv6GoogleAccessValueValuesEnum)ri   s    r   rY   rY   n  s=    		#	#)@@ +) Q
 r   c                    U R                  UR                  5       UR                  UR                  5       UR                  S9nUR
                  (       a  UR
                  Ul        UR                  cB  UR                  c5  UR                  c(  UR                  c  UR                  c  UR                  Gb  U R                  UR                  S9nUR                  (       a4  [        R                  " U 5      R!                  UR                  5      Ul        UR                  b  UR                  Ul        UR                  (       a4  [        R&                  " U 5      R!                  UR                  5      Ul        UR                  b  UR                  Ul        UR                  b  UR                  Ul        Xl        U(       GaQ  UR                  c(  UR0                  c  UR2                  c  UR(                  Gb  UR.                  b  UR.                  OU R                  UR                  S9nUR0                  (       a4  [        R4                  " U 5      R!                  UR0                  5      Ul        UR2                  b  UR2                  Ul        UR(                  (       a4  [        R6                  " U 5      R!                  UR(                  5      Ul        UR                  b  UR                  Ul        UR                  b  UR                  Ul        Xl        UR8                  (       a*  U R                   R;                  UR8                  5      Ul        UR8                  U R                   R:                  R<                  :X  Gd)  UR8                  U R                   R:                  R>                  :X  d  UR8                  U R                   R:                  R@                  :X  d  UR8                  U R                   R:                  RB                  :X  d  U	(       a.  UR8                  U R                   R:                  RD                  :X  dj  U(       a.  UR8                  U R                   R:                  RF                  :X  d5  U(       aC  UR8                  U R                   R:                  RH                  :X  a  SUl%        SUl&        SUl        [O        USS5      (       a*  U R                   RQ                  URR                  5      Ul)        URT                  b4  [        RV                  " U 5      R!                  URT                  5      Ul,        URZ                  (       a*  U R                   R]                  URZ                  5      Ul/        UR`                  (       a*  U R                   Rc                  UR`                  5      Ul2        U(       aJ  URf                  (       a9  SUl4        URj                  b%  URl                  Ro                  URj                  5        URp                  (       a  URp                  Ul9        URt                  (       a  URt                  Ul;        URx                  (       a  URx                  Ul=        U(       a  UR                  5       Ul>        UR~                  b  [        XR~                  5      UlA        U
(       a;  UR                  (       a*  U R                   R                  UR                  5      UlD        U$ )zCreate the subnet resource.)namedescriptionnetworkprivateIpGoogleAccessN)enableroleT)Erx   Namer|   SelfLinkenable_private_ip_google_accessrangeipCidrRangeenable_flow_logslogging_aggregation_intervallogging_flow_samplinglogging_metadatalogging_filter_exprlogging_metadata_fieldsSubnetworkLogConfigr    GetLoggingAggregationIntervalArgGetEnumForChoiceaggregationIntervalflowSamplingGetLoggingMetadataArgmetadata
filterExprmetadataFields	logConfigaggregation_intervalflow_sampling*GetLoggingAggregationIntervalArgDeprecatedGetLoggingMetadataArgDeprecatedpurposePurposeValueValuesEnumr)   r*   r+   r,   r.   r/   r0   r~   enableFlowLogsgetattrRoleValueValuesEnumr   private_ipv6_google_access_typerY   privateIpv6GoogleAccess
stack_typeStackTypeValueValuesEnum	stackTypeipv6_access_typeIpv6AccessTypeValueValuesEnumipv6AccessType	enable_l2enableL2vlanvlansr"   reserved_internal_rangereservedInternalRangeexternal_ipv6_prefixexternalIpv6Prefixinternal_ipv6_prefixinternalIpv6PrefixipCollectionresource_manager_tags_CreateSubnetworkParamsparamsresolve_subnet_mask ResolveSubnetMaskValueValuesEnumresolveSubnetMask)ri   
subnet_refnetwork_refargsrb   rc   rd   re   ip_collection_refrg   rh   
subnetwork
log_configs                r   _CreateSubnetworkr   ~  s    ""??""""$ @@	 # B* 
ZZ!ZZJ
'
''3
  ,
'
*
"".--T5J5J-KJ((','M'M
($$T%F%FG $!!- $ : :j!77
$$T%:%:; +"66j##/"&">">j%)!!-&$--*C","6"6"B*



&
&d.C.C
&
D  
	"	"<<**4+D+DE 	& 
			'"&"4"4
	#CC&&t}}5 			!	!	- $ 8 8
		%	%	1$($@$@
!'	\\!,,CCJ 				3	3	P	PQ							3	3	J	J
K							3	3	H	H
I							3	3	K	K
L )    77FFG $    77AAB '    77LLM
 (,J$ $JJT64  ))==diiHJO	))566	&&t'K'KL & 
__#..GGJ 
99!!	#  DNNJyydii(	!!'+'C'CJ$	$($=$=J!	$($=$=J!/88:J	+/,,J !



>
>&& "
 
r   c           	         [         R                  " U5      nU R                  n[        [        R
                  " U5      5       VVs/ s H  u  pEUR                  R                  XES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SubnetworkParamssortedsix	iteritemsResourceManagerTagsValueAdditionalProperty)ri   r   resource_manager_tags_mapr   r   r   additional_propertiess          r   r   r     s    !889NO  $$& s}}-FGHH*# %%88S8NH   
 994 : 
 	s   %B c                    UR                   n[        R                  " S5      R                  XR                  5      n	[
        R                  " 5       R                  U UR                  [        R                  " U5      S9n
SnU R                  (       a.  [
        R                  " 5       R                  XR                  5      n[        UR                  U
U	U UUUUUUU5      nUR                  R                  UU
R                  U
R                  S9n[         R"                  " UU R$                  U R&                  5      nXR(                  l        UR-                  UR.                  R0                  SU4/5      $ )<Issues a list of requests necessary for adding a subnetwork.r   )scope_listerN)r   regionprojectInsert)clientrJ   rK   ResolveAsResource	resourcesr   rH   compute_flagsGetDefaultScopeListerip_collectionr`   r   ri   ComputeSubnetworksInsertRequestr   r   r   CreateSecondaryRangessecondary_range,secondary_range_with_reserved_internal_ranger   secondaryIpRangesMakeRequestsapitools_clientsubnetworks)r   holderrb   rc   rd   re   rg   rh   r   r   r   r   r   requestsecondary_rangess                  r   _Runr   !  sm    ==&==466G6G
  7"  '');;
 66v> < @* 	224FF  !oo
"$!* OO;;   < "'
 #88

77 *:&			v55AA8&( ) 
* *r   c                   l    \ rS rSrSrSrSrSr\R                  r
SrSrSr\" 5       r\S 5       rS rSrg)	CreateiW  zCreate a GA subnet.FTc           
          [        UU R                  U R                  U R                  U R                  U R
                  U R                  U R                  5        g )N)ro   _include_alpha_logging_include_aggregate_purpose_include_l2_include_custom_hardware_link_api_version_include_peer_migration_purpose_include_resolve_subnet_mask)clsra   s     r   ArgsCreate.Argsf  sJ    ""&&))++((	r   c           
          [         R                  " U R                  5       5      n[        UUU R                  U R
                  U R                  U R                  U R                  U R                  5      $ )r   )
r   ComputeApiHolderReleaseTrackr   r   r   r   r   r   r   )selfr   r   s      r   Run
Create.Runs  sd    **4+<+<+>?F##''**,,))	 	r   r   N)__name__
__module____qualname____firstlineno____doc__r   r   r   rM   rN   r   r   r   r   r   detailed_helpclassmethodr   r   __static_attributes__r   r   r   r   r   W  sS      $+33,"'$(!!&/-
 
r   r   c                   4    \ rS rSrSr\R                  rSrSr	g)
CreateBetai  z*Create a subnet in the Beta release track.Tr   N)
r   r   r   r   r   rM   COMPUTE_BETA_API_VERSIONr   r   r   r   r   r   r  r    s    255,!%r   r  c                   H    \ rS rSrSrSrSrSr\R                  r
SrSrSrSrg)CreateAlphai  z+Create a subnet in the Alpha release track.Tr   N)r   r   r   r   r   r   r   r   rM   rU   r   r   r   r   r   r   r   r   r  r    s3    3#+66,"&$(!!%r   r  ))r   
__future__r   r   r   googlecloudsdk.api_lib.computer   r   r   rM   googlecloudsdk.api_lib.utilr	   googlecloudsdk.callioper
   r   "googlecloudsdk.command_lib.computer   r   r   +googlecloudsdk.command_lib.compute.networksrJ   3googlecloudsdk.command_lib.compute.networks.subnets$googlecloudsdk.command_lib.util.apisr   r   r   ro   rY   r   r   r   UniverseCompatibleReleaseTracksr   GACreateCommandr   BETAr  ALPHAr  r   r   r   <module>r     s   ( &  ' 7 8 ? , / ( E J N E : 
$v3r	 Pf 3*l D%%(()&T & * &R D%%**+& & ,& D%%++,	&* 	& -	&r   