Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
mysql migration and vnet subnet
  • Loading branch information
DaeunYim committed Jul 19, 2021
commit 09b26b58a0fd9bb85e961fcc83ddfc258ae1d03d
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@
import string
import yaml
from knack.log import get_logger
from knack.prompting import prompt_y_n, NoTTYException
from msrestazure.tools import parse_resource_id
from msrestazure.azure_exceptions import CloudError
from azure.cli.core.util import CLIError
from azure.cli.core.azclierror import AuthenticationError
from azure.core.paging import ItemPaged
from azure.cli.core.commands.client_factory import get_subscription_id
Expand Down Expand Up @@ -190,7 +192,6 @@ def _postgres_parse_list_skus(result, database_engine):

tiers = result[0].supported_flexible_server_editions
tiers_dict = {}
iops_dict = {}
for tier_info in tiers:
tier_name = tier_info.name
tier_dict = {}
Expand All @@ -202,8 +203,6 @@ def _postgres_parse_list_skus(result, database_engine):
versions.add(version.name)
for vcores in version.supported_vcores:
skus.add(vcores.name)
if database_engine == 'mysql':
sku_iops_dict[vcores.name] = vcores.supported_iops
tier_dict["skus"] = skus
tier_dict["versions"] = versions

Expand Down Expand Up @@ -445,3 +444,22 @@ def fill_action_template(cmd, database_engine, server, database_name, administra
def get_git_root_dir():
process = run_subprocess_get_output("git rev-parse --show-toplevel")
return process.stdout.read().strip().decode('UTF-8')


def get_user_confirmation(message, yes=False):
if yes:
return True
try:
if not prompt_y_n(message):
return False
else:
return True
except NoTTYException:
raise CLIError(
'Unable to prompt for confirmation as no tty available. Use --yes.')


def _is_resource_name(resource):
if len(resource.split('/')) == 1:
return True
return False
29 changes: 24 additions & 5 deletions src/azure-cli/azure/cli/command_modules/rdbms/_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,7 @@ def _flexible_server_params(command_group):
overriding_none_arg_type = CLIArgumentType(local_context_attribute=LocalContextAttribute(name='context_name', actions=[LocalContextAction.GET]))

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', id_part='name', options_list=['--name', '-n'], arg_type=server_name_arg_type)

with self.argument_context('{} flexible-server create'.format(command_group)) as c:
Expand Down Expand Up @@ -289,7 +290,7 @@ def _flexible_server_params(command_group):
'To learn more about IOPS based on compute and storage, refer to IOPS in Azure Database for MySQL Flexible Server')
c.argument('auto_grow', arg_type=get_enum_type(['Enabled', 'Disabled']), options_list=['--storage-auto-grow'], default='Enabled',
help='Enable or disable autogrow of the storage. Default value is Enabled.')

c.argument('yes', options_list=['--yes', '-y'], action='store_true', help='Do not prompt for confirmation.')
c.argument('vnet', options_list=['--vnet'], help='Name or ID of a new or existing virtual network. If you want to use a vnet from different resource group or subscription, please provide a resource ID. The name must be between 2 to 64 characters. The name must begin with a letter or number, end with a letter, number or underscore, and may contain only letters, numbers, underscores, periods, or hyphens.')
c.argument('vnet_address_prefix', options_list=['--address-prefixes'], help='The IP address prefix to use when creating a new virtual network in CIDR format. Default value is 10.0.0.0/16.')
c.argument('subnet_address_prefix', options_list=['--subnet-prefixes'], help='The subnet IP address prefix to use when creating a new VNet in CIDR format. Default value is 10.0.0.0/24.')
Expand Down Expand Up @@ -323,19 +324,33 @@ def _flexible_server_params(command_group):
help='The name of the new server that is created by the restore command.')
c.argument('restore_point_in_time', options_list=['--restore-time'], default=get_current_time(),
help='The point in time in UTC to restore from (ISO8601 format), e.g., 2017-04-26T02:10:00+00:00')
c.argument('vnet', options_list=['--vnet'], help='Name or ID of a new or existing virtual network. If you want to use a vnet from different resource group or subscription, please provide a resource ID. The name must be between 2 to 64 characters. The name must begin with a letter or number, end with a letter, number or underscore, and may contain only letters, numbers, underscores, periods, or hyphens.')
c.argument('vnet_address_prefix', options_list=['--address-prefixes'], help='The IP address prefix to use when creating a new virtual network in CIDR format. Default value is 10.0.0.0/16.')
c.argument('subnet_address_prefix', options_list=['--subnet-prefixes'], help='The subnet IP address prefix to use when creating a new VNet in CIDR format. Default value is 10.0.0.0/24.')
c.argument('subnet', options_list=['--subnet'],
help='Name or resource ID of a new or existing subnet. If you want to use a subnet from different resource group or subscription, please provide resource ID instead of name. Please note that the subnet will be delegated to Microsoft.DBforPostgreSQL/flexibleServers/Microsoft.DBforMySQL/flexibleServers. After delegation, this subnet cannot be used for any other type of Azure resources.')
c.argument('private_dns_zone_arguments', options_list=['--private-dns-zone'],
help='This parameter only applies for a server with private access. The name or id of new or existing private dns zone. You can use the private dns zone from same resource group, different resource group, or different subscription. If you want to use a zone from different resource group or subscription, please provide resource Id. CLI creates a new private dns zone within the same resource group if not provided by users.')
if command_group == 'postgres':
c.argument('source_server', options_list=['--source-server'],
help='The name of the source server to restore from.')
c.argument('zone', options_list=['--zone'],
help='Availability zone into which to provision the resource.')
c.argument('private_dns_zone_arguments', options_list=['--private-dns-zone'],
help='This parameter only applies for a server with private access. The name or id of new or existing private dns zone. You can use the private dns zone from same resource group, different resource group, or different subscription. If you want to use a zone from different resource group or subscription, please provide resource Id. CLI creates a new private dns zone within the same resource group if not provided by users.')
c.argument('subnet', options_list=['--subnet'],
help='Resource ID of an existing subnet. Please note that the subnet will be delegated to Microsoft.DBforPostgreSQL/flexibleServers if not already delegated. After delegation, this subnet cannot be used for any other type of Azure resources.')
elif command_group == 'mysql':
c.argument('source_server', options_list=['--source-server'],
help='The name or resource ID of the source server to restore from.')

