Skip to content

Commit

Permalink
[RDBMS] Add autogrow parameter for MySQL and add database name to out…
Browse files Browse the repository at this point in the history
…put json when created (#18441)

* Add autogrow feature and postgres db name show when created

* autogrow parameter for update added

* add validators file

* Add different subnet to restore server

* private dns zone validator

* server name validator and database delete warninng message deleted

* restore network added

* pg restore dns zone add when only microsoft dns zone

* mysql ha validation added

* style fix
  • Loading branch information
DaeunYim authored Jun 28, 2021
1 parent 0014abe commit 3f185a3
Show file tree
Hide file tree
Showing 8 changed files with 106 additions and 157 deletions.
8 changes: 6 additions & 2 deletions src/azure-cli/azure/cli/command_modules/rdbms/_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,12 +285,14 @@ def _flexible_server_params(command_group):
help='Number of IOPS to be allocated for this server. You will get certain amount of free IOPS based '
'on compute and storage provisioned. The default value for IOPS is free IOPS. '
'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('vnet_resource_id', 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_arm_resource_id', 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.')
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 flexibleServers provider. After delegation, this subnet cannot be used for any other type of Azure resources.')
c.argument('server_name', options_list=['--name', '-n'], arg_type=server_name_setter_arg_type)
c.argument('location', arg_type=get_location_type(self.cli_ctx))
c.argument('administrator_login', default=generate_username(), options_list=['--admin-user', '-u'], arg_group='Authentication', arg_type=administrator_login_setter_arg_type,
Expand All @@ -305,7 +307,7 @@ def _flexible_server_params(command_group):
c.argument('high_availability', default="Disabled", options_list=['--high-availability'], help='Enable or disable high availability feature. Default value is Disabled. High availability can only be set during flexible server create time')
c.argument('assign_identity', options_list=['--assign-identity'],
help='Generate and assign an Azure Active Directory Identity for this server for use with key management services like Azure KeyVault. No need to enter extra argument.')
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('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 as virtual network if not provided by users.')
c.argument('database_name', id_part=None, arg_type=database_name_setter_arg_type, options_list=['--database-name', '-d'], help='The name of the database to be created when provisioning the database server')

with self.argument_context('{} flexible-server delete'.format(command_group)) as c:
Expand All @@ -326,6 +328,8 @@ def _flexible_server_params(command_group):
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_arm_resource_id', 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.')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,8 +205,8 @@ def database_delete_func(client, resource_group_name=None, server_name=None, dat
"If your parameter persistence is turned OFF, consider passing them explicitly.")
if not yes:
user_confirmation(
"Are you sure you want to delete the server '{0}' in resource group '{1}'".format(server_name,
resource_group_name), yes=yes)
"Are you sure you want to delete the database '{0}' of server '{1}'".format(database_name,
server_name), yes=yes)

try:
result = client.begin_delete(resource_group_name, server_name, database_name)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
generate_password, parse_maintenance_window, get_mysql_list_skus_info
from .flexible_server_custom_common import create_firewall_rule
from .flexible_server_virtual_network import prepare_private_network
from .validators import mysql_arguments_validator, validate_server_name
from .validators import mysql_arguments_validator, validate_server_name, validate_auto_grow_update, validate_mysql_ha_enabled

logger = get_logger(__name__)
DEFAULT_DB_NAME = 'flexibleserverdb'
Expand All @@ -35,7 +35,7 @@ def flexible_server_create(cmd, client, resource_group_name=None, server_name=No
administrator_login_password=None, version=None,
backup_retention=None, tags=None, public_access=None, database_name=None,
subnet_arm_resource_id=None, high_availability=None, zone=None, assign_identity=False,
vnet_resource_id=None, vnet_address_prefix=None, subnet_address_prefix=None, iops=None):
vnet_resource_id=None, vnet_address_prefix=None, subnet_address_prefix=None, iops=None, auto_grow=None):

# Populate desired parameters
location, resource_group_name, server_name = generate_missing_parameters(cmd, location, resource_group_name,
Expand Down Expand Up @@ -95,7 +95,7 @@ def flexible_server_create(cmd, client, resource_group_name=None, server_name=No
sku_name, tier, storage_mb, administrator_login,
administrator_login_password,
version, tags, delegated_subnet_arguments, assign_identity, public_access,
high_availability, zone, iops)
high_availability, zone, iops, auto_grow)

# Adding firewall rule
if public_access is not None and str(public_access).lower() != 'none':
Expand Down Expand Up @@ -175,6 +175,7 @@ def flexible_server_update_custom_func(cmd, instance,
assign_identity=False,
replication_role=None,
maintenance_window=None,
ha_enabled=None,
iops=None):
# validator
location = ''.join(instance.location.lower().split())
Expand Down Expand Up @@ -208,7 +209,11 @@ def flexible_server_update_custom_func(cmd, instance,
if backup_retention:
instance.storage_profile.backup_retention_days = backup_retention

if ha_enabled:
validate_mysql_ha_enabled(instance)

if auto_grow:
validate_auto_grow_update(instance, auto_grow)
instance.storage_profile.storage_autogrow = auto_grow

if subnet_arm_resource_id:
Expand Down Expand Up @@ -246,6 +251,7 @@ def flexible_server_update_custom_func(cmd, instance,
ssl_enforcement=ssl_enforcement,
delegated_subnet_arguments=instance.delegated_subnet_arguments,
tags=tags,
ha_enabled=ha_enabled,
replication_role=replication_role)

if assign_identity:
Expand Down Expand Up @@ -367,7 +373,7 @@ def flexible_list_skus(cmd, client, location):
def _create_server(db_context, cmd, resource_group_name, server_name, location, backup_retention, sku_name, tier,
storage_mb, administrator_login, administrator_login_password, version, tags,
delegated_subnet_arguments,
assign_identity, public_network_access, ha_enabled, availability_zone, iops):
assign_identity, public_network_access, ha_enabled, availability_zone, iops, auto_grow):
logging_name, server_client = db_context.logging_name, db_context.server_client
logger.warning('Creating %s Server \'%s\' in group \'%s\'...', logging_name, server_name, resource_group_name)

Expand All @@ -385,7 +391,8 @@ def _create_server(db_context, cmd, resource_group_name, server_name, location,
storage_profile=mysql_flexibleservers.models.StorageProfile(
backup_retention_days=backup_retention,
storage_mb=storage_mb,
storage_iops=iops),
storage_iops=iops,
storage_autogrow=auto_grow),
location=location,
create_mode="Default",
delegated_subnet_arguments=delegated_subnet_arguments,
Expand Down Expand Up @@ -534,7 +541,7 @@ def _determine_iops(storage_gb, iops_info, iops_input, tier, sku_name):
if iops_input and iops_input > free_iops:
iops = min(iops_input, max_supported_iops)

logger.warning("IOPS is set to %d which is either your input or free/maximum IOPS supported for your storage size and SKU.", iops)
logger.warning("IOPS is %d which is either your input or free(maximum) IOPS supported for your storage size and SKU.", iops)
return iops


Expand Down
Loading

0 comments on commit 3f185a3

Please sign in to comment.