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
Prev Previous commit
Next Next commit
linter issue fix
Praveenkumar Ravikumar committed Jul 13, 2021
commit 8646fb98f364200fd829aa31c48a1e4b4982cfba
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
@@ -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: 12 additions & 0 deletions src/azure-cli/azure/cli/command_modules/redis/_params.py
Original file line number Diff line number Diff line change
@@ -47,6 +47,18 @@ 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('reboot_type', help='Which Redis node(s) to reboot. Depending on this value data loss is possible.')
c.argument('shard_id', help='If clustering is enabled, the ID of the shard to be rebooted.')

with self.argument_context('redis regenerate-keys') as c:
c.argument('key_type', help='The Redis access key to regenerate.')

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')
2 changes: 1 addition & 1 deletion src/azure-cli/azure/cli/command_modules/redis/commands.py
Original file line number Diff line number Diff line change
@@ -43,7 +43,7 @@ def load_command_table(self, _):
g.custom_command('create', 'cli_redis_patch_schedule_create_or_update', client_factory=cf_patch_schedules)
g.custom_command('update', 'cli_redis_patch_schedule_create_or_update', client_factory=cf_patch_schedules)
g.custom_command('delete', 'cli_redis_patch_schedule_delete', client_factory=cf_patch_schedules)
g.custom_command('show', 'cli_redis_patch_schedule_get', client_factory=cf_patch_schedules)
g.custom_show_command('show', 'cli_redis_patch_schedule_get', client_factory=cf_patch_schedules)

with self.command_group('redis firewall-rules', redis_firewall_rules) as g:
g.custom_command('create', 'cli_redis_firewall_create', client_factory=cf_firewall_rule)
16 changes: 13 additions & 3 deletions src/azure-cli/azure/cli/command_modules/redis/custom.py
Original file line number Diff line number Diff line change
@@ -127,13 +127,17 @@ def cli_redis_create_server_link(cmd, client, resource_group_name, name, server_
server_role=replication_role)
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
return client.create_or_update(resource_group_name, name, "default", RedisPatchSchedule(schedule_entries=schedule_entries))
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")

@@ -149,20 +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
return client.create_or_update(resource_group_name, name, rule_name, RedisFirewallRule(start_ip=start_ip, end_ip=end_ip))
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
return client.force_reboot(resource_group_name, name, RedisRebootParameters(reboot_type=reboot_type, shard_id=shard_id))
param = RedisRebootParameters(reboot_type=reboot_type, shard_id=shard_id)
return client.force_reboot(resource_group_name, name, param)

# endregion