
                            d Z ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddl	m
Z
 ddlmZ dd	lmZ d
 Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zej:                  j<                  fdZ	 	 	 	 d0dZ 	 	 	 	 	 	 	 d1dZ!	 	 d2dZ"d Z#d Z$d Z%d  Z&d! Z'd" Z(d# Z)d$ Z*d% Z+d& Z,	 d3d'Z-	 d3d(Z.d) Z/d* Z0d+ Z1d, Z2d- Z3ej:                  jh                  fd.Z5d/ Z6y)4zKHelper functions for constructing and validating AlloyDB instance requests.    )absolute_import)division)unicode_literals)api_util)baseDetailedArgumentError)labels_util)
propertiesc                 t    t        | ||      }|j                  ||j                  |j                               S )ax  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      sE     19I4P MM$]]))+ N     c                 t    t        | ||      }|j                  ||j                  |j                               S )a{  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   sH     5
 MM$]]))+ N r   c                 t    t        | ||      }|j                  ||j                  |j                               S )a{  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   sH     6
 MM$]]))+ N r   c                     |j                   s|j                  r'| j                  |j                   |j                        S t        d      )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                    |j                         }t        ||j                        |_        t	        ||      |_        | j                  j                  dt        j                  j                  j                  j                  |j                  |j                  |j                        }|j!                         |_        t%        j&                  ||j                   j(                  d      |_        t-        ||j.                        |_        |j0                  |j                   j2                  j4                  k(  r!|j7                  |j8                        |_        t=        ||j>                  |j@                  |jB                  |jD                        |_#        tI        ||jJ                  |jL                        |_'        tQ        ||jR                  |jT                  |jV                  |jX                        |_-        |j\                  s|j^                  |j`                  2tc        ||j\                  |j^                  |j`                        |_2        |jf                  rti        ||jf                  |jj                  |jl                  |jn                  |jp                  |jr                  |jt                  |jv                  |jx                  |jz                  |j|                  |j~                  |	      |_@        |S )
aU  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           
          t        | ||      }t        ||j                  |j                  |j                  |j
                  |j                  |j                  |j                        |_	        |S )ad  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_queries)
r   _ObservabilityConfigrz   r{   r|   r}   r~   r   r   observabilityConfigr   r   r   r   s       r   r   r      sl     19I4P*>#'#D#D-1-X-X-1-X-X373d3d373d3d262b2b040^0^	+' 
r   c                      t        | ||      }|S )ae  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   s       r   r!   r!      s     5 
r   c                    |j                         }| j                  j                  dt        j                  j
                  j                  j                  |j                  |j                  |j                        }|j                         |_        |j                   j                  j                  |_        t!        ||j"                        |_        t'        ||j(                  |j*                        |_        t/        j0                  ||j                   j2                  d      |_        t7        ||j8                  |j:                  |j<                  |j>                        |_         |jB                  s|jD                  |jF                  2tI        ||jB                  |jD                  |jF                        |_%        |jL                  rtO        ||jL                  |jP                  |jR                  |jT                  |jV                  |jX                  |jZ                  |j\                  |j^                  |j`                  |jb                  |jd                  |      |_3        |S )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                     t        | ||      S )a|  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   J  s     
-
 r   c                      t        | ||      }|S )a}  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   \  s     > 
r   c                 t    t        | ||      }|j                  ||j                  |j                               S )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   p  sH    
 : 
	Y	Y %%' 
Z 
 r   c                 t    t        | ||      }|j                  ||j                  |j                               S )zTValidates command line input arguments and passes parent's resources for beta track.r   )r   r   r   r   r   s        r   +ConstructSecondaryCreateRequestFromArgsBetar     sH     > 
	Y	Y %%' 
Z 
 r   c                 t    t        | ||      }|j                  ||j                  |j                               S )zUValidates command line input arguments and passes parent's resources for alpha track.r   )r   r   r   r   r   s        r   ,ConstructSecondaryCreateRequestFromArgsAlphar     sH     ? 
	Y	Y %%' 
Z 
 r   c                     t        | ||t        j                  j                        \  }}|rdj	                  |      nd}| j                  ||j                         |      S )a1  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     sh     Ed$:K:K:N:NU "%t$		O	O $$& 
P 
 r   c                    d}d}d}d}d}d}	d}
