
                            S r SSKrSSKJr  SSKJr  SSKJr  SSKJr	  SSKJ
r
  SSKJr  SSKJr  SS	KJr  SS
KJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKr\R0                  R2                  rSSS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(S  r)S! r*S" r+S# r,S$ r-S% r.S& r/S' r0S( r1S3S) jr2S* r3S4S+ jr4S, r5S- r6S. r7 " S/ S0\85      r9 " S1 S2\95      r:g)53Common utility functions for sql instance commands.    N)	constants)
exceptions)instance_prop_reducers)	instances)validate)base)info_holder)labels_util)execution_utils)log)
properties)
console_ioPD_HDDPD_SSDHYPERDISK_BALANCED)HDDSSDr   c                     [         R                  " U R                  5        UR                  R	                  U R                  S[
        R                  R                  R                  R                  0SS9$ )z-Validates and returns the instance reference.projectzsql.instances)params
collection)
r   ValidateInstanceNameinstanceresource_parserParser   VALUEScorer   	GetOrFail)argsclients     /lib/googlecloudsdk/command_lib/sql/instances.pyGetInstanceRefr#   -   s\    
.				%	%
mm**//77AAB  
& 
     c                     / nU R                  S5      (       a#   UR                  US   U R                  /5        U$ U$ ! [         a    [        R
                  " SS5      ef = f)zCGets the args for specifying a database during instance connection.databasez
--databasez5This instance does not support the database argument.)IsSpecifiedextendr&   KeyErrorr   InvalidArgumentException)r    flagscommand_line_argss      r"   GetDatabaseArgsr-   7   sr    	j!!j 14==AB
 
		  //
O s	    > "A c                 h    [         R                  R                  SR                  U5      5        [        R
                  " U 5        g! [         a`    [         R                  " SR                  SR                  U 5      5      5        [         R                  " [        R                  " 5       5         gf = f)z0Connects to the instance using the relevant CLI.z+Connecting to database with SQL user [{0}].zFailed to execute command "{0}" N)r   statuswriteformatr   ExecOSErrorerrorjoinPrintr
   
