Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
)
class Update(AAZCommand):
"""Update an existing (overwrite/recreate, with potential downtime) cache cluster

:example: Updates cluster SKU
az redisenterprise update --cluster-name "cache1" --sku "ComputeOptimized_X5" --resource-group "rg1"
"""

_aaz_info = {
Expand Down
2 changes: 2 additions & 0 deletions src/redisenterprise/azext_redisenterprise/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ def load_command_table(self, _): # pylint: disable=unused-argument
g.custom_command('create', 'redisenterprise_create', supports_no_wait=True)
g.custom_command('list', 'redisenterprise_list')
g.custom_show_command('show', 'redisenterprise_show')
from .custom import RedisEnterpriseUpdate
self.command_table["redisenterprise update"] = RedisEnterpriseUpdate(loader=self)
with self.command_group("redisenterprise database"):
from .custom import DatabaseFlush, DatabaseCreate, DatabaseDelete, DatabaseExport, DatabaseForceUnlink
from .custom import DatabaseImport, DatabaseListKey, DatabaseRegenerateKey
Expand Down
38 changes: 38 additions & 0 deletions src/redisenterprise/azext_redisenterprise/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,51 @@
from .aaz.latest.redisenterprise import List as _ClusterList
from .aaz.latest.redisenterprise import Show as _ClusterShow
from .aaz.latest.redisenterprise import Wait as _DatabaseWait
from .aaz.latest.redisenterprise import Update as _Update
from azure.cli.core.azclierror import (
MutuallyExclusiveArgumentError,
)

logger = get_logger(__name__)


class RedisEnterpriseUpdate(_Update):

def pre_instance_update(self, instance):
"""Called before the instance is updated"""
try:
current_sku = str(instance.sku.name) if hasattr(instance, 'sku') and instance.sku else None
except (AttributeError, TypeError):
current_sku = None

new_sku = str(self.ctx.args.sku) if self.ctx.args.sku is not None else None

if new_sku and current_sku and new_sku != current_sku:
self._handle_sku_change(current_sku, new_sku, instance)

def _handle_sku_change(self, current_sku, new_sku, instance):
"""Handle SKU change logic for capacity and zones"""
# Check if changing from Azure Cache for Redis Enterprise to Azure Managed Redis SKU types
# that don't support capacity/zones
if (current_sku.startswith('Enterprise') and
(new_sku.startswith('Balanced_') or
new_sku.startswith('ComputeOptimized_') or
new_sku.startswith('MemoryOptimized_') or
new_sku.startswith('FlashOptimized_'))):
# Unset capacity and zones in the instance
try:
if hasattr(instance, 'sku') and instance.sku and hasattr(instance.sku, 'capacity'):
instance.sku.capacity = None
except (AttributeError, TypeError):
pass

try:
if hasattr(instance, 'zones'):
instance.zones = None
except (AttributeError, TypeError):
pass


class DatabaseFlush(_DatabaseFlush):

@classmethod
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,21 @@ def step_create(test, checks=None, cache_num=1):
'--port 10000 '
'--resource-group "{rg}"',
checks=checks)
elif test.kwargs.get('sku-update'):
test.cmd('az redisenterprise create '
'--cluster-name "{cluster}" '
'--sku "{initial_sku}" '
'--location "centraluseuap" '
'--tags tag1="value1" '
'--minimum-tls-version "1.2" '
'--client-protocol "Encrypted" '
'--clustering-policy "EnterpriseCluster" '
'--public-network-access "Enabled" '
'--access-keys-auth Enabled '
'--eviction-policy "NoEviction" '
'--port 10000 '
'--resource-group "{rg}"',
checks=checks)
else:
test.cmd('az redisenterprise create '
'--cluster-name "{cluster}" '
Expand Down Expand Up @@ -165,6 +180,16 @@ def step_delete(test, checks=None):
'--resource-group "{rg}"',
checks=checks)

def step_update(test, checks=None):
if checks is None:
checks = []
if test.kwargs.get('sku-update'):
test.cmd('az redisenterprise update '
'--cluster-name "{cluster}" '
'--sku "{new_sku}" '
'--resource-group "{rg}"',
checks=checks)

def step_database_update(test, checks=None):
if checks is None:
checks = []
Expand Down
Loading
Loading