d}d	}d
}| j                         }g }|j                         |_        |j                  r"|j                  |_        |j                  |       t        | |j                        }|r||_        |j                  |       t        j                  || j                   j                  d      }|r||_        |j                  |       |j                  s|j                  rf| j                  |j                  |j                        |_        |j                  r|j                  |       |j                  r|j                  |       |j"                  r2| j%                  |j"                        |_        |j                  |       |j(                  r|j                  |	       |j*                  r|j                  |
       |j,                  |j                  |       |j.                  |j                  |       t1        | |j(                  |j*                  |j,                  |j.                        |_        |j4                  d}|j                  |       |j6                  rd}|j                  |       |j4                  |j6                  r&t9        | |j6                  |j4                        |_        |j<                  s|j>                  |j@                  2tC        | |j<                  |j>                  |j@                        |_"        |j@                  d}|j                  |       |j<                  r9|jD                  jF                  s#|j                  d       |j                  d       n:|j<                  r|j                  d       |j>                  |j                  d       |jH                  0|jJ                  $|jL                  s|jN                  |jP                  rHtS        | |jH                  |jJ                  |jL                  |jN                  |jP                        |_*        |jJ                  |jL                  r|j                  d       |jH                  |j                  d       |jN                  |jP                  r|j                  d       |tV        jX                  jZ                  k(  r8|j\                  |j^                  x|j`                  l|jb                  `|jd                  T|jf                  H|jh                  <|jj                  0|jl                  $|jn                  |jp                  |jr                  |j                  d       tu        ||| |j\                  |j^                  |j`                  |jb                  |jd                  |jf                  |jh                  |jj                  |jl                  |jn                  |jp                  |jr                        |_;        ||fS )as  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.*$ 
E	!!r   Nc                     t        |du|du|du|dug      }|sy| j                         }|||_        |||_        |||_        |||_        |S )aW  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(KO%+7*PO',8/ ) +6*OO'	r   c           
          t        |du|du|du|du|du|du|dug      }|sy| j                         }	|||	_        |||	_        |||	_        |||	_        |||	_        |||	_        |||	_        |	S )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                     t        |du|dug      }|sy| j                         }||_        | j                         }t	        | |      |_        ||_        |S )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     ss    " d$   
  .DDF/A,))+*$%5x@*'1$	!!r   c                 n    |r3| j                   j                  j                  |j                               S y N)rQ   AvailabilityTypeValueValuesEnumlookup_by_nameupper)r   rS   s     r   rR   rR     s5    $$DDSS!  
r   c                 n    |r3| j                   j                  j                  |j                               S y r   )rQ   re   r   r   )r   rc   s     r   rb   rb   $  s5    $$@@OO  
r   c                 n    |r3| j                   j                  j                  |j                               S y r   )UpdatePolicyModeValueValuesEnumr   r   )r   update_modes     r   _ParseUpdateModer   ,  s5    ((<<KK  
r   c                     |dk(  r | j                   j                  j                  S |dk(  r | j                   j                  j                  S y )NENCRYPTED_ONLYALLOW_UNENCRYPTED_AND_ENCRYPTED)r   SslModeValueValuesEnumr   r   )r   rm   s     r   r   r   4  sK    !!%%<<KKK44""99YY 
r   c                     |dk(  r | j                   j                  j                  S |dk(  r | j                   j                  j                  S y )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                     | j                  d      }| j                  d      }| j                  d      }| j                  d      }| j                  d      }t        ||du|du|dug      }|sy|j                         }|rt        |      |_        |||_        |5||j                  st        d      t        |||j                        |_        |||_	        |S )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   J  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            
         | j                  d      }|sy| j                  d      }| j                  d      }| j                  d      }| j                  d      }| j                  d      }| j                  d      }| j                  d	      }| j                  d
      }	| j                  d      }
| j                  d      }| j                  d      }| j                  d      }|j                         }||_        i }||j                         |d<   |||d<   |||d<   |||d<   |||d<   |||d<   |dj	                  |      |d<   |	dj	                  |	      |d<   |
|
|d<   |||d<   |t        |      |d<   |j                  j                  |j                         D cg c],  \  }}|j                  j                  j                  ||      . c}}      |_	        |S c c}}w )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   configr
  r  r  s                     r   rt   rt     sP   $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+*E/".E/ &5E
"#$.AE
*+#"4E
88K0E-*),2K)LE
%& .E
#/& 

*+ ('*+B'CE
#$!66AA
 "KKM	 *jc5 
/
/
:
:
M
MU N  *	 B &, 
-s   $1G%
c                    |j                  d      }|j                  d      }|j                  d      }|j                  d      }|j                  d      }|j                  d      }|j                  d      }	|j                  d      }
|j                  d	      }|j                  d
      }|j                  d      }|j                  d      }|j                  d      }t        |du|du|du|du|du|du|	du|
du|du|du|du|dug      }|sy|j                         }i }|s|	d|_        |S t	        j
                  |      }|j                  }|j                  | j                               }|j                  j                  |      }|j                  du}|r8|j                  j                  "g d}|D ]  }t        ||      \  }}|s|||<    |||_        n|r|j                  j                  |_        ||j                         |d<   |||d<   |||d<   |||d<   |||d<   |	|	|d<   |
dj                  |
      |d<   |dj                  |      |d<   |||d<   |||d<   |t!        |      |d<   |j                  j#                  |j%                         D cg c],  \  }}|j                  j"                  j'                  ||      . c}}      |_        |S c c}}w ) aS  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   NFr^   )r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  )r   r   r   r   r   AlloyDBClientalloydb_client3AlloydbProjectsLocationsClustersInstancesGetRequestr   %projects_locations_clusters_instancesGetrv   r
  &_CheckIfConnectionPoolConfigFlagExistsr  r   r  r  r  r	  )rx   r   r   rE   r   r   r  r  r  r   r   r   r   r   r   r   should_update_configr  r
  r   r  reqexisting_instancehas_existing_config
