Skip to content

Commit

Permalink
[Redisenterprise] Add cli code for redis enterprise 2022-01-01 (#4808)
Browse files Browse the repository at this point in the history
* Add cli generated code for 2022-01-01

* Fix previous manual tests

* Incomplete: tests (failing)

* Geo replicated database creation succeeding

* Force unlinking working

* Cleanup

* Cleanup

* Add recordings

* Linting

* Cleanup env

* Update version and release notes

* Make sure sku name is optional during patching

* Add note in examples

* Added lines after style check

* Update

Co-authored-by: Kanchan Joshi <[email protected]>
  • Loading branch information
koderjoker and Kanchan Joshi authored Jun 13, 2022
1 parent 61a2e64 commit 1f790be
Show file tree
Hide file tree
Showing 42 changed files with 8,241 additions and 1,554 deletions.
8 changes: 8 additions & 0 deletions src/redisenterprise/HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@
Release History
===============

0.1.2
++++++
- Added support for active georeplication
- Creating a georeplicated database
- Creating a cache with a georeplicated database
- Force unlinking databases
- Added support for importing from multiple blobs

0.1.1
++++++
* Renamed remaining snake_case command output fields to camelCase to be consistent with the REST API.
Expand Down
21 changes: 12 additions & 9 deletions src/redisenterprise/azext_redisenterprise/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,10 @@
# Changes may cause incorrect behavior and will be lost if the code is
# regenerated.
# --------------------------------------------------------------------------
# pylint: disable=unused-import

import azext_redisenterprise._help
from azure.cli.core import AzCommandsLoader
from azext_redisenterprise.generated._help import helps # pylint: disable=unused-import
try:
from azext_redisenterprise.manual._help import helps # pylint: disable=reimported
except ImportError:
pass


class RedisEnterpriseManagementClientCommandsLoader(AzCommandsLoader):
Expand All @@ -33,8 +30,11 @@ def load_command_table(self, args):
try:
from azext_redisenterprise.manual.commands import load_command_table as load_command_table_manual
load_command_table_manual(self, args)
except ImportError:
pass
except ImportError as e:
if e.name.endswith('manual.commands'):
pass
else:
raise e
return self.command_table

def load_arguments(self, command):
Expand All @@ -43,8 +43,11 @@ def load_arguments(self, command):
try:
from azext_redisenterprise.manual._params import load_arguments as load_arguments_manual
load_arguments_manual(self, command)
except ImportError:
pass
except ImportError as e:
if e.name.endswith('manual._params'):
pass
else:
raise e


COMMAND_LOADER_CLS = RedisEnterpriseManagementClientCommandsLoader
20 changes: 20 additions & 0 deletions src/redisenterprise/azext_redisenterprise/_help.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# --------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for
# license information.
#
# Code generated by Microsoft (R) AutoRest Code Generator.
# Changes may cause incorrect behavior and will be lost if the code is
# regenerated.
# --------------------------------------------------------------------------
# pylint: disable=wildcard-import
# pylint: disable=unused-wildcard-import
# pylint: disable=unused-import
from .generated._help import helps # pylint: disable=reimported
try:
from .manual._help import helps # pylint: disable=reimported
except ImportError as e:
if e.name.endswith('manual._help'):
pass
else:
raise e
7 changes: 5 additions & 2 deletions src/redisenterprise/azext_redisenterprise/action.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,8 @@
from .generated.action import * # noqa: F403
try:
from .manual.action import * # noqa: F403
except ImportError:
pass
except ImportError as e:
if e.name.endswith('manual.action'):
pass
else:
raise e
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
{
"azext.isPreview": true,
"azext.minCliCoreVersion": "2.15.0"
}
7 changes: 5 additions & 2 deletions src/redisenterprise/azext_redisenterprise/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,8 @@
from .generated.custom import * # noqa: F403
try:
from .manual.custom import * # noqa: F403
except ImportError:
pass
except ImportError as e:
if e.name.endswith('manual.custom'):
pass
else:
raise e
52 changes: 43 additions & 9 deletions src/redisenterprise/azext_redisenterprise/generated/_help.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@
from knack.help_files import helps


helps['redisenterprise'] = '''
type: group
short-summary: Manage Redis Enterprise
'''

helps['redisenterprise operation-status'] = """
type: group
short-summary: Manage operation status with redisenterprise
Expand All @@ -26,11 +31,6 @@
az redisenterprise operation-status show --operation-id "testoperationid" --location "West US"
"""

helps['redisenterprise'] = """
type: group
short-summary: Manage redis enterprise with redisenterprise
"""

helps['redisenterprise list'] = """
type: command
short-summary: "Lists all RedisEnterprise clusters in a resource group. And Gets all RedisEnterprise clusters in \
Expand Down Expand Up @@ -140,16 +140,31 @@
Usage: --modules name=XX args=XX
name: Required. The name of the module, e.g. 'RedisBloom', 'RediSearch', 'RedisTimeSeries'
args: Configuration options for the module, e.g. 'ERROR_RATE 0.00 INITIAL_SIZE 400'.
args: Configuration options for the module, e.g. 'ERROR_RATE 0.01 INITIAL_SIZE 400'.
Multiple actions can be specified by using more than one --modules argument.
- name: --linked-databases
short-summary: "List of database resources to link with this database"
long-summary: |
Usage: --linked-databases id=XX
id: Resource ID of a database resource to link with this database.
Multiple actions can be specified by using more than one --linked-databases argument.
examples:
- name: RedisEnterpriseDatabasesCreate
text: |-
az redisenterprise database create --cluster-name "cache1" --client-protocol "Encrypted" \
--clustering-policy "EnterpriseCluster" --eviction-policy "AllKeysLRU" --modules name="RedisBloom" args="ERROR_RATE \
0.00 INITIAL_SIZE 400" --modules name="RedisTimeSeries" args="RETENTION_POLICY 20" --modules name="RediSearch" \
--persistence aof-enabled=true aof-frequency="1s" --port 10000 --resource-group "rg1"
- name: RedisEnterpriseDatabasesCreate With Active Geo Replication
text: |-
az redisenterprise database create --cluster-name "cache1" --client-protocol "Encrypted" \
--clustering-policy "EnterpriseCluster" --eviction-policy "NoEviction" --group-nickname "groupName" --linked-databases \
id="/subscriptions/subid1/resourceGroups/rg1/providers/Microsoft.Cache/redisEnterprise/cache1/databases/default" \
--linked-databases id="/subscriptions/subid2/resourceGroups/rg2/providers/Microsoft.Cache/redisEnterprise/cache2/databa\
ses/default" --port 10000 --resource-group "rg1"
"""

helps['redisenterprise database update'] = """
Expand All @@ -165,6 +180,14 @@
rdb-enabled: Sets whether RDB is enabled.
aof-frequency: Sets the frequency at which data is written to disk.
rdb-frequency: Sets the frequency at which a snapshot of the database is created.
- name: --linked-databases
short-summary: "List of database resources to link with this database"
long-summary: |
Usage: --linked-databases id=XX
id: Resource ID of a database resource to link with this database.
Multiple actions can be specified by using more than one --linked-databases argument.
examples:
- name: RedisEnterpriseDatabasesUpdate
text: |-
Expand All @@ -191,14 +214,25 @@
indow.net/urlToBlobContainer?sasKeyParameters" --resource-group "rg1"
"""

helps['redisenterprise database force-unlink'] = """
type: command
short-summary: "Forcibly removes the link to the specified database resource."
examples:
- name: How to unlink a database during a regional outage
text: |-
az redisenterprise database force-unlink --cluster-name "cache1" --unlink-ids "/subscriptions/subid2/resourceGr\
oups/rg2/providers/Microsoft.Cache/redisEnterprise/cache2/databases/default" --resource-group "rg1"
"""

helps['redisenterprise database import'] = """
type: command
short-summary: "Imports a database file to target database."
short-summary: "Imports database files to target database."
examples:
- name: RedisEnterpriseDatabasesImport
text: |-
az redisenterprise database import --cluster-name "cache1" --sas-uri "https://contosostorage.blob.core.w\
indow.net/urltoBlobFile?sasKeyParameters" --resource-group "rg1"
az redisenterprise database import --cluster-name "cache1" --sas-uris "https://contosostorage.blob.core.\
window.net/urltoBlobFile1?sasKeyParameters" "https://contosostorage.blob.core.window.net/urltoBlobFile2?sasKeyParameter\
s" --resource-group "rg1"
"""

helps['redisenterprise database list-keys'] = """
Expand Down
19 changes: 17 additions & 2 deletions src/redisenterprise/azext_redisenterprise/generated/_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
from azure.cli.core.commands.validators import get_default_location_from_resource_group
from azext_redisenterprise.action import (
AddPersistence,
AddModules
AddModules,
AddLinkedDatabases
)


Expand Down Expand Up @@ -107,6 +108,10 @@ def load_arguments(self, _):
c.argument('persistence', action=AddPersistence, nargs='+', help='Persistence settings', is_preview=True)
c.argument('modules', action=AddModules, nargs='+', help='Optional set of redis modules to enable in this '
'database - modules can only be added at creation time.')
c.argument('group_nickname', type=str, help='Name for the group of linked database resources', arg_group='Geo '
'Replication')
c.argument('linked_databases', action=AddLinkedDatabases, nargs='+', help='List of database resources to link '
'with this database', arg_group='Geo Replication')

with self.argument_context('redisenterprise database update') as c:
c.argument('resource_group_name', resource_group_name_type)
Expand All @@ -120,6 +125,10 @@ def load_arguments(self, _):
'VolatileRandom', 'NoEviction']), help='Redis eviction '
'policy - default is VolatileLRU')
c.argument('persistence', action=AddPersistence, nargs='+', help='Persistence settings', is_preview=True)
c.argument('group_nickname', type=str, help='Name for the group of linked database resources', arg_group='Geo '
'Replication')
c.argument('linked_databases', action=AddLinkedDatabases, nargs='+', help='List of database resources to link '
'with this database', arg_group='Geo Replication')

with self.argument_context('redisenterprise database delete') as c:
c.argument('resource_group_name', resource_group_name_type)
Expand All @@ -132,11 +141,17 @@ def load_arguments(self, _):
'RedisEnterprise cluster.', id_part='name')
c.argument('sas_uri', type=str, help='SAS URI for the target directory to export to')

with self.argument_context('redisenterprise database force-unlink') as c:
c.argument('resource_group_name', resource_group_name_type)
c.argument('cluster_name', options_list=['--cluster-name', '--name', '-n'], type=str, help='The name of the '
'RedisEnterprise cluster.', id_part='name')
c.argument('unlink_ids', nargs='+', help='The resource IDs of the database resources to be unlinked.')

with self.argument_context('redisenterprise database import') as c:
c.argument('resource_group_name', resource_group_name_type)
c.argument('cluster_name', options_list=['--cluster-name', '--name', '-n'], type=str, help='The name of the '
'RedisEnterprise cluster.', id_part='name')
c.argument('sas_uri', type=str, help='SAS URI for the target blob to import from')
c.argument('sas_uris', nargs='+', help='SAS URIs for the target blobs to import from')

with self.argument_context('redisenterprise database list-keys') as c:
c.argument('resource_group_name', resource_group_name_type)
Expand Down
59 changes: 53 additions & 6 deletions src/redisenterprise/azext_redisenterprise/generated/action.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,13 @@
# Changes may cause incorrect behavior and will be lost if the code is
# regenerated.
# --------------------------------------------------------------------------


# pylint: disable=protected-access

# pylint: disable=no-self-use


import argparse
from collections import defaultdict
from knack.util import CLIError
Expand All @@ -19,7 +24,7 @@ def __call__(self, parser, namespace, values, option_string=None):
action = self.get_action(values, option_string)
namespace.persistence = action

def get_action(self, values, option_string): # pylint: disable=no-self-use
def get_action(self, values, option_string):
try:
properties = defaultdict(list)
for (k, v) in (x.split('=', 1) for x in values):
Expand All @@ -31,17 +36,25 @@ def get_action(self, values, option_string): # pylint: disable=no-self-use
for k in properties:
kl = k.lower()
v = properties[k]

if kl == 'aof-enabled':
d['aof_enabled'] = v[0]

elif kl == 'rdb-enabled':
d['rdb_enabled'] = v[0]

elif kl == 'aof-frequency':
d['aof_frequency'] = v[0]

elif kl == 'rdb-frequency':
d['rdb_frequency'] = v[0]

else:
raise CLIError('Unsupported Key {} is provided for parameter persistence. All possible keys are: '
'aof-enabled, rdb-enabled, aof-frequency, rdb-frequency'.format(k))
raise CLIError(
'Unsupported Key {} is provided for parameter persistence. All possible keys are: aof-enabled,'
' rdb-enabled, aof-frequency, rdb-frequency'.format(k)
)

return d


Expand All @@ -50,7 +63,7 @@ def __call__(self, parser, namespace, values, option_string=None):
action = self.get_action(values, option_string)
super(AddModules, self).__call__(parser, namespace, action, option_string)

def get_action(self, values, option_string): # pylint: disable=no-self-use
def get_action(self, values, option_string):
try:
properties = defaultdict(list)
for (k, v) in (x.split('=', 1) for x in values):
Expand All @@ -62,11 +75,45 @@ def get_action(self, values, option_string): # pylint: disable=no-self-use
for k in properties:
kl = k.lower()
v = properties[k]

if kl == 'name':
d['name'] = v[0]

elif kl == 'args':
d['args'] = v[0]

else:
raise CLIError('Unsupported Key {} is provided for parameter modules. All possible keys are: name, '
'args'.format(k))
raise CLIError(
'Unsupported Key {} is provided for parameter modules. All possible keys are: name, args'.format(k)
)

return d


class AddLinkedDatabases(argparse._AppendAction):
def __call__(self, parser, namespace, values, option_string=None):
action = self.get_action(values, option_string)
super(AddLinkedDatabases, self).__call__(parser, namespace, action, option_string)

def get_action(self, values, option_string):
try:
properties = defaultdict(list)
for (k, v) in (x.split('=', 1) for x in values):
properties[k].append(v)
properties = dict(properties)
except ValueError:
raise CLIError('usage error: {} [KEY=VALUE ...]'.format(option_string))
d = {}
for k in properties:
kl = k.lower()
v = properties[k]

if kl == 'id':
d['id'] = v[0]

else:
raise CLIError(
'Unsupported Key {} is provided for parameter linked-databases. All possible keys are: id'.format(k)
)

return d
Loading

0 comments on commit 1f790be

Please sign in to comment.