
    'M                        d Z ddlmZ ddlmZ ddlmZ ddlmZ ddlm	Z
 ddlmZ ddlmZ ddlmZ dd	lmZ ddlmZ dd
lmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddl Z dZ!ddiZ"d Z#d Z$d Z%d Z&ejN                   ejP                  ejR                  jT                         G d dejV                                      Z, ejP                  ejR                  jZ                        ejN                   G d dejV                                      Z. ejP                  ejR                  j^                        ejN                   G d dejV                                      Z0y) !Creates a new Cloud SQL instance.    )absolute_import)division)unicode_literals)
exceptions)api_util)
operations)validate)base)resource_args)flags)	instances)labels_util)log)
properties)resource_lex)resource_propertyNi  EXAMPLESa          To create a MySQL 8.0 instance with ID ``prod-instance'' that has 2
        CPUs, 4 GB of RAM, and is in the region ``us-central1'' (a zone will be
        auto-assigned), where the 'root' user has its password set to
        ``password123'', run:

          $ {command} prod-instance --database-version=MYSQL_8_0 --cpu=2 --memory=4GB --region=us-central1 --root-password=password123

        To create a Postgres 15 instance with ID ``prod-instance'' that has 2
        CPUs, 8 GiB of RAM, and is in the zone ``us-central1-a'', where the
        'postgres' user has its password set to ``password123'', run:

          $ {command} prod-instance --database-version=POSTGRES_15 --cpu=2 --memory=8GiB --zone=us-central1-a --root-password=password123

        To create a SQL Server 2022 Express instance with ID ``prod-instance''
        that has 2 CPUs, 3840MiB of RAM, and is in the zone ``us-central1-a'',
        where the 'sqlserver' user has its password set to ``password123'',
        run:

          $ {command} prod-instance --database-version=SQLSERVER_2022_EXPRESS --cpu=2 --memory=3840MiB --zone=us-central1-a --root-password=password123
        c                    t         j                  j                  |        | j                  j	                  t        j                                t        j                  |        t        j                  |        t        j                  |        t        j                  |        t        j                  |        t        j                  |        t        j                  |        t        j                  | d       t        j                  |        t        j                   |        t        j"                  |        t        j$                  | d       t        j&                  |        t        j(                  |        t        j*                  |        | j-                  dt/        j0                         d       t        j2                  |        t        j4                  |        t        j6                  |        t        j8                  |        t        j:                  |        t        j<                  |        t        j>                  | d       t        j@                  |        t        jB                  | d       t        jD                  | d       t        jF                  |        t        jH                  |        t        jJ                  |        t        jL                  |        t        jN                  |        t        jP                  |        t        jR                  |        t        jT                  |        t        jV                  |        t        jX                  |        t        jZ                  |        t        j\                  |        t        j^                  |        t        j`                  |        t        jb                  |        t        jd                  |        t        jf                  |        t        jh                  |        dd	d
