Skip to content

Commit ca0c491

Browse files
authored
[RDBMS] Introduce MySQL georestore command and update validators (Azure#19782)
* 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
1 parent e5d7876 commit ca0c491

File tree

39 files changed

+81361
-27837
lines changed

39 files changed

+81361
-27837
lines changed

eastus2.json

Whitespace-only changes.

src/azure-cli/azure/cli/command_modules/rdbms/_flexible_server_util.py

+7-2
Original file line numberDiff line numberDiff line change
@@ -209,14 +209,16 @@ def _postgres_parse_list_skus(result, database_engine):
209209

210210
tiers_dict[tier_name] = tier_dict
211211

212-
return tiers_dict, single_az
212+
return {'sku_info': tiers_dict,
213+
'single_az': single_az}
213214

214215

215216
def _mysql_parse_list_skus(result, database_engine):
216217
result = _get_list_from_paged_response(result)
217218
if not result:
218219
raise InvalidArgumentValueError("No available SKUs in this location")
219220
single_az = 'ZoneRedundant' not in result[0].supported_ha_mode
221+
geo_paried_region = result[0].supported_geo_backup_regions
220222

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

246-
return tiers_dict, single_az, iops_dict
248+
return {'sku_info': tiers_dict,
249+
'single_az': single_az,
250+
'iops_info': iops_dict,
251+
'geo_paired_regions': geo_paried_region}
247252

248253

249254
def _get_available_values(sku_info, argument, tier=None):

src/azure-cli/azure/cli/command_modules/rdbms/_helptext_mysql.py

+252-159
Large diffs are not rendered by default.

src/azure-cli/azure/cli/command_modules/rdbms/_helptext_pg.py

+213-173
Large diffs are not rendered by default.

src/azure-cli/azure/cli/command_modules/rdbms/_params.py

+25-3
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
resource_group_name_type,
1616
get_three_state_flag)
1717
from azure.cli.command_modules.rdbms.validators import configuration_value_validator, validate_subnet, \
18-
tls_validator, public_access_validator, maintenance_window_validator, ip_address_validator, retention_validator
18+
tls_validator, public_access_validator, maintenance_window_validator, ip_address_validator, \
19+
retention_validator, firewall_rule_name_validator
1920
from azure.cli.core.local_context import LocalContextAttribute, LocalContextAction
2021

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

403+
geo_redundant_backup_arg_type = CLIArgumentType(
404+
options_list=['--geo-redundant-backup'],
405+
arg_type=get_enum_type(['Enabled', 'Disabled']),
406+
help='Whether or not geo redundant backup is enabled.'
407+
)
408+
402409
with self.argument_context('{} flexible-server'.format(command_group)) as c:
403410
c.argument('resource_group_name', arg_type=resource_group_name_type)
404411
c.argument('server_name', arg_type=server_name_arg_type)
@@ -421,6 +428,7 @@ def _flexible_server_params(command_group):
421428
c.argument('auto_grow', default='Enabled', arg_type=auto_grow_arg_type)
422429
c.argument('high_availability', arg_type=mysql_high_availability_arg_type, default="Disabled")
423430
c.argument('backup_retention', default=7, arg_type=mysql_backup_retention_arg_type)
431+
c.argument('geo_redundant_backup', default='Disabled', arg_type=geo_redundant_backup_arg_type)
424432
c.argument('location', arg_type=get_location_type(self.cli_ctx))
425433
c.argument('administrator_login', default=generate_username(), arg_type=administrator_login_arg_type)
426434
c.argument('administrator_login_password', arg_type=administrator_login_password_arg_type)
@@ -453,6 +461,21 @@ def _flexible_server_params(command_group):
453461
c.argument('public_access', options_list=['--public-access'], arg_type=get_enum_type(['Enabled', 'Disabled']),
454462
help='Determines the public access. ')
455463

