
                             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	\
5      r " S
 S\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g)z0Utility for updating Memorystore Redis clusters.    )absolute_import)division)unicode_literals)encoding)cluster_util)utilc                       \ rS rSrSrSrg)Error   zExceptions for this module. N__name__
__module____qualname____firstlineno____doc____static_attributes__r       <lib/googlecloudsdk/command_lib/redis/clusters_update_util.pyr
   r
      s    #r   r
   c                       \ rS rSrSrSrg)InvalidTimeOfDayError   z&Error for passing invalid time of day.r   Nr   r   r   r   r   r      s    .r   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)fieldpatch_requestupdate_masks      r   AddFieldToUpdateMaskr    "   sK    ((+1$!,s!2U!:m 
  %	r   c                     [         R                  " U 5      n[        R                  " X5      nXBR                  l        [        SU5      nU$ )Nredis_configs)r   GetMessagesForResourcer   PackageClusterRedisConfigclusterredisConfigsr    )cluster_refredis_configs_dictr   messagesnew_redis_configss        r   AddNewRedisClusterConfigsr+   ,   sF    ((5("<< (9$&F-	r   c                     UR                  S5      (       a'  UR                  UR                  l        [	        SU5      nU$ )z>Hook to add replica count to the redis cluster update request.replica_count)IsSpecifiedr-   r%   replicaCountr    unused_cluster_refargsr   s      r   UpdateReplicaCountr3   6   s9    	o&&)-););M&(-HM	r   c                 v    UR                  S5      (       d  UR                  S5      (       a  [        SU5      nU$ )zKHook to update maintenance window policy to the update mask of the request.maintenance_window_daymaintenance_window_hourmaintenance_windowr.   r    r0   s      r   UpdateMaintenanceWindowPolicyr9   >   s;     /00			3	4	4()=}MM	r   c                 l    UR                  S5      (       a  SUR                  l        [        SU5      nU$ )z"Hook to remove maintenance policy.maintenance_window_anyNr7   )r.   r%   maintenancePolicyr    r0   s      r   UpdateMaintenanceWindowAnyr=   H   s5    	.//.2M+()=}MM	r   c                     UR                  S5      (       a'  UR                  UR                  l        [	        SU5      nU$ )zLHook to update simulate maintenance event to the update mask of the request.simulate_maintenance_event)r.   r?   r%   simulateMaintenanceEventr    r0   s      r   UpdateSimulateMaintenanceEventrA   P   sD    	233'' 2 )$mM 
r   c                     UR                  S5      (       a'  UR                  UR                  l        [	        SU5      nU$ )z<Hook to add shard count to the redis cluster update request.shard_count)r.   rC   r%   
shardCountr    r0   s      r   UpdateShardCountrE   \   s9    	m$$'+'7'7M$(FM	r   c                     UR                  S5      (       a'  UR                  UR                  l        [	        SU5      nU$ )zDHook to add maintenance version to the redis cluster update request.maintenance_version)r.   rG   r%   maintenanceVersionr    r0   s      r   UpdateMaintenanceVersionrI   d   s;    	+,,/3/G/GM,()>NM	r   c                     UR                  S5      (       a'  UR                  UR                  l        [	        SU5      nU$ )zBHook to add delete protection to the redis cluster update request.deletion_protectiondeletion_protection_enabled)r.   rK   r%   deletionProtectionEnabledr    r0   s      r   UpdateDeletionProtectionrN   l   s?    	+,,6:6N6NM3(%}M 
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$ )zAHook to update redis configs to the redis cluster update request.update_redis_configr&   N)	r.   getattrr%   r   MessageToDictr&   updaterP   r+   )r'   r2   r   config_dicts       r   UpdateRedisConfigsrU   v   su    	+,,K}$$nd;;**=+@+@+M+MNkt//0--M 
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$ )zAHook to remove redis configs to the redis cluster update request.r&   Nremove_redis_config)	rQ   r%   r.   r   rR   r&   rW   popr+   )r'   r2   r   rT   removed_keys        r   RemoveRedisConfigsrZ      s    	&&	=	=	+,,(()>)>)K)KLK//ook4( 0--M 
r   c                    UR                  S5      (       dB  UR                  S5      (       d,  UR                  S5      (       d  UR                  S5      (       a  [        SU5      nUR                  R                  (       ax  UR                  S5      (       d1  UR                  S5      (       d  SUR                  R                  l        UR                  S5      (       d  SUR                  R                  l        U$ )zCHook to add persistence config to the redis cluster update request.persistence_moderdb_snapshot_periodrdb_snapshot_start_timeaof_append_fsyncpersistence_configN)r.   r    r%   persistenceConfig	rdbConfig	aofConfigr0   s      r   UpdatePersistenceConfigrd      s     )**			/	0	0			3	4	4			,	-	-()=}MM ,,1224;K;K!< < ;?m--7.//:>m--7	r   c                 J    UR                  S5      (       a  [        SU5      nU$ )z:Hook to add node type to the redis cluster update request.	node_typer8   r0   s      r   UpdateNodeTyperg      s%    	k""(mDM	r   c                     UR                  S5      (       d,  UR                  S5      (       d  UR                  S5      (       a  [        SU5      nU$ )zHHook to add automated backup config to the redis cluster update request.automated_backup_ttlautomated_backup_start_timeautomated_backup_modeautomated_backup_configr8   r0   s      r   UpdateAutomatedBackupConfigrm      sQ     -..			7	8	8			1	2	2(!=M 
r   c                 4    U S:  d  U S:  a  [        S5      eU $ )Nr      z4A valid time of day must be specified (0, 23) hours.)r   )maintenance_window_start_times    r   $CheckMaintenanceWindowStartTimeFieldrq      s*    "Q&*G"*L
>  
'&r   N)r   
__future__r   r   r   apitools.base.pyr    googlecloudsdk.command_lib.redisr   r   	Exceptionr
   r   r    r+   r3   r9   r=   rA   rE   rI   rN   rU   rZ   rd   rg   rm   rq   r   r   r   <module>rv      s    7 &  ' % 9 1$I $/E /	
0
'r   