
    %                        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\
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.    )absolute_import)division)unicode_literals)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%   0   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   8   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   AddFieldToUpdateMaskrA   S   sK    ((+1$!,s!2U!:m 
  %	r   c                     UR                  S5      (       a'  UR                  UR                  l        [	        SU5      nU$ )Nr(   )r9   r(   instancedisplayNamerA   r   r   r   s      r   AddDisplayNamerF   ]   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_refrC   messagesrH   s       r   _WarnForDestructiveSizeUpdaterT   d   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)r9   rT   rC   r,   memorySizeGbrA   )rR   r   r   s      r   AddSizerX   ~   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+   )	getattrrC   r9   r   MessageToDictrZ   r+   popAddNewRedisConfigs)rR   r   r   config_dictremoved_keys        r   RemoveRedisConfigsra      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.   rZ   )	r9   r[   rC   r   r\   rZ   updater.   r^   )rR   r   r   r_   s       r   UpdateRedisConfigsrd      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   rK   PackageInstanceRedisConfigrC   rZ   rA   )rR   redis_configs_dictr   rS   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)r9   r   WarnOnAuthEnabledr)   rA   rE   s      r   UpdateAuthEnabledrm      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.r5   maintenance_policyr9   rA   rE   s      r   UpdateMaintenanceWindowDayrq      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.r6   ro   rp   rE   s      r   UpdateMaintenanceWindowHourrs      '    	/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.r7   Nro   )r9   rC   maintenancePolicyrA   rE   s      r   UpdateMaintenanceWindowAnyrw      s5    	.///3M,()=}MM	r   c                 J    UR                  S5      (       a  [        SU5      nU$ )z Hook to update persistence mode.r2   persistence_configrp   rE   s      r   UpdatePersistenceModerz      s'    	())()=}MM	r   c                 J    UR                  S5      (       a  [        SU5      nU$ )z#Hook to update RDB snapshot period.r3   ry   rp   rE   s      r   UpdateRdbSnapshotPeriodr|      s'    	+,,()=}MM	r   c                 J    UR                  S5      (       a  [        SU5      nU$ )z'Hook to update RDB snapshot start time.r4   ry   rp   rE   s      r   UpdateRdbSnapshotStartTimer~      rt   r   c                 J    UR                  S5      (       a  [        SU5      nU$ )zHook to update replica count.r1   rp   rE   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/   rp   rE   s      r   UpdateReadReplicasModer      '    	*++()=}MM	r   c                 J    UR                  S5      (       a  [        SU5      nU$ )z"Hook to update secondary IP range.r0   rp   rE   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   rp   rE   s      r   UpdateMaintenanceVersionr      s'    	+,,()>NM	r   N)'r   
__future__r   r   r   apitools.base.pyr    googlecloudsdk.command_lib.redisr   googlecloudsdk.corer   googlecloudsdk.core.consoler	   	six.movesr
   Errorr   r    r#   r%   r   rA   rF   rT   rX   ra   rd   r^   rm   rq   rs   rw   rz   r|   r~   r   r   r   r   r   r   r   <module>r      s    8 &  ' % 1 * 2 M
(( MQQQF64r   