464+
with self.argument_context('{} flexible-server geo-restore'. format(command_group)) as c:
465+
c.argument('location', arg_type=get_location_type(self.cli_ctx), required=True)
466+
c.argument('sku_name', arg_type=sku_name_arg_type)
467+
c.argument('source_server', arg_type=source_server_arg_type)
468+
c.argument('vnet', arg_type=vnet_arg_type)
469+
c.argument('vnet_address_prefix', arg_type=vnet_address_prefix_arg_type)
470+
c.argument('subnet', arg_type=subnet_arg_type)
471+
c.argument('subnet_address_prefix', arg_type=subnet_address_prefix_arg_type)
472+
c.argument('private_dns_zone_arguments', private_dns_zone_arguments_arg_type)
473+
c.argument('zone', arg_type=zone_arg_type)
474+
c.argument('yes', arg_type=yes_arg_type)
475+
if command_group == 'mysql':
476+
c.argument('public_access', options_list=['--public-access'], arg_type=get_enum_type(['Enabled', 'Disabled']),
477+
help='Determines the public access. ')
478+
456479
with self.argument_context('{} flexible-server update'.format(command_group)) as c:
457480
c.argument('administrator_login_password', arg_type=administrator_login_password_arg_type)
458481
c.argument('maintenance_window', options_list=['--maintenance-window'], validator=maintenance_window_validator,
@@ -518,7 +541,7 @@ def _flexible_server_params(command_group):
518541
for scope in ['create', 'delete', 'show', 'update']:
519542
argument_context_string = '{} flexible-server firewall-rule {}'.format(command_group, scope)
520543
with self.argument_context(argument_context_string) as c:
521-
c.argument('firewall_rule_name', id_part='child_name_1', options_list=['--rule-name', '-r'],
544+
c.argument('firewall_rule_name', id_part='child_name_1', options_list=['--rule-name', '-r'], validator=firewall_rule_name_validator,
522545
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. ')
523546
c.argument('end_ip_address', options_list=['--end-ip-address'], validator=ip_address_validator,
524547
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. ')
@@ -537,7 +560,6 @@ def _flexible_server_params(command_group):
537560

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

542564
with self.argument_context('{} flexible-server db create'.format(command_group)) as c:
543565
c.argument('charset', help='The charset of the database. The default value is UTF8')

src/azure-cli/azure/cli/command_modules/rdbms/_transformers.py

+22-2
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,13 @@ def table_transform_output_list_servers(result):
3131
new_entry['Resource Group'] = key['resourceGroup']
3232
new_entry['Location'] = key['location']
3333
new_entry['Version'] = key['version']
34-
new_entry['Storage Size(GiB)'] = int(key['storageProfile']['storageMb']) / 1024.0
34+
new_entry['Storage Size(GiB)'] = int(key['storage']['storageSizeGb'])
3535
new_entry['Tier'] = key['sku']['tier']
3636
new_entry['SKU'] = key['sku']['name']
3737

3838
if 'flexibleServers' in result[0]['id']:
3939
new_entry['State'] = key['state']
40-
new_entry['HA State'] = key['haState']
40+
new_entry['HA State'] = key['highAvailability']['state']
4141
new_entry['Availability zone'] = key['availabilityZone']
4242

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

102102
return table_result
103+
104+
105+
def table_transform_output_parameters(result):
106+
107+
table_result = []
108+
109+
if not result:
110+
return table_result
111+
112+
for key in result:
113+
new_entry = OrderedDict()
114+
new_entry['Name'] = key['name']
115+
new_entry['DataType'] = key['dataType']
116+
new_entry['DefaultValue'] = key['defaultValue']
117+
new_entry['Source'] = key['source']
118+
new_entry['AllowedValues'] = key['allowedValues']
119+
120+
table_result.append(new_entry)
121+
122+
return table_result

src/azure-cli/azure/cli/command_modules/rdbms/custom.py

+1
Original file line numberDiff line numberDiff line change
@@ -707,6 +707,7 @@ def server_ad_admin_set(client, resource_group_name, server_name, login=None, si
707707
'''
708708

709709
parameters = {
710+
'administratorType': 'ActiveDirectory',
710711
'login': login,
711712
'sid': sid,
712713
'tenant_id': _get_tenant_id()

src/azure-cli/azure/cli/command_modules/rdbms/flexible_server_commands.py

+9-7
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@
2121
from ._transformers import (
2222
table_transform_output,
2323
table_transform_output_list_servers,
24-
table_transform_output_list_skus)
24+
table_transform_output_list_skus,
25+
table_transform_output_parameters)
2526

2627
# from .transformers import table_transform_connection_string
2728
# from .validators import db_up_namespace_processor
@@ -119,8 +120,8 @@ def load_flexibleserver_command_table(self, _):
119120
is_preview=True) as g:
120121
g.custom_command('create', 'firewall_rule_create_func', custom_command_type=flexible_server_custom_common)
121122
g.custom_command('delete', 'firewall_rule_delete_func', custom_command_type=flexible_server_custom_common)
122-
g.show_command('show', 'get')
123-
g.command('list', 'list_by_server')
123+
g.custom_show_command('show', 'firewall_rule_get_func', custom_command_type=flexible_server_custom_common)
124+
g.custom_command('list', 'firewall_rule_list_func', custom_command_type=flexible_server_custom_common)
124125
g.generic_update_command('update',
125126
getter_name='flexible_firewall_rule_custom_getter', getter_type=flexible_server_custom_common,
126127
setter_name='flexible_firewall_rule_custom_setter', setter_type=flexible_server_custom_common,
@@ -141,7 +142,7 @@ def load_flexibleserver_command_table(self, _):
141142

142143
with self.command_group('postgres flexible-server parameter', postgres_flexible_config_sdk,
143144
custom_command_type=flexible_servers_custom_postgres,
144-
client_factory=cf_postgres_flexible_config,
145+
client_factory=cf_postgres_flexible_config, table_transformer=table_transform_output_parameters,
145146
is_preview=True) as g:
146147
g.custom_command('set', 'flexible_parameter_update')
147148
g.show_command('show', 'get')
@@ -177,6 +178,7 @@ def load_flexibleserver_command_table(self, _):
177178
is_preview=True) as g:
178179
g.custom_command('create', 'flexible_server_create', table_transformer=table_transform_output)
179180
g.custom_command('restore', 'flexible_server_restore', supports_no_wait=True)
181+
g.custom_command('geo-restore', 'flexible_server_georestore', supports_no_wait=True)
180182
g.command('start', 'begin_start')
181183
g.custom_command('stop', 'flexible_server_stop', custom_command_type=flexible_server_custom_common)
182184
g.custom_command('delete', 'server_delete_func')
@@ -196,8 +198,8 @@ def load_flexibleserver_command_table(self, _):
196198
is_preview=True) as g:
197199
g.custom_command('create', 'firewall_rule_create_func', custom_command_type=flexible_server_custom_common)
198200
g.custom_command('delete', 'firewall_rule_delete_func', custom_command_type=flexible_server_custom_common)
199-
g.show_command('show', 'get')
200-
g.command('list', 'list_by_server')
201+
g.custom_show_command('show', 'firewall_rule_get_func', custom_command_type=flexible_server_custom_common)
202+
g.custom_command('list', 'firewall_rule_list_func', custom_command_type=flexible_server_custom_common)
201203
g.generic_update_command('update',
202204
getter_name='flexible_firewall_rule_custom_getter', getter_type=flexible_server_custom_common,
203205
setter_name='flexible_firewall_rule_custom_setter', setter_type=flexible_server_custom_common,
@@ -207,7 +209,7 @@ def load_flexibleserver_command_table(self, _):
207209

208210
with self.command_group('mysql flexible-server parameter', mysql_flexible_config_sdk,
209211
custom_command_type=flexible_servers_custom_mysql,
210-
client_factory=cf_mysql_flexible_config,
212+
client_factory=cf_mysql_flexible_config, table_transformer=table_transform_output_parameters,
211213
is_preview=True) as g:
212214
g.custom_command('set', 'flexible_parameter_update')
213215
g.show_command('show', 'get')

0 commit comments

Comments
 (0)