InfoHolder)cmd_argssql_users     r"   ConnectToInstancer;   D   s|    (JJ5<<XF "	 (II/66sxx7IJKIIk$$&'(s   AA A'B10B1c                    U R                   R                  R                  5       nU(       a!  U(       a
  [        5         UR	                  5       $ S H;  n[        XR                  SS5      S5      (       d  M&  [        R                  " SS5      e   g)zDParses the CMEK resource arg, makes sure the key format was correct.)zdisk-encryption-keyzdisk-encryption-key-keyringzdisk-encryption-key-locationzdisk-encryption-key-project-_Nz--disk-encryption-keyznot fully specified.)	CONCEPTSkms_keyr   _ShowCmekPromptRelativeNamegetattrreplacer   r*   )r    
is_primarykms_refkeywords       r"   _GetAndValidateCmekKeyNamerH   P   sv    MM!!'')' !! 
sC0$	7	711#%;
 	
r$   c                 @    U R                   =(       d    U R                  $ N)zonegce_zoner    s    r"   _GetZonerN   g   s    		#dmm#r$   c                 (    SU ;   a  U R                   $ g )Nsecondary_zone)rP   rM   s    r"   _GetSecondaryZonerQ   k   s    	r$   c                 d   U R                  S5      (       a4  [        [        R                  " SU 5      R	                  S5      5      nUS:  $ U R                  S5      (       aP  [        R                  " SU 5      n[        UR	                  S5      5      [        UR	                  S5      5      4nUS:  $ g	)
a  Checks if the replica inherits the tier of the primary for E+ instances.

Ideally, this would be the case for all database versions. However, changing
it now is technically a breaking change, so we are only adding support for new
database types going forward.

Args:
  replica_database_version: The database version of the replica.

Returns:
  True if the replica infers the tier from the primary (database version is
  PG16+).
	POSTGRES_z^POSTGRES_(\d+).*      MYSQL_z^MYSQL_(\d+)_(\d+).*   )   r   F)
startswithintresearchgroup)replica_database_versiondatabase_major_versionmatchs      r"   1DoesEnterprisePlusReplicaInferTierForDatabaseTypera   r   s     ((55 !
		&(@AGGJ "B&&((22 II-/GHE!%++a.13u{{1~3FG!F**	r$   c                 <    U [         R                  R                  :H  $ rJ   )r	   ReleaseTrackALPHArelease_tracks    r"   _IsAlpharg      s    	$++11	11r$   c                 `    U [         R                  R                  :H  =(       d    [        U 5      $ rJ   )r	   rc   BETArg   re   s    r"   IsBetaOrNewerrj      s#    	$++00	0	KH]4KKr$   c                     U(       aC  U R                   R                  R                  UR                  SS5      R	                  5       5      $ g Nr=   r>   )SettingsActivationPolicyValueValuesEnumlookup_by_namerD   upper)sql_messagespolicys     r"   _ParseActivationPolicyrs      s@      @@OOsC &&(  
r$   c                 x    U(       a3  U R                   R                  R                  UR                  5       5      $ g rJ   )rm   AvailabilityTypeValueValuesEnumro   rp   )rq   availability_types     r"   _ParseAvailabilityTyperw      s5      @@OO!  
r$   c                 x    U(       a3  U R                   R                  R                  UR                  5       5      $ g rJ   )DatabaseInstanceDatabaseVersionValueValuesEnumro   rp   )rq   database_versions     r"   ParseDatabaseVersionr|      s5    ((GGVV   
r$   c                 x    U(       a3  U R                   R                  R                  UR                  5       5      $ g rJ   )rm   PricingPlanValueValuesEnumro   rp   )rq   pricing_plans     r"   _ParsePricingPlanr      s5      ;;JJ  
r$   c                 x    U(       a3  U R                   R                  R                  UR                  5       5      $ g rJ   )rm   ReplicationTypeValueValuesEnumro   rp   )rq   replications     r"   _ParseReplicationTyper      s5      ??NN  
r$   c                 x    U(       a3  U R                   R                  R                  UR                  5       5      $ g rJ   )rm   DataDiskTypeValueValuesEnumro   rp   )rq   storage_types     r"   _ParseStorageTyper      s5      <<KK  
r$   c                     U(       aC  U R                   R                  R                  UR                  SS5      R	                  5       5      $ g rl   )rm   EditionValueValuesEnumro   rD   rp   )rq   editions     r"   _ParseEditionr      s@      77FFS!'')  
r$   c                     U(       aC  U R                   R                  R                  UR                  SS5      R	                  5       5      $ g rl   )ry   InstanceTypeValueValuesEnumro   rD   rp   )rq   instance_types     r"   _ParseInstanceTyper      sB    ((DDSSc3'--/  
r$   c                 h    U R                   R                  R                  UR                  5       5      $ rJ   )rm   #ConnectorEnforcementValueValuesEnumro   rp   )rq   connector_enforcements     r"   _ParseConnectorEnforcementr      s-    ??NN

%
%
'r$   c                 h    U R                   R                  R                  UR                  5       5      $ rJ   )rm   DataApiAccessValueValuesEnumro   rp   )rq   data_api_accesss     r"   _ParseDataApiAccessr      s-    88GG



!r$   c                 h    U R                   R                  R                  UR                  5       5      $ rJ   )IpConfigurationSslModeValueValuesEnumro   rp   )rq   ssl_modes     r"   _ParseSslModer      s+    		%	%	<	<	K	Knn
 r$   c                 h    U R                   R                  R                  UR                  5       5      $ rJ   )r   ServerCaModeValueValuesEnumro   rp   )rq   server_ca_modes     r"   _ParseServerCaModer      s-    "">>MM



 r$   c                 h    U R                   R                  R                  UR                  5       5      $ rJ   )r   ,ServerCertificateRotationModeValueValuesEnumro   rp   )rq    server_certificate_rotation_modes     r"   #_ParseServerCertificateRotationModer      s-    ""OO^^
*
0
0
2r$   c                     SnU (       a'  [         R                  " UR                  SS5      5        g [         R                  " UR                  SS5      5        g )NzUpgrade your First Generation instance{} to Second Generation before we auto-upgrade {} on March 4, 2020, ahead of the full decommission of First Generation on March 25, 2020.sthem itr   warningr2   )pluralmessages     r"   ShowV1DeprecationWarningr      s?    , 

 KKsF+,KKr4()r$   c                     U R                  S5      nU R                  S5      =(       d    U R                  S5      nU(       d  U(       d  [        R                  " S5        ggg)zShow warnings if both region and zone are specified or neither is.

Args:
    args: argparse.Namespace, The arguments that the command was invoked with.
regionrL   rK   zhStarting with release 233.0.0, you will need to specify either a region or a zone to create an instance.N)r'   r   r   )r    region_specifiedzone_specifieds      r"   ShowZoneDeprecationWarningsr     sU     %%h/##J/K43C3CF3K. nKK	; -
r$   c                     Uc&  [         R                  " SR                  U 5      5        g [         R                  " SR                  X5      5        g )NzYour {} will be encrypted with a customer-managed key. If anyone destroys this key, all data encrypted with it will be permanently lost.zYour {} will be encrypted with {}'s customer-managed encryption key. If anyone destroys this key, all data encrypted with it will be permanently lost.r   )resource_type_labelinstance_type_labels     r"   ShowCmekWarningr     sB     KK	*+ KK	"F#6Lr$   c                  X    [         R                  " S5        [        R                  " SS9  g )NzYou are creating a Cloud SQL instance encrypted with a customer-managed key. If anyone destroys a customer-managed key, all data encrypted with it will be permanently lost.
T)cancel_on_no)r   r   r   PromptContinue r$   r"   rA   rA   -  s#    ++'
 .r$   c                  0    [         R                  " S5        g )Na"  Failover replicas will soon be deprecated and support will be discontinued. We recommend migrating to the new high availability configuration, based on regional persistent disks (RePD). For more information, see https://cloud.google.com/sql/docs/mysql/configure-legacy-ha#update-from-legacyr   r   r   r$   r"   &_ShowFailoverReplicaDeprecationWarningr   6  s    ++Wr$   c                  0    [         R                  " S5        g )NzqEnabling accelerated replica mode on a replica may cause it to be recreated in the event of an unplanned restart.r   r   r$   r"   "_ShowAcceleratedReplicaModeWarningr   @  s    ++8r$   c                       \ rS rSrSr\S\4S j5       r\S\4S j5       r\\4S j5       r	\SS\4S j5       r
\SS\4S j5       r\S\4S	 j5       rS
rg)_BaseInstancesiG  r   Nc           
         SU;  a  SUl         SU;  a  SUl        SU;  a  SUl        UR                  S5      (       d  SUl        UR                  S[        R                  " X2R                  UR                  UR                  5      [        XR                  5      [        XR                  5      [        XR                  5      S9nUR                   (       a  UR                   Ul        [!        UR"                  SLUR$                  SLUR&                  /5      (       a  UR)                  5       Ul        UR"                  b  U R-                  XRR"                  5        UR&                  (       a&  U R/                  XRR&                  UR0                  5        UR$                  b  UR$                  UR*                  l        [!        UR                  [5        U5      [7        U5      /5      (       a3  UR9                  S	UR                  [5        U5      [7        U5      S
9Ul        UR<                  (       a+  [?        UR<                  [@        RB                  -  5      Ul"        UR                  S5      (       a  [?        URF                  5      Ul$        UR                  S5      (       a  [?        URJ                  5      Ul&        URN                  b  URN                  Ul(        URS                  S5      (       a  [U        XRV                  5      Ul,        URS                  S5      (       aU  UR*                  (       d  UR)                  5       Ul        [        RZ                  " UR\                  5      UR*                  l/        UR                  S5      (       aA  UR*                  (       d  UR)                  5       Ul        UR`                  UR*                  l1        UR                  S5      (       a  UR*                  (       d  UR)                  5       Ul        UR*                  Rd                  (       d  URg                  5       UR*                  l2        URh                  UR*                  Rd                  l5        URS                  S5      (       a  UR*                  (       d  UR)                  5       Ul        UR*                  Rd                  (       d  URg                  5       UR*                  l2        URl                  UR*                  Rd                  l7        UR                  S5      (       a{  UR*                  (       d  UR)                  5       Ul        UR*                  Rd                  (       d  URg                  5       UR*                  l2        / UR*                  Rd                  l7        UR                  S5      (       a  UR*                  (       d  UR)                  5       Ul        UR*                  Rd                  (       d  URg                  5       UR*                  l2        URp                  UR*                  Rd                  l9        UR                  S5      (       a{  UR*                  (       d  UR)                  5       Ul        UR*                  Rd                  (       d  URg                  5       UR*                  l2        SUR*                  Rd                  l9        URt                  b  URt                  Ul;        URS                  S5      (       a  [y        XRz                  5      Ul>        UR                  S5      (       a  UR~                  Ul@        URS                  S5      (       a  [        XR                  5      UlB        UR                  S5      (       aA  UR                  (       d  UR                  5       UlC        UR                  UR                  lF        URS                  S5      (       aJ  UR*                  (       d  UR)                  5       Ul        [        XR                  5      UR*                  lI        UR                  b  UR                  UlK        UR                  b  UR                  UlM        UR                  S5      (       aJ  UR*                  (       d  UR)                  5       Ul        [        XR                  5      UR*                  lP        UR                  b  UR                  UlR        UR                  S5      (       a  SUlS        UR                  S5      (       aA  UR*                  (       d  UR)                  5       Ul        UR                  UR*                  lU        UR                  S5      (       a`  UR                  (       aO  UR*                  R                  UR(                  R                  R                  :w  a  [        R                  " S5      eO`UR*                  (       aO  UR*                  R                  UR(                  R                  R                  :X  a  [        R                  " S S!5      eUR                  S"5      (       aJ  UR*                  (       d  UR)                  5       Ul        [        XR                  5      UR*                  l^        UR                  S#5      (       aA  UR*                  (       d  UR)                  5       Ul        UR                  UR*                  l`        UR                  S$5      (       a7  UR*                  (       d  UR)                  5       Ul        / UR*                  l`        UR                  S%5      (       a  [        XR                  5      Ulc        [        U5      (       Ga!  URS                  S&5      (       ae  U(       a  UR                  RP                  (       d  URN                  (       a  UR                  =(       d    S'Ulg        O[        R                  " S(S)5      eUR                  b  UR                  Uli        UR                  S*5      (       aA  UR                  (       d  UR                  5       Ulj        UR                  UR                  lm        UR                  S+5      (       a  [        5         UR                  Ulp        U$ ),aH  Constructs instance settings from the command line arguments.

Args:
  sql_messages: module, The messages module that should be used.
  args: argparse.Namespace, The arguments that this command was invoked
    with.
  instance: sql_messages.DatabaseInstance, The original instance, for
    settings that depend on the previous state.
  release_track: base.ReleaseTrack, the release track that this was run
    under.

Returns:
  A settings object representing the instance settings.

Raises:
  ToolException: An error other than http error occurred while executing the
      command.
authorized_gae_appsNfollow_gae_appr   PER_USEr   zsql#settings)kindtierpricingPlanreplicationTypeactivationPolicysql#locationPreferencer   followGaeApplicationrK   secondaryZonestorage_provisioned_iopsstorage_provisioned_throughputrv   networkenable_google_private_pathenable_private_service_connectallowed_psc_projectsclear_allowed_psc_projectspsc_network_attachment_uri clear_psc_network_attachment_urir   r   "recreate_replicas_on_primary_crashr   enable_data_cacher   r   !enable_auto_upgrade_minor_versionTserver_ca_poolz\`--server-ca-pool` can only be specified when the server CA mode is CUSTOMER_MANAGED_CAS_CA.z--server-ca-poolzhTo create an instance with server CA mode CUSTOMER_MANAGED_CAS_CA, [--server-ca-pool] must be specified.r    custom_subject_alternative_names&clear_custom_subject_alternative_namesr   storage_auto_increase_limitr   z--storage-auto-increasezsTo set the storage capacity limit using [--storage-auto-increase-limit], [--storage-auto-increase] must be enabled.enable_db_aligned_atomic_writesenable_accelerated_replica_mode)qr   r   r   IsKnownAndSpecifiedr   rm   reducersMachineTyper   memorycpur   r   rs   activation_policyauthorizedGaeApplicationsany	assign_iprequire_sslauthorized_networksr   ipConfigurationSetIpConfigurationEnabledSetAuthorizedNetworksAclEntry
requireSslrN   rQ   LocationPreferencelocationPreferencestorage_sizerZ   r   BYTES_TO_GBdataDiskSizeGbr   dataDiskProvisionedIopsr   dataDiskProvisionedThroughputstorage_auto_increasestorageAutoResizer'   rw   rv   availabilityTypePrivateNetworkUrlr   privateNetworkr   'enablePrivatePathForGoogleCloudServices	pscConfig	PscConfigr   
pscEnabledr   allowedConsumerProjectsr   networkAttachmentUrideletion_protectiondeletionProtectionEnabledr   r   connectorEnforcementr   recreateReplicasOnPrimaryCrashr   r   dataCacheConfigDataCacheConfigr   dataCacheEnabledr   r   sslModeenable_google_ml_integrationenableGoogleMlIntegrationenable_dataplex_integrationenableDataplexIntegrationr   r   serverCaModeretain_backups_on_deleteretainBackupsOnDeleteautoUpgradeEnabledr   serverCaPoolr   CUSTOMER_MANAGED_CAS_CAsql_exceptionsArgumentErrorr   RequiredArgumentExceptionr   r   serverCertificateRotationModer   customSubjectAlternativeNamesr   r   dataApiAccessrj   settingsr   storageAutoResizeLimit(replication_lag_max_seconds_for_recreatereplicationLagMaxSecondsdbAlignedAtomicWritesConfigDbAlignedAtomicWritesConfigr   dbAlignedAtomicWritesr   r   acceleratedReplicaMode)clsrq   r    r   rf   r  s         r"   _ConstructBaseSettingsFromArgs-_BaseInstances._ConstructBaseSettingsFromArgsJ  s	   : D(!%dt# dT!#d##M22d$$!!(IIt{{DHHM%l4E4EF-l<L<LM/00
 % H +/+C+Ch(
d"$    
 ".!=!=!?h		#%%h?		!	!!!..0E0E	
 
			%.2.>.>  +
D$1B41HIJJ$0$C$C'#22~)$/	 %D %h!  #D$5$5	8M8M$M Nh :;;),T-J-J)Kh& @AA/2

-
-0h, !!-#'#=#=h +,,"8
..#h 	""%%#/#?#?#A 080J0J
,,1h-  <==%%#/#?#?#A 

)
) F  @AA%%#/#?#?#A %%//-9-C-C-E  *

-
- ((3 .//%%#/#?#?#A %%//-9-C-C-E  *

#
# ((@  <==%%#/#?#?#A %%//-9-C-C-E  *CEh((@ <==%%#/#?#?#A %%//-9-C-C-E  *

)
) ((=  BCC%%#/#?#?#A %%//-9-C-C-E  *@Bh((=++/+C+Ch(/00&@
22'h#  DEE

1
1 - 	""&|\\Bh 344%%#/#?#?#A 262H2Hh/
##%%#/#?#?#A )6
*h& ((4+/+L+Lh(''3+/+K+Kh( 011%%#/#?#?#A .@
++/h+ $$0'+'D'Dh$ CDD$(h! 011%%#/#?#?#A .2.A.Ah+  011d6I6I

"
"
/
/))EE]]^ **+
 	
^ 	  $$11''CC[[\ 00
   BCC%%#/#?#?#A 
-AA <  BCC%%#/#?#?#A 

/
/ <  HII%%#/#?#?#A ?Ah< 1222
,, h
 ]##			7	8	8 **<<&&
 ..3! 
) 44'?  
	6	6	B99 	) 
	!	!"C	D	D33668 
. 00 	,,B 
	!	!"C	D	D*,*.*N*N'Or$   c                    U(       a  UR                   OSnU R                  XX45      n[        R                  " UUUR                  UR
                  UR                  UR                  UR                  UR                  UR                  SS9
nU(       a  U R                  Xg5        U(       a:  UR                  S5      (       a$  [        R                  " XUR                  S9Ul        [        R                   " UUUR"                  UR$                  UR&                  S9Ul        UR*                  (       ag  UR,                  (       aV  / Ul        UR.                  R1                  [        R2                  " UUUR*                  UR,                  UR4                  S95        [        R6                  " UUR8                  UR:                  UR<                  UR>                  UR@                  S9Ul!        URD                  (       a.  [G        U[H        RK                  URD                  5      5      Ul&        [        RN                  " UURP                  URR                  URT                  URV                  URX                  S	9Ul-        UR                  S
5      (       a[  [        R\                  " UUR^                  UR`                  URb                  URd                  URf                  URh                  S9Ul5        [        Rl                  " UURn                  URp                  URr                  5      Ul:        URv                  b  URv                  Ul<        UR                  S5      (       d  UR                  S5      (       a1  [        Rz                  " UUR|                  UR~                  5      Ul@        UR                  S5      (       a=  UR                  b0  UR                  5       UlC        UR                  UR                  lD        UR                  S5      (       a  UR                  (       d  UR                  5       UlF        UR                  R                  (       d  UR                  5       UR                  lH        [        R                  " XR                  5      UR                  R                  lL        [        R                  " UUUR                  UR                  S9nU(       a  U R                  Xh5        UR                  S5      (       d  UR                  S5      (       a5  [        R                  " UUR                  UR                  SSS9n	U	b  XlT        [        R                  " UUR                  UR                  UR                  UR                  UR                  UR                  UR                  S9n
U
b  Xl]        [        U5      (       Ga"  [        R                  " X!R                  R                  5      Ulc        UR                  (       aA  UR                  (       d  UR                  5       UlF        UR                  UR                  le        [        R                  " UUR                  S9nUb  Xlh        UR                  S5      (       a)  [        R                  " UUR                  SS9nUb  Xlk        UR                  S5      (       a$  [        R                  " UUR                  S9Uln        U$ )z>Constructs create settings object from base settings and args.NFbackup_enabledbackup_locationbackup_start_timeenable_bin_logenable_point_in_time_recoveryretained_backups_countretained_transaction_log_dayspatch_requestdatabase_flags)r2  maintenance_release_channelmaintenance_window_daymaintenance_window_hour"deny_maintenance_period_start_date deny_maintenance_period_end_datedeny_maintenance_period_time&insights_config_query_insights_enabled#insights_config_query_string_length'insights_config_record_application_tags%insights_config_record_client_address&insights_config_query_plans_per_minutedomainmodedns_serversadmin_credential_secret_keyorganizational_unitpassword_policy_min_lengthrG  password_policy_complexitypassword_policy_reuse_interval+password_policy_disallow_username_substring(password_policy_password_change_intervalenable_password_policyentra_id_tenant_identra_id_application_idthreads_per_corepsc_auto_connectionsfinal_backup_enabledfinal_backup_retention_daysenable_connection_poolingconnection_pool_flagsrU  rV  clear_connection_pool_flagscurrent_config)auto_scale_enabledauto_scale_min_node_countauto_scale_max_node_countauto_scale_target_metricsauto_scale_disable_scale_inauto_scale_in_cooldown_secondsauto_scale_out_cooldown_seconds)db_aligned_atomic_writesperformance_capture_configrb  rY  unc_mappings)rd  )or  r&  r   BackupConfigurationbackupr+  r,  r-  r.  r/  r0  AddBackupConfigToSettingsr   DatabaseFlagsr2  databaseFlagsMaintenanceWindowr4  r5  r6  maintenanceWindowr8  r9  denyMaintenancePeriodsappendDenyMaintenancePeriodr:  InsightsConfigr<  r=  r>  r?  r@  insightsConfigr   r   STORAGE_TYPE_MAPPINGgetdataDiskTypeActiveDirectoryConfigactive_directory_domainactive_directory_modeactive_directory_dns_servers#active_directory_secret_manager_key$active_directory_organizational_unitactiveDirectoryConfigPasswordPolicyrG  rI  rJ  rK  rL  rM  passwordValidationPolicySqlServerAuditConfigaudit_bucket_pathaudit_retention_intervalaudit_upload_intervalsqlServerAuditConfig	time_zonetimeZoneSqlServerEntraIdConfigrN  rO  entraidConfigrP  AdvancedMachineFeaturesadvancedMachineFeaturesthreadsPerCorer'   r   r   r   r  PscAutoConnectionsrQ  pscAutoConnectionsFinalBackupConfigurationfinal_backuprT  AddFinalBackupConfigToSettingsConnectionPoolConfigrU  rV  connectionPoolConfigReadPoolAutoScaleConfigrZ  r[  r\  r]  r^  r_  r`  readPoolAutoScaleConfigrj   r   ParseCreateArgsrm   UserLabelsValue
userLabelsallocated_ip_range_nameallocatedIpRanger"  r   r!  PerformanceCaptureConfigrb  performanceCaptureConfigUncMappingsrd  uncMappings)r%  rq   r    r   rf   original_settingsr  backup_configurationfinal_backup_configuration
mcp_configread_pool_auto_scale_configdb_aligned_atomic_writes_configrb  s                r"    _ConstructCreateSettingsFromArgs/_BaseInstances._ConstructCreateSettingsFromArgsq  s    .6))411HH $77{{,,00**&*&H&H#::&*&H&H 	##HC(()9::'55
$:M:M h "*!;!;$($D$D#:: $ < <"H 	//11(*h%%%,,

(
(151X1X/3/T/T+/+L+L '55/3/Z/Z,0,T,T040\0\.2.X.X/3/Z/ZH /
,001B1BCh &.%C%C++''55$($L$L EE&H"  <==*2*A*A
%)%D%D%)%D%D)-)L)L6:6f6f373`3`!%!<!<+h' %-$A$A%%""	%H! ~~!..h 		!	!";	<	<'>>


!
!

&
& h 	  !344!!-)5)M)M)Oh&8<8M8Mh&&5.//%%#/#?#?#A %%//-9-C-C-E  *

%
%l4M4M
N ((; "*!B!B!..$($D$D	" "	((N # 		!	!"9	:	:00
$($B$B $ : :&*j 
	(2%"*"B"B22"&"@"@"&"@"@"&"@"@$($D$D'+'J'J(,(L(L	# #.)D& ]##'77
%%55h 
	%	%''%1%A%A%C(
"484P4P  1(0(L(L
#'#G#G)% 
)	4/N,		!	!">	?	?%-%F%F'+'F'F&
"
 &1.H
+		!	!.	1	1'33** 

 Or$   c                 l   UR                   nU R                  XX45      nUR                  (       a  / Ul        [	        UR
                  [        U5      [        U5      /5      (       a3  UR                  SUR
                  [        U5      [        U5      S9Ul	        UR                  (       a7  UR                  (       d  UR                  5       Ul        / UR                  l        UR                  b  UR                  Ul        [         R"                  " UUUR$                  (       + UR&                  UR(                  UR*                  UR,                  UR.                  UR0                  SS9
nU(       a  U R3                  Xg5        U(       aF  UR5                  S5      (       a0  [         R6                  " UUUR8                  UR:                  S9Ul        [         R>                  " UUUR@                  URB                  URD                  S9Ul#        URH                  (       a  / Ul%        URL                  (       d"  URN                  (       d  URP                  (       aV  / Ul%        URJ                  RS                  [         RT                  " UUURL                  URN                  URP                  S95        URV                  (       a.  [Y        U[Z        R]                  URV                  5      5      Ul/        [         R`                  " UURb                  URd                  URf                  URh                  URj                  S	9Ul6        [         Rn                  " UURp                  URr                  URt                  URv                  URx                  S
9Ul=        [         R|                  " UUR~                  UR                  UR                  UR                  UR                  UR                  S9UlE        [         R                  " UUR                  UR                  UR                  S9UlJ        UR                  b0  UR                  5       UlM        UR                  UR                  lN        UR                  b  UR                  UlP        UR5                  S5      (       d,  UR5                  S5      (       d  UR5                  S5      (       a<  [         R                  " UUR                  UR                  UR                  5      UlU        [         R                  " UUUR                  UR                  S9nU(       a  U R                  Xh5        [         R                  " UUR                  UR                  UR                  UR                  S9n	U	b  Xl^        UR5                  S5      (       a  UR                  (       d  UR                  5       Ul        UR                  R                  (       d  UR                  5       UR                  l_        [         R                  " XR                  5      UR                  R                  lc        UR5                  S5      (       a{  UR                  (       d  UR                  5       Ul        UR                  R                  (       d  UR                  5       UR                  l_        / UR                  R                  lc        [         R                  " UUR                  UR                  UR                  UR                  UR                  UR                  UR                  UR                  S9	n
U
b  Xll        [        U5      (       Ga[  [        R                  R                  U5      nUR                  UR                  R                  UR                   R                  5      nUR                  (       a  UR                  Ult        UR                  (       aA  UR                  (       d  UR                  5       Ul        UR                  UR                  lx        UR5                  S5      (       a/  [         R                  " UUR                  UR                  S9Ul|        UR5                  S5      (       a3  [         R                  " UUR                  UR                  S9nUb  Xl        G[        U5      (       a   U$ )z=Constructs patch settings object from base settings and args.r   r   Tr)  r2  )r2  clear_database_flagsr3  r7  r;  rA  rH  )bucketretention_intervalupload_intervalrN  rO  clear_entra_id_configrR  rW  rQ  clear_psc_auto_connections)rZ  r[  r\  r]  r^  r_  r`  rY  rd  )rd  clear_unc_mappingsrb  rc  )r  r&  clear_gae_appsr   r   r   rN   rQ   r   r   clear_authorized_networksr   r   authorizedNetworksenable_database_replicationdatabaseReplicationEnabledr   re  	no_backupr+  r,  r-  r.  r/  r0  rg  r   rh  r2  r  ri  rj  r4  r5  r6  rk  remove_deny_maintenance_periodrl  r8  r9  r:  rm  rn  r   r   rq  rr  rs  ro  r<  r=  r>  r?  r@  rp  rt  ru  rv  rw  rx  ry  rz  r{  rG  rI  rJ  rK  rL  rM  r|  r}  r~  r  r  r  rP  r  r  r  r  r  r  rN  rO  r  r  r  r  rT  r  r  rU  rV  rX  r  r   r  r  rQ  r  r  rZ  r[  r\  r]  r^  r_  r`  r  rj   r   ExplicitNullificationDiffFromUpdateArgsApplyrm   r  r  needs_updatelabelsr  r  r  rd  r  r  r  rb  r  rg   )r%  rq   r    r   rf   r  r  r  r  updated_configr  labels_difflabels_updaterb  s                 r"   _ConstructPatchSettingsFromArgs._BaseInstances._ConstructPatchSettingsFromArgs5  s-   
 !))11HH +-h(
D$1B41HIJJ$0$C$C'#22~)$/	 %D %h! %%%%#/#?#?#A 46h1''3,0,L,Lh)#77>>),,00**&*&H&H#::&*&H&H 	##HC(()9::'55

,,#88	 h "*!;!;$($D$D#:: $ < <"H **(*h% 	//00,,(*h%%%,,

(
(151X1X/3/T/T+/+L+L /
,001B1BCh '55/3/Z/Z,0,T,T040\0\.2.X.X/3/Z/ZH &.%C%C++''55$($L$L EE&H" )1(?(?#'#B#B#'#B#B'+'J'J484d4d151^1^#::)H% %-$A$A%%8822	%H! ()5)M)M)Oh&8<8M8Mh&&5~~!..h 	  !566##$=>>##$;<<'>>


!
!

&
&

$
$	 h "*!B!B!..$($D$D	" "	((N 22"&"@"@"88$($D$D(==N !&4# 677%%#/#?#?#A %%//-9-C-C-E  *

%
%l4M4M
N ((;  <==%%#/#?#?#A %%//-9-C-C-E  *>@h((;"*"B"B22"&"@"@"&"@"@"&"@"@$($D$D'+'J'J(,(L(L(@@
# #.)D& ]##99HHNk!''



/
/1B1B1M1Mm 
	#	#+22 
	%	%''%1%A%A%C(
"484P4P  1		!	!.	1	1'33**#66 
 
	!	!">	?	?%-%F%F'+'F'F,EE&
"
 &1.H
+ 
Or$   c                 Z    AAAUR                  SS9nU(       a  U R                  Xd5        U$ )a  Construct a Cloud SQL instance from command line args.

Args:
  sql_messages: module, The messages module that should be used.
  args: argparse.Namespace, The CLI arg namespace.
  original: sql_messages.DatabaseInstance, The original instance, if some of
    it might be used to fill fields in the new one.
  instance_ref: reference to DatabaseInstance object, used to fill project
    and instance information.
  release_track: base.ReleaseTrack, the release track that this was run
    under.

Returns:
  sql_messages.DatabaseInstance, The constructed (and possibly partial)
  database instance.

Raises:
  ToolException: An error other than http error occurred while executing the
      command.
zsql#instance)r   )ry   SetProjectAndInstanceFromRef)r%  rq   r    originalinstance_refrf   instance_resources          r"   _ConstructBaseInstanceFromArgs-_BaseInstances._ConstructBaseInstanceFromArgs  s7    : 	h$55>5J	&&'8Gr$   c                 (
   [        U5        U R                  XX45      n[        R                  " UR                  [        U5      [        U5      5      Ul        [        XR                  5      Ul	        UR                  S5      (       a  UR                  Ul        UR                  S5      (       a  UR                  Ul        [        U5      (       aI  UR!                  S5      (       a3  [        R"                  " XR$                  UR&                  5      nXvl        U$ U R+                  XX55      Ul        UR                  S5      (       a%  UR.                  R0                  R2                  Ul        UR                  S5      (       a  UR6                  R8                  R:                  nUR<                  S:X  a  [?        5         URA                  SSS9Ul!        URD                  (       aL  URB                  (       a  URD                  URB                  l#        O@URA                  S	URD                  S
9Ul!        O UR6                  R8                  RH                  nUR                  S5      (       d  XR,                  l%        UR                  S5      (       a2  [?        5         UR.                  RM                  URN                  S9Ul(        URR                  (       a  URR                  UR,                  l)        [        U5      (       Ga  UR!                  S5      (       a  UR!                  S5      (       d  [T        RV                  " SS5      eUR!                  S5      (       d-  UR!                  S5      (       d  [T        RV                  " SS5      eURX                  (       a  [Z        R\                  " S5      Ul/        [        R@                  " UUR`                  UR^                  URb                  URd                  URf                  URh                  5      Ul!        UR                  SL n	[k        X)5      n
U
(       a  URm                  SU
S9nXl7        [q        US5      nUbi  UR.                  Rs                  [t        Rv                  " U5       VVs/ s H)  u  pUR.                  Rr                  Ry                  UUS9PM+     snnS9Ul=        UR                  S5      (       a  [}        XR~                  5      Ul@        UR                  S5      (       a  UR                  UlB        U$ s  snnf )zCConstructs Instance for create request from base instance and args.master_instance_nameroot_passwordsource_ip_address$enforce_new_sql_network_architectureFAILOVERz)sql#demoteMasterMysqlReplicaConfigurationT)r   failoverTargetzsql#replicaConfiguration)r   cascadableReplicar   failover_replica_name)namemaster_usernamez--master-instance-namezcTo create a read replica of an external master instance, [--master-instance-name] must be specifiedmaster_passwordprompt_for_master_passwordz--master-passwordzTo create a read replica of an external master instance, [--master-password] or [--prompt-for-master-password] must be specifiedzMaster Instance Password: Nzsql#diskEncryptionConfiguration)r   
kmsKeyNametags)keyvalue)additionalPropertiesr   
node_count)Cr   r  r   Regionr   rN   rQ   r|   r{   databaseVersionr   r  masterInstanceNamer  rootPasswordrj   r'   OnPremisesConfigurationr  source_portonPremisesConfigurationr  r  ry   %SqlNetworkArchitectureValueValuesEnumNEW_NETWORK_ARCHITECTUREsqlNetworkArchitecturerm   r   ASYNCHRONOUSreplica_typer   ReplicaConfigurationreplicaConfigurationcascadable_replicar  SYNCHRONOUSr   FailoverReplicaValuer  failoverReplica	collationr   r  r  r   PromptPasswordr  r  master_dump_file_pathmaster_ca_certificate_pathclient_certificate_pathclient_key_pathrH   DiskEncryptionConfigurationdiskEncryptionConfigurationrC   	TagsValuesix	iteritemsAdditionalPropertyr  r   r   instanceTyper  	nodeCount)r%  rq   r    r  r  rf   r  on_premises_configurationr   rE   key_nameconfigr  tagr  s                  r"   ConstructCreateInstanceFromArgs._BaseInstances.ConstructCreateInstanceFromArgs<  s     %::H  (Xd^%6t%<  )=++)%  677-1-F-F*00'+'9'9$ ]##(8(89L(M(M"*"B"B
..0@0@# 3L/!$!E!EH"  FGG

'
'
M
M
f
f .  677



>
>
K
K  
		j	(.0--@# .  	. 
	 	 11%% 
0
0
B
 //1$($;$; 0  
0 


>
>
J
J  ##M223>  0 788,.

'
'
<
<-- =  ' ~~-1^^  * ]##(8(89J(K(K45522$N
 	
 

,
-
-:;;22C
 	
 
	(	()88( 
 08/L/L








$
$

)
)

&
&


0, #55=J)$;H770X 8 f 7=34 D+<<FF !$d 3 
 !4*#	 ++55HH I  !4   G   00'9
**($ --$(OO!! s   :0T
c                    U R                  XX45      n[        XR                  5      Ul        UR                  Ul        U R                  XX55      Ul        UR                  (       a%  UR                  R                  R                  Ul        UR                  (       a%  UR                  R                  R                  Ul        UR                  S5      (       a  UR                  Ul        UR#                  S5      (       a/  UR
                  Ul        [$        R&                  R)                  5         UR#                  S5      (       a8  UR                  UR
                  :X  a  [$        R&                  R)                  5         [+        U5      (       a  UR#                  S5      (       ao  UR                  R,                  c  UR/                  5       UR                  l        UR                  R,                  R0                  UR                  R,                  l        UR                  S5      (       a'  UR3                  5       nUR4                  Ul        Xvl        UR                  S5      (       a'  UR8                  b  UR8                  R;                  5         UR                  S5      (       a  UR<                  Ul        UR                  S5      (       a  [A        XRB                  5      Ul"        UR                  S	5      (       a  URF                  Ul$        U$ )
zBConstructs Instance for patch request from base instance and args.(switch_transaction_logs_to_cloud_storagesimulate_maintenance_eventmaintenance_versionreconcile_psa_networkingfailover_dr_replica_nameclear_failover_dr_replica_name*include_replicas_for_major_version_upgrader   r  )%r  r|   r{   r  r  maintenanceVersionr  r   upgrade_sql_network_architecturery   r  r  r  r  r   r  *switchTransactionLogsToCloudStorageEnabledr'   api_utilInstancesV1Beta4(PrintAndConfirmSimulatedMaintenanceEventrj   r   r   r   ReplicationClusterr  failoverDrReplicaNamereplicationClusterClearFailoverDrReplicaNamer  %includeReplicasForMajorVersionUpgrader   r   r  r  r  )r%  rq   r    r  r  rf   r  replication_clusters           r"   ConstructPatchInstanceFromArgs-_BaseInstances.ConstructPatchInstanceFromArgs  s    ::H )=++)% ,0+C+C(!$!D!DH" ,,

'
'
M
M
f
f . 00

'
'
M
M
f
f .  JKK

7
7 B 455-5-H-H*HHJ
 	.//$$(C(CCHHJ]##(8(8") ) 
	#	#	3	3	;((* 	""2 


+
+
:
:   00?  :;;(;;=262O2O/-@* @AA		-	-	9,,GGI LMM

9
9 = 00'9
**($ --$(OO!r$   r   )__name__
__module____qualname____firstlineno____doc__classmethodDEFAULT_RELEASE_TRACKr&  r  r  r  r  r  __static_attributes__r   r$   r"   r   r   G  s    ;
 )d dL	 
 )A AF 7L_ _B 
 )" "H 
 )] ]~  )P Pr$   r   c                   h    \ rS rSrSr\S 5       r\S 5       r\S 5       r\S 5       r	\S 5       r
Srg	)
r  i0  z3Common utility functions for sql instances V1Beta4.c                 H    UR                   U l         UR                  U l        g rJ   )r   r   r  )r  r  s     r"   r  -InstancesV1Beta4.SetProjectAndInstanceFromRef3  s      , 4 4)22r$   c                     Xl         g rJ   )backupConfiguration)r  backup_configs     r"   rg  *InstancesV1Beta4.AddBackupConfigToSettings8  s    #0 r$   c                     Xl         g rJ   )finalBackupConfig)r  final_backup_configs     r"   r  /InstancesV1Beta4.AddFinalBackupConfigToSettings<  s    !4r$   c                 $    XR                   l        g rJ   )r   ipv4Enabled)r  r   s     r"   r   *InstancesV1Beta4.SetIpConfigurationEnabled@  s    +4(r$   c                 \    U Vs/ s H
  nU" SUS9PM     snU R                   l        g s  snf )Nzsql#aclEntry)r   r  )r   r  )r  r   acl_entry_valuens       r"   r   &InstancesV1Beta4.SetAuthorizedNetworksD  s6     %3$A 	^15$3H/ 3s   )r   N)r  r  r  r  r  staticmethodr  rg  r  r   r   r  r   r$   r"   r  r  0  sg    ;3 3 1 1 5 5 5 5  r$   r  )FrJ   );r  r[   googlecloudsdk.api_lib.sqlr   r   r  r   r   r   r  r   googlecloudsdk.callioper	   googlecloudsdk.command_libr
   $googlecloudsdk.command_lib.util.argsr   googlecloudsdk.corer   r   r   googlecloudsdk.core.consoler   r  rc   GAr  rq  r#   r-   r;   rH   rN   rQ   ra   rg   rj   rs   rw   r|   r   r   r   r   r   r   r   r   r   r   r   r   r   rA   r   r   objectr   r  r   r$   r"   <module>r5     s   : 
 0 C I < / ( . 2 < / # * 2 
)),,  . 
	(
.$<2L	*$/fV fR~ r$   