
    {o                     L   S r SSK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Qr\R&                  " SS9rSrSrSrS rS rS r                 SS jrSS jrS rS rS rS r                   S S jr!S r"S r#S r$g)!zSpanner instance API helper.    N)
list_pager)timestamp_pb2)response_util)apis)iam_util)
properties)	resources)
console_io)zroles/spanner.adminzroles/spanner.databaseAdminzroles/spanner.databaseReaderzroles/spanner.databaseUserzroles/spanner.viewer   )secondsspannerv1autoscalingConfigc                    SU;  a+  SU;  a%  SU;  a  SU;  a  SU;  a  SU;  a  SU;  a  SU;  a  g	U R                  U R                  5       S
9nSU;   a  US   UR                  l        SU;   a  US   UR                  l        SU;   a  US   UR                  l        SU;   a  US   UR                  l        SU;   a
  US   Ul        SU;   a
  US   Ul        SU;   a
  US   Ul	        SU;   a
  US   Ul
        U$ )zReturns AutoscalingConfigOverrides object if any override is found in the parsed command-line flag key-value pairs, otherwise returns None.	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_autoscalingN)autoscalingLimits)AutoscalingConfigOverridesAutoscalingLimitsr   minNodesmaxNodesminProcessingUnitsmaxProcessingUnits2autoscalingTargetHighPriorityCpuUtilizationPercent+autoscalingTargetTotalCpuUtilizationPercent!disableHighPriorityCpuAutoscalingdisableTotalCpuAutoscaling)msgsasymmetric_autoscaling_optionobjs      /lib/googlecloudsdk/api_lib/spanner/instances.pyMaybeGetAutoscalingOverrider(   .   sc    66
:
:
 (E
E
 (E
E
$,I
I
$A
A
1*+
)1N
N''..0 	( 	# 11%B;%OC"11%B;%OC"<</L0C, <</L0C,  #@@%&@A : 88%&89 3 -0MM%&MN ) %(EE%&EF " 
*    c                    Uc  Uc  gUc  U$ Uc  U$ UnUR                   Gb  UR                   c  U R                  5       Ul         UR                   R                  b%  UR                   R                  UR                   l        UR                   R                  b%  UR                   R                  UR                   l        UR                   R                  b%  UR                   R                  UR                   l        UR                   R
                  b%  UR                   R
                  UR                   l        UR                   b  UR                  Ul        UR                  b  UR                  Ul        UR                  b)  UR                  Ul        UR                  (       a  SUl        UR                  b)  UR                  Ul	        UR                  (       a  SUl        U$ )a,  Merges two AutoscalingConfigOverrides objects.

Args:
  msgs: The messages module for the Spanner API.
  existing_overrides: The existing AutoscalingConfigOverrides object.
  new_overrides: The new AutoscalingConfigOverrides object to merge.

Returns:
  The merged AutoscalingConfigOverrides object.
N)
r   r   r   r   r   r   r    r!   r"   r#   )r$   existing_overridesnew_overridesresults       r'   MergeAutoscalingConfigOverrider.   `   s    M$9 &$$0'!%!7!7!9f&&//;

)
)
2
2 ' &&//;

)
)
2
2 ' &&99E

)
)
<
< 1 &&99E

)
)
<
< 1 FF 	HH = >>JAA 6 44@77 , //BFf?--9(5(P(PF%((;?f8	-r)   c                    0 nUR                   =n(       a+  UR                   H  nUXFR                  R                  '   M     U HO  nUR                  R                  nX;   a-  XH   n[	        XR
                  UR
                  5      XH   l        MK  XtU'   MQ     UR                   R                  R                  5         UR                  5        H(  n	UR                   R                  R                  U	5        M*     g)zPatch asymmetric autoscaling options.

Args:
  msgs: API messages module.
  instance_obj: The instance object to patch.
  current_instance: The current instance object.
  asym_options_patch: A list of AsymmetricAutoscalingOption objects to patch.