with self.argument_context('{} flexible-server georestore'. format(command_group)) as c:
c.argument('resource_group_name', arg_type=resource_group_name_type)
c.argument('location', arg_type=get_location_type(self.cli_ctx), required=True)
c.argument('source_server', options_list=['--source-server', '-s'], required=True, help='The name or ID of the source server to restore from.')
c.argument('geo_redundant_backup', options_list=['--geo-redundant-backup'], help='Enable or disable geo-redundant backups. Default value is Disabled. Not supported in Basic pricing tier.')
c.argument('vnet', options_list=['--vnet'], help='Name or ID of a new or existing virtual network. If you want to use a vnet from different resource group or subscription, please provide a resource ID. The name must be between 2 to 64 characters. The name must begin with a letter or number, end with a letter, number or underscore, and may contain only letters, numbers, underscores, periods, or hyphens.')
c.argument('vnet_address_prefix', options_list=['--address-prefixes'], help='The IP address prefix to use when creating a new virtual network in CIDR format. Default value is 10.0.0.0/16.')
c.argument('subnet_address_prefix', options_list=['--subnet-prefixes'], help='The subnet IP address prefix to use when creating a new VNet in CIDR format. Default value is 10.0.0.0/24.')
c.argument('subnet', options_list=['--subnet'],
help='Name or resource ID of a new or existing subnet. If you want to use a subnet from different resource group or subscription, please provide resource ID instead of name. Please note that the subnet will be delegated to flexible servers. After delegation, this subnet cannot be used for any other type of Azure resources.')

with self.argument_context('{} flexible-server update'.format(command_group)) as c:
c.ignore('assign_identity')
c.argument('administrator_login_password', options_list=['--admin-password', '-p'],
Expand Down Expand Up @@ -378,6 +393,10 @@ def _flexible_server_params(command_group):
help='The number of days a backup is retained. Range of 7 to 35 days. Default is 7 days.', validator=retention_validator)
c.argument('standby_availability_zone', options_list=['--standby-zone'], help="availability zone information of the standby.")

with self.argument_context('{} flexible-server restart'.format(command_group)) as c:
c.argument('fail_over', options_list=['--failover'],
help='forced or planned failover for server restart operation')

with self.argument_context('{} flexible-server list-skus'.format(command_group)) as c:
c.argument('location', arg_type=get_location_type(self.cli_ctx))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,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('georestore', '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', 'flexible_server_delete')
Expand All @@ -111,7 +112,7 @@ def load_flexibleserver_command_table(self, _):
setter_arg_name='parameters',
custom_func_name='flexible_server_update_custom_func')
g.custom_wait_command('wait', 'flexible_server_postgresql_get')
g.command('restart', 'begin_restart')
g.custom_command('restart', 'flexible_server_restart')

with self.command_group('postgres flexible-server firewall-rule', postgres_flexible_firewall_rule_sdk,
custom_command_type=flexible_servers_custom_postgres,
Expand Down Expand Up @@ -176,6 +177,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('georestore', '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 Down
Loading