dd}tk        jl                  | d|       t        jn                  |        t        jp                  |        t        jr                  |        t        jt                  |        t        jv                  |        t        jx                  |        t        jz                  | t|               t        j~                  | d       t        j                  |        t        j                  |        t        j                  |        t        j                  |        | j                         }t        j                  |       t        j                  |       t        j                  |        t        j                  |        t        j                  |        t        j                  |        t        j                  |        t        j                  |        t        j                  |        t        j                  |        t        j                  |        t        j                  |        t        j                  |        t        j                  |        t        j                  |        t        j                  | d       t        j                  | d       t        j                  | d       t        j                  | d       t        j                  | d       t        j                  |        t        j                  |        t        j                  |        t        j                  |        t        j                  |        y)z>Declare flag and positional arguments for this command parser.F)allow_empty)show_negated_in_helpinstancezCloud SQL instance ID.)typehelpT--disk-encryption-keyz--disk-encryption-key-keyringz--disk-encryption-key-locationz--disk-encryption-key-project)zkms-keyzkms-keyringzkms-locationzkms-project)flag_overrideshiddenN)^r   
ASYNC_FLAGAddToParserdisplay_info	AddFormatr   GetInstanceListFormatAddActivationPolicyAddActiveDirectoryDomainAddAssignIpAddAuthorizedNetworksAddAvailabilityType	AddBackupAddBackupStartTimeAddBackupLocationAddCPUAddInstanceCollationAddDatabaseFlagsAddEnableBinLogAddRetainedBackupsCountAddRetainedTransactionLogDaysAddFailoverReplicaNameadd_argumentcommand_validateInstanceNameRegexpValidatorAddMaintenanceReleaseChannelAddMaintenanceWindowDayAddMaintenanceWindowHour!AddDenyMaintenancePeriodStartDateAddDenyMaintenancePeriodEndDateAddDenyMaintenancePeriodTime%AddInsightsConfigQueryInsightsEnabled"AddInsightsConfigQueryStringLength&AddInsightsConfigRecordApplicationTags$AddInsightsConfigRecordClientAddress$AddInsightsConfigQueryPlansPerMinuteAddMasterInstanceName	AddMemoryAddPasswordPolicyMinLengthAddPasswordPolicyComplexityAddPasswordPolicyReuseInterval*AddPasswordPolicyDisallowUsernameSubstring'AddPasswordPolicyPasswordChangeInterval%AddPasswordPolicyEnablePasswordPolicyAddReplicaTypeAddReplicationAddRequireSslAddRootPasswordAddStorageAutoIncreaseAddStorageSizeAddStorageTypeAddTier
AddEditionkms_resource_argsAddKmsKeyResourceArgAddEnablePointInTimeRecovery
AddNetworkAddSqlServerAuditAddDeletionProtectionAddSqlServerTimeZoneAddConnectorEnforcement
AddTimeout"_INSTANCE_CREATION_TIMEOUT_SECONDSAddEnableGooglePrivatePathAddThreadsPerCoreAddCascadableReplicaAddEnableDataCache!AddRecreateReplicasOnPrimaryCrash	add_groupAddEnablePrivateServiceConnectAddAllowedPscProjects AddCustomSubjectAlternativeNames
AddSslModeAddEnableGoogleMLIntegrationAddEnableDataplexIntegrationAddPscAutoConnectionsAddServerCaModeAddTagsAddRetainBackupsOnDeleteAddServerCaPoolAddStorageProvisionedIopsAddStorageProvisionedThroughputAddInstanceTypeAddNodeCountAddActiveDirectoryMode"AddActiveDirectorySecretManagerKey$AddActiveDirectoryOrganizationalUnitAddActiveDirectoryDNSServersClearActiveDirectoryDNSServersAddForceSqlNetworkArchitectureAddFinalBackupAddFinalbackupRetentionDaysAddEnableConnectionPoolingAddConnectionPoolFlags)parserkms_flag_overridespsc_setup_groups      #lib/surface/sql/instances/create.pyAddBaseArgsr   C   s
    //f% ; ; =>F#  (Ff%F#//&6"&e4,,vV$ U;'%%f-v&779#  
 $$V,'  ())&1''/$$V,--f4P**62..4 ,,V$O,,V4f%//&""6*##F+&&v.226://7--f5vvfv&vv--6(464	 ((j); $$V,6&!f%V$'6=>""6F&!V$6"))&1$$&/&&7o.((06$$V,$$V,f%--  (!!&)''/Vvd3**6$?,,VDA$$VD9&&vd;&&v.v##F+""6*v&    c                 T   t        j                  |        t        j                  |        t        j                  |        t	        j
                  |        t        j                  |        t        j                  |        t        j                  |        t        j                  |        y)zCDeclare beta flag and positional arguments for this command parser.N)
