
    z                     @   S r SSKJr  SSKJr  SSKJr  SSKJr  SSKJ	r	  SSKJ
r  SSKJr  SS	KJr  SS
KJr  SSKJr   " S S\R&                  5      r " S S\R&                  5      r " S S\R&                  5      r " S S\R&                  5      r " S S\R&                  5      r " S S\R&                  5      r " S S\R&                  5      r " S S\R&                  5      r " S S\R&                  5      r " S S\R&                  5      rSS  jrSS! jrSS" jr S# r!S$ r"S% r#S& r$S' r%S( r&S) r'  SS* jr(SS+ jr)SS, jr*    SS- jr+SS. jr,S/ r-SS0 jr. SS1 jr/SS2 jr0SS3 jr1SS4 jr2SS5 jr3SS6 jr4SS7 jr5SS8 jr6SS9 jr7SS: jr8SS; jr9 SS< jr:S= r;    SS> jr<SS? jr=   SSA jr>   SSB jr?SC r@SD rASE rB      SSF jrC   SSG jrDSSH jrESSI jrFSSJ jrGSSK jrHSSL jrISSM jrJSN rKSO rLSP rMSSQ jrNSR rOSS rPST rQSU rRSV rSSW rTSX rUSY rVSZ rWS[ rXS\ rYS] rZS^ r[S_ r\S` r]Sa r^Sb r_Sc r`Sd raSe rbSf rcSg rdSh reSi rfSj rgSSk jrhSSl jriSSm jrjSSn jrkSSo jrlSSp jrmSq rnSr roSs rpSt rqSu rrSv rsSw rtSx ruSy rvSz rwS{ rxS| ryS} rzS~ r{S r|S r}S r~g@)z:Provides common arguments for the Spanner command surface.    )FilesCompleter)descriptor_pb2)	databases)arg_parsers)base)
exceptions)
ddl_parser)split_file_parser)
completers)filesc                   (   ^  \ rS rSrU 4S jrSrU =r$ )BackupCompleter   c                 8   > [         [        U ]
  " SSSS/S.UD6  g )Nz"spanner.projects.instances.backupszspanner backups list --uriinstance
collectionlist_commandflags )superr   __init__selfkwargs	__class__s     /lib/googlecloudsdk/command_lib/spanner/flags.pyr   BackupCompleter.__init__   s,    	/4) 71l 	    r   __name__
__module____qualname____firstlineno__r   __static_attributes____classcell__r   s   @r   r   r           r   r   c                   (   ^  \ rS rSrU 4S jrSrU =r$ )BackupScheduleCompleter'   c                 :   > [         [        U ]
  " SSSSS/S.UD6  g )Nz4spanner.projects.instances.databases.backupSchedulesz#spanner backup-schedules list --uridatabaser   r   r   )r   r*   r   r   s     r   r    BackupScheduleCompleter.__init__)   s0    	
