
    6                         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
r
S rS	 r                    SS
 jrS rS rg)z8Code that's shared between multiple subnets subcommands.    )absolute_import)division)unicode_literals)
exceptions)flagsNc                     U(       a"  U(       a  U R                   R                  UUUS9$ U(       a  U R                   R                  XS9$ U R                   R                  XS9$ )z%Creates a subnetwork secondary range.)	rangeNamereservedInternalRangeipCidrRange)r	   r
   )r	   r   )messagesSubnetworkSecondaryRange)clientnameip_cidr_rangereserved_internal_ranges       3lib/googlecloudsdk/api_lib/compute/subnets_utils.py_CreateSecondaryRanger      ss    ??335! 4 # # ??33 4 G G ??33 4 3 3    c                    / n0 n0 n[        5       nU(       a=  U H7  n[        R                  " U5       H  u  pxXU'   UR                  U5        M     M9     U(       a=  U H7  n[        R                  " U5       H  u  pyXU'   UR                  U5        M     M9     [	        U5       H=  nUR                  [        XUR                  U5      UR                  U5      5      5        M?     U$ )z)Creates all secondary ranges of a subnet.)setsix	iteritemsaddsortedappendr   get)
r   secondary_range,secondary_range_with_reserved_internal_rangesecondary_rangesrange_name_to_cidr%range_name_to_reserved_internal_rangerange_names
range_namer   internal_ranges
             r   CreateSecondaryRangesr%   )   s     *,'+*'*}}_'E
#*)6:&
# (F + 2G(+o(F
$*<Jj9
# )G H ;'j 2 6 6z B155jA	CD (
 
