
                             d Z ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlm	Z	  G d d	e
      Z G d
 de      Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zy)z0Utility for updating Memorystore Redis clusters.    )absolute_import)division)unicode_literals)encoding)cluster_util)utilc                       e Zd ZdZy)ErrorzExceptions for this module.N__name__
__module____qualname____doc__     <lib/googlecloudsdk/command_lib/redis/clusters_update_util.pyr
   r
      s    #r   r
   c                       e Zd ZdZy)InvalidTimeOfDayErrorz&Error for passing invalid time of day.Nr   r   r   r   r   r      s    .r   r   c                 v    |j                   }|r#|j                  |       dk(  r|dz   | z   |_         |S | |_         |S )Nr   ,)
updateMaskcount)fieldpatch_requestupdate_masks      r   AddFieldToUpdateMaskr   "   sM    ((+1$!,s!2U!:m 
  %M	r   c                     t        j                  |       }t        j                  ||      }||j                  _        t        d|      }|S )Nredis_configs)r   GetMessagesForResourcer   PackageClusterRedisConfigclusterredisConfigsr   )cluster_refredis_configs_dictr   messagesnew_redis_configss        r   AddNewRedisClusterConfigsr'   ,   sJ    ((5("<<( (9-$&F-	r   c                 v    |j                  d      r'|j                  |j                  _        t	        d|      }|S )z>Hook to add replica count to the redis cluster update request.replica_count)IsSpecifiedr)   r!   replicaCountr   unused_cluster_refargsr   s      r   UpdateReplicaCountr/   6   s6    	o&)-););M&(-HM	r   c                 b    |j                  d      s|j                  d      rt        d|      }|S )zKHook to update maintenance window policy to the update mask of the request.maintenance_window_daymaintenance_window_hourmaintenance_windowr*   r   r,   s      r   UpdateMaintenanceWindowPolicyr5   >   s5     /0			3	4()=}MM	r   c                 b    |j                  d      rd|j                  _        t        d|      }|S )z"Hook to remove maintenance policy.maintenance_window_anyNr3   )r*   r!   maintenancePolicyr   r,   s      r   UpdateMaintenanceWindowAnyr9   H   s2    	./.2M+()=}MM	r   c                 v    |j                  d      r'|j                  |j                  _        t	        d|      }|S )zLHook to update simulate maintenance event to the update mask of the request.simulate_maintenance_event)r*   r;   r!   simulateMaintenanceEventr   r,   s      r   UpdateSimulateMaintenanceEventr=   P   sA    	23'' 2 )$mM 
r   c                 v    |j                  d      r'|j                  |j                  _        t	        d|      }|S )z<Hook to add shard count to the redis cluster update request.shard_count)r*   r?   r!   
shardCountr   r,   s      r   UpdateShardCountrA   \   s6    	m$'+'7'7M$(FM	r   c                 v    |j                  d      r'|j                  |j                  _        t	        d|      }|S )zBHook to add delete protection to the redis cluster update request.deletion_protectiondeletion_protection_enabled)r*   rC   r!   deletionProtectionEnabledr   r,   s      r   UpdateDeletionProtectionrF   d   s<    	+,6:6N6NM3(%}M 
r   c                     |j                  d      rji }t        |j                  dd      r)t        j                  |j                  j
                        }|j                  |j                         t        | ||      }|S )zAHook to update redis configs to the redis cluster update request.update_redis_configr"   N)	r*   getattrr!   r   MessageToDictr"   updaterH   r'   )r#   r.   r   config_dicts       r   UpdateRedisConfigsrM   n   sq    	+,K}$$nd;**=+@+@+M+MNkt//0-[-M 
r   c                    t        |j                  dd      s|S |j                  d      rYt        j                  |j                  j
                        }|j                  D ]  }|j                  |d        t        | ||      }|S )zAHook to remove redis configs to the redis cluster update request.r"   Nremove_redis_config)	rI   r!   r*   r   rJ   r"   rO   popr'   )r#   r.   r   rL   removed_keys        r   RemoveRedisConfigsrR   {   s|    	&&	=	+,(()>)>)K)KLK//ook4( 0-[-M 
r   c                    |j                  d      s3|j                  d      s"|j                  d      s|j                  d      rt        d|      }|j                  j                  ri|j                  d      s,|j                  d      sd|j                  j                  _        |j                  d      sd|j                  j                  _        |S )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	aofConfigr,   s      r   UpdatePersistenceConfigr\      s     )*			/	0			3	4			,	-()=}MM ,,124;K;K!< ;?m--7./:>m--7	r   c                 @    |j                  d      rt        d|      }|S )z:Hook to add node type to the redis cluster update request.	node_typer4   r,   s      r   UpdateNodeTyper_      s"    	k"(mDM	r   c                     |j                  d      s"|j                  d      s|j                  d      rt        d|      }|S )zHHook to add automated backup config to the redis cluster update request.automated_backup_ttlautomated_backup_start_timeautomated_backup_modeautomated_backup_configr4   r,   s      r   UpdateAutomatedBackupConfigre      sH     -.			7	8			1	2(!=M 
r   c                 0    | dk  s| dkD  rt        d      | S )Nr      z4A valid time of day must be specified (0, 23) hours.)r   )maintenance_window_start_times    r   $CheckMaintenanceWindowStartTimeFieldri      s*    "Q&*G"*L
>  
'&r   N)r   
__future__r   r   r   apitools.base.pyr    googlecloudsdk.command_lib.redisr   r   	Exceptionr
   r   r   r'   r/   r5   r9   r=   rA   rF   rM   rR   r\   r_   re   ri   r   r   r   <module>rn      sz    7 &  ' % 9 1$I $/E /	
0
'r   