
    $                         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\R                  5      rS	 rS
 rS rS rS rS rS rS rS rS rS rS rS rS rS rS rS rS rS rS r S r!S r"g) z1Utility for updating Memorystore Redis instances.    )encoding)util)
exceptions)
console_io)filterc                       \ rS rSrSrSrg)NoFieldsSpecified   zDError for calling update command with no args that represent fields. N)__name__
__module____qualname____firstlineno____doc____static_attributes__r       =lib/googlecloudsdk/command_lib/redis/instances_update_util.pyr	   r	      s    Lr   r	   c                      S/n[        XU5      $ )z7Checks if fields to update are registered for GA track.maintenance_versionCheckFieldsSpecifiedCommonunused_instance_refargspatch_requestadditional_update_argss       r   CheckFieldsSpecifiedGAr            
$D9O	PPr   c                      S/n[        XU5      $ )z9Checks if fields to update are registered for BETA track.r   r   r   s       r   CheckFieldsSpecifiedBetar    %   r   r   c                      S/n[        XU5      $ )z:Checks if fields to update are registered for ALPHA track.r   r   r   s       r   CheckFieldsSpecifiedAlphar"   -   r   r   c                 r    / SQU-   n[        [        U R                  U5      5      (       a  U$ [        S5      e)z;Checks fields to update that are registered for all tracks.)clear_labelsdisplay_nameenable_authremove_labelsremove_redis_configsizeupdate_labelsupdate_redis_configread_replicas_modesecondary_ip_rangereplica_countpersistence_moderdb_snapshot_periodrdb_snapshot_start_timemaintenance_window_daymaintenance_window_hourmaintenance_window_anyz<Must specify at least one valid instance parameter to update)listr   IsSpecifiedr	   )r   r   r   update_argss       r   r   r   5   sE    $ %+& 
&!!;
/00D	F Fr   c                     UR                   nU(       a$  UR                  U 5      S:X  a  US-   U -   Ul         U$ Xl         U$ )Nr   ,)
updateMaskcount)fieldr   update_masks      r   AddFieldToUpdateMaskr>   P   sK    ((+1$!,s!2U!:m 
  %	r   c                     UR                  S5      (       a'  UR                  UR                  l        [	        SU5      nU$ )Nr%   )r6   r%   instancedisplayNamer>   r   r   r   s      r   AddDisplayNamerC   Z   s9    	n%%)-):):M&(GM	r   c                 D   [         R                  " U 5      nSnUR                  UR                  R                  R
                  :X  a  US-  nO9UR                  UR                  R                  R                  :X  a  US-  nOUS-  nUS-  n[        R                  " USSS9  g	)
z7Adds prompt that warns about a destructive size update.z#Change to instance size requested. zzScaling a Basic Tier instance may result in data loss, and the instance will briefly be unavailable during the operation. zScaling a Standard Tier instance may result in the loss of unreplicated data, and the instance will be briefly unavailable during failover. zoScaling a redis instance may result in data loss, and the instance will be briefly unavailable during scaling. zlFor more information please take a look at https://cloud.google.com/memorystore/docs/redis/scaling-instancesz#Do you want to proceed with update?T)messageprompt_stringcancel_on_noN)	r   GetMessagesForResourcetierInstanceTierValueValuesEnumBASICSTANDARD_HAr   PromptContinue)instance_refr@   messagesrE   s       r   _WarnForDestructiveSizeUpdaterQ   a   s    ((6(1']]h'';;AAA  G }}))==III 0 1G
  H IG	JK' 9r   c                     UR                  S5      (       a<  [        XR                  5        UR                  UR                  l        [        SU5      nU$ )zDPython hook to add size update to the redis instance update request.r)   memory_size_gb)r6   rQ   r@   r)   memorySizeGbr>   )rO   r   r   s      r   AddSizerU   {   sF    	f!,0F0FG*.))M'()9=IM	r   c                 $   [        UR                  SS 5      (       d  U$ UR                  S5      (       a[  [        R                  " UR                  R
                  5      nUR                   H  nUR                  US 5        M     [        XU5      nU$ )NredisConfigsr(   )	getattrr@   r6   r   MessageToDictrW   r(   popAddNewRedisConfigs)rO   r   r   config_dictremoved_keys        r   RemoveRedisConfigsr^      s{    	''	>	>	+,,(()?)?)L)LMK//ook4( 0&|-PM	r   c                    UR                  S5      (       ao  0 n[        UR                  SS 5      (       a*  [        R                  " UR                  R
                  5      nUR                  UR                  5        [        XU5      nU$ )Nr+   rW   )	r6   rX   r@   r   rY   rW   updater+   r[   )rO   r   r   r\   s       r   UpdateRedisConfigsra      sp    	+,,K}%%~t<<**=+A+A+N+NOkt//0&|-PM	r   c                     [         R                  " U 5      n[         R                  " UU5      nXBR                  l        [        SU5      nU$ )Nredis_configs)r   rH   PackageInstanceRedisConfigr@   rW   r>   )rO   redis_configs_dictr   rP   new_redis_configss        r   r[   r[      sH    ((6(556H6>@(9%&F-	r   c                     UR                  S5      (       a,  [        R                  " UR                  5        [	        SU5      nU$ )z;Hook to add auth_enabled to the update mask of the request.r&   auth_enabled)r6   r   WarnOnAuthEnabledr&   r>   rB   s      r   UpdateAuthEnabledrj      s9    	m$$4++,(GM	r   c                 J    UR                  S5      (       a  [        SU5      nU$ )zHHook to update maintenance window day to the update mask of the request.r2   maintenance_policyr6   r>   rB   s      r   UpdateMaintenanceWindowDayrn      s'    	.//()=}MM	r   c                 J    UR                  S5      (       a  [        SU5      nU$ )zIHook to update maintenance window hour to the update mask of the request.r3   rl   rm   rB   s      r   UpdateMaintenanceWindowHourrp      '    	/00()=}MM	r   c                 l    UR                  S5      (       a  SUR                  l        [        SU5      nU$ )z"Hook to remove maintenance window.r4   Nrl   )r6   r@   maintenancePolicyr>   rB   s      r   UpdateMaintenanceWindowAnyrt      s5    	.///3M,()=}MM	r   c                 J    UR                  S5      (       a  [        SU5      nU$ )z Hook to update persistence mode.r/   persistence_configrm   rB   s      r   UpdatePersistenceModerw      s'    	())()=}MM	r   c                 J    UR                  S5      (       a  [        SU5      nU$ )z#Hook to update RDB snapshot period.r0   rv   rm   rB   s      r   UpdateRdbSnapshotPeriodry      s'    	+,,()=}MM	r   c                 J    UR                  S5      (       a  [        SU5      nU$ )z'Hook to update RDB snapshot start time.r1   rv   rm   rB   s      r   UpdateRdbSnapshotStartTimer{      rq   r   c                 J    UR                  S5      (       a  [        SU5      nU$ )zHook to update replica count.r.   rm   rB   s      r   UpdateReplicaCountr}      s%    	o&&(-HM	r   c                 J    UR                  S5      (       a  [        SU5      nU$ )z"Hook to update read replicas mode.r,   rm   rB   s      r   UpdateReadReplicasModer      '    	*++()=}MM	r   c                 J    UR                  S5      (       a  [        SU5      nU$ )z"Hook to update secondary IP range.r-   rm   rB   s      r   UpdateSecondaryIpRanger      r   r   c                 J    UR                  S5      (       a  [        SU5      nU$ )zEHook to update maintenance version to the update mask of the request.r   rm   rB   s      r   UpdateMaintenanceVersionr      s'    	+,,()>NM	r   N)#r   apitools.base.pyr    googlecloudsdk.command_lib.redisr   googlecloudsdk.corer   googlecloudsdk.core.consoler   	six.movesr   Errorr	   r   r    r"   r   r>   rC   rQ   rU   r^   ra   r[   rj   rn   rp   rt   rw   ry   r{   r}   r   r   r   r   r   r   <module>r      s    8 & 1 * 2 M
(( MQQQF64r   