N)	r   asymmetricAutoscalingOptionsreplicaSelectionlocationr.   	overridesclearvaluesappend)
r$   instance_objcurrent_instanceasym_options_patchoption_by_locationconfigexisting_optionpatch_optionr2   opts
             r'   !PatchAsymmetricAutoscalingOptionsr?      s     111V1!>>
 99BBC ?
 )l,,55H%*4o/M
))<+A+A0",
 &2" )   ==CCE&&(c""??FFsK )r)   c                 ~   [         R                  " [        [        5      n[         R                  " [        [        5      n[
        R                  R                  US[        R                  R                  R                  R                  0SS9n[
        R                  R                  S[        R                  R                  R                  R                  S9nUR                  UR                  5       US9nU(       a  UUl        OpU(       a  UUl        OaU(       d%  U(       d  U(       d  U(       d  U	c  U
c
  U(       d  Ub5  UR%                  UR'                  UUUUS9UR)                  U	U
US9US	9Ul        Ub  UUl        Ub  UR/                  US
9Ul        Ub  UUl        U(       a>  UR5                  5       (       a)  UR                  5       S-   UR5                  5       -   Ul        Ub   UR                  R9                  U5      Ul        Ub   UR                  R=                  U5      Ul        Ubm  UR                  RA                  [C        URE                  5       5       VVs/ s H*  u  nnUR                  R@                  RG                  UUS9PM,     snnS9Ul$        UbV  U HP  nUR*                  RJ                  RM                  URO                  [Q        UU5      URS                  US   S9S95        MR     URU                  UR                  5       URW                  U US9S9nURX                  R                  U5      $ s  snnf )a=  Create a new instance.

Args:
  instance: The instance to create.
  config: The instance config to use.
  description: The instance description.
  nodes: The number of nodes to use.
  processing_units: The number of processing units to use.
  autoscaling_min_nodes: The minimum number of nodes to use.
  autoscaling_max_nodes: The maximum number of nodes to use.
  autoscaling_min_processing_units: The minimum number of processing units to
    use.
  autoscaling_max_processing_units: The maximum number of processing units to
    use.
  autoscaling_high_priority_cpu_target: The high priority CPU target to use.
    Zero is a valid value.
  autoscaling_total_cpu_target: The total CPU target to use. Zero is a valid
    value.
  autoscaling_storage_target: The storage target to use.
  asymmetric_autoscaling_options: A list of ordered dict of key-value pairs
    representing the asymmetric autoscaling options.
  disable_downscaling: Whether to disable downscaling for the instance.
  instance_type: The instance type to use.
  expire_behavior: The expire behavior to use.
  default_storage_type: The default storage type to use.
  ssd_cache: The ssd cache to use.
  edition: The edition to use.
  default_backup_schedule_type: The type of default backup schedule to use.
  tags: The parsed tags value.

Returns:
  The created instance.

projectsId spanner.projects.instanceConfigsparams
collectionspanner.projectsrA   )r;   displayNamer   r   r   r   !highPriorityCpuUtilizationPercenttotalCpuUtilizationPercentstorageUtilizationPercentr   autoscalingTargetsdisableDownscalingexpireBehavior/ssdCaches/)keyvalue)additionalPropertiesr2   r2   )r3   r1   )
instanceIdinstance)parentcreateInstanceRequest)-r   GetClientInstance_SPANNER_API_NAME_SPANNER_API_VERSIONGetMessagesModuler	   REGISTRYParser   VALUEScoreproject	GetOrFailCreateInstanceRelativeName	nodeCountprocessingUnitsAutoscalingConfigr   AutoscalingTargetsr   instanceTypeFreeInstanceMetadatafreeInstanceMetadatadefaultStorageTypestripssdCacheEditionValueValuesEnumedition(DefaultBackupScheduleTypeValueValuesEnumdefaultBackupScheduleType	TagsValuesorteditemsAdditionalPropertytagsr0   r6   AsymmetricAutoscalingOptionr(   InstanceReplicaSelection%SpannerProjectsInstancesCreateRequestCreateInstanceRequestprojects_instances)rY   r;   descriptionnodesprocessing_unitsautoscaling_min_nodesautoscaling_max_nodes autoscaling_min_processing_units autoscaling_max_processing_units$autoscaling_high_priority_cpu_targetautoscaling_total_cpu_targetautoscaling_storage_targetasymmetric_autoscaling_optionsdisable_downscalinginstance_typeexpire_behaviordefault_storage_type	ssd_cachert   default_backup_schedule_typer{   clientr$   
config_refproject_refr7   rT   rU   asym_optionreqs                                 r'   rf   rf      s=   p !!"35IJ&			 13G	H$!!''J--22::DDE3 ( *
 ""))Z%6%6%;%;%C%C%M%M * + $$&K  , "L#3L 		)	)	-	9	%	1	#		(%)%;%;00**??	 1 
  22.R'C&@ 3 

 / &< &L"  -L (,(A(A& )B )L% %&:L#9??$$!M1IOO4EE  ==??HL!->>(	
 *
 
// %TZZ\2
2
U MM##663e6L2
 0 L $/5$$AAHH

*
*3D+F#<<&z2  =   +  6 	22%%' 66 7  	3 	# 
	"	"	)	)#	../
s   1L9
c                 6   [         R                  " [        [        5      n[         R                  " [        [        5      n[
        R                  Ul        UR                  U R                  5       UR                  UUS9S9nUR                  R                  U5      $ )zDSaves the given policy on the instance, overwriting whatever exists.)policy
updateMask)resourcesetIamPolicyRequest)r   r\   r]   r^   r_   r   !MAX_LIBRARY_IAM_SUPPORTED_VERSIONversion+SpannerProjectsInstancesSetIamPolicyRequestrh   SetIamPolicyRequestr   SetIamPolicy)instance_refr   
field_maskr   r$   r   s         r'   	SetPolicyr   _  s    !!"35IJ&			 13G	H$==&.88((*22&>H 3 J 	9 	K# 
	"	"	/	/	44r)   c           	      @   [         R                  " [        [        5      n[         R                  " [        [        5      nUR                  U R                  5       UR                  UR                  [        R                  S9S9S9nUR                  R                  U5      $ )z#Gets the IAM policy on an instance.)requestedPolicyVersion)options)r   getIamPolicyRequest)r   r\   r]   r^   r_   +SpannerProjectsInstancesGetIamPolicyRequestrh   GetIamPolicyRequestGetPolicyOptionsr   r   r   GetIamPolicy)r   r   r$   r   s       r'   r   r   k  s    !!"35IJ&			 13G	H$88((*22''88 ( : 3 ; 	9 	<# 
	"	"	/	/	44r)   c                    [         R                  " [        [        5      n[         R                  " [        [        5      n[
        R                  R                  U S[        R                  R                  R                  R                  0SS9nUR                  UR                  5       S9nUR                  R!                  U5      $ )zDelete an instance.rA   spanner.projects.instancesrC   name)r   r\   r]   r^   r_   r	   r`   ra   r   rb   rc   rd   re   %SpannerProjectsInstancesDeleteRequestrh   r   DeleterY   r   r$   refr   s        r'   r   r   x  s    !!"35IJ&			 13G	H$  J--22::DDE- 	! 	/# 	228H8H8J2K#		"	"	)	)#	..r)   c                    [         R                  " [        [        5      n[         R                  " [        [        5      n[
        R                  R                  U S[        R                  R                  R                  R                  0SS9nUR                  UR                  5       S9nUR                  R!                  U5      $ )zGet an instance by name.rA   r   rC   r   )r   r\   r]   r^   r_   r	   r`   ra   r   rb   rc   rd   re   "SpannerProjectsInstancesGetRequestrh   r   Getr   s        r'   r   r     s    !!"35IJ&			 13G	H$  J--22::DDE- 	! 	/# 	//S5E5E5G/H#		"	"	&	&s	++r)   c                  \   [         R                  " [        [        5      n [         R                  " [        [        5      n[
        R                  R                  S[        R                  R                  R                  R                  S9n[        R                  " 5       nUR                  [         R                   R#                  5       [$        -   5        UR'                  UR)                  5       UR+                  5       S9n[,        R.                  " U R0                  USS[2        R4                  S9$ )zList instances in the project.rF   rG   )rZ   instanceDeadline	instancespageSize)fieldbatch_size_attributeget_field_func)r   r\   r]   r^   r_   r	   r`   rf   r   rb   rc   rd   re   r   	TimestampFromDatetimedatetimeutcnowUNREACHABLE_INSTANCE_TIMEOUT#SpannerProjectsInstancesListRequestrh   ToJsonStringr   YieldFromListr   r   GetFieldAndLogUnreachable)r   r$   r   tp_protor   s        r'   Listr     s    !!"35IJ&			 13G	H$""))Z%6%6%;%;%C%C%M%M * O+$$&(
 #??A00%%',,. 	1 	0# 
	!	!	%"<<
> >r)   c           
      
   / nUb  UR                  S5        Ub  UR                  S5        Ub  UR                  S5        U(       a  U(       d  U(       a*  U(       a#  Uc  U	b  U
(       a  UR                  [        5        OU(       a  UR                  S5        U(       a  UR                  S5        U(       a  UR                  S5        U(       a  UR                  S5        Ub  UR                  S5        U	b  UR                  S	5        U
(       a  UR                  S
5        Ub  UR                  S5        [        R                  " [        [
        5      n[        R                  " [        [
        5      nUR                  US9nU(       a  UUl        OpU(       a  UUl	        OaU(       d%  U(       d  U(       d  U(       d  Uc  U	c
  U
(       d  Ub5  UR                  UR                  UUUUS9UR                  UU	U
S9US9Ul        Ub  [        U;  a  UR                  S5        [        U 5      n/ nU H<  nUR                  UR                  UR!                  US   S9[#        UU5      S95        M>     UR                  c  UR                  5       Ul        [%        UUUU5        Ub  [        U;  a  UR                  S5        [        U 5      n['        U5      nUR                  c  UR                  5       Ul        / UR                  l        UR                  R(                   HD  nUR*                  R,                  U;  d  M  UR                  R(                  R                  U5        MF     Ub  UR                  S5        UUl        Ub%  UR                  S5        UR1                  US9Ul        UbZ  UR                  S5        SnUR5                  5       (       a+  [        U 5      nUR6                  S-   UR5                  5       -   nUUl        Ub1  UR                  S5        UR                  R;                  U5      Ul        Ub1  UR                  S5        UR                  R?                  U5      Ul         [B        RD                  RG                  U S[H        RJ                  RL                  RN                  RP                  0SS9nURS                  URU                  5       URW                  SRY                  U5      US 9S!9nURZ                  R]                  U5      $ )"zUpdate an instance.rH   znodeCount,autoscalingConfigz!processingUnits,autoscalingConfigz,autoscalingConfig.autoscalingLimits.minNodesz,autoscalingConfig.autoscalingLimits.maxNodesz6autoscalingConfig.autoscalingLimits.minProcessingUnitsz6autoscalingConfig.autoscalingLimits.maxProcessingUnitszFautoscalingConfig.autoscalingTargets.highPriorityCpuUtilizationPercentz?autoscalingConfig.autoscalingTargets.totalCpuUtilizationPercentz>autoscalingConfig.autoscalingTargets.storageUtilizationPercentz$autoscalingConfig.disableDownscaling)rH   rI   rJ   rN   z.autoscalingConfig.asymmetricAutoscalingOptionsr2   rW   )r1   r3   rm   z#freeInstanceMetadata.expireBehaviorrQ   rr    rS   rt   rv   rA   r   rC   ,)	fieldMaskrY   )r   updateInstanceRequest)/r6   _FIELD_MASK_AUTOSCALING_CONFIGr   r\   r]   r^   r_   rg   rj   ri   rk   r   rl   r   r   r|   r}   r(   r?   setr0   r1   r2   rm   rn   ro   rq   r;   rr   rs   rt   ru   rv   r	   r`   ra   r   rb   rc   rd   re   $SpannerProjectsInstancesPatchRequestrh   UpdateInstanceRequestjoinr   Patch)rY   r   r   r   r   r   r   r   r   r   r   r   r   $clear_asymmetric_autoscaling_optionsr   r   ssd_cache_idrt   r   fieldsr   r$   r7   r8   r9   r   locations_to_remover   instance_resr   r   s                                  r'   r   r     s   , &
MM- 

MM/0!
MM56 !6
*/O
.
:
&
2'
MM01mmBCmmBC'mmLM'mmLM+7mm
R $/mm
K "mm
J &mm:;!!"35IJ&			 13G	H$;7,#3L "L		)	)	-	9	%	1	#		(%)%;%;00**??	 1 
  22.R'C&@ 3 

 / &< &L" $/%V3mmDE8} 6

*
*#<<&z2  =   4D+F	 +  6 %%-'+'='='?l$%l,.@ *5%V3mmDE8}BC%%-'+'='='?l$BDL""? 
	+	+	H	H 			%	%	.	.6I	I&&CCJJ	
 
I 
MM.! -L 
MM78(,(A(A& )B )(L% 
MM*I]l%%58J8J8LLi%L
MM)==??HL!-
MM-.>>(	
 * 	  J--22::DDE- 	! 	/# 	11 66HHV$| 7 = 	2 	># 
	"	"	(	(	--r)   c                 .   [         R                  " [        [        5      n[         R                  " [        [        5      n[        U 5      nUR                  UR                  S9nUR                  R                  U5      nU(       a?  / nUR                   H+  nUR                  UR                  UR                  S.5        M-     U$ [        5       n	UR                   H  nU	R                  UR                  5        M      U	 Vs/ s H  nSU0PM	     nnU$ s  snf )z,Get all the replica regions for an instance.r   )r2   typer2   )r   r\   r]   r^   r_   r   (SpannerProjectsInstanceConfigsGetRequestr;   projects_instanceConfigsreplicasr6   r2   r   r   add)
rY   verbose_flagr   r$   r   
config_req
config_rescommand_outputitem
region_sets
             r'   GetLocationsr   L  s    !!"35IJ&			 13G	H$X,<< =  *..22:>*N##		JK $ 
	 J##nnT]]# $5?@ZTz4(ZN@	 As    Dc                 |   [         R                  " [        [        5      n[         R                  " [        [        5      n[
        R                  R                  US[        R                  R                  R                  R                  0SS9n[
        R                  R                  U S[        R                  R                  R                  R                  0SS9n[        R                  " SR                  U [!        U 5      U5      SSS9  S	UR#                  5       0nUb}  / US'   U Hr  nUS   R%                  S5      n	0 n
/ U
S'   U	 H  nU
S   R'                  U5        M     UR(                  " S0 U
D6nUS   R'                  UR+                  US   US95        Mt     UR-                  UR.                  " S0 UD6UR#                  5       S9nUR0                  R3                  U5      R4                  n[6        R8                  " SU5      R;                  S5      n[=        SR                  UR#                  5       X5      5        g
)a)  Moves an instance from one instance-config to another.

Args:
    instance: Instance to move.
    target_instance_config: The target instance configuration to move the
      instance.
    target_database_move_configs: Configurations for databases in the
      destination instance config.

The configs can be google-managed or user-managed.
Ex: gcloud spanner instances move instance-to-move
--target-config=instance-config-to-move-to

Above example will move the instance(instance-to-move) to the following
instance config(instance-config-to-move-to).
rA   rB   rC   r   a:  You are about to move instance {0} from {1} to {2}. This is a long-running operation with potential service implications:


	* Increased latencies: Read and write operations may experience delays.

	* Elevated abort rate: Transactions may have a higher chance of failing.

	* Spiked CPU utilization: System resources will be strained, impacting performance.

	* Additional costs: Instance moves incur extra charges, as described in the documentation.

	* Backups: It is important that you copy your backups before moving your instance. Backups need to be deleted from the Instance before the move. You cannot create a backup while the move is in progress.

Before proceeding, and for detailed information and best practices, refer to the documentation at https://cloud.google.com/spanner/docs/move-instance#move-prerequisites.TzDo you want to proceed)messagecancel_on_noprompt_stringtargetConfigNtargetDatabaseMoveConfigszkms-key-namesr   kmsKeyNameszdatabase-id)
databaseIdencryptionConfig)moveInstanceRequestr   z.*/operations/(.*)   zj
Instance move started for {0}

Track progress with: gcloud spanner operations describe {1} --instance={2} )r   r\   r]   r^   r_   r	   r`   ra   r   rb   rc   rd   re   r
   PromptContinueformatGetInstanceConfigrh   splitr6   InstanceEncryptionConfigDatabaseMoveConfig#SpannerProjectsInstancesMoveRequestMoveInstanceRequestr   Mover   researchgroupprint)rY   target_instance_configtarget_database_move_configsr   r$   r   r   req_argstarget_database_move_configkms_key_namesencryption_config_argskms_key_nameencryption_configmove_reqmove_operation_idoperation_ids                   r'   r   r   `  s?   " !!"35IJ&			 13G	H$!!''J--22::DDE3 ( *
 ##))J--22::DDE- * ,
 U 6)(35K ,+. j5578(!-,.H()'C#1/BHHMm!.0]+',}-44\B (77 " *+22

!
!4]C0 "  (D 5522>X>$$& 6 ( //44X>CC/1BCII!L,%%+V

#
#
%|&r)   c                    [         R                  " [        [        5      n[         R                  " [        [        5      n[
        R                  R                  U S[        R                  R                  R                  R                  0SS9nUR                  UR                  5       SS9nUR                  R!                  U5      n["        R$                  " SUR&                  5      R)                  S5      nU$ )z/Get the instance config of the passed instance.rA   r   rC   r;   )r   r   z.*/instanceConfigs/(.*)r   )r   r\   r]   r^   r_   r	   r`   ra   r   rb   rc   rd   re   r   rh   r   r   r   r   r;   r   )rY   r   r$   r   instance_reqinstance_infoinstance_configs          r'   r   r     s    !!"35IJ&			 13G	H$##))J--22::DDE- * ,
 88$$&( 9 , ++//=-II!5!5	E!H  
r)   )NNNNNNNNNNNNNNNNN)N)NNNNNNNNNNNNNNNNNN)%__doc__r   r   apitools.base.pyr   cloudsdk.google.protobufr   googlecloudsdk.api_lib.spannerr   googlecloudsdk.api_lib.utilr   googlecloudsdk.command_lib.iamr   googlecloudsdk.corer   r	   googlecloudsdk.core.consoler
   KNOWN_ROLES	timedeltar   r]   r^   r   r(   r.   r?   rf   r   r   r   r   r   r   r   r   r   r   r)   r'   <module>r     s   #  	 ' 2 8 , 3 * ) 2  (11"=   !4 .dET LP %)%))-!%##'!%	+O/d	5
5	/	,>, 
%)%))-!%##')-!%'e.P(Rjr)   