
    ]                        S r SSKJr  SSKJr  SSKJ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\R8                  R:                  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& r0S' r1S( r2S) r3S* r4S+ r5S6S, jr6S- r7S7S. jr8S/ r9S0 r:S1 r; " S2 S3\<5      r= " S4 S5\=5      r>g)83Common utility functions for sql instance commands.    )absolute_import)division)unicode_literalsN)	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&   0   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%   GetDatabaseArgsr0   :   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>   G   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%   _GetAndValidateCmekKeyNamerK   S   sv    MM!!'')' !! 
sC0$	7	711#%;
 	
r'   c                 @    U R                   =(       d    U R                  $ N)zonegce_zoner#   s    r%   _GetZonerQ   j   s    		#dmm#r'   c                 (    SU ;   a  U R                   $ g )Nsecondary_zone)rS   rP   s    r%   _GetSecondaryZonerT   n   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%   1DoesEnterprisePlusReplicaInferTierForDatabaseTyperd   u   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  $ rM   )r   ReleaseTrackALPHArelease_tracks    r%   _IsAlpharj      s    	$++11	11r'   c                 `    U [         R                  R                  :H  =(       d    [        U 5      $ rM   )r   rf   BETArj   rh   s    r%   IsBetaOrNewerrm      s#    	$++00	0	KH]4KKr'   c                     U(       aC  U R                   R                  R                  UR                  SS5      R	                  5       5      $ g Nr@   rA   )SettingsActivationPolicyValueValuesEnumlookup_by_namerG   upper)sql_messagespolicys     r%   _ParseActivationPolicyrv      s@      @@OOsC &&(  
r'   c                 x    U(       a3  U R                   R                  R                  UR                  5       5      $ g rM   )rp   AvailabilityTypeValueValuesEnumrr   rs   )rt   availability_types     r%   _ParseAvailabilityTyperz      s5      @@OO!  
r'   c                 x    U(       a3  U R                   R                  R                  UR                  5       5      $ g rM   )DatabaseInstanceDatabaseVersionValueValuesEnumrr   rs   )rt   database_versions     r%   ParseDatabaseVersionr      s5    ((GGVV   
r'   c                 x    U(       a3  U R                   R                  R                  UR                  5       5      $ g rM   )rp   PricingPlanValueValuesEnumrr   rs   )rt   pricing_plans     r%   _ParsePricingPlanr      s5      ;;JJ  
r'   c                 x    U(       a3  U R                   R                  R                  UR                  5       5      $ g rM   )rp   ReplicationTypeValueValuesEnumrr   rs   )rt   replications     r%   _ParseReplicationTyper      s5      ??NN  
r'   c                 x    U(       a3  U R                   R                  R                  UR                  5       5      $ g rM   )rp   DataDiskTypeValueValuesEnumrr   rs   )rt   storage_types     r%   _ParseStorageTyper      s5      <<KK  
r'   c                     U(       aC  U R                   R                  R                  UR                  SS5      R	                  5       5      $ g ro   )rp   EditionValueValuesEnumrr   rG   rs   )rt   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 ro   )r|   InstanceTypeValueValuesEnumrr   rG   rs   )rt   instance_types     r%   _ParseInstanceTyper      sB    ((DDSSc3'--/  
r'   c                 h    U R                   R                  R                  UR                  5       5      $ rM   )rp   #ConnectorEnforcementValueValuesEnumrr   rs   )rt   connector_enforcements     r%   _ParseConnectorEnforcementr      s-    ??NN

%
%
'r'   c                 h    U R                   R                  R                  UR                  5       5      $ rM   )rp   DataApiAccessValueValuesEnumrr   rs   )rt   data_api_accesss     r%   _ParseDataApiAccessr      s-    88GG



