Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

{Redis} Migrate to Track 2 Mgmt SDK #18793

Merged
merged 13 commits into from
Jul 16, 2021
30 changes: 30 additions & 0 deletions src/azure-cli/azure/cli/command_modules/redis/_help.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,3 +86,33 @@
short-summary: Update a Redis cache.
long-summary: Scale or update settings of a Redis cache.
"""

helps['redis force-reboot'] = """
type: command
short-summary: Reboot specified Redis node(s).
long-summary: Usage example - az redis force-reboot --name testCacheName --resource-group testResourceGroup --reboot-type {AllNodes, PrimaryNode, SecondaryNode} [--shard-id]
"""

helps['redis import-method'] = """
type: command
short-summary: Import data into Redis cache.
long-summary: Usage example - az redis import-method --name testCacheName --resource-group testResourceGroup --files [--file-format]
"""

helps['redis patch-schedule delete'] = """
type: command
short-summary: Deletes the patching schedule of a redis cache.
long-summary: Usage example - az redis patch-schedule delete --name testCacheName --resource-group testResourceGroup
"""

helps['redis patch-schedule show'] = """
type: command
short-summary: Gets the patching schedule of a redis cache.
long-summary: Usage example - az redis patch-schedule show --name testCacheName --resource-group testResourceGroup [--query-examples]
"""

helps['redis regenerate-keys'] = """
type: command
short-summary: Regenerate Redis cache's access keys.
long-summary: Usage example - az redis regenerate-keys --name testCacheName --resource-group testResourceGroup --key-type {Primary, Secondary}
"""
12 changes: 10 additions & 2 deletions src/azure-cli/azure/cli/command_modules/redis/_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ def load_arguments(self, _):
c.argument('name', arg_type=cache_name)
c.argument('redis_configuration', help='JSON encoded configuration settings. Use @{file} to load from a file.',
type=JsonString)
c.argument('reboot_type', arg_type=get_enum_type(RebootType))
c.argument('key_type', arg_type=get_enum_type(RedisKeyType))
c.argument('reboot_type', arg_type=get_enum_type(RebootType), help='Which Redis node(s) to reboot. Depending on this value data loss is possible.')
c.argument('key_type', arg_type=get_enum_type(RedisKeyType), help='The Redis access key to regenerate.')
c.argument('files', help='SAS url for blobs that needs to be imported', nargs='+')
c.argument('format', arg_type=format_type)
c.argument('file_format', arg_type=format_type)
Expand All @@ -47,6 +47,14 @@ def load_arguments(self, _):
c.argument('cache_name', arg_type=cache_name, id_part=None)
c.argument('rule_name', help='Name of the firewall rule')

with self.argument_context('redis firewall-rules') as c:
c.argument('end_ip', help='Highest IP address included in the range.')
c.argument('rule_name', help='The name of the firewall rule.')
c.argument('start_ip', help='Lowest IP address included in the range.')

with self.argument_context('redis force-reboot') as c:
c.argument('shard_id', help='If clustering is enabled, the ID of the shard to be rebooted.')

with self.argument_context('redis server-link') as c:
c.argument('name', arg_type=cache_name, id_part=None)
c.argument('server_to_link', help='Resource ID or name of the redis cache to be linked')
Expand Down
42 changes: 26 additions & 16 deletions src/azure-cli/azure/cli/command_modules/redis/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,34 +26,44 @@ def load_command_table(self, _):
operations_tmpl='azure.mgmt.redis.operations#LinkedServerOperations.{}',
client_factory=cf_linked_server)

redis_patch_schedules_custom = CliCommandType(
operations_tmpl='azure.cli.command_modules.redis.custom#{}',
client_factory=cf_patch_schedules)
redis_firewall_rules_custom = CliCommandType(
operations_tmpl='azure.cli.command_modules.redis.custom#{}',
client_factory=cf_firewall_rule)
redis_linked_server_custom = CliCommandType(
operations_tmpl='azure.cli.command_modules.redis.custom#{}',
client_factory=cf_linked_server)

with self.command_group('redis', redis_sdk) as g:
g.custom_command('create', 'cli_redis_create', client_factory=cf_redis)
g.command('delete', 'delete', confirmation=True)
g.custom_command('create', 'cli_redis_create')
g.command('delete', 'begin_delete', confirmation=True)
g.custom_command('export', 'cli_redis_export')
g.command('force-reboot', 'force_reboot')
g.command('import-method', 'import_data', deprecate_info=g.deprecate(redirect='redis import', hide=True))
g.command('import', 'import_data')
g.custom_command('force-reboot', 'cli_redis_force_reboot')
g.custom_command('import-method', 'cli_redis_import', deprecate_info=g.deprecate(redirect='redis import', hide=True))
g.custom_command('import', 'cli_redis_import')
g.custom_command('list', 'cli_redis_list_cache')
g.command('list-keys', 'list_keys')
g.command('regenerate-keys', 'regenerate_key')
g.custom_command('regenerate-keys', 'cli_redis_regenerate_key')
g.show_command('show', 'get')
g.generic_update_command('update', setter_name='update', custom_func_name='cli_redis_update')

with self.command_group('redis patch-schedule', redis_patch) as g:
g.command('create', 'create_or_update')
g.command('update', 'create_or_update')
g.command('delete', 'delete')
g.show_command('show', 'get')
with self.command_group('redis patch-schedule', redis_patch, custom_command_type=redis_patch_schedules_custom) as g:
g.custom_command('create', 'cli_redis_patch_schedule_create_or_update')
g.custom_command('update', 'cli_redis_patch_schedule_create_or_update')
g.custom_command('delete', 'cli_redis_patch_schedule_delete')
g.custom_show_command('show', 'cli_redis_patch_schedule_get')

with self.command_group('redis firewall-rules', redis_firewall_rules) as g:
g.command('create', 'create_or_update')
g.command('update', 'create_or_update')
with self.command_group('redis firewall-rules', redis_firewall_rules, custom_command_type=redis_firewall_rules_custom) as g:
g.custom_command('create', 'cli_redis_firewall_create')
g.custom_command('update', 'cli_redis_firewall_create')
g.command('delete', 'delete')
g.show_command('show', 'get')
g.command('list', 'list_by_redis_resource')

with self.command_group('redis server-link', redis_linked_server) as g:
g.custom_command('create', 'cli_redis_create_server_link', client_factory=cf_linked_server)
with self.command_group('redis server-link', redis_linked_server, custom_command_type=redis_linked_server_custom) as g:
g.custom_command('create', 'cli_redis_create_server_link')
g.command('delete', 'delete')
g.show_command('show', 'get')
g.command('list', 'list')
42 changes: 39 additions & 3 deletions src/azure-cli/azure/cli/command_modules/redis/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
def cli_redis_export(cmd, client, resource_group_name, name, prefix, container, file_format=None):
from azure.mgmt.redis.models import ExportRDBParameters
parameters = ExportRDBParameters(prefix=prefix, container=container, format=file_format)
return client.export_data(resource_group_name, name, parameters)
return client.begin_export_data(resource_group_name, name, parameters)


# pylint: disable=unused-argument
Expand Down Expand Up @@ -95,7 +95,7 @@ def cli_redis_create(cmd, client,
static_ip=static_ip,
zones=zones,
tags=tags)
return client.create(resource_group_name, name, params)
return client.begin_create(resource_group_name, name, params)


def get_key_value_pair(string):
Expand Down Expand Up @@ -125,7 +125,21 @@ def cli_redis_create_server_link(cmd, client, resource_group_name, name, server_
params = RedisLinkedServerCreateParameters(linked_redis_cache_id=cache_to_link.id,
linked_redis_cache_location=cache_to_link.location,
server_role=replication_role)
return client.create(resource_group_name, name, cache_to_link.name, params)
return client.begin_create(resource_group_name, name, cache_to_link.name, params)


def cli_redis_patch_schedule_create_or_update(client, resource_group_name, name, schedule_entries):
from azure.mgmt.redis.models import RedisPatchSchedule
param = RedisPatchSchedule(schedule_entries=schedule_entries)
return client.create_or_update(resource_group_name, name, "default", param)


def cli_redis_patch_schedule_get(client, resource_group_name, name):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to make these changes too? Ideally if we just define it with the right factory in commands.py, it will auto get from the SDK without a redirection here. Redisrection is required only if you want to do special cases. like first getting a Resource group before passing the name etc

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reason for redirection is to avoid a new required param "default".
The new SDK has a mandatory parameter "default" and it can take only one value "default".
I think it is the result of adding the new param in our api spec.
To avoid this mandatory parameter in CLI and to ensure backward compatibility, we have this redirection with that param included implicitly.

return client.get(resource_group_name, name, "default")


def cli_redis_patch_schedule_delete(client, resource_group_name, name):
return client.delete(resource_group_name, name, "default")


def cli_redis_list_cache(client, resource_group_name=None):
Expand All @@ -139,4 +153,26 @@ def get_cache_from_resource_id(client, cache_resource_id):
id_comps = parse_resource_id(cache_resource_id)
return client.get(id_comps['resource_group'], id_comps['name'])


def cli_redis_firewall_create(client, resource_group_name, name, rule_name, start_ip, end_ip):
from azure.mgmt.redis.models import RedisFirewallRule
param = RedisFirewallRule(start_ip=start_ip, end_ip=end_ip)
return client.create_or_update(resource_group_name, name, rule_name, param)


def cli_redis_regenerate_key(client, resource_group_name, name, key_type):
from azure.mgmt.redis.models import RedisRegenerateKeyParameters
return client.regenerate_key(resource_group_name, name, RedisRegenerateKeyParameters(key_type=key_type))


def cli_redis_import(client, resource_group_name, name, files, file_format=None):
from azure.mgmt.redis.models import ImportRDBParameters
return client.begin_import_data(resource_group_name, name, ImportRDBParameters(files=files, format=file_format))


def cli_redis_force_reboot(client, resource_group_name, name, reboot_type, shard_id=None):
from azure.mgmt.redis.models import RedisRebootParameters
param = RedisRebootParameters(reboot_type=reboot_type, shard_id=shard_id)
return client.force_reboot(resource_group_name, name, param)

# endregion
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ interactions:
uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/cli_test_redis000001/providers/Microsoft.Cache/Redis/redis000002?api-version=2018-03-01
response:
body: {string: '{"id":"/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/cli_test_redis000001/providers/Microsoft.Cache/Redis/redis000002","location":"West
US 2","name":"redis000002","type":"Microsoft.Cache/Redis","tags":{"test":"tryingzones"},"properties":{"provisioningState":"Creating","redisVersion":"3.2.7","sku":{"name":"Premium","family":"P","capacity":1},"enableNonSslPort":false,"minimumTlsVersion":"1.2","redisConfiguration":{"maxclients":"7500","maxmemory-reserved":"200","maxfragmentationmemory-reserved":"300","maxmemory-delta":"200"},"accessKeys":{"primaryKey":"7bdcv7iw7nGLYirN5AgGdtDSjh71Yo6rG0UK1StuIHU=","secondaryKey":"b0vCMUFvbowIR2dJxAo22y3C2IOlFEcCuy92Z0DZzBM="},"hostName":"redis000002.redis.cache.windows.net","port":6379,"sslPort":6380,"linkedServers":[]},"zones":["2","1"]}'}
US 2","name":"redis000002","type":"Microsoft.Cache/Redis","tags":{"test":"tryingzones"},"properties":{"provisioningState":"Creating","redisVersion":"3.2.7","sku":{"name":"Premium","family":"P","capacity":1},"enableNonSslPort":false,"minimumTlsVersion":"1.2","redisConfiguration":{"maxclients":"7500","maxmemory-reserved":"200","maxfragmentationmemory-reserved":"300","maxmemory-delta":"200"},"accessKeys":{"primaryKey":"*****","secondaryKey":"*****"},"hostName":"redis000002.redis.cache.windows.net","port":6379,"sslPort":6380,"linkedServers":[]},"zones":["2","1"]}'}
headers:
cache-control: [no-cache]
content-length: ['894']
Expand Down Expand Up @@ -109,7 +109,7 @@ interactions:
uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/cli_test_redis000001/providers/Microsoft.Cache/Redis/redis000003?api-version=2018-03-01
response:
body: {string: '{"id":"/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/cli_test_redis000001/providers/Microsoft.Cache/Redis/redis000003","location":"West
US 2","name":"redis000003","type":"Microsoft.Cache/Redis","tags":{},"properties":{"provisioningState":"Creating","redisVersion":"3.2.7","sku":{"name":"Basic","family":"C","capacity":0},"enableNonSslPort":false,"tenantSettings":{"hello":"1"},"redisConfiguration":{"maxclients":"256","maxmemory-reserved":"2","maxfragmentationmemory-reserved":"12","maxmemory-delta":"2"},"accessKeys":{"primaryKey":"Nyu88ebVfsqtmmNh36TDL9xBZYGYs2LjfTzYqzgek58=","secondaryKey":"attWpI6KNdy6ikyUU5DdK1QHP4qcuXu+q3WcyXuvPig="},"hostName":"redis000003.redis.cache.windows.net","port":6379,"sslPort":6380,"linkedServers":[]}}'}
US 2","name":"redis000003","type":"Microsoft.Cache/Redis","tags":{},"properties":{"provisioningState":"Creating","redisVersion":"3.2.7","sku":{"name":"Basic","family":"C","capacity":0},"enableNonSslPort":false,"tenantSettings":{"hello":"1"},"redisConfiguration":{"maxclients":"256","maxmemory-reserved":"2","maxfragmentationmemory-reserved":"12","maxmemory-delta":"2"},"accessKeys":{"primaryKey":"*****","secondaryKey":"*****"},"hostName":"redis000003.redis.cache.windows.net","port":6379,"sslPort":6380,"linkedServers":[]}}'}
headers:
cache-control: [no-cache]
content-length: ['853']
Expand Down
Loading