r   c                 B   S nUb  U R                   R                  5       nUUl        U R                   R                  UR                  UR
                  UR                  5       US9nU R                  U R                  R                  SU4/5      $ Uc  Ub  U R                   R                  5       nU R                  U R                  R                  SU R                   R                  " S0 UR                  5       D64/5      S   nUR                  Ul        UR                  Ul        UR                  R                  [!        XU5      5        U R                  [#        XU5      /5      $ UGb  U R                   R                  5       nU R                  U R                  R                  SU R                   R                  " S0 UR                  5       D64/5      S   nUR                  Ul        UR                  Ul        US    Hz  nUUR                   Vs/ s H  nUR$                  PM     sn;  d  M0  [&        R(                  " SSR+                  UUR                   Vs/ s H  nUR$                  PM     sn5      5      e   UR                   Vs/ s H  nUR$                  US   ;  d  M  UPM     snUl        / nUR                  (       d  UR-                  S	5        U R                  R/                  U5         U R                  [#        XU5      /5      sSSS5        $ Uc  Uc  U	c
  U
c  Uc  UGbG  U R                   R                  5       nU R                  U R                  R                  SU R                   R                  " S0 UR                  5       D64/5      S   nUR                  Ul        U R                   R1                  US
9nUb4  [2        R4                  " U R                   5      R7                  U5      Ul        U	b  U	Ul        U
b4  [2        R<                  " U R                   5      R7                  U
5      Ul        Ub  UUl         Ub  UUl!        UUl"        U R                  [#        XU5      /5      $ Ub  U R                   R                  5       nU R                  U R                  R                  SU R                   R                  " S0 UR                  5       D64/5      S   nUR                  Ul        U R                   R                  RG                  [I        U" U5      5      5      Ul%        U R                  [#        XU5      /5      $ Ub  U R                   R                  5       nU R                  U R                  R                  SU R                   R                  " S0 UR                  5       D64/5      S   nUR                  Ul        UUl&        U R                  [#        XU5      /5      $ Ub  U R                   R                  5       nU R                  U R                  R                  SU R                   R                  " S0 UR                  5       D64/5      S   nUR                  Ul        U R                   R                  RO                  U5      Ul(        U R                  [#        XU5      /5      $ UGb  U R                   R                  5       nU R                  U R                  R                  SU R                   R                  " S0 UR                  5       D64/5      S   nUR                  Ul        U R                   R                  RR                  RT                  Ul+        U R                   RY                  UR                  URZ                  UR
                  UUS9nU R                  U R                  R                  SU4/5      $ Uc  Uc
  Uc  Uc  UGb  U R                   R                  5       nU R                  U R                  R                  SU R                   R                  " S0 UR                  5       D64/5      S   nUR                  Ul        Ub*  U R                   R                  R]                  U5      Ul/        Ub*  U R                   R                  Ra                  U5      Ul1        Ub  UUl2        Ub  UUl3        Ub  UUl4        U R                  [#        XU5      /5      $ U R                  / 5      $ s  snf s  snf s  snf ! , (       d  f       N.= f)a  Make the appropriate update request for the args.

Args:
  client: GCE API client
  subnet_ref: Reference to a subnetwork
  enable_private_ip_google_access: Enable/disable access to Google Cloud APIs
    from this subnet for instances without a public ip address.
  allow_cidr_routes_overlap: Allow/Disallow this subnetwork's ranges to
    conflict with existing static routes.
  add_secondary_ranges: List of secondary IP ranges to add to the subnetwork
    for use in IP aliasing.
  add_secondary_ranges_with_reserved_internal_range: List of secondary IP
    ranges that are associated with InternalRange resources.
  remove_secondary_ranges: List of secondary ranges to remove from the
    subnetwork.
  enable_flow_logs: Enable/disable flow logging for this subnet.
  aggregation_interval: The internal at which to aggregate flow logs.
  flow_sampling: The sampling rate for flow logging in this subnet.
  metadata: Whether metadata fields should be added reported flow logs.
  filter_expr: custom CEL expression for filtering flow logs
  metadata_fields: custom metadata fields to be added to flow logs
  set_new_purpose: Update the purpose of the subnet.
  set_role_active: Updates the role of a BACKUP subnet to ACTIVE.
  drain_timeout_seconds: The maximum amount of time to drain connections from
    the active subnet to the backup subnet with set_role_active=True.
  private_ipv6_google_access_type: The private IPv6 google access type for the
    VMs in this subnet.
  stack_type: The stack type for this subnet.
  ipv6_access_type: The IPv6 access type for this subnet.
  external_ipv6_prefix: The IPv6 external prefix to be assigned to this
    subnet.
  internal_ipv6_prefix: The IPv6 internal prefix to be assigned to this
    subnet. When ULA is enabled, the prefix will be ignored.
  ip_collection: The IP collection that provisions BYOIP v6 addresses for this
    subnet.

Returns:
  response, result of sending the update request for the subnetwork
c                 B    U R                  SS5      R                  5       $ )N-_)replaceupper)xs    r   <lambda>-MakeSubnetworkUpdateRequest.<locals>.<lambda>   s    aiiS1779r   N)projectregion
subnetwork*subnetworksSetPrivateIpGoogleAccessRequestSetPrivateIpGoogleAccessGetr   zremove-secondary-rangesz;Subnetwork does not have a range {}, present ranges are {}.secondaryIpRanges)enable)r/   r1   r0   subnetworkResourcedrainTimeoutSecondsPatch )5r   *SubnetworksSetPrivateIpGoogleAccessRequestprivateIpGoogleAccess1ComputeSubnetworksSetPrivateIpGoogleAccessRequestr/   r0   NameMakeRequestsapitools_clientsubnetworks
SubnetworkComputeSubnetworksGetRequestAsDictr5   fingerprintextendr%   CreateSubnetworkPatchRequestr	   calliope_exceptionsUnknownArgumentExceptionformatr   IncludeFieldsSubnetworkLogConfigr    GetLoggingAggregationIntervalArgGetEnumForChoiceaggregationIntervalflowSamplingGetLoggingMetadataArgmetadata
filterExprmetadataFields	logConfig&PrivateIpv6GoogleAccessValueValuesEnumConvertPrivateIpv6GoogleAccessprivateIpv6GoogleAccessallowSubnetCidrRoutesOverlapPurposeValueValuesEnumpurposeRoleValueValuesEnumACTIVEroleComputeSubnetworksPatchRequestr1   StackTypeValueValuesEnum	stackTypeIpv6AccessTypeValueValuesEnumipv6AccessTypeexternalIpv6PrefixinternalIpv6PrefixipCollection) r   
subnet_refenable_private_ip_google_accessallow_cidr_routes_overlapadd_secondary_ranges1add_secondary_ranges_with_reserved_internal_rangeremove_secondary_rangesenable_flow_logsaggregation_intervalflow_samplingrR   filter_exprmetadata_fieldsset_new_purposeset_role_activedrain_timeout_secondsprivate_ipv6_google_access_type
stack_typeipv6_access_typeexternal_ipv6_prefixinternal_ipv6_prefixip_collectionconvert_to_enumgoogle_accessgoogle_access_requestr1   original_subnetworkr   rcleared_fields
log_configpatch_requests                                    r   MakeSubnetworkUpdateRequestr   B   s	   ~ :/$0BBD *IM' 	II&&$$!(7D	 	J 	F  				+	+-G		     	(9E++-J --				+	+U		5	5	L
8I8I8K	L	N/  	
 $7#H#HJ 0<<J  ''=	?@
 	%f*	EFH H*++-J --				+	+U		5	5	L