r   AddExternalMasterGroupAddInstanceResizeLimitAddAllocatedIpRangeNamer   AddCreateLabelsFlags&AddReplicationLagMaxSecondsForRecreateAddEnableDbAlignedAtomicWritesAddEnableAcceleratedReplicaModeAddEnableAutoUpgrader{   s    r~   AddBetaArgsr      sr    v&v&'""6*..v6&&v.''/V$r   c                 2    t        j                  | d       y)z,Declare alpha flags for this command parser.Tr   N)r   AddReadPoolAutoScaleConfigr   s    r~   AddAlphaArgsr      s    ""6$7r   c                    t        j                  t         j                        }|j                  }|j                  }t        j                  | j                         t        j                  |        |j                  j                  | j                  dt        j                  j                  j                  j                  id      }| j!                  d      ri|j                  j                  | j"                  dt        j                  j                  j                  j                  id      }	 |j$                  j'                  |j)                  |j                  |j                              }| j!                  d      s|jD                  | _"        | j!                  d      s|jF                  jH                  | _%        | j!                  d      sI| j!                  d      s8| j!                  d      s'|jL                  r|jL                  jN                  | _'        | jQ                  d      r:|jF                  jH                  jS                  d      stU        jV                  d      |jX                  rm| jD                  |jD                  k(  rt[        j\                  dd       nc| j!                  d      st7        j^                  dd      t[        j\                  d       n&| j!                  d      rtU        jV                  d      | j!                  d      r| jD                  |jD                  k(  rt7        j`                  dd      | j!                  d      rt7        j`                  dd      | jQ                  d      rA| j!                  d      r0| jJ                  jS                  d      stU        jV                  d      | j!                  d      rB| jJ                  jS                  d      r'| j!                  d      st7        j^                  dd       | jb                  s]| j!                  d!      r&| j!                  d      s;tU        jV                  d"      | j!                  d#      rtU        jV                  d$      | jQ                  d%      r&| jQ                  d&      stU        jV                  d'      | jQ                  d(      r&| jQ                  d&      stU        jV                  d)      | jQ                  d*      r&| jQ                  d+      stU        jV                  d,      | jd                  :tg        d-| jd                  v d.| jd                  v g      rt/        jh                  d/       | j!                  d0      rd| jj                  d1k(  rU| jN                  xr t[        jl                  | jJ                        }| j!                  d      s|stU        jV                  d2      tZ        jn                  jq                  || ||3      }d}	 |j$                  js                  |ju                  ||j                  4            }|j                  jw                  d5|jH                  |j                  6      }| jx                  rX| j!                  d7      sd8| _=        |j|                  j'                  |j                  |j                  |j                  9            S t|        j                  j                  ||d:| jJ                  z   | j                  ;       t/        j                  |       |j$                  j'                  |j)                  |j                  |j                              }|S # t*        j,                  $ r}t/        j0                  dt3        j4                  |             t7        j8                  |      }	t;        j&                  |	j<                  j>                  tA        jB                  d      d      d	k(  rd
}
t7        j8                  |
       d}~ww xY w# t*        j,                  $ r}t/        j0                  dt3        j4                  |             t7        j8                  |      }	t;        j&                  |	j<                  j>                  tA        jB                  d      d      d<k(  rSt;        j&                  |	j<                  j>                  tA        jB                  d=      d      }
t7        j8                  |
       d}~ww xY w)>a  Creates a new Cloud SQL instance.

  Args:
    args: argparse.Namespace, The arguments that this command was invoked with.
    release_track: base.ReleaseTrack, the release track that this was run under.

  Returns:
    A dict object representing the operations resource describing the create
    operation if the create was successful.
  Raises:
    HttpException: A http error response was received while executing api
        request.
    ArgumentError: An argument supplied by the user was incorrect, such as
      specifying an invalid CMEK configuration or attempting to create a V1
      instance.
    RequiredArgumentException: A required argument was not supplied by the user,
      such as omitting --root-password on a SQL Server instance.
  projectzsql.instances)params
collectionmaster_instance_name)r   r   zoperation : %szerror.errors[0].reasonNnotAuthorizedzQYou are either not authorized to access the master instance or it does not exist.regiondatabase_versiontiercpumemoryenable_accelerated_replica_modeMYSQL_z>--enable-accelerated-replica-mode is only supported for MySQL.replicazthe master instancedisk_encryption_keyr   zy`--disk-encryption-key` is required when creating a cross-region replica of an instance with customer-managed encryption.zw`--disk-encryption-key` cannot be specified when creating a replica of an instance without customer-managed encryption.cascadable_replicaz--cascadable-replicazt`--cascadable-replica` can only be specified when creating a replica that is in a different region than the primary.zX`--cascadable-replica` can only be specified when `--master-instance-name` is specified.	SQLSERVERroot_passwordz--root-passwordzA`--root-password` is required when creating SQL Server instances.enable_bin_logzD`--enable-bin-log` cannot be specified when --no-backup is specifiedenable_point_in_time_recoveryzS`--enable-point-in-time-recovery` cannot be specified when --no-backup is specifiedallowed_psc_projectsenable_private_service_connectzD`--allowed-psc-projects` requires `--enable-private-service-connect`psc_auto_connectionszD`--psc-auto-connections` requires `--enable-private-service-connect` custom_subject_alternative_namesserver_ca_modezH`--custom-subject-alternative-names` requires customer managed server CAsync_binloginnodb_flush_log_at_trx_commitzChanging innodb_flush_log_at_trx_commit or sync_binlog may cause data loss. Check https://cloud.google.com/sql/docs/mysql/flags for more details.editionzenterprise-plusz-`--edition=enterprise-plus` requires `--tier`)instance_refrelease_track)databaseInstancer   zsql.operations)	operationr   formatdefault)r   r   z Creating Cloud SQL instance for )max_wait_secondserrorMaxInstancePerLabelzerror.message)Ecommon_api_util	SqlClientAPI_VERSION_DEFAULT
sql_clientsql_messagesr
   ValidateInstanceNamer   ValidateInstanceLocationresource_parserParser   VALUEScorer   	GetOrFailIsSpecifiedr   r   GetSqlInstancesGetRequestapitools_exceptions	HttpErrorr   debugsix	text_typer   HttpExceptionr   payloadcontentr   ParseKeyr   databaseVersionnamer   settingsr   IsKnownAndSpecified
