Skip to content

Commit

Permalink
[RDBMS] Introduce MySQL georestore command and update validators (#19782
Browse files Browse the repository at this point in the history
)

* test recordings

* add server name checker for mysql and update tests

* georestore

* geo restore

* replica validator update

* style fixed

* firewall rule fix

* update helptext for mysql

* linter and style issue fixed

* Update _helptext_mysql.py

* Update test and help text

* update transformer and test recordings

* linter issue fixed

* uncomment tests

* Add firewall rule operation validation and update API to mysql GA API

* linter issue fixed
  • Loading branch information
DaeunYim authored Oct 22, 2021
1 parent e5d7876 commit ca0c491
Show file tree
Hide file tree
Showing 39 changed files with 81,361 additions and 27,837 deletions.
Empty file added eastus2.json
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -209,14 +209,16 @@ def _postgres_parse_list_skus(result, database_engine):

tiers_dict[tier_name] = tier_dict

return tiers_dict, single_az
return {'sku_info': tiers_dict,
'single_az': single_az}


def _mysql_parse_list_skus(result, database_engine):
result = _get_list_from_paged_response(result)
if not result:
raise InvalidArgumentValueError("No available SKUs in this location")
single_az = 'ZoneRedundant' not in result[0].supported_ha_mode
geo_paried_region = result[0].supported_geo_backup_regions

tiers = result[0].supported_flexible_server_editions
tiers_dict = {}
Expand All @@ -243,7 +245,10 @@ def _mysql_parse_list_skus(result, database_engine):
iops_dict[tier_name] = sku_iops_dict
tiers_dict[tier_name] = tier_dict

return tiers_dict, single_az, iops_dict
return {'sku_info': tiers_dict,
'single_az': single_az,
'iops_info': iops_dict,
'geo_paired_regions': geo_paried_region}


def _get_available_values(sku_info, argument, tier=None):
Expand Down
411 changes: 252 additions & 159 deletions src/azure-cli/azure/cli/command_modules/rdbms/_helptext_mysql.py

Large diffs are not rendered by default.

386 changes: 213 additions & 173 deletions src/azure-cli/azure/cli/command_modules/rdbms/_helptext_pg.py

Large diffs are not rendered by default.

28 changes: 25 additions & 3 deletions src/azure-cli/azure/cli/command_modules/rdbms/_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
resource_group_name_type,
get_three_state_flag)
from azure.cli.command_modules.rdbms.validators import configuration_value_validator, validate_subnet, \
tls_validator, public_access_validator, maintenance_window_validator, ip_address_validator, retention_validator
tls_validator, public_access_validator, maintenance_window_validator, ip_address_validator, \
retention_validator, firewall_rule_name_validator
from azure.cli.core.local_context import LocalContextAttribute, LocalContextAction

from .randomname.generate import generate_username
Expand Down Expand Up @@ -399,6 +400,12 @@ def _flexible_server_params(command_group):
help='The name or resource ID of the source server to restore from.'
)

geo_redundant_backup_arg_type = CLIArgumentType(
options_list=['--geo-redundant-backup'],
arg_type=get_enum_type(['Enabled', 'Disabled']),
help='Whether or not geo redundant backup is enabled.'
)

with self.argument_context('{} flexible-server'.format(command_group)) as c:
c.argument('resource_group_name', arg_type=resource_group_name_type)
c.argument('server_name', arg_type=server_name_arg_type)
Expand All @@ -421,6 +428,7 @@ def _flexible_server_params(command_group):
c.argument('auto_grow', default='Enabled', arg_type=auto_grow_arg_type)
c.argument('high_availability', arg_type=mysql_high_availability_arg_type, default="Disabled")
c.argument('backup_retention', default=7, arg_type=mysql_backup_retention_arg_type)
c.argument('geo_redundant_backup', default='Disabled', arg_type=geo_redundant_backup_arg_type)
c.argument('location', arg_type=get_location_type(self.cli_ctx))
c.argument('administrator_login', default=generate_username(), arg_type=administrator_login_arg_type)
c.argument('administrator_login_password', arg_type=administrator_login_password_arg_type)
Expand Down Expand Up @@ -453,6 +461,21 @@ def _flexible_server_params(command_group):
c.argument('public_access', options_list=['--public-access'], arg_type=get_enum_type(['Enabled', 'Disabled']),
help='Determines the public access. ')

