From 23c7bef497881e25b9519e1eba6b2b18f624f503 Mon Sep 17 00:00:00 2001 From: Alfan Date: Mon, 10 Apr 2017 15:42:36 -0700 Subject: [PATCH 1/7] adding ability to scale for redis cache --- .../azure/cli/command_modules/redis/_params.py | 7 ++++--- .../azure/cli/command_modules/redis/custom.py | 12 ++++++++++-- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/src/command_modules/azure-cli-redis/azure/cli/command_modules/redis/_params.py b/src/command_modules/azure-cli-redis/azure/cli/command_modules/redis/_params.py index c1ca22f5ea7..87b53676e6f 100644 --- a/src/command_modules/azure-cli-redis/azure/cli/command_modules/redis/_params.py +++ b/src/command_modules/azure-cli-redis/azure/cli/command_modules/redis/_params.py @@ -51,14 +51,15 @@ def __init__(self, value): register_cli_argument('redis', 'reboot_type', **enum_choice_list(RebootType)) register_cli_argument('redis', 'key_type', **enum_choice_list(RedisKeyType)) register_cli_argument('redis', 'shard_id', type=int) +register_cli_argument('redis', 'sku_name', **enum_choice_list(SkuName)) +register_cli_argument('redis', 'sku_family', **enum_choice_list(SkuFamily)) +register_cli_argument('redis', 'sku_capacity', choices=[str(n) for n in range(0, 7)]) + register_cli_argument('redis import-method', 'files', nargs='+') register_cli_argument('redis patch-schedule set', 'schedule_entries', type=ScheduleEntryList) register_cli_argument('redis create', 'name', arg_type=name_type, completer=None) -register_cli_argument('redis create', 'sku_name', **enum_choice_list(SkuName)) -register_cli_argument('redis create', 'sku_family', **enum_choice_list(SkuFamily)) -register_cli_argument('redis create', 'sku_capacity', choices=[str(n) for n in range(0, 7)]) register_cli_argument('redis create', 'enable_non_ssl_port', action='store_true') register_cli_argument('redis create', 'tenant_settings', type=JsonString) register_cli_argument('redis create', 'shard_count', type=int) diff --git a/src/command_modules/azure-cli-redis/azure/cli/command_modules/redis/custom.py b/src/command_modules/azure-cli-redis/azure/cli/command_modules/redis/custom.py index 32441e7d77d..3b8b0841307 100644 --- a/src/command_modules/azure-cli-redis/azure/cli/command_modules/redis/custom.py +++ b/src/command_modules/azure-cli-redis/azure/cli/command_modules/redis/custom.py @@ -19,10 +19,18 @@ def cli_redis_import_method(client, resource_group_name, name, file_format, file parameters = ImportRDBParameters(files, file_format) return client.import_method(resource_group_name, name, files, parameters) -def cli_redis_update_settings(client, resource_group_name, name, redis_configuration): +def cli_redis_update_settings(client, resource_group_name, name, redis_configuration = None, sku_name = None, sku_family = None, sku_capacity = None): + if sku_name != None or sku_family != None or sku_capacity != None: + if sku_name is None or sku_family is None or sku_capacity is None: + raise ValueError("All arguments for Sku : --sku-name,--sku-family and --sku-capacity must be provided. Please add -h to the command to see supported values") + existing = client.get(resource_group_name, name) - existing.redis_configuration.update(redis_configuration) + if redis_configuration != None: + existing.redis_configuration.update(redis_configuration) + if sku_name != None and sku_family != None and sku_capacity != None : + existing.sku = Sku(sku_name, sku_family, sku_capacity) + # Due to swagger/mgmt SDK quirkiness, we have to manually copy over # the resource retrieved to a create_or_update_parameters object update_params = RedisCreateOrUpdateParameters( From 05171217ecc6cad9c84138742e94ff10f888b799 Mon Sep 17 00:00:00 2001 From: Alfan Date: Mon, 10 Apr 2017 16:18:38 -0700 Subject: [PATCH 2/7] adding tests for redis cache, adding change in history.rst --- azure-cli.pyproj | 1 + .../azure-cli-redis/HISTORY.rst | 2 + .../recordings/test_create_redis_cache.yaml | 176 ++++++++++++++++++ .../tests/test_redis_scenario.py | 14 ++ 4 files changed, 193 insertions(+) create mode 100644 src/command_modules/azure-cli-redis/tests/recordings/test_create_redis_cache.yaml create mode 100644 src/command_modules/azure-cli-redis/tests/test_redis_scenario.py diff --git a/azure-cli.pyproj b/azure-cli.pyproj index 329dab7523d..18c6b217c4e 100644 --- a/azure-cli.pyproj +++ b/azure-cli.pyproj @@ -449,6 +449,7 @@ + Code diff --git a/src/command_modules/azure-cli-redis/HISTORY.rst b/src/command_modules/azure-cli-redis/HISTORY.rst index 440f835e1cb..683f7e5347a 100644 --- a/src/command_modules/azure-cli-redis/HISTORY.rst +++ b/src/command_modules/azure-cli-redis/HISTORY.rst @@ -3,6 +3,8 @@ Release History =============== +* Adding ability to scale for redis cache + 0.1.1b3 (2017-02-22) ++++++++++++++++++++ diff --git a/src/command_modules/azure-cli-redis/tests/recordings/test_create_redis_cache.yaml b/src/command_modules/azure-cli-redis/tests/recordings/test_create_redis_cache.yaml new file mode 100644 index 00000000000..342e992ceaf --- /dev/null +++ b/src/command_modules/azure-cli-redis/tests/recordings/test_create_redis_cache.yaml @@ -0,0 +1,176 @@ +interactions: +- request: + body: '{"location": "westus", "tags": {"use": "az-test"}}' + headers: + Accept: [application/json] + Accept-Encoding: ['gzip, deflate'] + CommandName: [group create] + Connection: [keep-alive] + Content-Length: ['50'] + Content-Type: [application/json; charset=utf-8] + User-Agent: [python/3.6.1 (Windows-10-10.0.14393-SP0) requests/2.9.1 msrest/0.4.7 + msrest_azure/0.4.7 resourcemanagementclient/0.30.2 Azure-SDK-For-Python + AZURECLI/2.0.2+dev] + accept-language: [en-US] + method: PUT + uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/clitest.rg000001?api-version=2016-09-01 + response: + body: {string: '{"id":"/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/clitest.rg000001","name":"clitest.rg000001","location":"westus","tags":{"use":"az-test"},"properties":{"provisioningState":"Succeeded"}}'} + headers: + cache-control: [no-cache] + content-length: ['326'] + content-type: [application/json; charset=utf-8] + date: ['Mon, 10 Apr 2017 23:14:47 GMT'] + expires: ['-1'] + pragma: [no-cache] + strict-transport-security: [max-age=31536000; includeSubDomains] + x-ms-ratelimit-remaining-subscription-writes: ['1199'] + status: {code: 201, message: Created} +- request: + body: '{"location": "WestUS", "properties": {"sku": {"name": "Basic", "family": + "C", "capacity": 0}}}' + headers: + Accept: [application/json] + Accept-Encoding: ['gzip, deflate'] + CommandName: [redis create] + Connection: [keep-alive] + Content-Length: ['94'] + Content-Type: [application/json; charset=utf-8] + User-Agent: [python/3.6.1 (Windows-10-10.0.14393-SP0) requests/2.9.1 msrest/0.4.7 + msrest_azure/0.4.7 redismanagementclient/1.0.0 Azure-SDK-For-Python AZURECLI/2.0.2+dev] + accept-language: [en-US] + method: PUT + uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/clitest.rg000001/providers/Microsoft.Cache/Redis/cli000002?api-version=2016-04-01 + response: + body: {string: '{"id":"/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/clitest.rg000001/providers/Microsoft.Cache/Redis/cli000002","location":"West + US","name":"cli000002","type":"Microsoft.Cache/Redis","tags":{},"properties":{"provisioningState":"Creating","redisVersion":"3.2","sku":{"name":"Basic","family":"C","capacity":0},"enableNonSslPort":false,"redisConfiguration":{"maxclients":"256","maxmemory-reserved":"2","maxfragmentationmemory-reserved":"12","maxmemory-delta":"2"},"accessKeys":{"primaryKey":"sigfIJwLK3x5mKBM+FVVW3prFyhT31tWsuSs1nEzHUY=","secondaryKey":"MIYVlv+BCA29Y96iiLHI2yJkY86DmvPUp2EucJIMYpg="},"hostName":"cli000002.redis.cache.windows.net","port":6379,"sslPort":6380}}'} + headers: + cache-control: [no-cache] + content-length: ['798'] + content-type: [application/json; charset=utf-8] + date: ['Mon, 10 Apr 2017 23:14:49 GMT'] + expires: ['-1'] + location: ['https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/clitest.rg000001/providers/Microsoft.Cache/redis/cli000002?api-version=2016-04-01'] + pragma: [no-cache] + server: [Microsoft-HTTPAPI/2.0] + strict-transport-security: [max-age=31536000; includeSubDomains] + x-ms-ratelimit-remaining-subscription-writes: ['1199'] + x-rp-server-mvid: [7c53f2fa-3f55-4e40-bab5-9c22bd480fa7] + status: {code: 201, message: Created} +- request: + body: null + headers: + Accept: [application/json] + Accept-Encoding: ['gzip, deflate'] + CommandName: [redis show] + Connection: [keep-alive] + Content-Type: [application/json; charset=utf-8] + User-Agent: [python/3.6.1 (Windows-10-10.0.14393-SP0) requests/2.9.1 msrest/0.4.7 + msrest_azure/0.4.7 redismanagementclient/1.0.0 Azure-SDK-For-Python AZURECLI/2.0.2+dev] + accept-language: [en-US] + method: GET + uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/clitest.rg000001/providers/Microsoft.Cache/Redis/cli000002?api-version=2016-04-01 + response: + body: {string: '{"id":"/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/clitest.rg000001/providers/Microsoft.Cache/Redis/cli000002","location":"West + US","name":"cli000002","type":"Microsoft.Cache/Redis","tags":{},"properties":{"provisioningState":"Creating","redisVersion":"3.2","sku":{"name":"Basic","family":"C","capacity":0},"enableNonSslPort":false,"redisConfiguration":{"maxclients":"256","maxmemory-reserved":"2","maxfragmentationmemory-reserved":"12","maxmemory-delta":"2"},"accessKeys":null,"hostName":"cli000002.redis.cache.windows.net","port":6379,"sslPort":6380}}'} + headers: + cache-control: [no-cache] + content-length: ['679'] + content-type: [application/json; charset=utf-8] + date: ['Mon, 10 Apr 2017 23:14:50 GMT'] + expires: ['-1'] + pragma: [no-cache] + server: [Microsoft-HTTPAPI/2.0] + strict-transport-security: [max-age=31536000; includeSubDomains] + transfer-encoding: [chunked] + vary: [Accept-Encoding] + x-rp-server-mvid: [7c53f2fa-3f55-4e40-bab5-9c22bd480fa7] + status: {code: 200, message: OK} +- request: + body: null + headers: + Accept: [application/json] + Accept-Encoding: ['gzip, deflate'] + CommandName: [redis list] + Connection: [keep-alive] + Content-Type: [application/json; charset=utf-8] + User-Agent: [python/3.6.1 (Windows-10-10.0.14393-SP0) requests/2.9.1 msrest/0.4.7 + msrest_azure/0.4.7 redismanagementclient/1.0.0 Azure-SDK-For-Python AZURECLI/2.0.2+dev] + accept-language: [en-US] + method: GET + uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/clitest.rg000001/providers/Microsoft.Cache/Redis/?api-version=2016-04-01 + response: + body: {string: '{"value":[{"id":"/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/clitest.rg000001/providers/Microsoft.Cache/Redis/cli000002","location":"West + US","name":"cli000002","type":"Microsoft.Cache/Redis","tags":{},"properties":{"provisioningState":"Creating","redisVersion":"3.2","sku":{"name":"Basic","family":"C","capacity":0},"enableNonSslPort":false,"redisConfiguration":{"maxclients":"256","maxmemory-reserved":"2","maxfragmentationmemory-reserved":"12","maxmemory-delta":"2"},"accessKeys":null,"hostName":"cli000002.redis.cache.windows.net","port":6379,"sslPort":6380}}]}'} + headers: + cache-control: [no-cache] + content-length: ['691'] + content-type: [application/json; charset=utf-8] + date: ['Mon, 10 Apr 2017 23:14:50 GMT'] + expires: ['-1'] + pragma: [no-cache] + server: [Microsoft-HTTPAPI/2.0] + strict-transport-security: [max-age=31536000; includeSubDomains] + transfer-encoding: [chunked] + vary: [Accept-Encoding] + x-rp-server-mvid: [7c53f2fa-3f55-4e40-bab5-9c22bd480fa7] + status: {code: 200, message: OK} +- request: + body: null + headers: + Accept: [application/json] + Accept-Encoding: ['gzip, deflate'] + CommandName: [redis list-keys] + Connection: [keep-alive] + Content-Length: ['0'] + Content-Type: [application/json; charset=utf-8] + User-Agent: [python/3.6.1 (Windows-10-10.0.14393-SP0) requests/2.9.1 msrest/0.4.7 + msrest_azure/0.4.7 redismanagementclient/1.0.0 Azure-SDK-For-Python AZURECLI/2.0.2+dev] + accept-language: [en-US] + method: POST + uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/clitest.rg000001/providers/Microsoft.Cache/Redis/cli000002/listKeys?api-version=2016-04-01 + response: + body: {string: '{"primaryKey":"sigfIJwLK3x5mKBM+FVVW3prFyhT31tWsuSs1nEzHUY=","secondaryKey":"MIYVlv+BCA29Y96iiLHI2yJkY86DmvPUp2EucJIMYpg="}'} + headers: + cache-control: [no-cache] + content-length: ['123'] + content-type: [application/json; charset=utf-8] + date: ['Mon, 10 Apr 2017 23:14:51 GMT'] + expires: ['-1'] + pragma: [no-cache] + server: [Microsoft-HTTPAPI/2.0] + strict-transport-security: [max-age=31536000; includeSubDomains] + transfer-encoding: [chunked] + vary: [Accept-Encoding] + x-ms-ratelimit-remaining-subscription-writes: ['1197'] + x-rp-server-mvid: [7c53f2fa-3f55-4e40-bab5-9c22bd480fa7] + status: {code: 200, message: OK} +- request: + body: null + headers: + Accept: [application/json] + Accept-Encoding: ['gzip, deflate'] + CommandName: [group delete] + Connection: [keep-alive] + Content-Length: ['0'] + Content-Type: [application/json; charset=utf-8] + User-Agent: [python/3.6.1 (Windows-10-10.0.14393-SP0) requests/2.9.1 msrest/0.4.7 + msrest_azure/0.4.7 resourcemanagementclient/0.30.2 Azure-SDK-For-Python + AZURECLI/2.0.2+dev] + accept-language: [en-US] + method: DELETE + uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/clitest.rg000001?api-version=2016-09-01 + response: + body: {string: ''} + headers: + cache-control: [no-cache] + content-length: ['0'] + date: ['Mon, 10 Apr 2017 23:14:52 GMT'] + expires: ['-1'] + location: ['https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/operationresults/eyJqb2JJZCI6IlJFU09VUkNFR1JPVVBERUxFVElPTkpPQi1DTElURVNUOjJFUkcwQzVGMDMzNUJBODk1OUZGMzdCRUM1OThEMTYzNjBDRkE2OHw3MDQ4MDA1MUMzQTQ5NjE2LVdFU1RVUyIsImpvYkxvY2F0aW9uIjoid2VzdHVzIn0?api-version=2016-09-01'] + pragma: [no-cache] + retry-after: ['15'] + strict-transport-security: [max-age=31536000; includeSubDomains] + x-ms-ratelimit-remaining-subscription-writes: ['1198'] + status: {code: 202, message: Accepted} +version: 1 diff --git a/src/command_modules/azure-cli-redis/tests/test_redis_scenario.py b/src/command_modules/azure-cli-redis/tests/test_redis_scenario.py new file mode 100644 index 00000000000..77db9c49180 --- /dev/null +++ b/src/command_modules/azure-cli-redis/tests/test_redis_scenario.py @@ -0,0 +1,14 @@ +from azure.cli.testsdk import ScenarioTest, JMESPathCheck, ResourceGroupPreparer + +class RedisCacheTests(ScenarioTest): + @ResourceGroupPreparer() + def test_create_redis_cache(self, resource_group): + name = self.create_random_name(prefix='cli', length=24) + self.cmd('az redis create -n {} -g {} -l {} --sku-name {} --sku-family {} --sku-capacity {}'.format( + name, resource_group, 'WestUS', 'Basic','C','0')) + self.cmd('az redis show -n {} -g {}'.format(name, resource_group), checks=[ + JMESPathCheck('name', name), + JMESPathCheck('provisioningState', 'Creating') + ]) + self.cmd('az redis list -g {}'.format(resource_group)) + self.cmd('az redis list-keys -n {} -g {}'.format(name, resource_group)) From e9e91e7b5565798f4794be9eaedd3cd39713c479 Mon Sep 17 00:00:00 2001 From: Alfan Date: Mon, 10 Apr 2017 17:10:50 -0700 Subject: [PATCH 3/7] fixing test failures --- .../azure/cli/command_modules/redis/custom.py | 4 ++-- .../azure-cli-redis/tests/test_redis_scenario.py | 5 +++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/command_modules/azure-cli-redis/azure/cli/command_modules/redis/custom.py b/src/command_modules/azure-cli-redis/azure/cli/command_modules/redis/custom.py index 3b8b0841307..f5d7d249fa5 100644 --- a/src/command_modules/azure-cli-redis/azure/cli/command_modules/redis/custom.py +++ b/src/command_modules/azure-cli-redis/azure/cli/command_modules/redis/custom.py @@ -19,7 +19,7 @@ def cli_redis_import_method(client, resource_group_name, name, file_format, file parameters = ImportRDBParameters(files, file_format) return client.import_method(resource_group_name, name, files, parameters) -def cli_redis_update_settings(client, resource_group_name, name, redis_configuration = None, sku_name = None, sku_family = None, sku_capacity = None): +def cli_redis_update_settings(client, resource_group_name, name, redis_configuration=None, sku_name=None, sku_family=None, sku_capacity=None): if sku_name != None or sku_family != None or sku_capacity != None: if sku_name is None or sku_family is None or sku_capacity is None: raise ValueError("All arguments for Sku : --sku-name,--sku-family and --sku-capacity must be provided. Please add -h to the command to see supported values") @@ -28,7 +28,7 @@ def cli_redis_update_settings(client, resource_group_name, name, redis_configura if redis_configuration != None: existing.redis_configuration.update(redis_configuration) - if sku_name != None and sku_family != None and sku_capacity != None : + if sku_name != None and sku_family != None and sku_capacity != None: existing.sku = Sku(sku_name, sku_family, sku_capacity) # Due to swagger/mgmt SDK quirkiness, we have to manually copy over diff --git a/src/command_modules/azure-cli-redis/tests/test_redis_scenario.py b/src/command_modules/azure-cli-redis/tests/test_redis_scenario.py index 77db9c49180..2fc330ba3d7 100644 --- a/src/command_modules/azure-cli-redis/tests/test_redis_scenario.py +++ b/src/command_modules/azure-cli-redis/tests/test_redis_scenario.py @@ -1,3 +1,8 @@ +# -------------------------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for license information. +# -------------------------------------------------------------------------------------------- + from azure.cli.testsdk import ScenarioTest, JMESPathCheck, ResourceGroupPreparer class RedisCacheTests(ScenarioTest): From 3fea8297069cfc1420d9723afe53b5f0883834e3 Mon Sep 17 00:00:00 2001 From: Alfan Date: Tue, 11 Apr 2017 11:10:51 -0700 Subject: [PATCH 4/7] fixing build errors --- .../azure/cli/command_modules/redis/custom.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/command_modules/azure-cli-redis/azure/cli/command_modules/redis/custom.py b/src/command_modules/azure-cli-redis/azure/cli/command_modules/redis/custom.py index f5d7d249fa5..554060626a2 100644 --- a/src/command_modules/azure-cli-redis/azure/cli/command_modules/redis/custom.py +++ b/src/command_modules/azure-cli-redis/azure/cli/command_modules/redis/custom.py @@ -19,9 +19,11 @@ def cli_redis_import_method(client, resource_group_name, name, file_format, file parameters = ImportRDBParameters(files, file_format) return client.import_method(resource_group_name, name, files, parameters) -def cli_redis_update_settings(client, resource_group_name, name, redis_configuration=None, sku_name=None, sku_family=None, sku_capacity=None): +def cli_redis_update_settings(client, resource_group_name, name, redis_configuration=None, # pylint:disable=too-many-arguments + sku_name=None, sku_family=None, sku_capacity=None): if sku_name != None or sku_family != None or sku_capacity != None: if sku_name is None or sku_family is None or sku_capacity is None: + # pylint:disable=line-too-long raise ValueError("All arguments for Sku : --sku-name,--sku-family and --sku-capacity must be provided. Please add -h to the command to see supported values") existing = client.get(resource_group_name, name) @@ -30,7 +32,7 @@ def cli_redis_update_settings(client, resource_group_name, name, redis_configura if sku_name != None and sku_family != None and sku_capacity != None: existing.sku = Sku(sku_name, sku_family, sku_capacity) - + # Due to swagger/mgmt SDK quirkiness, we have to manually copy over # the resource retrieved to a create_or_update_parameters object update_params = RedisCreateOrUpdateParameters( From 34d64e8a54d52569a0e53e946ef1fc111e9aa5ad Mon Sep 17 00:00:00 2001 From: Alfan Date: Thu, 13 Apr 2017 10:41:26 -0700 Subject: [PATCH 5/7] removing sku-capacity and sku-family and adding vm-size as variable. Adding 'getting deprecated' message for update-settings command --- .../azure-cli-redis/HISTORY.rst | 3 +- .../azure/cli/command_modules/redis/_help.py | 7 +++ .../cli/command_modules/redis/_params.py | 26 +++++++--- .../cli/command_modules/redis/commands.py | 3 ++ .../azure/cli/command_modules/redis/custom.py | 52 ++++++++++++------- .../recordings/test_create_redis_cache.yaml | 30 +++++------ .../tests/test_redis_params.py | 7 ++- .../tests/test_redis_scenario.py | 4 +- 8 files changed, 85 insertions(+), 47 deletions(-) diff --git a/src/command_modules/azure-cli-redis/HISTORY.rst b/src/command_modules/azure-cli-redis/HISTORY.rst index 683f7e5347a..6c552594929 100644 --- a/src/command_modules/azure-cli-redis/HISTORY.rst +++ b/src/command_modules/azure-cli-redis/HISTORY.rst @@ -3,7 +3,8 @@ Release History =============== -* Adding ability to scale for redis cache +* Adding update command which also adds the ability to scale for redis cache +* Adding 'getting deprecated' message for update-settings command 0.1.1b3 (2017-02-22) ++++++++++++++++++++ diff --git a/src/command_modules/azure-cli-redis/azure/cli/command_modules/redis/_help.py b/src/command_modules/azure-cli-redis/azure/cli/command_modules/redis/_help.py index b2904890f3d..bb03371881f 100644 --- a/src/command_modules/azure-cli-redis/azure/cli/command_modules/redis/_help.py +++ b/src/command_modules/azure-cli-redis/azure/cli/command_modules/redis/_help.py @@ -26,6 +26,13 @@ helps['redis update-settings'] = """ type: command short-summary: Update the settings of a redis cache. + long-summary: | + WARNING: This command is being deprecated. Please use 'update' command +""" + +helps['redis update'] = """ + type: command + short-summary: Scale or update settings of a redis cache """ helps['redis patch-schedule'] = """ diff --git a/src/command_modules/azure-cli-redis/azure/cli/command_modules/redis/_params.py b/src/command_modules/azure-cli-redis/azure/cli/command_modules/redis/_params.py index 87b53676e6f..359c476bbbd 100644 --- a/src/command_modules/azure-cli-redis/azure/cli/command_modules/redis/_params.py +++ b/src/command_modules/azure-cli-redis/azure/cli/command_modules/redis/_params.py @@ -4,6 +4,7 @@ # -------------------------------------------------------------------------------------------- # pylint: disable=line-too-long +from enum import Enum from azure.cli.core.commands.parameters import ( get_resource_name_completion_list, enum_choice_list, @@ -14,7 +15,6 @@ from azure.mgmt.redis.models.redis_management_client_enums import ( RebootType, RedisKeyType, - SkuFamily, SkuName) from azure.mgmt.redis.models import ( @@ -32,6 +32,19 @@ def __init__(self, value): dictval = shell_safe_json_parse(value) self.update(dictval) +class VmSize(Enum): + C0 = 'C0' + C1 = 'C1' + C2 = 'C2' + C3 = 'C3' + C4 = 'C4' + C5 = 'C5' + C6 = 'C6' + P1 = 'P1' + P2 = 'P2' + P3 = 'P3' + P4 = 'P4' + class ScheduleEntryList(list): def __init__(self, value): super(ScheduleEntryList, self).__init__() @@ -51,16 +64,15 @@ def __init__(self, value): register_cli_argument('redis', 'reboot_type', **enum_choice_list(RebootType)) register_cli_argument('redis', 'key_type', **enum_choice_list(RedisKeyType)) register_cli_argument('redis', 'shard_id', type=int) -register_cli_argument('redis', 'sku_name', **enum_choice_list(SkuName)) -register_cli_argument('redis', 'sku_family', **enum_choice_list(SkuFamily)) -register_cli_argument('redis', 'sku_capacity', choices=[str(n) for n in range(0, 7)]) +register_cli_argument('redis', 'sku', **enum_choice_list(SkuName)) +register_cli_argument('redis', 'vm_size', **enum_choice_list(VmSize)) +register_cli_argument('redis', 'enable_non_ssl_port', action='store_true') +register_cli_argument('redis', 'shard_count', type=int) +register_cli_argument('redis', 'subnet_id') # TODO: Create generic id completer similar to name register_cli_argument('redis import-method', 'files', nargs='+') register_cli_argument('redis patch-schedule set', 'schedule_entries', type=ScheduleEntryList) register_cli_argument('redis create', 'name', arg_type=name_type, completer=None) -register_cli_argument('redis create', 'enable_non_ssl_port', action='store_true') register_cli_argument('redis create', 'tenant_settings', type=JsonString) -register_cli_argument('redis create', 'shard_count', type=int) -register_cli_argument('redis create', 'subnet_id') # TODO: Create generic id completer similar to name diff --git a/src/command_modules/azure-cli-redis/azure/cli/command_modules/redis/commands.py b/src/command_modules/azure-cli-redis/azure/cli/command_modules/redis/commands.py index 4de213b4b99..716fa02cf24 100644 --- a/src/command_modules/azure-cli-redis/azure/cli/command_modules/redis/commands.py +++ b/src/command_modules/azure-cli-redis/azure/cli/command_modules/redis/commands.py @@ -6,6 +6,7 @@ #pylint: disable=line-too-long from azure.cli.core.commands import cli_command +from azure.cli.core.commands.arm import cli_generic_update_command from azure.cli.command_modules.redis._client_factory import (cf_redis, cf_patch_schedules) cli_command(__name__, 'redis create', 'azure.cli.command_modules.redis.custom#cli_redis_create', cf_redis) @@ -20,6 +21,8 @@ cli_command(__name__, 'redis show', 'azure.mgmt.redis.operations.redis_operations#RedisOperations.get', cf_redis) cli_command(__name__, 'redis update-settings', 'azure.cli.command_modules.redis.custom#cli_redis_update_settings', cf_redis) +cli_generic_update_command(__name__, 'redis update', 'azure.mgmt.redis.operations.redis_operations#RedisOperations.get', 'azure.mgmt.redis.operations.redis_operations#RedisOperations.create_or_update', cf_redis, custom_function_op='azure.cli.command_modules.redis.custom#cli_redis_update') + cli_command(__name__, 'redis patch-schedule set', 'azure.mgmt.redis.operations.patch_schedules_operations#PatchSchedulesOperations.create_or_update', cf_patch_schedules) cli_command(__name__, 'redis patch-schedule delete', 'azure.mgmt.redis.operations.patch_schedules_operations#PatchSchedulesOperations.delete', cf_patch_schedules) cli_command(__name__, 'redis patch-schedule show', 'azure.mgmt.redis.operations.patch_schedules_operations#PatchSchedulesOperations.get', cf_patch_schedules) diff --git a/src/command_modules/azure-cli-redis/azure/cli/command_modules/redis/custom.py b/src/command_modules/azure-cli-redis/azure/cli/command_modules/redis/custom.py index 554060626a2..00aa7c7c30d 100644 --- a/src/command_modules/azure-cli-redis/azure/cli/command_modules/redis/custom.py +++ b/src/command_modules/azure-cli-redis/azure/cli/command_modules/redis/custom.py @@ -10,6 +10,9 @@ Sku, ) +import azure.cli.core.azlogging as azlogging +logger = azlogging.get_az_logger(__name__) + def cli_redis_export(client, resource_group_name, name, prefix, container, file_format=None): # pylint:disable=too-many-arguments parameters = ExportRDBParameters(prefix, container, file_format) @@ -19,19 +22,11 @@ def cli_redis_import_method(client, resource_group_name, name, file_format, file parameters = ImportRDBParameters(files, file_format) return client.import_method(resource_group_name, name, files, parameters) -def cli_redis_update_settings(client, resource_group_name, name, redis_configuration=None, # pylint:disable=too-many-arguments - sku_name=None, sku_family=None, sku_capacity=None): - if sku_name != None or sku_family != None or sku_capacity != None: - if sku_name is None or sku_family is None or sku_capacity is None: - # pylint:disable=line-too-long - raise ValueError("All arguments for Sku : --sku-name,--sku-family and --sku-capacity must be provided. Please add -h to the command to see supported values") +def cli_redis_update_settings(client, resource_group_name, name, redis_configuration): + logger.warning('This command is getting deprecated. Please use "redis update" command') existing = client.get(resource_group_name, name) - if redis_configuration != None: - existing.redis_configuration.update(redis_configuration) - - if sku_name != None and sku_family != None and sku_capacity != None: - existing.sku = Sku(sku_name, sku_family, sku_capacity) + existing.redis_configuration.update(redis_configuration) # Due to swagger/mgmt SDK quirkiness, we have to manually copy over # the resource retrieved to a create_or_update_parameters object @@ -49,8 +44,31 @@ def cli_redis_update_settings(client, resource_group_name, name, redis_configura ) return client.create_or_update(resource_group_name, name, parameters=update_params) -def cli_redis_create(client, resource_group_name, name, location, sku_name, # pylint:disable=too-many-arguments - sku_family, sku_capacity, tags=None, redis_configuration=None, +def cli_redis_update(instance, sku=None, vm_size=None): + if sku != None: + instance.sku.name = sku + + if vm_size != None: + instance.sku.family = vm_size[0] + instance.sku.capacity = vm_size[1] + + update_params = RedisCreateOrUpdateParameters( + instance.location, + instance.sku, + instance.tags, + instance.redis_version, + instance.redis_configuration, + instance.enable_non_ssl_port, + instance.tenant_settings, + instance.shard_count, + instance.subnet_id, + instance.static_ip, + ) + + return update_params + +def cli_redis_create(client, resource_group_name, name, location, sku, # pylint:disable=too-many-arguments + vm_size, tags=None, redis_configuration=None, enable_non_ssl_port=None, tenant_settings=None, shard_count=None, subnet_id=None, static_ip=None): # pylint:disable=line-too-long @@ -58,9 +76,8 @@ def cli_redis_create(client, resource_group_name, name, location, sku_name, # py :param resource_group_name: Name of resource group :param name: Name of redis cache :param location: Location - :param sku_name: What type of redis cache to deploy. Valid values: (Basic, Standard, Premium). - :param sku_family: Which family to use. Valid values: (C, P). - :param sku_capacity: What size of redis cache to deploy. Valid values for C family (0, 1, 2, 3, 4, 5, 6), for P family (1, 2, 3, 4) + :param sku: What type of redis cache to deploy. Valid values: (Basic, Standard, Premium). + :param vm_size: What size of redis cache to deploy. Valid values for C family (C0, C1, C2, C3, C4, C5, C6), for P family (P1, P2, P3, P4) :param redis_configuration: All Redis Settings. Few possible keys rdb-backup-enabled, rdb-storage-connection-string, rdb-backup-frequency, maxmemory-delta, maxmemory-policy, notify-keyspace-events, maxmemory-samples, slowlog-log-slower-than, slowlog-max-len, list-max-ziplist-entries, list-max-ziplist-value, hash-max-ziplist-entries, hash-max-ziplist-value, set-max-intset-entries, zset-max-ziplist-entries, zset-max-ziplist-value etc. :param enable_non_ssl_port: If the value is true, then the non-ssl redis server port (6379) will be enabled. :param tenant_settings: Json dictionary with tenant settings @@ -70,7 +87,7 @@ def cli_redis_create(client, resource_group_name, name, location, sku_name, # py """ params = RedisCreateOrUpdateParameters( location, - Sku(sku_name, sku_family, sku_capacity), + Sku(sku, vm_size[0], vm_size[1]), tags, None, # Version is deprecated and ignored redis_configuration, @@ -81,4 +98,3 @@ def cli_redis_create(client, resource_group_name, name, location, sku_name, # py static_ip) return client.create_or_update(resource_group_name, name, params) - diff --git a/src/command_modules/azure-cli-redis/tests/recordings/test_create_redis_cache.yaml b/src/command_modules/azure-cli-redis/tests/recordings/test_create_redis_cache.yaml index 342e992ceaf..67f0c89168a 100644 --- a/src/command_modules/azure-cli-redis/tests/recordings/test_create_redis_cache.yaml +++ b/src/command_modules/azure-cli-redis/tests/recordings/test_create_redis_cache.yaml @@ -20,7 +20,7 @@ interactions: cache-control: [no-cache] content-length: ['326'] content-type: [application/json; charset=utf-8] - date: ['Mon, 10 Apr 2017 23:14:47 GMT'] + date: ['Thu, 13 Apr 2017 17:18:10 GMT'] expires: ['-1'] pragma: [no-cache] strict-transport-security: [max-age=31536000; includeSubDomains] @@ -43,19 +43,19 @@ interactions: uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/clitest.rg000001/providers/Microsoft.Cache/Redis/cli000002?api-version=2016-04-01 response: body: {string: '{"id":"/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/clitest.rg000001/providers/Microsoft.Cache/Redis/cli000002","location":"West - US","name":"cli000002","type":"Microsoft.Cache/Redis","tags":{},"properties":{"provisioningState":"Creating","redisVersion":"3.2","sku":{"name":"Basic","family":"C","capacity":0},"enableNonSslPort":false,"redisConfiguration":{"maxclients":"256","maxmemory-reserved":"2","maxfragmentationmemory-reserved":"12","maxmemory-delta":"2"},"accessKeys":{"primaryKey":"sigfIJwLK3x5mKBM+FVVW3prFyhT31tWsuSs1nEzHUY=","secondaryKey":"MIYVlv+BCA29Y96iiLHI2yJkY86DmvPUp2EucJIMYpg="},"hostName":"cli000002.redis.cache.windows.net","port":6379,"sslPort":6380}}'} + US","name":"cli000002","type":"Microsoft.Cache/Redis","tags":{},"properties":{"provisioningState":"Creating","redisVersion":"3.2","sku":{"name":"Basic","family":"C","capacity":0},"enableNonSslPort":false,"redisConfiguration":{"maxclients":"256","maxmemory-reserved":"2","maxfragmentationmemory-reserved":"12","maxmemory-delta":"2"},"accessKeys":{"primaryKey":"lr7S+XpwKd7wmVgX60N9Ajz6RNPTf+0VlsPNaWXKUYY=","secondaryKey":"lakNGov3L8Ki919D/yxR1ATPCEl6TlQON5iaeqO4Eaw="},"hostName":"cli000002.redis.cache.windows.net","port":6379,"sslPort":6380}}'} headers: cache-control: [no-cache] content-length: ['798'] content-type: [application/json; charset=utf-8] - date: ['Mon, 10 Apr 2017 23:14:49 GMT'] + date: ['Thu, 13 Apr 2017 17:18:13 GMT'] expires: ['-1'] location: ['https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/clitest.rg000001/providers/Microsoft.Cache/redis/cli000002?api-version=2016-04-01'] pragma: [no-cache] server: [Microsoft-HTTPAPI/2.0] strict-transport-security: [max-age=31536000; includeSubDomains] x-ms-ratelimit-remaining-subscription-writes: ['1199'] - x-rp-server-mvid: [7c53f2fa-3f55-4e40-bab5-9c22bd480fa7] + x-rp-server-mvid: [5a0a88c0-0183-48c7-85e3-df64396b7fab] status: {code: 201, message: Created} - request: body: null @@ -77,14 +77,14 @@ interactions: cache-control: [no-cache] content-length: ['679'] content-type: [application/json; charset=utf-8] - date: ['Mon, 10 Apr 2017 23:14:50 GMT'] + date: ['Thu, 13 Apr 2017 17:18:14 GMT'] expires: ['-1'] pragma: [no-cache] server: [Microsoft-HTTPAPI/2.0] strict-transport-security: [max-age=31536000; includeSubDomains] transfer-encoding: [chunked] vary: [Accept-Encoding] - x-rp-server-mvid: [7c53f2fa-3f55-4e40-bab5-9c22bd480fa7] + x-rp-server-mvid: [5a0a88c0-0183-48c7-85e3-df64396b7fab] status: {code: 200, message: OK} - request: body: null @@ -106,14 +106,14 @@ interactions: cache-control: [no-cache] content-length: ['691'] content-type: [application/json; charset=utf-8] - date: ['Mon, 10 Apr 2017 23:14:50 GMT'] + date: ['Thu, 13 Apr 2017 17:18:15 GMT'] expires: ['-1'] pragma: [no-cache] server: [Microsoft-HTTPAPI/2.0] strict-transport-security: [max-age=31536000; includeSubDomains] transfer-encoding: [chunked] vary: [Accept-Encoding] - x-rp-server-mvid: [7c53f2fa-3f55-4e40-bab5-9c22bd480fa7] + x-rp-server-mvid: [5a0a88c0-0183-48c7-85e3-df64396b7fab] status: {code: 200, message: OK} - request: body: null @@ -130,20 +130,20 @@ interactions: method: POST uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/clitest.rg000001/providers/Microsoft.Cache/Redis/cli000002/listKeys?api-version=2016-04-01 response: - body: {string: '{"primaryKey":"sigfIJwLK3x5mKBM+FVVW3prFyhT31tWsuSs1nEzHUY=","secondaryKey":"MIYVlv+BCA29Y96iiLHI2yJkY86DmvPUp2EucJIMYpg="}'} + body: {string: '{"primaryKey":"lr7S+XpwKd7wmVgX60N9Ajz6RNPTf+0VlsPNaWXKUYY=","secondaryKey":"lakNGov3L8Ki919D/yxR1ATPCEl6TlQON5iaeqO4Eaw="}'} headers: cache-control: [no-cache] content-length: ['123'] content-type: [application/json; charset=utf-8] - date: ['Mon, 10 Apr 2017 23:14:51 GMT'] + date: ['Thu, 13 Apr 2017 17:18:17 GMT'] expires: ['-1'] pragma: [no-cache] server: [Microsoft-HTTPAPI/2.0] strict-transport-security: [max-age=31536000; includeSubDomains] transfer-encoding: [chunked] vary: [Accept-Encoding] - x-ms-ratelimit-remaining-subscription-writes: ['1197'] - x-rp-server-mvid: [7c53f2fa-3f55-4e40-bab5-9c22bd480fa7] + x-ms-ratelimit-remaining-subscription-writes: ['1199'] + x-rp-server-mvid: [5a0a88c0-0183-48c7-85e3-df64396b7fab] status: {code: 200, message: OK} - request: body: null @@ -165,12 +165,12 @@ interactions: headers: cache-control: [no-cache] content-length: ['0'] - date: ['Mon, 10 Apr 2017 23:14:52 GMT'] + date: ['Thu, 13 Apr 2017 17:18:18 GMT'] expires: ['-1'] - location: ['https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/operationresults/eyJqb2JJZCI6IlJFU09VUkNFR1JPVVBERUxFVElPTkpPQi1DTElURVNUOjJFUkcwQzVGMDMzNUJBODk1OUZGMzdCRUM1OThEMTYzNjBDRkE2OHw3MDQ4MDA1MUMzQTQ5NjE2LVdFU1RVUyIsImpvYkxvY2F0aW9uIjoid2VzdHVzIn0?api-version=2016-09-01'] + location: ['https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/operationresults/eyJqb2JJZCI6IlJFU09VUkNFR1JPVVBERUxFVElPTkpPQi1DTElURVNUOjJFUkc0NjQ5Qzc5M0FDODdGQzFGNkJENEQzRjRCNEQ4RENGODBEQ3w1Njg3QUMzOEYxM0I3RjBDLVdFU1RVUyIsImpvYkxvY2F0aW9uIjoid2VzdHVzIn0?api-version=2016-09-01'] pragma: [no-cache] retry-after: ['15'] strict-transport-security: [max-age=31536000; includeSubDomains] - x-ms-ratelimit-remaining-subscription-writes: ['1198'] + x-ms-ratelimit-remaining-subscription-writes: ['1199'] status: {code: 202, message: Accepted} version: 1 diff --git a/src/command_modules/azure-cli-redis/tests/test_redis_params.py b/src/command_modules/azure-cli-redis/tests/test_redis_params.py index 5dec26d9ad0..997bf299d42 100644 --- a/src/command_modules/azure-cli-redis/tests/test_redis_params.py +++ b/src/command_modules/azure-cli-redis/tests/test_redis_params.py @@ -28,11 +28,10 @@ def setUpClass(cls): def test_parse_redis_create(self): args = mock_echo_args('redis create', - '--tenant-settings {\"hello\":1} -g wombat -n asldkj --sku-family c -l westus --sku-capacity 1 --sku-name basic') # pylint: disable=line-too-long + '--tenant-settings {\"hello\":1} -g wombat -n asldkj -l westus --sku basic --vm-size C1 ') # pylint: disable=line-too-long subset = set(dict( - sku_family='C', - sku_capacity='1', - sku_name='Basic', + vm_size='C1', + sku='Basic', name='asldkj' ).items()) diff --git a/src/command_modules/azure-cli-redis/tests/test_redis_scenario.py b/src/command_modules/azure-cli-redis/tests/test_redis_scenario.py index 2fc330ba3d7..341b01bb922 100644 --- a/src/command_modules/azure-cli-redis/tests/test_redis_scenario.py +++ b/src/command_modules/azure-cli-redis/tests/test_redis_scenario.py @@ -9,8 +9,8 @@ class RedisCacheTests(ScenarioTest): @ResourceGroupPreparer() def test_create_redis_cache(self, resource_group): name = self.create_random_name(prefix='cli', length=24) - self.cmd('az redis create -n {} -g {} -l {} --sku-name {} --sku-family {} --sku-capacity {}'.format( - name, resource_group, 'WestUS', 'Basic','C','0')) + self.cmd('az redis create -n {} -g {} -l {} --sku {} --vm-size {}'.format( + name, resource_group, 'WestUS', 'Basic','C0')) self.cmd('az redis show -n {} -g {}'.format(name, resource_group), checks=[ JMESPathCheck('name', name), JMESPathCheck('provisioningState', 'Creating') From ff25e142b02cfb9ec5efaf91afb925a9d8887bdf Mon Sep 17 00:00:00 2001 From: Alfan Date: Thu, 13 Apr 2017 12:47:50 -0700 Subject: [PATCH 6/7] fixing build --- .../azure-cli-redis/azure/cli/command_modules/redis/_params.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/command_modules/azure-cli-redis/azure/cli/command_modules/redis/_params.py b/src/command_modules/azure-cli-redis/azure/cli/command_modules/redis/_params.py index 359c476bbbd..441206d1c07 100644 --- a/src/command_modules/azure-cli-redis/azure/cli/command_modules/redis/_params.py +++ b/src/command_modules/azure-cli-redis/azure/cli/command_modules/redis/_params.py @@ -32,7 +32,7 @@ def __init__(self, value): dictval = shell_safe_json_parse(value) self.update(dictval) -class VmSize(Enum): +class VmSize(Enum): # pylint: disable=too-few-public-methods C0 = 'C0' C1 = 'C1' C2 = 'C2' From 73dec9d9dc3f3d0d0be004a02ca089e5d4504b8e Mon Sep 17 00:00:00 2001 From: Alfan Date: Fri, 14 Apr 2017 16:52:41 -0700 Subject: [PATCH 7/7] incorporating CR comments --- .../azure-cli-redis/HISTORY.rst | 2 +- .../azure/cli/command_modules/redis/_help.py | 2 +- .../azure/cli/command_modules/redis/_params.py | 18 ++---------------- .../cli/command_modules/redis/commands.py | 4 +++- .../azure/cli/command_modules/redis/custom.py | 18 +++++++++++++++--- .../azure-cli-redis/tests/test_redis_params.py | 3 +-- 6 files changed, 23 insertions(+), 24 deletions(-) diff --git a/src/command_modules/azure-cli-redis/HISTORY.rst b/src/command_modules/azure-cli-redis/HISTORY.rst index 6c552594929..6dd99a374f4 100644 --- a/src/command_modules/azure-cli-redis/HISTORY.rst +++ b/src/command_modules/azure-cli-redis/HISTORY.rst @@ -4,7 +4,7 @@ Release History =============== * Adding update command which also adds the ability to scale for redis cache -* Adding 'getting deprecated' message for update-settings command +* Deprecates the 'update-settings' command. 0.1.1b3 (2017-02-22) ++++++++++++++++++++ diff --git a/src/command_modules/azure-cli-redis/azure/cli/command_modules/redis/_help.py b/src/command_modules/azure-cli-redis/azure/cli/command_modules/redis/_help.py index bb03371881f..e11d723e522 100644 --- a/src/command_modules/azure-cli-redis/azure/cli/command_modules/redis/_help.py +++ b/src/command_modules/azure-cli-redis/azure/cli/command_modules/redis/_help.py @@ -25,7 +25,7 @@ helps['redis update-settings'] = """ type: command - short-summary: Update the settings of a redis cache. + short-summary: (DEPRECATED) Update the settings of a redis cache. long-summary: | WARNING: This command is being deprecated. Please use 'update' command """ diff --git a/src/command_modules/azure-cli-redis/azure/cli/command_modules/redis/_params.py b/src/command_modules/azure-cli-redis/azure/cli/command_modules/redis/_params.py index 441206d1c07..e96a6ba1477 100644 --- a/src/command_modules/azure-cli-redis/azure/cli/command_modules/redis/_params.py +++ b/src/command_modules/azure-cli-redis/azure/cli/command_modules/redis/_params.py @@ -4,7 +4,6 @@ # -------------------------------------------------------------------------------------------- # pylint: disable=line-too-long -from enum import Enum from azure.cli.core.commands.parameters import ( get_resource_name_completion_list, enum_choice_list, @@ -32,19 +31,6 @@ def __init__(self, value): dictval = shell_safe_json_parse(value) self.update(dictval) -class VmSize(Enum): # pylint: disable=too-few-public-methods - C0 = 'C0' - C1 = 'C1' - C2 = 'C2' - C3 = 'C3' - C4 = 'C4' - C5 = 'C5' - C6 = 'C6' - P1 = 'P1' - P2 = 'P2' - P3 = 'P3' - P4 = 'P4' - class ScheduleEntryList(list): def __init__(self, value): super(ScheduleEntryList, self).__init__() @@ -65,10 +51,10 @@ def __init__(self, value): register_cli_argument('redis', 'key_type', **enum_choice_list(RedisKeyType)) register_cli_argument('redis', 'shard_id', type=int) register_cli_argument('redis', 'sku', **enum_choice_list(SkuName)) -register_cli_argument('redis', 'vm_size', **enum_choice_list(VmSize)) +register_cli_argument('redis', 'vm_size', help='Size of redis cache to deploy. Example : values for C family (C0, C1, C2, C3, C4, C5, C6). For P family (P1, P2, P3, P4)') register_cli_argument('redis', 'enable_non_ssl_port', action='store_true') register_cli_argument('redis', 'shard_count', type=int) -register_cli_argument('redis', 'subnet_id') # TODO: Create generic id completer similar to name +register_cli_argument('redis', 'subnet_id') register_cli_argument('redis import-method', 'files', nargs='+') diff --git a/src/command_modules/azure-cli-redis/azure/cli/command_modules/redis/commands.py b/src/command_modules/azure-cli-redis/azure/cli/command_modules/redis/commands.py index 716fa02cf24..453f4d32c23 100644 --- a/src/command_modules/azure-cli-redis/azure/cli/command_modules/redis/commands.py +++ b/src/command_modules/azure-cli-redis/azure/cli/command_modules/redis/commands.py @@ -21,7 +21,9 @@ cli_command(__name__, 'redis show', 'azure.mgmt.redis.operations.redis_operations#RedisOperations.get', cf_redis) cli_command(__name__, 'redis update-settings', 'azure.cli.command_modules.redis.custom#cli_redis_update_settings', cf_redis) -cli_generic_update_command(__name__, 'redis update', 'azure.mgmt.redis.operations.redis_operations#RedisOperations.get', 'azure.mgmt.redis.operations.redis_operations#RedisOperations.create_or_update', cf_redis, custom_function_op='azure.cli.command_modules.redis.custom#cli_redis_update') +cli_generic_update_command(__name__, 'redis update', 'azure.mgmt.redis.operations.redis_operations#RedisOperations.get', + 'azure.mgmt.redis.operations.redis_operations#RedisOperations.create_or_update', + cf_redis, custom_function_op='azure.cli.command_modules.redis.custom#cli_redis_update') cli_command(__name__, 'redis patch-schedule set', 'azure.mgmt.redis.operations.patch_schedules_operations#PatchSchedulesOperations.create_or_update', cf_patch_schedules) cli_command(__name__, 'redis patch-schedule delete', 'azure.mgmt.redis.operations.patch_schedules_operations#PatchSchedulesOperations.delete', cf_patch_schedules) diff --git a/src/command_modules/azure-cli-redis/azure/cli/command_modules/redis/custom.py b/src/command_modules/azure-cli-redis/azure/cli/command_modules/redis/custom.py index 00aa7c7c30d..57100f96250 100644 --- a/src/command_modules/azure-cli-redis/azure/cli/command_modules/redis/custom.py +++ b/src/command_modules/azure-cli-redis/azure/cli/command_modules/redis/custom.py @@ -3,6 +3,9 @@ # Licensed under the MIT License. See License.txt in the project root for license information. # -------------------------------------------------------------------------------------------- +from msrest.exceptions import ClientException +from azure.cli.core.util import CLIError + from azure.mgmt.redis.models import ( ImportRDBParameters, ExportRDBParameters, @@ -50,7 +53,7 @@ def cli_redis_update(instance, sku=None, vm_size=None): if vm_size != None: instance.sku.family = vm_size[0] - instance.sku.capacity = vm_size[1] + instance.sku.capacity = vm_size[1:] update_params = RedisCreateOrUpdateParameters( instance.location, @@ -67,6 +70,12 @@ def cli_redis_update(instance, sku=None, vm_size=None): return update_params +def wrong_vmsize_argument_exception_handler(ex): + # pylint:disable=line-too-long + if ("The value of the parameter 'properties.sku.family/properties.sku.capacity' is invalid" in format(ex)) or ("The value of the parameter 'properties.sku.family' is invalid" in format(ex)): + raise CLIError('Invalid VM size. Example for Valid values: For C family (C0, C1, C2, C3, C4, C5, C6), for P family (P1, P2, P3, P4)') + raise ex + def cli_redis_create(client, resource_group_name, name, location, sku, # pylint:disable=too-many-arguments vm_size, tags=None, redis_configuration=None, enable_non_ssl_port=None, tenant_settings=None, shard_count=None, @@ -87,7 +96,7 @@ def cli_redis_create(client, resource_group_name, name, location, sku, # pylint: """ params = RedisCreateOrUpdateParameters( location, - Sku(sku, vm_size[0], vm_size[1]), + Sku(sku, vm_size[0], vm_size[1:]), tags, None, # Version is deprecated and ignored redis_configuration, @@ -97,4 +106,7 @@ def cli_redis_create(client, resource_group_name, name, location, sku, # pylint: subnet_id, static_ip) - return client.create_or_update(resource_group_name, name, params) + try: + return client.create_or_update(resource_group_name, name, params) + except ClientException as err: + wrong_vmsize_argument_exception_handler(err) diff --git a/src/command_modules/azure-cli-redis/tests/test_redis_params.py b/src/command_modules/azure-cli-redis/tests/test_redis_params.py index 997bf299d42..bf13420bcfe 100644 --- a/src/command_modules/azure-cli-redis/tests/test_redis_params.py +++ b/src/command_modules/azure-cli-redis/tests/test_redis_params.py @@ -27,8 +27,7 @@ def setUpClass(cls): def test_parse_redis_create(self): - args = mock_echo_args('redis create', - '--tenant-settings {\"hello\":1} -g wombat -n asldkj -l westus --sku basic --vm-size C1 ') # pylint: disable=line-too-long + args = mock_echo_args('redis create', '--tenant-settings {\"hello\":1} -g wombat -n asldkj -l westus --sku basic --vm-size C1 ') # pylint: disable=line-too-long subset = set(dict( vm_size='C1', sku='Basic',