
    %                        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
 ddlmZ dd	lmZ  G d
 de
j                        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d Zd Z d Z!d Z"d Z#d Z$d  Z%d! Z&y")#z1Utility for updating Memorystore Redis instances.    )absolute_import)division)unicode_literals)encoding)util)
exceptions)
console_io)filterc                       e Zd ZdZy)NoFieldsSpecifiedzDError for calling update command with no args that represent fields.N)__name__
__module____qualname____doc__     =lib/googlecloudsdk/command_lib/redis/instances_update_util.pyr   r      s    Lr   r   c                 "    dg}t        |||      S )z7Checks if fields to update are registered for GA track.maintenance_versionCheckFieldsSpecifiedCommonunused_instance_refargspatch_requestadditional_update_argss       r   CheckFieldsSpecifiedGAr       !      
$D-9O	PPr   c                 "    dg}t        |||      S )z9Checks if fields to update are registered for BETA track.r   r   r   s       r   CheckFieldsSpecifiedBetar    (   r   r   c                 "    dg}t        |||      S )z:Checks if fields to update are registered for ALPHA track.r   r   r   s       r   CheckFieldsSpecifiedAlphar"   0   r   r   c                 h    g d|z   }t        t        | j                  |            r|S t        d      )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   sB    $ %+& 
&!!;
/0D	F Fr   c                 v    |j                   }|r#|j                  |       dk(  r|dz   | z   |_         |S | |_         |S )Nr   ,)
updateMaskcount)fieldr   update_masks      r   AddFieldToUpdateMaskr>   S   sM    ((+1$!,s!2U!:m 
  %M	r   c                 v    |j                  d      r'|j                  |j                  _        t	        d|      }|S )Nr%   )r6   r%   instancedisplayNamer>   r   r   r   s      r   AddDisplayNamerC   ]   s6    	n%)-):):M&(GM	r   c                 B   t        j                  |       }d}|j                  |j                  j                  j
                  k(  r|dz  }n8|j                  |j                  j                  j                  k(  r|dz  }n|dz  }|dz  }t        j                  |dd       y	)
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   d   s    ((6(1']]h'';;AAA  G }}))==III 0 1G
  H IG	JK' 9r   c                     |j                  d      r=t        | |j                         |j                  |j                  _        t        d|      }|S )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   ~   sE    	f!,0F0FG*.))M'()9=IM	r   c                    t        |j                  dd       s|S |j                  d      rYt        j                  |j                  j
                        }|j                  D ]  }|j                  |d         t        | ||      }|S )NredisConfigsr(   )	getattrr@   r6   r   MessageToDictrW   r(   popAddNewRedisConfigs)rO   r   r   config_dictremoved_keys        r   RemoveRedisConfigsr^      sw    	''	>	+,(()?)?)L)LMK//ook4( 0&|[-PM	r   c                     |j                  d      rji }t        |j                  dd       r)t        j                  |j                  j
                        }|j                  |j                         t        | ||      }|S )Nr+   rW   )	r6   rX   r@   r   rY   rW   updater+   r[   )rO   r   r   r\   s       r   UpdateRedisConfigsra      sl    	+,K}%%~t<**=+A+A+N+NOkt//0&|[-PM	r   c                     t        j                  |       }t        j                  ||      }||j                  _        t        d|      }|S )Nredis_configs)r   rH   PackageInstanceRedisConfigr@   rW   r>   )rO   redis_configs_dictr   rP   new_redis_configss        r   r[   r[      sJ    ((6(556H6>@(9-%&F-	r   c                 ~    |j                  d      r+t        j                  |j                         t	        d|      }|S )z;Hook to add auth_enabled to the update mask of the request.r&   auth_enabled)r6   r   WarnOnAuthEnabledr&   r>   rB   s      r   UpdateAuthEnabledrj      s6    	m$4++,(GM	r   c                 @    |j                  d      rt        d|      }|S )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                  d      rt        d|      }|S )zIHook to update maintenance window hour to the update mask of the request.r3   rl   rm   rB   s      r   UpdateMaintenanceWindowHourrp      $    	/0()=}MM	r   c                 b    |j                  d      rd|j                  _        t        d|      }|S )z"Hook to remove maintenance window.r4   Nrl   )r6   r@   maintenancePolicyr>   rB   s      r   UpdateMaintenanceWindowAnyrt      s2    	.//3M,()=}MM	r   c                 @    |j                  d      rt        d|      }|S )z Hook to update persistence mode.r/   persistence_configrm   rB   s      r   UpdatePersistenceModerw      s$    	()()=}MM	r   c                 @    |j                  d      rt        d|      }|S )z#Hook to update RDB snapshot period.r0   rv   rm   rB   s      r   UpdateRdbSnapshotPeriodry      s$    	+,()=}MM	r   c                 @    |j                  d      rt        d|      }|S )z'Hook to update RDB snapshot start time.r1   rv   rm   rB   s      r   UpdateRdbSnapshotStartTimer{      rq   r   c                 @    |j                  d      rt        d|      }|S )zHook to update replica count.r.   rm   rB   s      r   UpdateReplicaCountr}      s"    	o&(-HM	r   c                 @    |j                  d      rt        d|      }|S )z"Hook to update read replicas mode.r,   rm   rB   s      r   UpdateReadReplicasModer      $    	*+()=}MM	r   c                 @    |j                  d      rt        d|      }|S )z"Hook to update secondary IP range.r-   rm   rB   s      r   UpdateSecondaryIpRanger      r   r   c                 @    |j                  d      rt        d|      }|S )zEHook to update maintenance version to the update mask of the request.r   rm   rB   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   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   