flag_namesfexistsr  r  s                                r   r   r     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   $1K%
c                     | j                   j                  j                  y| j                   j                  j                  D ]!  }|j                  |k(  sd|j                  fc S  y)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   r
  r  r  r  )r   	flag_nameprops      r   r  r  I  s\     ""((==E++11FFdxx94:: G 
r   c                     | j                  d      }| j                  d      }| j                  d      }| j                  d      }| j                  d      }| j                  d      }|j                         }|r||_        |rg |_        n(|&|j                  j	                  t        ||             |r	g |_        |S |t        ||      |_        |S )	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                 4    | j                         }||_        |S )z4Generates the PSC interface config for the instance.)PscInterfaceConfignetworkAttachmentResource)r   rB   psc_interface_configs      r   r$  r$  ~  s"    
 *<<>3M0	r   c                     g }|D ]r  }| j                         }|j                  d      |_        |j                  d      |_        |j                  r|j                  r|j	                  |       it        d       |S )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   r&  r&    s}    
  (j557F'^^I6F'^^I6F&"8"8%%f-!*  ) 
"!r   c                 0    | dk(  ry| dk(  ryt        d      )aC  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                 |    g }||s|S |D ].  }| j                  t        |            }|j                  |       0 |S )a8  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)AuthorizedNetworkr  r   )r   r=   public_ip_enabledauth_networksr-  s        r   r   r     sO     -"+<-g003w<0HG! . 
r   c                     t        | ||t        j                  j                        \  }}|rdj	                  |      nd}| j                  ||j                         |      S z5Constructs the request to update an AlloyDB instance.r   r   Nr   )+ConstructInstanceAndUpdatePathsFromArgsBetar   r   BETAr   r   r   r   s         r   !ConstructPatchRequestFromArgsBetar?    sf    Hd%%**U "%t$		O	O $$& 
P 
 r   c                     t        | ||t        j                  j                        \  }}|rdj	                  |      nd}| j                  ||j                         |      S r<  ),ConstructInstanceAndUpdatePathsFromArgsAlphar   r   ALPHAr   r   r   r   s         r   "ConstructPatchRequestFromArgsAlpharC    sf    Id%%++U
 "%t$		O	O $$& 
P 
 r   c                    d}d}d}d}d}d}	d}
t        | |||      \  }}|j                  r>| j                  t        | |j                              |_        d	}|j                  |       |j                  |j                  |       |j                  |j                  |       |j                  |j                  |       |j                  |j                  |       |j                  |j                  |       |j                  |j                  |	       |j                  |j                  |
       t        | |j                  |j                  |j                  |j                  |j                  |j                  |j                        |_        |t        j                   j"                  k(  r8|j$                  |j&                  x|j(                  l|j*                  `|j,                  T|j.                  H|j0                  <|j2                  0|j4                  $|j6                  |j8                  |j:                  |j                  d
       t=        ||| |j$                  |j&                  |j(                  |j*                  |j,                  |j.                  |j0                  |j2                  |j4                  |j6                  |j8                  |j:                        |_        ||fS )a  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   ) r   r   r   r   updatePolicyr   rz   r{   r|   r}   r~   r   r   r   r   r   r   r>  rE   rF   rG   rH   ru   rJ   rK   rL   rM   rN   rO   rP   r   rv   )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_paths                 r   r=  r=    s    'D#, . , . 1 4 2 4 0 3 / 1 EdMU 
%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.*$ 
E	!!r   c                    t        | |||      \  }}|j                  |j                  x|j                  l|j                  `|j
                  T|j                  H|j                  <|j                  0|j                  $|j                  |j                  |j                  |j                  d       t        ||| |j                  |j                  |j                  |j                  |j
                  |j                  |j                  |j                  |j                  |j                  |j                  |j                        |_        ||fS )a  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   )r=  rE   rF   rG   rH   ru   rJ   rK   rL   rM   rN   rO   rP   r   r   rv   )r   rx   r   r   r   r   s         r   rA  rA  Y  sM    IdMU $$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.*" 
E	!!r   c                     | j                  |j                               }|j                  r#| j                  |j                        }||_        |S )a2  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   ConstructRestartRequestFromArgsrW    s]     NN'') O  
 
]]&== > O "1C	*r   )NNNN)NNNNNNN)NNr   )7__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   rb   r   r   r   rp   rt   r   r  rr   r$  r&  r   r   r?  rC  r=  rB  rA  rW   r   r   <module>r`     sF   R &  ' 3 ( G < *266	bJ4$?D$( 0 9=8I8I8L8LE"T )-+/,0*..f "&+/+/151504.2J^  "F	2!j?DEP&H  $ "*,, n"d 9=8I8I8O8O5"pr   