!41 I::& 	r   r   r    r'   s   @r   r*   r*   '   s     r   r*   c                   (   ^  \ rS rSrU 4S jrSrU =r$ )DatabaseCompleter2   c                 8   > [         [        U ]
  " SSSS/S.UD6  g )Nz$spanner.projects.instances.databaseszspanner databases list --urir   r   r   )r   r0   r   r   s     r   r   DatabaseCompleter.__init__4   s-    	
T+ 93l 	r   r   r    r'   s   @r   r0   r0   2   r(   r   r0   c                   (   ^  \ rS rSrU 4S jrSrU =r$ )DatabaseOperationCompleter<   c                 8   > [         [        U ]
  " SSSS/S.UD6  g )Nz/spanner.projects.instances.databases.operationsspanner operations list --urir   r   r   )r   r5   r   r   s     r   r   #DatabaseOperationCompleter.__init__>   s-    	
$d4 D4l 	r   r   r    r'   s   @r   r5   r5   <   r(   r   r5   c                   (   ^  \ rS rSrU 4S jrSrU =r$ )InstanceCompleterF   c                 4   > [         [        U ]
  " SSSS.UD6  g )Nzspanner.projects.instanceszspanner instances list --urir   r   r   )r   r;   r   r   s     r   r   InstanceCompleter.__init__H   s(    	
T+ /3 r   r   r    r'   s   @r   r;   r;   F        r   r;   c                   (   ^  \ rS rSrU 4S jrSrU =r$ )InstancePartitionCompleterO   c                 4   > [         [        U ]
  " SSSS.UD6  g )Nz-spanner.projects.instances.instancePartitionsz,alpha spanner instance-partitions list --urir>   r   )r   rB   r   r   s     r   r   #InstancePartitionCompleter.__init__Q   s(    	
$d4 BC r   r   r    r'   s   @r   rB   rB   O   s     r   rB   c                   (   ^  \ rS rSrU 4S jrSrU =r$ )InstanceConfigCompleterY   c                 4   > [         [        U ]
  " SSSS.UD6  g )Nz spanner.projects.instanceConfigsz#spanner instance-configs list --urir>   r   )r   rG   r   r   s     r   r    InstanceConfigCompleter.__init__[   s(    	
!41 5: r   r   r    r'   s   @r   rG   rG   Y   r@   r   rG   c                   (   ^  \ rS rSrU 4S jrSrU =r$ )OperationCompleterb   c                 8   > [         [        U ]
  " SSSS/S.UD6  g )Nz%spanner.projects.instances.operationsr8   r   r   r   )r   rL   r   r   s     r   r   OperationCompleter.__init__d   s-    	
d, :4l 	r   r   r    r'   s   @r   rL   rL   b   r(   r   rL   c                   (   ^  \ rS rSrU 4S jrSrU =r$ )DatabaseSessionCompleterl   c                 :   > [         [        U ]
  " SSSSS/S.UD6  g )Nz-spanner.projects.instances.databases.sessionsz%spanner databases sessions list --urir-   r   r   r   )r   rQ   r   r   s     r   r   !DatabaseSessionCompleter.__init__n   s0    	
"D2 B<:& 	r   r   r    r'   s   @r   rQ   rQ   l   r(   r   rQ   c                   (   ^  \ rS rSrU 4S jrSrU =r$ )DatabaseRoleCompleterv   c                 :   > [         [        U ]
  " SSSSS/S.UD6  g )Nz*spanner.projects.instances.databases.rolesz'beta spanner databases roles list --urir-   r   r   r   )r   rV   r   r   s     r   r   DatabaseRoleCompleter.__init__x   s0    	
/ ?>:& 	r   r   r    r'   s   @r   rV   rV   v   r(   r   rV   c                 z    U (       a  [         R                  " S[        US9$ [         R                  " SU[        US9$ )Nr-   	completerhelpz
--databaserequiredr\   r]   )r   Argumentr0   
positionalr_   texts      r   Databaserd      s6    ==/@tLL==x3D4Q Qr   c                 z    U (       a  [         R                  " S[        US9$ [         R                  " SU[        US9$ )Nbackupr[   z--backupr^   )r   r`   r   ra   s      r   Backuprg      s4    ==_4HH==XtM Mr   c                 0    [         R                  " SSSU S9$ )Nz--ddlappendF)actionr_   r]   r   r`   	help_texts    r   Ddlrn      s    		
 r   c                 8    [         R                  " SS[        U S9$ )Nz
--ddl-fileFr^   r   r`   r   rl   s    r   DdlFilerq      s    		
 r   c                 8    [         R                  " SS[        U S9$ )Nz--proto-descriptors-fileFr^   rp   rl   s    r   ProtoDescriptorsFilers      s    	 	
 r   c                 l    [         R                  " SS[        R                  [        R                  /U S9$ )Nz--database-dialectF)r_   choicesr]   )r   r`   r   DATABASE_DIALECT_POSTGRESQLDATABASE_DIALECT_GOOGLESQLrl   s    r   DatabaseDialectrx      s5    	

/
/

.
. 
 r   c                 0    [         R                  " SSU SS9$ )Nz--include-proto-descriptors
store_trueF)rj   r]   defaultrk   rl   s    r   IncludeProtoDescriptorsr|      s    	#	
 r   c                     U R                   (       a!  [        R                  " U R                   5      /$ U R                  =(       d    / $ N)ddl_filer   ReadFileContentsddlargss    r   GetDDLsFromArgsr      s/    	]]""4==122	Rr   c                    [        U 5      n/ nU H  n[        U S5      (       ax  U R                  (       ag  U R                  R                  5       [        R
                  :X  a;  UR                  UR                  S5       Vs/ s H  oD(       d  M  UPM     sn5        M  UR                  [        R                  " U5      5        M     U$ s  snf )zCBreak DDL statements on semicolon while preserving string literals.database_dialect;)
r   hasattrr   upperr   rv   extendsplitr	   PreprocessDDLWithParser)r   ddls
statementsxstmts        r   SplitDdlIntoStatementsr      s    		$*at'  ))d.C.C.I.I /88/9 !''#,?,$$,?@
::1=>  
 @s   ?
C
C
c                     U R                   (       aA  [        R                  " U R                   5      n[        R                  R                  U5        U$ g r~   )proto_descriptors_filer   ReadBinaryFileContentsr   FileDescriptorSet
FromString)r   proto_desc_contents     r   GetProtoDescriptorsr      sC    	  55##%$$//0BC	r   c                 8    [         R                  " S[        U US9$ )Nz--configr\   r_   r]   r   r`   rG   r_   rc   s     r   Configr      s!     
'	
 r   c                 ,    [         R                  " SXS9$ )Nz--descriptionr_   r]   rk   r   s     r   Descriptionr      s    		EEr   c                 z    U (       a  [         R                  " S[        US9$ [         R                  " SS[        US9$ )Nr   r[   
--instanceTr^   )r   r`   r;   )rb   rc   s     r   Instancer      s6    ==/@tLL==t/@tM Mr   c                 r    U (       a  [         R                  " S[        UUS9$ [         R                  " SXUS9$ )zInitialize an instance partition flag.

Args:
  positional: bool. If true, then it's a positional flag.
  required: bool. If true, then this flag is required.
  hidden: bool. If true, then this flag is hidden.
  text: helper test.

Returns:
instance_partition)r\   hiddenr]   z--instance-partitionr_   r   r]   )r   r`   rB   rb   r_   r   rc   s       r   InstancePartitionr      s>      ==,	  ==t r   c                 8    [         R                  " SU [        US9$ )Nz--nodesr_   typer]   r   r`   intr   s     r   Nodesr     s    		
 r   c           
          / SQnU R                  SS[        R                  " 5       [        R                  SSR	                  U5      S9  g)z(Makes the base.Argument for --tags flag.)z%List of tags KEY=VALUE pairs to bind.z%Each item must be expressed as eitherz%ID: `<tag-key-id>=<tag-value-id>` or
zENamespaced name: `<tag-key-namespaced-name>=<tag-value-short-name>`.
z%Example: `tagKeys/123=tagValues/223`
z?Example: `123/environment=production,123/costCenter=marketing`
z--tagsz	KEY=VALUET
)metavarr   rj   r   r]   N)add_argumentr   ArgDictUpdateActionjoin)parser
help_partss     r   AddTagsr   $  sH    * 	 %%99Z   r   c                     [        XS5      nU(       d  gU" [        UR                  5       5       VVs/ s H  u  pEUR                  XES9PM     snnS9$ s  snnf )zMakes the tags message object.N)keyvalue)additionalProperties)getattrsorteditemsAdditionalProperty)r   tags_messagetags_arg_nametagsr   r   s         r   GetTagsFromArgsr   8  s^    	d	+$		 #4::<00jc 
)
)c
)
?0
 s   A
c                 8    [         R                  " SU [        US9$ )Nz--processing-unitsr   r   r   s     r   ProcessingUnitsr   F  s     
XCd
 r   c                 8    [         R                  " SU [        SS9$ )Nz--autoscaling-max-nodesz4Maximum number of nodes for the autoscaled instance.r   r   r_   s    r   AutoscalingMaxNodesr   N      	A	
 r   c                 8    [         R                  " SU [        SS9$ )Nz--autoscaling-min-nodesz4Minimum number of nodes for the autoscaled instance.r   r   r   s    r   AutoscalingMinNodesr   W  r   r   c                 8    [         R                  " SU [        SS9$ )Nz"--autoscaling-max-processing-unitsz?Maximum number of processing units for the autoscaled instance.r   r   r   s    r   AutoscalingMaxProcessingUnitsr   `      	*L	
 r   c                 8    [         R                  " SU [        SS9$ )Nz"--autoscaling-min-processing-unitsz?Minimum number of processing units for the autoscaled instance.r   r   r   s    r   AutoscalingMinProcessingUnitsr   i  r   r   c                 :    [         R                  " SU U[        SS9$ )Nz&--autoscaling-high-priority-cpu-targetzYSpecifies the target percentage of high-priority CPU the autoscaled instance can utilize.r_   r   r   r]   r   r_   r   s     r    AutoscalingHighPriorityCpuTargetr   r  s$    	.#	
 	r   c                 :    [         R                  " SU U[        SS9$ )Nz--autoscaling-total-cpu-targetzQSpecifies the target percentage of total CPU the autoscaled instance can utilize.r   r   r   s     r   AutoscalingTotalCpuTargetr     s$    	&	
 	r   c                 8    [         R                  " SU [        SS9$ )Nz--autoscaling-storage-targetzOSpecifies the target percentage of storage the autoscaled instance can utilize.r   r   r   s    r   AutoscalingStorageTargetr     s!    	$
 r   c                 :    [         R                  " SU U[        SS9$ )Nz'--disable-high-priority-cpu-autoscalingzESet the flag to disable high priority CPU autoscaling on the replica.r   r   r`   boolr   s     r   !DisableHighPriorityCpuAutoscalingr     s$    	/	
 	r   c                 :    [         R                  " SU U[        SS9$ )Nz--disable-total-cpu-autoscalingz=Set the flag to disable total CPU autoscaling on the replica.r   r   r   s     r   DisableTotalCpuAutoscalingr     s"    	'J
 r   c                 N    [         R                  " SU U[        R                  SS9$ )Nz--disable-downscalingz@Set the flag to disable downscaling for the autoscaled instance.)r_   r   rj   r]   r   r`   r   StoreTrueFalseActionr   s     r   DisableDownScalingr     s(    	--M
 r   c                 .   Sn[         [        [        [        [        [        S.nU (       a	  [        US'   U(       a0  [        R                  " 5       US'   [        R                  " 5       US'   [        R
                  " S[        R                  " US/S9S	S
US9$ )a  Adds the --asymmetric-autoscaling-option flag.

Args:
  include_total_cpu_target: bool. If True, include 'total_cpu_target' in the
    ArgDict spec.
  include_disable_autoscaling_args: bool. If True, include
    'disable_high_priority_cpu_autoscaling' and
    'disable_total_cpu_autoscaling' in the ArgDict spec.

Returns:
  A base.Argument for the --asymmetric-autoscaling-option flag.
z>Specifies the asymmetric autoscaling option for the instance. )location	min_nodes	max_nodesmin_processing_unitsmax_processing_unitshigh_priority_cpu_targettotal_cpu_target%disable_high_priority_cpu_autoscalingdisable_total_cpu_autoscalingz--asymmetric-autoscaling-optionr   specrequired_keysFri   )r   r_   rj   r]   )strr   r   
ArgBooleanr   r`   r   )include_total_cpu_target include_disable_autoscaling_argsrm   r   s       r   AsymmetricAutoscalingOptionFlagr     s     O)$'$'(+
$ "D	%4?4J4J4LD	01,7,B,B,DD	()	'# 	
 	r   c                  V    [         R                  " S[        R                  " SS9SSSS9$ )Nz%--clear-asymmetric-autoscaling-option   
min_lengthLOCATIONFz_Specify a comma separated list of locations from which to remove asymmetric autoscaling options)r   r   r_   r]   )r   r`   r   ArgListr   r   r   %ClearAsymmetricAutoscalingOptionsFlagr     s/    	-!,,	
 	r   c                 f    U (       a  [         R                  " SX#S9$ [         R                  " SXUS9$ )Ncache_id)r   r]   z--ssd-cacher   rk   r   s       r   SsdCacher     s0     ==F>>==d r   c                     U (       a   gg)z+Returns the help text for the edition flag.ac  Spanner edition. You can upgrade your Standard edition instance to the `ENTERPRISE` edition or `ENTERPRISE_PLUS` edition. You can also upgrade your Enterprise edition instance to the `ENTERPRISE_PLUS` edition. You can downgrade your `ENTERPRISE_PLUS` edition instance to the `ENTERPRISE` or `STANDARD` edition. You can also downgrade your `ENTERPRISE` edition instance to the `STANDARD` edition. You must stop using the higher-tier edition features in order to downgrade. Otherwise, downgrade fails. For more information, see [Spanner editions overview](https://cloud.google.com/spanner/docs/editions-overview).zSpanner edition.r   )updates    r   GetEditionHelpTextr    s    		O 
r   Nc                 B    [         R                  " SU[        U5      U S9$ )Nz	--editionr_   r]   ru   )r   r`   r  )ru   r  r_   s      r   Editionr    s&    
 
f%	
 r   c                 0    [         R                  " SUUU S9$ )Nz--default-backup-schedule-typer  rk   )ru   r_   rc   s      r   DefaultBackupScheduleTyper    s!    
 
&	
 r   c                 8    [         R                  " SS[        U S9$ )Nz--splits-fileTr^   rp   rl   s    r   
SplitsFiler
  *  s    		
 r   c                 .    [         R                  " SSU S9$ )Nz--split-expiration-dateFr   rk   rl   s    r   SplitExpirationDater  3  s    	
 r   c                 .    [         R                  " SSU S9$ )Nz--initiatorFr   rk   rl   s    r   	Initiatorr  ;  s    	
 r   c                    UR                  SSS9n[        5       R                  U5        [        5       R                  U5        UR                  SS9n	U(       aB  U	R                  U SS9n
[	        SS9R                  U
5        [        SSS	9R                  U
5        O[	        U S9R                  U	5        U(       a  [        SSS	9R                  U	5        [        U S9R                  U	5        U	R                  SU S
S9nUR                  SS9n[        U S9R                  U5        [        U S9R                  U5        UR                  SS9n[        U S9R                  U5        [        U S9R                  U5        U(       ac  U(       aD  U	R                  SS9n[        UU5      R                  U5        [        5       R                  U5        g[        UUS9R                  U	S9  gg)a  Parse the instance capacity arguments, including manual and autoscaling.

Args:
  require_all_autoscaling_args: bool. If True, a complete autoscaling config
    is required.
  parser: the argparse parser for the command.
  add_asymmetric_option_flag: bool. If True, add the asymmetric autoscaling
    option flag.
  asymmetric_options_group: bool. If True, add the asymmetric autoscaling
    options group.
  autoscaling_cpu_target_group: bool. If True, add the autoscaling cpu target
    group.
  add_asymmetric_total_cpu_target_flag: bool. If True, add the asymmetric
    total cpu target flag.
  add_asymmetric_disable_autoscaling_flags: bool. If True, add the asymmetric
    disable autoscaling flags.
  add_disable_downscaling_flag: bool. If True, add the disable downscaling
    flag.
TFmutexr_   Autoscalingr]    r   r   r   FAutoscaling limits can be defined in either nodes or processing units.r  r_   r]   Autoscaling limits in nodes:'Autoscaling limits in processing units:)r  )r   r   r   N)add_argument_groupr   AddToParserr   r   r   r   r   r   r   r   r   r   r   )require_all_autoscaling_argsr   add_asymmetric_option_flagasymmetric_options_groupautoscaling_cpu_target_group$add_asymmetric_total_cpu_target_flag(add_asymmetric_disable_autoscaling_flagsadd_disable_downscaling_flagcapacity_parserautoscaling_config_group_parsercpu_target_options_group_parserautoscaling_limits_group_parser$autoscaling_node_limits_group_parser"autoscaling_pu_limits_group_parserasymmetric_options_group_parsers                  r   AddCapacityArgsForInstancer*  C  s(   : --D5-I/ 'o&0 %4$F$F %G %! " 	(::1 	; 	
 $ %k12tk12$-k12!tk12+k12$C$V$V+	 %W %! &88- 9  '
 ;<HH* ;<HH* &888 9  %
  +K23+K23  
)
<
< =  &
 &
.
2 	34+-99
) &#G+S 	:;%  r   c                    U R                  SSS9n[        SS9R                  U5        [        SS9R                  U5        U(       d  gUR                  SUS	9nUR                  US
S9n[	        SUS9R                  U5        [        SUS9R                  U5        [        US9R                  U5        UR                  SUSS9nUR                  SS9n[        US9R                  U5        [        US9R                  U5        UR                  SS9n	[        US9R                  U	5        [        US9R                  U	5        g)a  Parse the instance partition capacity arguments.

Args:
  parser: the argparse parser for the command.
  add_autoscaling_args: bool. If True, add the autoscaling arguments. This is
    required because these arguments are only available in the ALPHA track.
    This will be removed once the arguments are promoted to BETA and GA.
  autoscaling_args_hidden: bool. If True, mark the autoscaling arguments as
    hidden. This will be removed once the arguments are promoted to BETA and
    GA.
  require_all_autoscaling_args: bool. If True, a complete autoscaling config
    is required. This is required during instance partition creation, but not
    during instance partition update.
TFr  z+Number of nodes for the instance partition.)rc   z6Number of processing units for the instance partition.Nr  )r]   r   z)Target for high priority CPU utilization.r   r   r   r  r  r  r  r  )r  r   r  r   r   r   r   r   r   r   r   )
r   add_autoscaling_argsautoscaling_args_hiddenr  r#  r$  r%  r&  r'  r(  s
             r   #AddCapacityArgsForInstancePartitionr.    s   ( --D5-I/ :;GG CK  

 %4$F$F$ %G %!
 &88/: 9  " #$ K/0$ K/0$@AMM% %D$V$V+	 %W %! &88- 9  '
 ;<HH* ;<HH* &888 9  %
  +K23+K23r   c                 8    [         R                  " S[        U SS9$ )Nz--target-configz4Target Instance configuration to move the instances.r   r   r   s    r   TargetConfigr0    s!    	'A	
C Cr   c                 N    [         R                  " SU S[        R                  SS9$ )Nz--enable-drop-protectionenable_drop_protectionz5Enable database deletion protection on this database.)r_   destrj   r]   r   r   s    r   EnableDropProtectionr4    s(    	 #--B
 r   c                 v    [         R                  " SU S[        R                  S[        R                  " SS9SS9$ )Nz
--kms-keysKMS_KEYkms_keysr   r   zuUpdate KMS key references for this database. Users should always provide the full set of required KMS key references.)r_   r   rj   r3  r   r]   )r   r`   r   StoreOnceActionr   r   s    r   EnableUpdateKmsKeysr9  '  s<    	((!,B
 r   c                 X    [         R                  " SSU (       a	  [        SS9$ [        SS9$ )N	operationzOPERATION-IDzID of the operation)r   r\   r]   )r   r`   r5   rL   )r-   s    r   OperationIdr<  6  s5    	.6* 	
" " =O 	
" "r   c                 z    U (       a  [         R                  " S[        US9$ [         R                  " SU[        US9$ )Nsessionr[   	--sessionr^   )r   r`   rQ   ra   s      r   Sessionr@  >  s?    ==5DB B ==*	 r   c                     U R                  UUSS[        R                  " SS[        R                  " [        [        S.SS/S9S	9US
9$ )Nzlocation=LOCATION,type=TYPEstore:r   )r   r   r   r   r   )custom_delim_charr   element_type)r_   r   rj   r   r]   )r   r   r   r   r   )r   namerc   r_   s       r   ReplicaFlagrG  K  sb    			
+"**! (02	  
 
 r   c                     SR                  U R                  SS5      5      nU R                  S0 5      R                  SS5      (       a  US-  nU$ )z8Combines done and throttled fields into a single column.z{0}doneFmetadata	throttledz (throttled))formatget)resource	done_cells     r   _TransformOperationDonerP  ^  sI    ll8<<67)\\*b!%%k599I	r   c                 $   U R                  S5      nSnUR                  S5      nX2R                  S5      :X  d  X2R                  S5      :X  aD  UR                  S5      nUc  gUR                  S5      nUR                  S	5      nUc  Ub  US
-   $ U$ g)z:Combines endTime and progressPercent into a single column.rJ  7type.googleapis.com/google.spanner.admin.database.v1.{}@typeRestoreDatabaseMetadata OptimizeRestoredDatabaseMetadataprogressNendTimeprogressPercent%rM  rL  )rN  rJ  	base_typeop_typerV  progress_end_timeprogress_percents          r   _TransformOperationEndTimer_  f  s    \\*%(G)LL!'   ""#EFF||J'H Y/||$56 %5%A##r   c                     U R                  S5      nSnUR                  S5      nX2R                  S5      :X  d  X2R                  S5      :X  a  UR                  S5      $ UR                  S5      $ )z-Gets database ID depending on operation type.rJ  rR  rS  rT  rU  rF  r-   rZ  )rN  rJ  r[  r\  s       r   _TransformDatabaseIdra  {  sm    \\*%(G)LL!'  ! !$+/?/?
,0. %.<<	j	!!r   c                    U R                  SSS9nUR                  S[        SS9  UR                  S[        SS9  [	        SSS	S
9R                  U 5        [        SSSS
9R                  U 5        [        SSSSS9R                  U 5        SSSSSSSSSSS.
nUb  UR                  U5        U R                  SSS USS9  U R                  R                  S5        U R                  R                  S5        U R                  R                  S [        05        U R                  R                  S![        05        U R                  R                  S"[        05        g)#z.Add Common flags for the List operation group.Tr  z--instance-configzCThe ID of the instance configuration the operation is executing on.r[   r   z5The ID of the instance the operation is executing on.FzRFor database operations, the name of the database the operations are executing on.ra   zNFor backup operations, the name of the backup the operations are executing on.zdFor instance partition operations, the name of the instance partition the operation is executing on.r   zrReturns instance operations for the given instance. Note, type=INSTANCE does not work with --database or --backup.zIf only the instance is specified (--instance), returns all database operations associated with the databases in the instance. When a database is specified (--database), the command would return database operations for the given database.zIf only the instance is specified (--instance), returns all backup operations associated with backups in the instance. When a backup is specified (--backup), only the backup operations for the given backup are returned.a%  If only the instance is specified (--instance), returns all instance partition operations associated with instance partitions in the instance. When an instance partition is specified (--instance-partition), only the instance partition operations for the given instance partition are returned. zDatabase restore operations are returned for all databases in the given instance (--instance only) or only those associated with the given database (--database)zDatabase change quorum operations are returned for all databases in the given instance (--instance only) or only those associated with the given database (--database).zDatabase create operations are returned for all databases in the given instance (--instance only) or only those associated with the given database (--database)zDatabase update DDL operations are returned for all databases in the given instance (--instance only) or only those associated with the given database (--database)zoInstance configuration create operations are returned for the given instance configuration (--instance-config).zoInstance configuration update operations are returned for the given instance configuration (--instance-config).)
INSTANCEDATABASEBACKUPINSTANCE_PARTITIONDATABASE_RESTOREDATABASE_CHANGE_QUORUMDATABASE_CREATEDATABASE_UPDATE_DDLINSTANCE_CONFIG_CREATEINSTANCE_CONFIG_UPDATENz--typer  c                 "    U R                  5       $ r~   r   r   s    r   <lambda>#AddCommonListArgs.<locals>.<lambda>  
    QWWYr   z6(optional) List only the operations of the given type.r{   r   ru   r]   z
          table(
            name.basename():label=OPERATION_ID,
            metadata.statements.join(sep="
"),
            done():label=DONE,
            metadata.'@type'.split('.').slice(-1:).join()
          )
        rI  r-   endtime)	add_groupr   rG   r;   rd   r  rg   r   r  display_info	AddFormatAddCacheUpdaterAddTransformsrP  ra  r_  )r   additional_choicesmutex_grouptype_choicess       r   AddCommonListArgsr}    s     td ;+'P  
 !B  D )* +6+f*=)* +6+f*=5 KKE+<1
2
1
1
>>c4,l #*+C  E 	 !  	%%d+##V-D$EF##Z1E$FG##Y0J$KLr   c                     [        SSSS9R                  U 5        [        SSSS9R                  U 5        [        SSSSS9R                  U 5        [	        5       R                  U 5        g)zAdds common args to describe operations parsers shared across all stages.

The common arguments are Database, Backup and OperationId.

Args:
  parser: argparse.ArgumentParser to register arguments with.
FQFor a database operation, the name of the database the operation is executing on.ra   MFor a backup operation, the name of the backup the operation is executing on.fFor an instance partition operation, the name of the instance partition the operation is executing on.r   Nrd   r  rg   r   r<  r  s    r   AddCommonDescribeArgsr    st     '( )4F(;+	 K5 K-F#r   c                     [        SSSS9R                  U 5        [        SSSS9R                  U 5        [        SSSSS9R                  U 5        [	        5       R                  U 5        g)zAdds common args to cancel operations parsers shared across all stages.

The common arguments are Database, Backup and OperationId.

Args:
  parser: argparse.ArgumentParser to register arguments with.
Fr  ra   r  r  r   Nr  r  s    r   AddCommonCancelArgsr    st     '( )4F(;'( )4F(;5 K-F#r   c                  8    [         R                  " SS[        SS9$ )N--database-roleFz7Cloud Spanner database role to assume for this request.r^   )r   r`   rV   r   r   r   DatabaseRoler  ;  s    	%D	
 r   c                  .    [         R                  " SSSS9$ )N--sourceTzHFlag for specifying source database (e.g., PostgreSQL, MySQL, DynamoDB).r   rk   r   r   r   GetSpannerMigrationSourceFlagr  D  s    		
 r   c                  ,    [         R                  " SSS9$ )Nz--prefixz File prefix for generated files.r  rk   r   r   r   GetSpannerMigrationPrefixFlagr  O  s    	z(J	KKr   c                  ,    [         R                  " SSS9$ )Nz--source-profilez]Flag for specifying connection profile for source database (e.g., "file=<path>,format=dump").r  rk   r   r   r   $GetSpannerMigrationSourceProfileFlagr  S  s    	)
 r   c                  ,    [         R                  " SSS9$ )Nz--targetzbSpecifies the target database, defaults to Spanner (accepted values: Spanner) (default "Spanner").r  rk   r   r   r   GetSpannerMigrationTargetFlagr  ]  s    	<
 r   c                  .    [         R                  " SSSS9$ )Nz--target-profileTzXFlag for specifying connection profile for target database (e.g., "dialect=postgresql)".r   rk   r   r   r   $GetSpannerMigrationTargetProfileFlagr  g  s    	*	
 r   c                  .    [         R                  " SSSS9$ )Nr?  Tz7Specifies the file that you restore session state from.r   rk   r   r   r   GetSpannerMigrationSessionFlagr  r  s    	D
 r   c                  .    [         R                  " SSSS9$ )Nz--skip-foreign-keysrz   z<Skip creating foreign keys after data migration is complete.rj   r]   rk   r   r   r   &GetSpannerMigrationSkipForeignKeysFlagr  z  s    	I
 r   c                  ,    [         R                  " SSS9$ )Nz--write-limitzUNumber of parallel writers to Cloud Spanner during bulk data migrations (default 40).r  rk   r   r   r   !GetSpannerMigrationWriteLimitFlagr    s    	&
 r   c                  .    [         R                  " SSSS9$ )Nz	--dry-runrz   z_Flag for generating DDL and schema conversion report without creating a Cloud Spanner database.r  rk   r   r   r   GetSpannerMigrationDryRunFlagr    s    	,
- -r   c                  ,    [         R                  " SSS9$ )Nz--log-levelz=To configure the log level for the execution (INFO, VERBOSE).r  rk   r   r   r   GetSpannerMigrationLogLevelFlagr    s    	J
L Lr   c                  .    [         R                  " SSSS9$ )Nz--openrz   zEOpen the Spanner migration tool web interface in the default browser.r  rk   r   r   r   GetSpannerMigrationWebOpenFlagr    s    	x.
/ /r   c                  ,    [         R                  " SSS9$ )N--portzCThe port in which Spanner migration tool will run, defaults to 8080r  rk   r   r   r   GetSpannerMigrationWebPortFlagr    s    	
O
 r   c                  .    [         R                  " SSSS9$ )Nz--job-idTz(The job Id of an existing migration job.r   rk   r   r   r   GetSpannerMigrationJobIdFlagr    s    	4&P
 r   c                  ,    [         R                  " SSS9$ )Nz--data-shard-idszRelevant to sharded migrations. Optional comma separated list of data shard Ids, if nothing is specified, all shards are cleaned up.r  rk   r   r   r   #GetSpannerMigrationDataShardIdsFlagr    s    	Q
 r   c                  .    [         R                  " SSSS9$ )Nz--datastreamrz   zCleanup datastream resource(s).r  rk   r   r   r   0GetSpannerMigrationCleanupDatastreamResourceFlagr    s    	,
 r   c                  .    [         R                  " SSSS9$ )Nz
--dataflowrz   zCleanup dataflow resource(s).r  rk   r   r   r   .GetSpannerMigrationCleanupDataflowResourceFlagr    s    	<.M
 r   c                  .    [         R                  " SSSS9$ )Nz	--pub-subrz   zCleanup pubsub resource(s).r  rk   r   r   r   ,GetSpannerMigrationCleanupPubsubResourceFlagr    s    	,-J
 r   c                  .    [         R                  " SSSS9$ )Nz--monitoringrz   z Cleanup monitoring dashboard(s).r  rk   r   r   r   0GetSpannerMigrationCleanupMonitoringResourceFlagr    s    	-
 r   c                     SnS H   nU R                  U5      (       d  M  US-  nM"     US:  a  [        R                  " SS5      eg )Nr   )r   r-   rf   r   z.--database or --backup or --instance-partitionzAMust specify only --database or --backup or --instance-partition.)IsSpecifiedc_exceptionsInvalidArgumentException)r   exlusive_flag_countflags      r   #CheckExclusiveLROFlagsUnderInstancer    sV    :dQ ; 1

/
/8K  r   c                  ,    [         R                  " SSS9$ )Nz	--projectzIThe project in which the migration job and its resources will be created.r  rk   r   r   r   GetSpannerMigrationProjectFlagr    s    	
 r   c                  ,    [         R                  " SSS9$ )Nz--dataflow-templateziThe google cloud storage path of the minimal downtime migration template to use to run the migration job.r  rk   r   r   r   'GetSpannerMigrationDataflowTemplateFlagr    s    	7
 r   c                 .    [         R                  " U 5      $ r~   )r
   ParseSplitPointsr   s    r   GetSplitPointsr    s    		+	+D	11r   c                 ,    [         R                  " SXS9$ )Nz--table-namer   rk   reqrc   s     r   	TableNamer        	s
/ /r   c                 ,    [         R                  " SXS9$ )Nz--source-urir   rk   r  s     r   	SourceUrir    r  r   c                 ,    [         R                  " SXS9$ )Nz--source-formatr   rk   r  s     r   SourceFormatr    s    	#
2 2r   c                 ,    [         R                  " SXS9$ )Nz--schema-urir   rk   r  s     r   	SchemaUrir    r  r   c                 ,    [         R                  " SXS9$ )Nz--csv-field-delimiterr   rk   r  s     r   CsvFieldDelimiterr    s    	
8 8r   c                 ,    [         R                  " SXS9$ )Nz--csv-line-delimiterr   rk   r  s     r   CsvLineDelimiterr    s    	s
7 7r   c                  .    [         R                  " SSSS9$ )Nz--host	localhostz(Host on which Spanner server is located.r{   r]   rk   r   r   r   GetSpannerCliHostFlagr    s    	5
 r   c            	      V    [         R                  " SS [        R                  " SSS9SS9$ )Nr  r   i  )lower_boundupper_boundz3Port number that gcloud uses to connect to Spanner.)r{   r   r]   )r   r`   r   
BoundedIntr   r   r   GetSpannerCliPortFlagr  $  s,    	!!aUC@	
 r   c                  8    [         R                  " S[        SSS9$ )Nz--idle-transaction-timeoutr6   zDSet the idle transaction timeout. The default timeout is 60 seconds.)r   r{   r]   r   r   r   r   'GetSpannerCliIdleTransactionTimeoutFlagr  -  s    	"
P
 r   c                  .    [         R                  " SSSS9$ )Nz--skip-column-namesrz   z#Do not show column names in output.r  rk   r   r   r    GetSpannerCliSkipColumnNamesFlagr  8  s    	0
 r   c                  .    [         R                  " SSSS9$ )Nz--skip-system-commandrz   zDo not allow system command.r  rk   r   r   r   "GetSpannerCliSkipSystemCommandFlagr  @  s    	)
 r   c                  .    [         R                  " SSSS9$ )Nz--promptzspanner-cli> z'Set the prompt to the specified format.r  rk   r   r   r   GetSpannerCliPromptFlagr  H  s    	4
 r   c                  .    [         R                  " SSSS9$ )Nz--delimiterr   zSet the statement delimiter.r  rk   r   r   r   GetSpannerCliDelimiterFlagr  P  s    	)
 r   c                  .    [         R                  " SSSS9$ )Nz--tablerz   zShow output in table format.r  rk   r   r   r   GetSpannerCliTableFlagr  X  s    	)
 r   c                  .    [         R                  " SSSS9$ )Nz--htmlrz   zShow output in HTML format.r  rk   r   r   r   GetSpannerCliHtmlFlagr  `  s    	(
 r   c                  .    [         R                  " SSSS9$ )Nz--xmlrz   zShow output in XML format.r  rk   r   r   r   GetSpannerCliXmlFlagr  h  s    	'
 r   c                  .    [         R                  " SSSS9$ )Nz	--executer  z%Execute the statement and then exits.r  rk   r   r   r   GetSpannerCliExecuteFlagr  p  s    	2
 r   c                  .    [         R                  " SSSS9$ )Nr  r  z/Database role user used to access the database.r  rk   r   r   r   GetSpannerCliDatabaseRoleFlagr  x  s    	<
 r   c                  .    [         R                  " SSSS9$ )Nr  r  z1Execute the statement from a file and then exits.r  rk   r   r   r   GetSpannerCliSourceFlagr    s    	>
 r   c                  .    [         R                  " SSSS9$ )Nz--teer  z,Append a copy of the output to a named file.r  rk   r   r   r   GetSpannerCliTeeFlagr    s    	9
 r   c                  .    [         R                  " SSSS9$ )Nz--init-commandr  z'SQL statement to execute after startup.r  rk   r   r   r   GetSpannerCliInitCommandFlagr    s    	4
 r   c                  .    [         R                  " SSSS9$ )Nz--init-command-addr  z2Additional SQL statement to execute after startup.r  rk   r   r   r   GetSpannerCliInitCommandAddFlagr    s    	?
 r   c                  8    [         R                  " SSS SS/SS9$ )Nz--system-commandONc                 "    U R                  5       $ r~   rn  ro  s    r   rp  0GetSpannerCliSystemCommandFlag.<locals>.<lambda>  rr  r   OFFz.Enable or disable system commands. Default: ONrs  rk   r   r   r   GetSpannerCliSystemCommandFlagr    s&    	Um;
 r   )TTzCloud Spanner database ID.)TTzCloud Spanner backup ID.)r  )TzInstance configuration defines the geographic placement and replication of the databases in that instance. Available configurations can be found by running "gcloud spanner instance-configs list")TzDescription of the instance.)TzCloud Spanner instance ID.)TTTz$Cloud Spanner instance partition ID.)Fz!Number of nodes for the instance.)r   )Fz,Number of processing units for the instance.)F)FF)FT)FFTzCloud Spanner SSD Cache ID.)NFF)NFz>The default backup schedule type that is used in the instance.)FFFFFF)TFT)T)TTzCloud Spanner session IDr~   )zCloud Spanner table name)z#URI of the file with data to import)zTFormat of the file with data to import.Supported formats: csv or mysqldump or pgdump)z1URI of the file with schema of the data to import)zField delimiter for CSV files.)zLine delimiter for CSV files.)__doc__argcomplete.completersr   cloudsdk.google.protobufr   googlecloudsdk.api_lib.spannerr   googlecloudsdk.callioper   r   r   r  "googlecloudsdk.command_lib.spannerr	   r
   googlecloudsdk.command_lib.utilr   googlecloudsdk.core.utilr   ListCommandCompleterr   r*   r0   r5   r;   rB   rG   rL   rQ   rV   rd   rg   rn   rq   rs   rx   r|   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r  r  r
  r  r  r*  r.  r0  r4  r9  r<  r@  rG  rP  r_  ra  r}  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r   r   r   <module>r     s;   A 1 3 4 / ( > 9 @ 6 *j55 j== 
77 !@!@ 
77 !@!@ j== 88 z>> J;; QM	$ 	""FM 	/	:( H

	
 FK'T
 	&	& 
 	I
  %"!&).-2!&v<v !!%	V4rC"
&*
"kM\!$H$BL-L/	2/
/
2/
8
7r   