startswithsql_exceptionsArgumentErrordiskEncryptionConfigurationcommand_utilShowCmekWarningRequiredArgumentExceptionInvalidArgumentExceptionbackupdatabase_flagsanywarningr   1DoesEnterprisePlusReplicaInferTierForDatabaseTypeInstancesV1Beta4ConstructCreateInstanceFromArgsInsertSqlInstancesInsertRequestCreateasync_r   r	   SqlOperationsGetRequestr   OperationsV1Beta4WaitForOperationtimeoutCreatedResource)argsr   clientr   r   r   master_instance_refmaster_instance_resourceerrorexcmsgcan_infer_tierinstance_resourceoperation_refresult_operationnew_resources                   r~   RunBaseCreateCommandr      s/   & $$_%H%HI&  *$$,
.
##D)''--
mm**//77AAB  . , 
,- 0066!!:,,1199CCD" 7 
!+!5!5!9!9

-
-"***33 . "0 H%,33dk./6FFKKdV$!!%(D,<,<X,F$--*3388di AB
"
2
2
7
7
B
B8
L**L
 	

  ;;	077	7 	$$Y0EF 56 22#G
 	
 	$$Y/			/	0 ((@ 
 ,-	077	711"F
 	
 ,-//
 3   AB			,	-$$//9,,N  )*



*
*;
7/

.
.K 
 
()45 **
 	
 
		9	:((% 
 
$$%EF

&
&N  
$$%EF

&
&N 
 
($$%56

&
&	 
 
$t***&$*=*==. * KK	 
i T\\5F%F 			 	
JJ!!
  V$((
9 
 ##CC

#%	 D   -4
!++22...8L8L 	/ 	
 **11"''$$ 2 M {{h'""&&

.
.#++}7N7N /     11*T-B-BB	 2  %''++++ ((<3H3H 	, 	
L
 W (( 	ii #--0C"DE$$U+c


kk!!##$<=
 ! 	 &&s++#X 
	&	& 
IIm <=

"
"5
)CKK!!":;	

 &	& !!
++

|44_Etc $$S))	
s;   /A ] <C` B` `,B``c6Cc11c6c                   *    e Zd ZdZeZd Zed        Zy)r   r   c                 6    t        || j                               S Nr   ReleaseTrackselfr   s     r~   Runz
Create.Run      d&7&7&9::r   c                 n    t        |        t        j                  |        t        j                  |        y)@Args is called by calliope to gather arguments for this command.N)r   r   AddLocationGroupAddDatabaseVersionr   s    r~   ArgszCreate.Args  s(     	6"	V$r   N	__name__
__module____qualname____doc__DETAILED_HELPdetailed_helpr   staticmethodr   r   r~   r   r     s%     *-; % %r   r   c                   *    e Zd ZdZeZd Zed        Zy)
CreateBetar   c                 6    t        || j                               S r   r   r   s     r~   r   zCreateBeta.Run  r   r   c                     t        |        t        j                  |        t        |        t        j                  | d       yr   F)restrict_choicesN)r   r   r   r   r   r   s    r~   r  zCreateBeta.Args  s2     	6"	Ve<r   Nr  r
  r   r~   r  r    s%     *-; = =r   r  c                   *    e Zd ZdZeZd Zed        Zy)CreateAlphar   c                 6    t        || j                               S r   r   r   s     r~   r   zCreateAlpha.Run  r   r   c                     t        |        t        j                  |        t        |        t	        |        t        j
                  | d       yr  )r   r   r   r   r   r   r   s    r~   r  zCreateAlpha.Args  s:     	6"	Ve<r   Nr  r
  r   r~   r  r    s%     *-; = =r   r  )1r  
__future__r   r   r   apitools.base.pyr   r   googlecloudsdk.api_lib.sqlr   r   r   r	   r
   googlecloudsdk.callioper   googlecloudsdk.command_lib.kmsr   rR   googlecloudsdk.command_lib.sqlr   r   r   r4   $googlecloudsdk.command_lib.util.argsr   googlecloudsdk.corer   r   googlecloudsdk.core.resourcer   r   r   r[   r  r   r   r   r   DefaultUniverseOnlyReleaseTracksr   GACommandr   BETAr  ALPHAr  r
  r   r~   <module>r$     sI   ( &  ' > B C 1 / ( . M 0 D G < # * 5 : 
 &* "  2e'\	%8
J
Z D%%(()%T\\ % * %  D%%**+= =  ,=" D%%++,=$,, =  -=r   