8I8I8K	L	N/  	
 $7#H#HJ 0<<J'*	:+G+GH+Gaakk+GH	H!::% (%%+VJ,H,HI,Hqq{{,HI&KL 	L + '88$8a;;5a88 	
8$J 
 N''/0				-	-n	=  'JG
HJ 
>	= 	$(<(H!X%9?#>++-J --				+	+U		5	5	L
8I8I8K	L	N/  	
 1<<J44<L4MJ'','M'M
//(++,@A $  -j!77
//++H5 )j""1j%J	%f*	EFH H&2++-J --				+	+U		5	5	L
8I8I8K	L	N/  	
 1<<J 	""II* ?@B	C & 	%f*	EFH H ,++-J --**44Kz7H7H7JK0 /  	
	
 1<<J.GJ+	%f*	EF  "++-J --				+	+U		5	5	L
8I8I8K	L	N/  	
 1<<J33JJJ	%f*	EFH H"++-J --				+	+U		5	5	L
8I8I8K	L	N/  	
 1<<Joo00DDKKJOOOBB""((  %1 C M 

 
 
,
,g}	EF  		"		%		)		)++-J --**44Kz7H7H7JK0 /  	
	
 1<<J
//
$
$
=
=j
I  #
//
$
$
B
B 
 '&:j#'&:j#  -j	%f*	EF  
		R	  O I J$ 
>	=s$   ddd&d3d
dc                     U R                   R                  UR                  UR                  UR                  US9nU R
                  R                  SU4$ )N)r/   r1   r0   r7   r9   )r   r_   r/   r1   r0   r@   rA   )r   rg   subnetwork_resourcer   s       r   rG   rG   6  sU    //@@  &&,	 A .-
 
 
 
,
,g}	EEr   c                 0    SSSS.nUR                  U 5      $ )zReturn PrivateIpv6GoogleAccess enum defined in mixer.

Args:
  choice: Enum value of PrivateIpv6GoogleAccess defined in gcloud.
DISABLE_GOOGLE_ACCESS%ENABLE_BIDIRECTIONAL_ACCESS_TO_GOOGLE#ENABLE_OUTBOUND_VM_ACCESS_TO_GOOGLE)DISABLEENABLE_BIDIRECTIONAL_ACCESSENABLE_OUTBOUND_VM_ACCESS)r   )choicechoices_to_enums     r   rW   rW   ?  s'     )%L#H/
 
		V	$$r   )NNNNNNNNNNNNNNNNNNNN)__doc__
__future__r   r   r   googlecloudsdk.callioper   rH   3googlecloudsdk.command_lib.compute.networks.subnetsr   r   r   r%   r   rG   rW   r:   r   r   <module>r      sv    ? &  ' E E 
38 %)"6: $(-q!hF%r   