
    t                        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
 rS rS rS rS rS rS rS rS rS rS rS rS rS r\R:                  R<                  4S jr    S1S jr        S2S jr!  S3S jr"S r#S r$S r%S  r&S! r'S" r(S# r)S$ r*S% r+S& r,S' r- S4S( jr. S4S) jr/S* r0S+ r1S, r2S- r3S. r4\R:                  Rj                  4S/ jr6S0 r7g)5zKHelper functions for constructing and validating AlloyDB instance requests.    )absolute_import)division)unicode_literals)api_util)baseDetailedArgumentError)labels_util)
propertiesc                 l    [        XU5      nUR                  UUR                  UR                  5       S9$ )ah  Validates command line input arguments and passes parent's resources for GA track.

Args:
  client: Client for api_utils.py class.
  alloydb_messages: Messages module for the API client.
  project_ref: parent resource path of the resource being created
  args: Command line input arguments.

Returns:
  Fully-constructed request to create an AlloyDB instance.
instance
instanceIdparent)_ConstructInstanceFromArgs6AlloydbProjectsLocationsClustersInstancesCreateRequestr   RelativeNameclientalloydb_messagesproject_refargsinstance_resources        9lib/googlecloudsdk/command_lib/alloydb/instance_helper.py ConstructCreateRequestFromArgsGAr      sB     14P MM$]]))+ N     c                 l    [        XU5      nUR                  UUR                  UR                  5       S9$ )ak  Validates command line input arguments and passes parent's resources for beta tracks.

Args:
  client: Client for api_utils.py class.
  alloydb_messages: Messages module for the API client.
  project_ref: Parent resource path of the resource being created
  args: Command line input arguments.

Returns:
  Fully-constructed request to create an AlloyDB instance.
r   )_ConstructInstanceFromArgsBetar   r   r   r   s        r   "ConstructCreateRequestFromArgsBetar   5   sE     5
 MM$]]))+ N r   c                 l    [        XU5      nUR                  UUR                  UR                  5       S9$ )ak  Validates command line input arguments and passes parent's resources for alpha track.

Args:
  client: Client for api_utils.py class.
  alloydb_messages: Messages module for the API client.
  project_ref: Parent resource path of the resource being created
  args: Command line input arguments.

Returns:
  Fully-constructed request to create an AlloyDB instance.