!r'   c                 h    U R                   R                  R                  UR                  5       5      $ rM   )IpConfigurationSslModeValueValuesEnumrr   rs   )rt   ssl_modes     r%   _ParseSslModer      s+    		%	%	<	<	K	Knn
 r'   c                 h    U R                   R                  R                  UR                  5       5      $ rM   )r   ServerCaModeValueValuesEnumrr   rs   )rt   server_ca_modes     r%   _ParseServerCaModer      s-    "">>MM



 r'   c                 h    U R                   R                  R                  UR                  5       5      $ rM   )r   ,ServerCertificateRotationModeValueValuesEnumrr   rs   )rt    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   warningr5   )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.
regionrO   rN   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%   rD   rD   0  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   9  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   C  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)_BaseInstancesiJ  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5      (       GaQ  URS                  S%5      (       a  [        XR                  5      Uld        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   followGaeApplicationrN   secondaryZonestorage_provisioned_iopsstorage_provisioned_throughputry   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   rp   reducersMachineTyper   memorycpur   r   rv   activation_policyauthorizedGaeApplicationsany	assign_iprequire_sslauthorized_networksr   ipConfigurationSetIpConfigurationEnabledSetAuthorizedNetworksAclEntry
requireSslrQ   rT   LocationPreferencelocationPreferencestorage_sizer]   r   BYTES_TO_GBdataDiskSizeGbr   dataDiskProvisionedIopsr   dataDiskProvisionedThroughputstorage_auto_increasestorageAutoResizer*   rz   ry   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   customSubjectAlternativeNamesrm   r   r   dataApiAccesssettingsr   storageAutoResizeLimit(replication_lag_max_seconds_for_recreatereplicationLagMaxSecondsdbAlignedAtomicWritesConfigDbAlignedAtomicWritesConfigr   dbAlignedAtomicWritesr   r   acceleratedReplicaMode)clsrt   r#   r   ri   r   s         r%   _ConstructBaseSettingsFromArgs-_BaseInstances._ConstructBaseSettingsFromArgsM  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< ]##			+	,	,!4.."
 
		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)r5  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rJ  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rX  rY  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re  r\  unc_mappings)rg  )or   r)  r   BackupConfigurationbackupr.  r/  r0  r1  r2  r3  AddBackupConfigToSettingsr   DatabaseFlagsr5  databaseFlagsMaintenanceWindowr7  r8  r9  maintenanceWindowr;  r<  denyMaintenancePeriodsappendDenyMaintenancePeriodr=  InsightsConfigr?  r@  rA  rB  rC  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PasswordPolicyrJ  rL  rM  rN  rO  rP  passwordValidationPolicySqlServerAuditConfigaudit_bucket_pathaudit_retention_intervalaudit_upload_intervalsqlServerAuditConfig	time_zonetimeZoneSqlServerEntraIdConfigrQ  rR  entraidConfigrS  AdvancedMachineFeaturesadvancedMachineFeaturesthreadsPerCorer*   r   r   r  r  PscAutoConnectionsrT  pscAutoConnectionsFinalBackupConfigurationfinal_backuprW  AddFinalBackupConfigToSettingsConnectionPoolConfigrX  rY  connectionPoolConfigReadPoolAutoScaleConfigr]  r^  r_  r`  ra  rb  rc  readPoolAutoScaleConfigrm   r   ParseCreateArgsrp   UserLabelsValue
userLabelsallocated_ip_range_nameallocatedIpRanger%  r   r$  PerformanceCaptureConfigre  performanceCaptureConfigUncMappingsrg  uncMappings)r(  rt   r#   r   ri   original_settingsr   backup_configurationfinal_backup_configuration
mcp_configread_pool_auto_scale_configdb_aligned_atomic_writes_configre  s                r%    _ConstructCreateSettingsFromArgs/_BaseInstances._ConstructCreateSettingsFromArgst  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,  r5  )r5  clear_database_flagsr6  r:  r>  rD  rK  )bucketretention_intervalupload_intervalrQ  rR  clear_entra_id_configrU  rZ  rT  clear_psc_auto_connections)r]  r^  r_  r`  ra  rb  rc  r\  rg  )rg  clear_unc_mappingsre  rf  )r   r)  clear_gae_appsr   r   r   rQ   rT   r   r   clear_authorized_networksr   r   authorizedNetworksenable_database_replicationdatabaseReplicationEnabledr   rh  	no_backupr.  r/  r0  r1  r2  r3  rj  r   rk  r5  r  rl  rm  r7  r8  r9  rn  remove_deny_maintenance_periodro  r;  r<  r=  rp  rq  r   r   rt  ru  rv  rr  r?  r@  rA  rB  rC  rs  rw  rx  ry  rz  r{  r|  r}  r~  rJ  rL  rM  rN  rO  rP  r  r  r  r  r  r  rS  r  r  r  r  r  r  rQ  rR  r  r  r  r  rW  r  r  rX  rY  r[  r  r  r  r  rT  r  r  r]  r^  r_  r`  ra  rb  rc  r  rm   r   ExplicitNullificationDiffFromUpdateArgsApplyrp   r  r  needs_updatelabelsr  r  r  rg  r  r  r  re  r  rj   )r(  rt   r#   r   ri   r  r   r  r  updated_configr  labels_difflabels_updatere  s                 r%   _ConstructPatchSettingsFromArgs._BaseInstances._ConstructPatchSettingsFromArgs8  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   )r|   SetProjectAndInstanceFromRef)r(  rt   r#   originalinstance_refri   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   rQ   rT   r   r~   databaseVersionr   r  masterInstanceNamer  rootPasswordrm   r*   OnPremisesConfigurationr  source_portonPremisesConfigurationr  r   r|   %SqlNetworkArchitectureValueValuesEnumNEW_NETWORK_ARCHITECTUREsqlNetworkArchitecturerp   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_pathrK   DiskEncryptionConfigurationdiskEncryptionConfigurationrF   	TagsValuesix	iteritemsAdditionalPropertyr  r   r   instanceTyper  	nodeCount)r(  rt   r#   r  r  ri   r  on_premises_configurationr   rH   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_architecturer|   r  r  r  r  r   r   *switchTransactionLogsToCloudStorageEnabledr*   api_utilInstancesV1Beta4(PrintAndConfirmSimulatedMaintenanceEventrm   r   r   r  ReplicationClusterr  failoverDrReplicaNamereplicationClusterClearFailoverDrReplicaNamer  %includeReplicasForMajorVersionUpgrader   r   r  r  r  )r(  rt   r#   r  r  ri   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   J  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  i3  z3Common utility functions for sql instances V1Beta4.c                 H    UR                   U l         UR                  U l        g rM   )r   r   r  )r  r  s     r%   r  -InstancesV1Beta4.SetProjectAndInstanceFromRef6  s      , 4 4)22r'   c                     Xl         g rM   )backupConfiguration)r   backup_configs     r%   rj  *InstancesV1Beta4.AddBackupConfigToSettings;  s    #0 r'   c                     Xl         g rM   )finalBackupConfig)r   final_backup_configs     r%   r  /InstancesV1Beta4.AddFinalBackupConfigToSettings?  s    !4r'   c                 $    XR                   l        g rM   )r   ipv4Enabled)r   r   s     r%   r   *InstancesV1Beta4.SetIpConfigurationEnabledC  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.SetAuthorizedNetworksG  s6     %3$A 	^15$3H/ 3s   )r   N)r  r  r  r  r  staticmethodr  rj  r  r   r   r  r   r'   r%   r  r  3  sg    ;3 3 1 1 5 5 5 5  r'   r  )FrM   )?r  
__future__r   r   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  rf   GAr  rt  r&   r0   r>   rK   rQ   rT   rd   rj   rm   rv   rz   r   r   r   r   r   r   r   r   r   r   r   r   r   r   rD   r   r   objectr   r  r   r'   r%   <module>r9     s   : &  ' 	 0 C I < / ( . 2 < / # * 2 
)),,  . 
	(
.$<2L	*$/fV fR~ r'   