with self.argument_context('{} flexible-server geo-restore'. format(command_group)) as c:
c.argument('location', arg_type=get_location_type(self.cli_ctx), required=True)
c.argument('sku_name', arg_type=sku_name_arg_type)
c.argument('source_server', arg_type=source_server_arg_type)
c.argument('vnet', arg_type=vnet_arg_type)
c.argument('vnet_address_prefix', arg_type=vnet_address_prefix_arg_type)
c.argument('subnet', arg_type=subnet_arg_type)
c.argument('subnet_address_prefix', arg_type=subnet_address_prefix_arg_type)
c.argument('private_dns_zone_arguments', private_dns_zone_arguments_arg_type)
c.argument('zone', arg_type=zone_arg_type)
c.argument('yes', arg_type=yes_arg_type)
if command_group == 'mysql':
c.argument('public_access', options_list=['--public-access'], arg_type=get_enum_type(['Enabled', 'Disabled']),
help='Determines the public access. ')

with self.argument_context('{} flexible-server update'.format(command_group)) as c:
c.argument('administrator_login_password', arg_type=administrator_login_password_arg_type)
c.argument('maintenance_window', options_list=['--maintenance-window'], validator=maintenance_window_validator,
Expand Down Expand Up @@ -518,7 +541,7 @@ def _flexible_server_params(command_group):
for scope in ['create', 'delete', 'show', 'update']:
argument_context_string = '{} flexible-server firewall-rule {}'.format(command_group, scope)
with self.argument_context(argument_context_string) as c:
c.argument('firewall_rule_name', id_part='child_name_1', options_list=['--rule-name', '-r'],
c.argument('firewall_rule_name', id_part='child_name_1', options_list=['--rule-name', '-r'], validator=firewall_rule_name_validator,
help='The name of the firewall rule. If name is omitted, default name will be chosen for firewall name. The firewall rule name can only contain 0-9, a-z, A-Z, \'-\' and \'_\'. Additionally, the firewall rule name cannot exceed 128 characters. ')
c.argument('end_ip_address', options_list=['--end-ip-address'], validator=ip_address_validator,
help='The end IP address of the firewall rule. Must be IPv4 format. Use value \'0.0.0.0\' to represent all Azure-internal IP addresses. ')
Expand All @@ -537,7 +560,6 @@ def _flexible_server_params(command_group):

with self.argument_context('{} flexible-server db list'.format(command_group)) as c:
c.argument('server_name', id_part=None, options_list=['--server-name', '-s'], arg_type=server_name_arg_type)
c.argument('database_name', id_part=None, arg_type=database_name_arg_type)

with self.argument_context('{} flexible-server db create'.format(command_group)) as c:
c.argument('charset', help='The charset of the database. The default value is UTF8')
Expand Down
24 changes: 22 additions & 2 deletions src/azure-cli/azure/cli/command_modules/rdbms/_transformers.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@ def table_transform_output_list_servers(result):
new_entry['Resource Group'] = key['resourceGroup']
new_entry['Location'] = key['location']
new_entry['Version'] = key['version']
new_entry['Storage Size(GiB)'] = int(key['storageProfile']['storageMb']) / 1024.0
new_entry['Storage Size(GiB)'] = int(key['storage']['storageSizeGb'])
new_entry['Tier'] = key['sku']['tier']
new_entry['SKU'] = key['sku']['name']

if 'flexibleServers' in result[0]['id']:
new_entry['State'] = key['state']
new_entry['HA State'] = key['haState']
new_entry['HA State'] = key['highAvailability']['state']
new_entry['Availability zone'] = key['availabilityZone']

table_result.append(new_entry)
Expand Down Expand Up @@ -100,3 +100,23 @@ def table_transform_output_list_skus_single_server(result):
raise CLIError("There is no sku available for this location.")

return table_result


def table_transform_output_parameters(result):

table_result = []

if not result:
return table_result

for key in result:
new_entry = OrderedDict()
new_entry['Name'] = key['name']
new_entry['DataType'] = key['dataType']
new_entry['DefaultValue'] = key['defaultValue']
new_entry['Source'] = key['source']
new_entry['AllowedValues'] = key['allowedValues']

table_result.append(new_entry)

return table_result
1 change: 1 addition & 0 deletions src/azure-cli/azure/cli/command_modules/rdbms/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -707,6 +707,7 @@ def server_ad_admin_set(client, resource_group_name, server_name, login=None, si
'''

parameters = {
'administratorType': 'ActiveDirectory',
'login': login,
'sid': sid,
'tenant_id': _get_tenant_id()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
from ._transformers import (
table_transform_output,
table_transform_output_list_servers,
table_transform_output_list_skus)
table_transform_output_list_skus,
table_transform_output_parameters)

# from .transformers import table_transform_connection_string
# from .validators import db_up_namespace_processor
Expand Down Expand Up @@ -119,8 +120,8 @@ def load_flexibleserver_command_table(self, _):
is_preview=True) as g:
g.custom_command('create', 'firewall_rule_create_func', custom_command_type=flexible_server_custom_common)
g.custom_command('delete', 'firewall_rule_delete_func', custom_command_type=flexible_server_custom_common)
g.show_command('show', 'get')
g.command('list', 'list_by_server')
g.custom_show_command('show', 'firewall_rule_get_func', custom_command_type=flexible_server_custom_common)
g.custom_command('list', 'firewall_rule_list_func', custom_command_type=flexible_server_custom_common)
g.generic_update_command('update',
getter_name='flexible_firewall_rule_custom_getter', getter_type=flexible_server_custom_common,
setter_name='flexible_firewall_rule_custom_setter', setter_type=flexible_server_custom_common,
Expand All @@ -141,7 +142,7 @@ def load_flexibleserver_command_table(self, _):

with self.command_group('postgres flexible-server parameter', postgres_flexible_config_sdk,
custom_command_type=flexible_servers_custom_postgres,
client_factory=cf_postgres_flexible_config,
client_factory=cf_postgres_flexible_config, table_transformer=table_transform_output_parameters,
is_preview=True) as g:
g.custom_command('set', 'flexible_parameter_update')
g.show_command('show', 'get')
Expand Down Expand Up @@ -177,6 +178,7 @@ def load_flexibleserver_command_table(self, _):
is_preview=True) as g:
g.custom_command('create', 'flexible_server_create', table_transformer=table_transform_output)
g.custom_command('restore', 'flexible_server_restore', supports_no_wait=True)
g.custom_command('geo-restore', 'flexible_server_georestore', supports_no_wait=True)
g.command('start', 'begin_start')
g.custom_command('stop', 'flexible_server_stop', custom_command_type=flexible_server_custom_common)
g.custom_command('delete', 'server_delete_func')
Expand All @@ -196,8 +198,8 @@ def load_flexibleserver_command_table(self, _):
is_preview=True) as g:
g.custom_command('create', 'firewall_rule_create_func', custom_command_type=flexible_server_custom_common)
g.custom_command('delete', 'firewall_rule_delete_func', custom_command_type=flexible_server_custom_common)
g.show_command('show', 'get')
g.command('list', 'list_by_server')
g.custom_show_command('show', 'firewall_rule_get_func', custom_command_type=flexible_server_custom_common)
g.custom_command('list', 'firewall_rule_list_func', custom_command_type=flexible_server_custom_common)
g.generic_update_command('update',
getter_name='flexible_firewall_rule_custom_getter', getter_type=flexible_server_custom_common,
setter_name='flexible_firewall_rule_custom_setter', setter_type=flexible_server_custom_common,
Expand All @@ -207,7 +209,7 @@ def load_flexibleserver_command_table(self, _):

with self.command_group('mysql flexible-server parameter', mysql_flexible_config_sdk,
custom_command_type=flexible_servers_custom_mysql,
client_factory=cf_mysql_flexible_config,
client_factory=cf_mysql_flexible_config, table_transformer=table_transform_output_parameters,
is_preview=True) as g:
g.custom_command('set', 'flexible_parameter_update')
g.show_command('show', 'get')
Expand Down
Loading

0 comments on commit ca0c491

Please sign in to comment.