r   )_ConstructInstanceFromArgsAlphar   r   r   r   s        r   #ConstructCreateRequestFromArgsAlphar"   P   sE     6
 MM$]]))+ N r   c                     UR                   (       d  UR                  (       a$  U R                  UR                   UR                  S9$ [        S5      e)zJValidates command line input arguments and creates a MachineConfig object.cpuCountmachineTypez7Either --cpu-count or --machine-type must be specified.)	cpu_countmachine_typeMachineConfigr	   )r   r   s     r   $ConstructCreateMachineConfigFromArgsr*   k   sJ    	^^t(())T->-> *    A r   c                    UR                  5       n[        XR                  5      Ul        [	        X5      Ul        U R                  R                  S[        R                  R                  R                  R                  UR                  UR                  UR                  S9nUR!                  5       Ul        [$        R&                  " UUR                   R(                  SS9Ul        [-        XR.                  5      Ul        UR0                  UR                   R2                  R4                  :X  a  UR7                  UR8                  S9Ul        [=        UUR>                  UR@                  URB                  URD                  S9Ul#        [I        UURJ                  URL                  5      Ul'        [Q        UURR                  URT                  URV                  URX                  S9Ul-        UR\                  (       d  UR^                  c  UR`                  b/  [c        UUR\                  UR^                  UR`                  S9Ul2        URf                  (       a  [i        UURf                  URj                  URl                  URn                  URp                  URr                  URt                  URv                  URx                  URz                  UR|                  UR~                  US	9Ul@        U$ )
aG  Validates command line input arguments and passes parent's resources to create an AlloyDB instance.

Args:
  client: Client for api_utils.py class.
  alloydb_messages: Messages module for the API client.
  args: Command line input arguments.

Returns:
  An AlloyDB instance to create with the specified command line arguments.
-alloydb.projects.locations.clusters.instances
projectsIdlocationsId
clustersIdinstancesIddatabase_flagslabels_dest	nodeCount)#insights_config_query_string_length&insights_config_query_plans_per_minute'insights_config_record_application_tags%insights_config_record_client_addressr   assign_inbound_public_ipauthorized_external_networksoutbound_public_ipallocated_ip_range_overrider   allowed_psc_projectspsc_network_attachment_uripsc_auto_connectionsr   enable_connection_poolingconnection_pooling_pool_mode connection_pooling_min_pool_size connection_pooling_max_pool_size"connection_pooling_max_client_conn&connection_pooling_server_idle_timeout%connection_pooling_query_wait_timeoutconnection_pooling_stats_users,connection_pooling_ignore_startup_parameters"connection_pooling_server_lifetime1connection_pooling_client_connection_idle_timeout*connection_pooling_max_prepared_statementsr   )AInstanceParseAvailabilityTypeavailability_typeavailabilityTyper*   machineConfigresource_parserCreater   VALUEScoreproject	GetOrFailregionclusterr   r   namer
   ParseCreateArgsDatabaseFlagsValuedatabaseFlags_ParseInstanceTypeinstance_typeinstanceTypeInstanceTypeValueValuesEnum	READ_POOLReadPoolConfigread_pool_node_countreadPoolConfig_QueryInsightsConfigr7   r8   r9   r:   queryInsightsConfigClientConnectionConfigssl_moderequire_connectorsclientConnectionConfigNetworkConfigr<   r=   r>   r?   networkConfigrA   rB   rC   PscInstanceConfigpscInstanceConfigrE   _ConnectionPoolConfigrF   rG   rH   )connection_pooling_max_client_connectionsrJ   rK   rL   rM   rN   rO   rP   connectionPoolConfigr   r   r   r   instance_refs        r   r   r   w   s    '//1 (=..($ %I%! ''..5""''//99++-- / , (446$/$?$?
22"%!
 $6**$ 
 $$		"	"	>	>	H	HI (8'F'F++ (G ($ +?*.*R*R-1-X-X.2.Z.Z,0,V,V+' .D
mm
.* %2'#<<#'#D#D00"&"B"B%! 		(	(	4		"	"	.*;)!66#'#B#B!66	+' 
##-B)"&"@"@%)%F%F)-)N)N)-)N)N+/+Y+Y/3/Z/Z.2.X.X'+'J'J595f5f+/+R+R:>:p:p373b3b.*" 
r   c                 `   [        XU5      n[        UUR                  UR                  UR                  UR
                  UR                  UR                  UR                  S9Ul	        UR                  cu  UR                  ch  UR                  c[  UR                  cN  UR                  cA  UR                  c4  UR                   c'  UR"                  c  UR$                  c  UR&                  bD  [)        USSU5      nUR*                  (       d  UR-                  5       Ul        XCR*                  l        U$ )aV  Validates command line input arguments and passes parent's resources to create an AlloyDB instance for beta track.

Args:
  client: Client for api_utils.py class.
  alloydb_messages: Messages module for the API client.
  args: Command line input arguments.

Returns:
  An AlloyDB instance to create with the specified command line arguments.
)observability_config_enabled&observability_config_preserve_comments&observability_config_track_wait_events,observability_config_max_query_string_length,observability_config_record_application_tags+observability_config_query_plans_per_minute)observability_config_track_active_queriesN)r   _ObservabilityConfigrz   r{   r|   r}   r~   r   r   observabilityConfigautoscaler_max_node_count#autoscaler_cool_down_period_secondsautoscaler_target_cpu_usageenable_autoscalerautoscaler_set_scheduleautoscaler_schedule_cron_exp$autoscaler_schedule_duration_seconds"autoscaler_schedule_min_node_countautoscaler_schedule_time_zoneautoscaler_schedule_descriptionParseAutoScalingConfigri   rg   autoScalingConfig)r   r   r   r   auto_scaling_configs        r   r   r      s    14P*>#'#D#D-1-X-X-1-X-X373d3d373d3d262b2b040^0^	+' $$0		1	1	=		)	)	5				+		%	%	1		*	*	6		2	2	>		0	0	<		+	+	7		-	-	90$d ++)9)H)H)J&9L$$6	r   c                     [        XU5      nU$ )aW  Validates command line input arguments and passes parent's resources to create an AlloyDB instance for alpha track.

Args:
  client: Client for api_utils.py class.
  alloydb_messages: Messages module for the API client.
  args: Command line input arguments.

Returns:
  An AlloyDB instance to create with the specified command line arguments.
)r   r   r   r   r   s       r   r!   r!   	  s     5 
r   c                    UR                  5       nU R                  R                  S[        R                  R
                  R                  R                  UR                  UR                  UR                  S9nUR                  5       Ul        UR                   R                  R                  Ul        [!        XR"                  5      Ul        ['        XR(                  UR*                  5      Ul        [.        R0                  " UUR                   R2                  SS9Ul        [7        UUR8                  UR:                  UR<                  UR>                  S9Ul         URB                  (       d  URD                  c  URF                  b/  [I        UURB                  URD                  URF                  S9Ul%        URL                  (       a  [O        UURL                  URP                  URR                  URT                  URV                  URX                  URZ                  UR\                  UR^                  UR`                  URb                  URd                  US9Ul3        U$ )zmValidates command line input arguments and passes parent's resources to create an AlloyDB secondary instance.r,   r-   r2   r3   r;   r@   rD   )4rQ   rV   rW   r   rX   rY   rZ   r[   r\   r]   r   r   r^   re   	SECONDARYrd   rR   rS   rT   rl   rm   rn   ro   r
   r_   r`   ra   rp   r<   r=   r>   r?   rq   rA   rB   rC   rr   rs   rE   rt   rF   rG   rH   ru   rJ   rK   rL   rM   rN   rO   rP   rv   rw   s        r   #_ConstructSecondaryInstanceFromArgsr     s    '//1''..5""''//99++-- / , (446;;EE   (=..($ .Dt'>'>.* %0$?$?
22"%!
 %2'#<<#'#D#D00"&"B"B%! 		(	(	4		"	"	.*;)!66#'#B#B!66	+' 
##-B)"&"@"@%)%F%F)-)N)N)-)N)N+/+Y+Y/3/Z/Z.2.X.X'+'J'J595f5f+/+R+R:>:p:p373b3b.*" 
r   c                     [        XU5      $ )al  Validates command line input arguments and passes parent's resources to create an AlloyDB secondary instance for beta track.

Args:
  client: Client for api_utils.py class.
  alloydb_messages: Messages module for the API client.
  args: Command line input arguments.

Returns:
  An AlloyDB secondary instance to create with the specified command line
  arguments.
)r   )r   r   r   s      r   '_ConstructSecondaryInstanceFromArgsBetar   ]  s     
-
 r   c                     [        XU5      nU$ )am  Validates command line input arguments and passes parent's resources to create an AlloyDB secondary instance for alpha track.

Args:
  client: Client for api_utils.py class.
  alloydb_messages: Messages module for the API client.
  args: Command line input arguments.

Returns:
  An AlloyDB secondary instance to create with the specified command line
  arguments.
)r   r   s       r   (_ConstructSecondaryInstanceFromArgsAlphar   o  s     > 
r   c                 l    [        XU5      nUR                  UUR                  UR                  5       S9$ )zRValidates command line input arguments and passes parent's resources for GA track.r   )r   ?AlloydbProjectsLocationsClustersInstancesCreatesecondaryRequestr   r   r   r   cluster_refr   r   s        r   )ConstructSecondaryCreateRequestFromArgsGAr     sE    
 : 
	Y	Y %%' 
Z 
 r   c                 l    [        XU5      nUR                  UUR                  UR                  5       S9$ )zTValidates command line input arguments and passes parent's resources for beta track.r   )r   r   r   r   r   s        r   +ConstructSecondaryCreateRequestFromArgsBetar     sE     > 
	Y	Y %%' 
Z 
 r   c                 l    [        XU5      nUR                  UUR                  UR                  5       S9$ )zUValidates command line input arguments and passes parent's resources for alpha track.r   )r   r   r   r   r   s        r   ,ConstructSecondaryCreateRequestFromArgsAlphar     sE     ? 
	Y	Y %%' 
Z 
 r   c                     [        XU[        R                  R                  S9u  p4U(       a  SR	                  U5      OSnU R                  UUR                  5       US9$ )a#  Constructs the request to update an AlloyDB instance.

Args:
  alloydb_messages: Messages module for the API client.
  instance_ref: parent resource path of the resource being updated
  args: Command line input arguments.

Returns:
  Fully-constructed request to update an AlloyDB instance.
release_track,Nr   r^   
updateMask)'ConstructInstanceAndUpdatePathsFromArgsr   ReleaseTrackGAjoin5AlloydbProjectsLocationsClustersInstancesPatchRequestr   r   rx   r   r   pathsmasks         r   ConstructPatchRequestFromArgsr     sd     Ed$:K:K:N:N "%t$		O	O $$& 
P 
 r   c                    SnSnSnSnSnSn	Sn
SnS	nS
nU R                  5       n/ nUR                  5       Ul        UR                  (       a"  UR                  Ul        UR                  U5        [        XR                  5      nU(       a  UUl        UR                  U5        [        R                  " UU R                   R                  SS9nU(       a  UUl        UR                  U5        UR                  (       d  UR                  (       am  U R                  UR                  UR                  S9Ul        UR                  (       a  UR                  U5        UR                  (       a  UR                  U5        UR"                  (       a/  U R%                  UR"                  S9Ul        UR                  U5        UR(                  (       a  UR                  U	5        UR*                  (       a  UR                  U
5        UR,                  b  UR                  U5        UR.                  b  UR                  U5        [1        U UR(                  UR*                  UR,                  UR.                  5      Ul        UR4                  b  SnUR                  U5        UR6                  (       a  SnUR                  U5        UR4                  c  UR6                  (       a%  [9        XR6                  UR4                  5      Ul        UR<                  (       d  UR>                  c  UR@                  b/  [C        U UR<                  UR>                  UR@                  S9Ul"        UR@                  b  SnUR                  U5        UR<                  (       a>  URD                  RF                  (       d#  UR                  S5        UR                  S5        O@UR<                  (       a  UR                  S5        UR>                  b  UR                  S5        URH                  c<  URJ                  c/  URL                  (       d  URN                  c  URP                  (       aE  [S        U URH                  URJ                  URL                  URN                  URP                  S9Ul*        URJ                  c  URL                  (       a  UR                  S5        URH                  b  UR                  S5        URN                  c  URP                  (       a  UR                  S5        U[V        RX                  RZ                  :X  GaA  UR\                  c  UR^                  c  UR`                  cu  URb                  ch  URd                  c[  URf                  cN  URh                  cA  URj                  c4  URl                  c'  URn                  c  URp                  c  URr                  b  UR                  S5        [u        UUU UR\                  UR^                  UR`                  URb                  URd                  URf                  URh                  URj                  URl                  URn                  URp                  URr                  S9Ul;        X4$ )ac  Validates command line arguments and creates the instance and update paths.

Args:
  alloydb_messages: Messages module for the API client.
  instance_ref: parent resource path of the resource being updated
  args: Command line input arguments.
  release_track: The release track of the gcloud client.

Returns:
  An AlloyDB instance and paths for update.
rT   ra   zmachineConfig.cpuCountzmachineConfig.machineTypezreadPoolConfig.nodeCountz%queryInsightsConfig.queryStringLengthz'queryInsightsConfig.queryPlansPerMinutez)queryInsightsConfig.recordApplicationTagsz'queryInsightsConfig.recordClientAddressactivationPolicyr2   r3   r$   r5   z(clientConnectionConfig.requireConnectorsz(clientConnectionConfig.sslConfig.sslMode)r   r<   r=   r>   z$networkConfig.enableOutboundPublicIpznetworkConfig.enablePublicIpz(networkConfig.authorizedExternalNetworks)r   rA   rB    clear_psc_network_attachment_urirC   clear_psc_auto_connectionsz%pscInstanceConfig.pscInterfaceConfigsz)pscInstanceConfig.allowedConsumerProjectsz$pscInstanceConfig.pscAutoConnectionsrv   r   r   rE   rF   rG   rH   rI   rJ   rK   rL   rM   rN   rO   rP   )<rQ   r   r^   activation_policyr   appendrR   rS   rT   r
   r_   r`   ra   r'   r(   r)   rU   rh   rg   ri   r7   r8   r9   r:   rj   rk   rn   rm   rl   ro   r<   r=   r>   rp   rq   enablePublicIprA   rB   r   rC   r   rr   rs   r   r   r   rE   rF   rG   rH   ru   rJ   rK   rL   rM   rN   rO   rP   _UpdateConnectionPoolConfigrv   )r   rx   r   r   availability_type_pathdatabase_flags_pathcpu_count_pathmachine_type_pathread_pool_node_count_path(insights_config_query_string_length_path+insights_config_query_plans_per_minute_path,insights_config_record_application_tags_path*insights_config_record_client_address_pathactivation_policy_pathr   r   rS   r2   require_connectors_pathssl_mode_pathoutbound_public_ip_paths                        r   r   r     s    .'+.18- + 0 . 2 / 0 - .&//1
%'446	)-)?)?&	LL'(+.. ):&	LL'(..
22".
 &4#	LL$%	^^t((&6&D&DT->-> 'E '# ~~ll>"ll$%	'7'F'F++ (G ($ 
LL*+	--	LL9:	00	LL<=	11=	LL=>	//;	LL;<*>
..
11
22
00+' 
(H	LL()	]]>M	LL	(DMM/E--)@)@0,
 ##		*	*	6		 	 	,&3)!%!>!>%)%F%F22	'# 
(D	LL()
 ##--<<	LL/0	LL;<$$ll12((4ll=> +		(	(	4		.	.		"	"	.		(	(*;)!66#'#B#B)-)N)N!66#'#B#B+' %%1		.	.	LL89	*	LL<=	*d.M.M	LL78 t((+++
$$0		*	*	6		.	.	:		.	.	:		7	7	C		4	4	@		3	3	?		,	,	8		:	:	F		0	0	<		?	?	K		8	8	D	LL'(-H#)"&"@"@%)%F%F)-)N)N)-)N)N+/+Y+Y/3/Z/Z.2.X.X'+'J'J595f5f+/+R+R:>:p:p373b3b.*$ 
	!!r   Nc                     [        USLUSLUSLUSL/5      nU(       d  gU R                  5       nUb  Xl        Ub  X&l        Ub  UUl        Ub  XFl        U$ )a=  Generates the insights config for the instance.

Args:
  alloydb_messages: module, Message module for the API client.
  insights_config_query_string_length: number, length of the query string to
    be stored.
  insights_config_query_plans_per_minute: number, number of query plans to
    sample every minute.
  insights_config_record_application_tags: boolean, True if application tags
    should be recorded.
  insights_config_record_client_address: boolean, True if client address
    should be recorded.

Returns:
  alloydb_messages.QueryInsightsInstanceConfig or None
N)anyQueryInsightsInstanceConfigqueryStringLengthqueryPlansPerMinuterecordApplicationTagsrecordClientAddress)r   r7   r8   r9   r:   should_generate_configinsights_configs          r   rj   rj     s    0 )5,D8-T9+47	   
  %@@B/(4(K%+7*P',8/ ) +6*O'	r   c           
          [        USLUSLUSLUSLUSLUSLUSL/5      nU(       d  gU R                  5       n	Ub  Xl        Ub  UU	l        Ub  UU	l        Ub  UU	l        Ub  UU	l        Ub  UU	l        Ub  UU	l        U	$ )a}  Generates the observability config for the instance.

Args:
  alloydb_messages: module, Message module for the API client.
  observability_config_enabled: boolean, True if observability should be
    enabled.
  observability_config_preserve_comments: boolean, True if comments should be
    preserved in the query string.
  observability_config_track_wait_events: boolean, True if wait events should
    be tracked.
  observability_config_max_query_string_length: number, length of the query
    string to be stored.
  observability_config_record_application_tags: boolean, True if application
    tags should be recorded.
  observability_config_query_plans_per_minute: number, number of query plans
    to sample every minute.
  observability_config_track_active_queries: boolean, True if active queries
    should be tracked.

Returns:
  alloydb_messages.ObservabilityInstanceConfig or None
N)	r   ObservabilityInstanceConfigenabledpreserveCommentstrackWaitEventsmaxQueryStringLengthr   r   trackActiveQueries)
r   rz   r{   r|   r}   r~   r   r   r   observability_configs
             r   r   r     s    B "$.,D8,D82$>2$>1=/t;   
  *EEG!-#? +7. ) ,7. ( 2=4 - 2=4 . 1<3 , /:1 + 
r   c                     [        USLUSL/5      nU(       d  gU R                  5       nX$l        U R                  5       n[	        X5      Ul        XTl        U$ )a}  Generates the client connection config for the instance.

Args:
  alloydb_messages: module, Message module for the API client.
  ssl_mode: string, SSL mode to use when connecting to the database.
  require_connectors: boolean, whether or not to enforce connections to the
    database to go through a connector (ex: Auth Proxy).

Returns:
  alloydb_messages.ClientConnectionConfig
N)r   rl   requireConnectors	SslConfig_ParseSSLModesslMode	sslConfig)r   rm   rn   r   client_connection_config
ssl_configs         r   rl   rl     sk    " d$   
  .DDF/A,))+*$%5@*'1$	!!r   c                 x    U(       a3  U R                   R                  R                  UR                  5       5      $ g N)rQ   AvailabilityTypeValueValuesEnumlookup_by_nameupper)r   rS   s     r   rR   rR   /  s5    $$DDSS!  
r   c                 `   UR                   b  UR                   (       d  gU R                  5       nU(       a  U(       a  [        R                  " U5      nUR                  nU R                  UR                  5       S9nUR                  R                  U5      nUR                  (       a1  UR                  R                  (       a  UR                  R                  nUR                  (       d  U R                  5       Ul        UR                  b  UR                  UR                  l        UR                  b  UR                  UR                  l        UR                  R"                  (       d  U R%                  5       UR                  l        UR&                  b%  UR&                  UR                  R"                  l        UR                   b8  UR                   =(       d    UR                  R*                  UR                  l        U(       Ga	  UR,                  bH  / n	UR.                   H0  n
U
R0                  UR,                  :w  d  M  U	R3                  U
5        M2     Xl        UR4                  bM  / n	UR.                   H5  n
U
R0                  UR4                  :X  a  SU
l        U	R3                  U
5        M7     Xl        UR8                  bM  / n	UR.                   H5  n
U
R0                  UR8                  :X  a  SU
l        U	R3                  U
5        M7     Xl        UR:                  Gb  SnU R=                  5       n
UR:                  U
l        UR.                   H#  nUR0                  UR:                  :X  d  M  Un
Sn  O   UR>                  b  UR>                  U
l         URB                  b  URB                  U
l"        URF                  b  URF                  U
l$        URJ                  b  URJ                  U
l&        URN                  b  URN                  U
l(        U(       a  UR.                  R3                  U
5        U$ )a]  Parses command line arguments and creates an AutoScalingConfig object.

Args:
  alloydb_messages: Messages module for the API client.
  instance_ref: A reference to the instance.
  release_track: The release track of the gcloud client.
  args: Command line input arguments.

Returns:
  A fully-constructed alloydb_messages.AutoScalingConfig object.
Nr^   TF))r   AutoScalingConfigr   AlloyDBClientalloydb_client3AlloydbProjectsLocationsClustersInstancesGetRequestr   %projects_locations_clusters_instancesGetri   r   policyPolicyr   maxNodeCountr   coolDownPeriodSeccpuUtilizationCpuUtilizationr   utilizationTargetr   autoscaler_delete_schedule	schedulesr^   r   autoscaler_disable_scheduledisabledautoscaler_enable_scheduler   Scheduler   cronExpressionr   durationSecr   minNodeCountr   timeZoner   description)r   rx   r   r   r   r   r   reqexisting_instancenew_schedulesscheduleis_new_scheduless                r   r   r   7  s    
'0F0F(::<m##M2F**N

N
N&&( O C 	<<@@E  	((,,>>-<<NN		#	#!1!8!8!:	##/.2.L.L+	--900 0 
	#	#	2	2'') - 
%%1(( --? 
'D"5"<"<"D"D &  &&2m)33(==D;;;


x
( 4 '4#''3m)33(==D<<<"(
X& 4 '4#&&2m)33(==D;;;#(
X& 4 '4#	!!-O((*H00HM **	
4//	/	 +
 ((4 $ A Ah00<!FFh..:"EEh))5<<h++7!AAh##**84	r   c                 x    U(       a3  U R                   R                  R                  UR                  5       5      $ g r   )rQ   re   r   r   )r   rc   s     r   rb   rb     s5    $$@@OO  
r   c                 x    U(       a3  U R                   R                  R                  UR                  5       5      $ g r   )UpdatePolicyModeValueValuesEnumr   r   )r   update_modes     r   _ParseUpdateModer
    s5    ((<<KK  
r   c                     US:X  a   U R                   R                  R                  $ US:X  a   U R                   R                  R                  $ g )NENCRYPTED_ONLYALLOW_UNENCRYPTED_AND_ENCRYPTED)r   SslModeValueValuesEnumr  r  )r   rm   s     r   r   r     sK    !!%%<<KKK44""99YY 
r   c                     US:X  a   U R                   R                  R                  $ US:X  a   U R                   R                  R                  $ g )NTRANSACTIONSESSION)ConnectionPoolConfigPoolModeValueValuesEnumPOOL_MODE_TRANSACTIONPOOL_MODE_SESSION)r   	pool_modes     r   _ParsePoolModer    sM    ---EE[[ I--EEWW 
r   c                     U R                  S5      nU R                  S5      nU R                  S5      nU R                  S5      nU R                  S5      n[        UUSLUSLUSL/5      nU(       d  gUR                  5       nU(       a  [        U5      Ul        Ub  XGl        Ub;  Ub  UR                  (       d  [        S5      e[        UUUR                  5      Ul        Ub  UUl	        U$ )z.Generates the network config for the instance.r<   r=   r   r>   r?   NzCannot update an instance's authorized networks and disable Public-IP. You must do one or the other. Note, that disabling Public-IP will clear the list of authorized networks.)
getr   InstanceNetworkConfig_ParseAssignInboundPublicIpr   enableOutboundPublicIpr	    _ParseAuthorizedExternalNetworksauthorizedExternalNetworksallocatedIpRangeOverride)kwargsr<   r=   r   r>   r?   r   instance_network_configs           r   rp   rp     s   #ZZ(BC!',J!KZZ 23zz"67 &

+H I$"$.!-	   
  -BBD-H .* #5G2!- ,'66!  	)(#22	
 6 !,# 4 
! r   c                     U R                  S5      nU(       d  gU R                  S5      nU R                  S5      nU R                  S5      nU R                  S5      nU R                  S5      nU R                  S5      nU R                  S	5      nU R                  S
5      n	U R                  S5      n
U R                  S5      nU R                  S5      nU R                  S5      nUR                  5       nXl        0 nUb  UR                  5       US'   Ub  X?S'   Ub  XOS'   Ub  X_S'   Ub  XoS'   Ub  XS'   Ub  SR	                  U5      US'   U	b  SR	                  U	5      US'   U
b  XS'   Ub  UUS'   Ub  [        U5      US'   UR                  R                  UR                  5        VVs/ s H*  u  nnUR                  R                  R                  UUS9PM,     snnS9Ul	        U$ s  snnf )z9Generates the connection pooling config for the instance.rE   NrF   rG   rH   rI   rJ   rK   rL   rM   rN   rO   rP   r   r  min_pool_sizemax_pool_sizemax_client_connectionsserver_connection_idle_timeoutquery_wait_timeoutr   stats_usersignore_startup_parametersserver_lifetimeclient_connection_idle_timeoutmax_prepared_statementskeyvalueadditionalProperties)
r  r  r   lowerr   str
FlagsValueitemsAdditionalPropertyflags)r   rE   r  r#  default_pool_sizemax_client_connserver_idle_timeoutr'  r(  r)  r*  r+  r,  r   configr7  r.  r/  s                     r   rt   rt     sB   $jj)DE	"jj78)**?@-jj!CDJJCD/

#KLzz"IJ

;<+$jj4 JJ*/ $*::9$  #JJ2 ZZ 23002&,.
%"*E+*/"./ &5
"#$.A
*+#"4
88K0E-*),2K)LE
%& .
#/& 

*+ ('*+B'CE
#$!66AA
 "KKM	 *jc5 
/
/
:
:
M
MU N  *	 B &, 
-s   -1G+
c                     UR                  S5      nUR                  S5      nUR                  S5      nUR                  S5      nUR                  S5      nUR                  S5      nUR                  S5      n	UR                  S5      n
UR                  S	5      nUR                  S
5      nUR                  S5      nUR                  S5      nUR                  S5      n[        USLUSLUSLUSLUSLUSLU	SLU
SLUSLUSLUSLUSL/5      nU(       d  gUR                  5       n0 nU(       d  Ub	  SUl        U$ [        R
                  " U5      nUR                  nUR                  U R                  5       S9nUR                  R                  U5      nUR                  SLnU(       aA  UR                  R                  b*  / SQnU H   n[        UU5      u  nnU(       d  M  UUU'   M"     Ub  UUl        O"U(       a  UR                  R                  Ul        Ub  UR                  5       US'   Ub  UUS'   Ub  UUS'   Ub  UUS'   Ub  UUS'   U	b  U	US'   U
b  SR                  U
5      US'   Ub  SR                  U5      US'   Ub  UUS'   Ub  UUS'   Ub  [!        U5      US'   UR                  R#                  UR%                  5        VVs/ s H*  u  nnUR                  R"                  R'                  UUS9PM,     snnS9Ul        U$ s  snnf ) aC  Updates the connection pooling config for the instance.

Args:
  instance_ref: A reference to the instance to be updated.
  release_track: The release track of the gcloud client.
  **kwargs: A map of the managed connection pooling flags and their values to
    be updated.

Returns:
  alloydb_messages.ConnectionPoolConfig
rE   rF   rG   rH   rI   rJ   rK   rL   rM   rN   rO   rP   r   NFr   )r  r#  r$  r%  r&  r'  r(  r)  r*  r+  r,  r  r#  r$  r%  r&  r'  r   r(  r)  r*  r+  r,  r-  r0  )r  r   r  r   r   r   r   r   r   r   r   rv   r7  &_CheckIfConnectionPoolConfigFlagExistsr2  r   r3  r4  r5  r6  )rx   r   r   rE   r  r#  r8  r9  r:  r'  r(  r)  r*  r+  r,  r   should_update_configr;  r7  r   r   r   r   has_existing_config
flag_namesfexistsr/  r.  s                                r   r   r   5  s    %jj)DEjj78)**?@-jj!CDJJCD/

#KLzz"IJ

;<+$jj4 JJ*/ $*::9$  #JJ2 ZZ 23t+t4t#T!%$t+T!$D0T)  
002&
% 
#'@'LFNM !!-0&((.LL$$& 	M 	# %JJNN	 *>>dJ

0
0
6
6
BJ <
Qmfe 
a  *.FN&;;CCFN"*E+*E/".E/ &5E
"#$.AE
*+#"4E
88K0E-*),2K)LE
%& .E
#/.LE
*+('*+B'CE
#$!66AA
 "KKM	 *jc5 
/
/
:
:
M
MU N  *	 B &, 
-s   1L

c                     U R                   R                  R                  c  gU R                   R                  R                   H#  nUR                  U:X  d  M  SUR                  4s  $    g)a  Checks if a flag exists in the instance's connection pool config.

Args:
  instance: The existing instance to check against.
  flag_name: The name of the flag to check if it exists in the instance.

Returns:
  True and the value of the flag if the flag exists, False otherwise.

)FNT)rv   r7  r1  r.  r/  )r   	flag_nameprops      r   r=  r=    s\     ""((==E++11FFdxx94:: G 
r   c                     U R                  S5      nU R                  S5      nU R                  S5      nU R                  S5      nU R                  S5      nU R                  S5      nUR                  5       nU(       a  X'l        U(       a  / Ul        O&Ub#  UR                  R	                  [        UUS95        U(       a	  / Ul        U$ Ub  [        UUS9Ul        U$ )	z3Generates the PSC instance config for the instance.r   rA   rB   r   rC   r   )r   rB   )r   rC   )r  rr   allowedConsumerProjectspscInterfaceConfigsr   _PscInterfaceConfigpscAutoConnections_PscAutoConnections)r   r   rA   rB   r   rC   r   psc_instance_configs           r   rr   rr     s    ZZ 23$:;%zz*FG%+ZZ(&"  $:;%zz*FG(::<2F/%.0+!-++22-'A	
  -/* 
 '-@)1.*
 
r   c                 2    U R                  5       nXl        U$ )z4Generates the PSC interface config for the instance.)PscInterfaceConfignetworkAttachmentResource)r   rB   psc_interface_configs      r   rI  rI    s    
 *<<>3M0	r   c                    / nU H}  nU R                  5       nUR                  S5      Ul        UR                  S5      Ul        UR                  (       a$  UR                  (       a  UR	                  U5        Mt  [        S5      e   U$ )z4Generates the PSC auto connections for the instance.rZ   networkzaInvalid PSC auto connection. Please provide both project and network for the PSC auto connection.)PscAutoConnectionConfigr  consumerProjectconsumerNetworkr   r	   )r   rC   out_psc_auto_connections
connectionr;  s        r   rK  rK    s}    
  (j557F'^^I6F'^^I6F&"8"8%%f-!*  ) 
"!r   c                 4    U S:X  a  gU S:X  a  g[        S5      e)a3  Parses the assign_inbound_public_ip flag.

Args:
  assign_inbound_public_ip: string, the Public-IP mode to use.

Returns:
  boolean, whether or not Public-IP is enabled.

Raises:
  ValueError if try to use any other value besides NO_PUBLIC_IP during
  instance creation, or if use an unrecognized argument.
NO_PUBLIC_IPFASSIGN_IPV4Tz>Unrecognized argument. Please use NO_PUBLIC_IP or ASSIGN_IPV4.r   )r<   s    r   r  r    s*     /.F	 r   c                     / nUb	  U(       d  U$ U H,  nU R                  [        U5      S9nUR                  U5        M.     U$ )a*  Parses the authorized_external_networks flag.

Args:
  alloydb_messages: Messages module for the API client.
  authorized_external_networks: list, list of authorized networks.
  public_ip_enabled: boolean, whether or not Public-IP is enabled.

Returns:
  list of alloydb_messages.AuthorizedNetwork
)	cidrRange)AuthorizedNetworkr3  r   )r   r=   public_ip_enabledauth_networksrR  s        r   r  r  '  sO     -"+<-g003w<0HG! . 
r   c                     [        XU[        R                  R                  S9u  p4U(       a  SR	                  U5      OSnU R                  UUR                  5       US9$ z5Constructs the request to update an AlloyDB instance.r   r   Nr   )+ConstructInstanceAndUpdatePathsFromArgsBetar   r   BETAr   r   r   r   s         r   !ConstructPatchRequestFromArgsBetard  =  sb    Hd%%** "%t$		O	O $$& 
P 
 r   c                     [        XU[        R                  R                  S9u  p4U(       a  SR	                  U5      OSnU R                  UUR                  5       US9$ ra  ),ConstructInstanceAndUpdatePathsFromArgsAlphar   r   ALPHAr   r   r   r   s         r   "ConstructPatchRequestFromArgsAlpharh  L  sb    Id%%++
 "%t$		O	O $$& 
P 
 r   c                    SnSnSnSnSnSn	Sn
[        XX#5      u  pUR                  (       a:  U R                  [        XR                  5      S9Ul        S	nUR                  U5        UR                  b  UR                  U5        UR                  b  UR                  U5        UR                  b  UR                  U5        UR                  b  UR                  U5        UR                  b  UR                  U5        UR                  b  UR                  U	5        UR                  b  UR                  U
5        [        U UR                  UR                  UR                  UR                  UR                  UR                  UR                  5      Ul        U[        R                   R"                  :X  GaA  UR$                  c  UR&                  c  UR(                  cu  UR*                  ch  UR,                  c[  UR.                  cN  UR0                  cA  UR2                  c4  UR4                  c'  UR6                  c  UR8                  c  UR:                  b  UR                  S
5        [=        UUU UR$                  UR&                  UR(                  UR*                  UR,                  UR.                  UR0                  UR2                  UR4                  UR6                  UR8                  UR:                  S9Ul        UR@                  c  URB                  c  URD                  c  URF                  cu  URH                  ch  URJ                  c[  URL                  cN  URN                  cA  URP                  c4  URR                  c'  URT                  c  URV                  c  URX                  bS  [[        XX25      nUR\                  (       d  U R_                  5       Ul.        XR\                  l0        UR                  S5        X4$ )ar  Validates command line arguments and creates the instance and update paths for beta track.

Args:
  alloydb_messages: Messages module for the API client.
  instance_ref: parent resource path of the resource being updated
  args: Command line input arguments.
  release_track: The release track of the gcloud client.

Returns:
  An AlloyDB instance and paths for update.
zobservabilityConfig.enabledz$observabilityConfig.preserveCommentsz#observabilityConfig.trackWaitEventsz(observabilityConfig.maxQueryStringLengthz)observabilityConfig.recordApplicationTagsz'observabilityConfig.queryPlansPerMinutez&observabilityConfig.trackActiveQueries)modezupdatePolicy.moderv   r   z readPoolConfig.autoScalingConfig)1r   r	  r  r
  updatePolicyr   rz   r{   r|   r}   r~   r   r   r   r   r   r   rc  rE   rF   rG   rH   ru   rJ   rK   rL   rM   rN   rO   rP   r   rv   r   r   r   r   r   r   r   r   r   r   r   r   r   r   ri   rg   r   )r   rx   r   r   !observability_config_enabled_path+observability_config_preserve_comments_path+observability_config_track_wait_events_path1observability_config_max_query_string_length_path1observability_config_record_application_tags_path0observability_config_query_plans_per_minute_path.observability_config_track_active_queries_pathr   r   update_mode_pathr   s                  r   rb  rb  \  s    'D#, . , . 1 4 2 4 0 3 / 1 Ed 
%5%B%B.0@0@A &C &" +	LL!"	&&2	LL23	00<	LL<=	00<	LL<=	66B	LLBC	66B	LLBC	55A	LLAB	33?	LL?@*>
''
11
11
77
77
66
44	+'& t((---
$$0		*	*	6		.	.	:		.	.	:		7	7	C		4	4	@		3	3	?		,	,	8		:	:	F		0	0	<		?	?	K		8	8	D	LL'(-H#)"&"@"@%)%F%F)-)N)N)-)N)N+/+Y+Y/3/Z/Z.2.X.X'+'J'J595f5f+/+R+R:>:p:p373b3b.*& $$0		1	1	=		)	)	5				+		(	(	4		%	%	1		*	*	6		2	2	>		0	0	<		+	+	7		)	)	5		(	(	4		-	-	90 ++)9)H)H)J&9L$$6	LL34		!!r   c                    [        XX#5      u  pEUR                  c  UR                  c  UR                  cu  UR                  ch  UR
                  c[  UR                  cN  UR                  cA  UR                  c4  UR                  c'  UR                  c  UR                  c  UR                  b  UR                  S5        [        UUU UR                  UR                  UR                  UR                  UR
                  UR                  UR                  UR                  UR                  UR                  UR                  UR                  S9Ul        XE4$ )as  Validates command line arguments and creates the instance and update paths for alpha track.

Args:
  alloydb_messages: Messages module for the API client.
  instance_ref: parent resource path of the resource being updated
  args: Command line input arguments.
  release_track: The release track of the gcloud client.

Returns:
  An AlloyDB instance and paths for update.
rv   r   )rb  rE   rF   rG   rH   ru   rJ   rK   rL   rM   rN   rO   rP   r   r   rv   )r   rx   r   r   r   r   s         r   rf  rf    sE    Id $$0		*	*	6		.	.	:		.	.	:		7	7	C		4	4	@		3	3	?		,	,	8		:	:	F		0	0	<		?	?	K		8	8	D	LL'(-H#)"&"@"@%)%F%F)-)N)N)-)N)N+/+Y+Y/3/Z/Z.2.X.X'+'J'J595f5f+/+R+R:>:p:p373b3b.*" 
	!!r   c                     U R                  UR                  5       S9nUR                  (       a  U R                  UR                  S9nXCl        U$ )a$  Constructs the request to restart an AlloyDB instance.

Args:
  alloydb_messages: Messages module for the API client.
  project_ref: parent resource path of the resource being updated
  args: Command line input arguments.

Returns:
  Fully-constructed request to restart an AlloyDB instance.
r   )nodeIds)7AlloydbProjectsLocationsClustersInstancesRestartRequestr   node_idsRestartInstanceRequestrestartInstanceRequest)r   r   r   r   restart_requests        r   ConstructRestartRequestFromArgsr|    s[     NN'') O  
 
]]&== > O "1	*r   )NNNN)NNNNNNN)NNr   )8__doc__
__future__r   r   r   googlecloudsdk.api_lib.alloydbr   googlecloudsdk.callioper   %googlecloudsdk.calliope.parser_errorsr	   $googlecloudsdk.command_lib.util.argsr
   googlecloudsdk.corer   r   r   r"   r*   r   r   r!   r   r   r   r   r   r   r   r   r   r   rj   r   rl   rR   r   rb   r
  r   r  rp   rt   r   r=  rr   rI  rK  r  r  rd  rh  rb  rg  rf  r|   r   r   <module>r     sN   R &  ' 3 ( G < *266	bJ*Z$?D$( 0 9=8I8I8L8LE"T )-+/,0*..f "&+/+/151504.2J^  "F^B	2!j?DEP&H  $ "*,, E"R 9=8I8I8O8O5"pr   