Skip to content

Commit

Permalink
[RDBMS] Change server default location (issue reported) (#18157)
Browse files Browse the repository at this point in the history
* Change rdbms server default location

* style fixed

* fixed tests yaml file
  • Loading branch information
DaeunYim authored Jun 11, 2021
1 parent 591539c commit e89f375
Show file tree
Hide file tree
Showing 5 changed files with 677 additions and 315 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,15 @@ def create_random_resource_name(prefix='azure', length=15):

def generate_missing_parameters(cmd, location, resource_group_name, server_name, db_engine):
# if location is not passed as a parameter or is missing from local context
if location is None:
if location is None and resource_group_name is None:
if db_engine == 'postgres':
location = DEFAULT_LOCATION_PG
else:
location = DEFAULT_LOCATION_MySQL
elif location is None and resource_group_name is not None:
resource_group_client = resource_client_factory(cmd.cli_ctx).resource_groups
resource_group = resource_group_client.get(resource_group_name=resource_group_name)
location = resource_group.location

# If resource group is there in local context, check for its existence.
resource_group_exists = True
Expand All @@ -69,12 +73,6 @@ def generate_missing_parameters(cmd, location, resource_group_name, server_name,
if server_name is None:
server_name = create_random_resource_name('server')

# This is for the case when user does not pass a location but the resource group exists in the local context.
# In that case, the location needs to be set to the location of the rg, not the default one.

# TODO: Fix this because it changes the default location even when I pass in a location param
# location = _update_location(cmd, resource_group_name)

return location, resource_group_name, server_name.lower()


Expand Down Expand Up @@ -237,13 +235,6 @@ def _get_list_from_paged_response(obj_list):
return list(obj_list) if isinstance(obj_list, ItemPaged) else obj_list


def _update_location(cmd, resource_group_name):
resource_client = resource_client_factory(cmd.cli_ctx)
rg = resource_client.resource_groups.get(resource_group_name)
location = rg.location
return location


def _create_resource_group(cmd, location, resource_group_name):
if resource_group_name is None:
resource_group_name = create_random_resource_name('group')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
from ._client_factory import get_mysql_flexible_management_client, cf_mysql_flexible_firewall_rules, \
cf_mysql_flexible_db, cf_mysql_check_resource_availability
from ._flexible_server_util import resolve_poller, generate_missing_parameters, parse_public_access_input, \
DEFAULT_LOCATION_MySQL, generate_password, parse_maintenance_window, get_mysql_list_skus_info
from .flexible_server_custom_common import user_confirmation, create_firewall_rule
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

Expand All @@ -36,9 +36,11 @@ def flexible_server_create(cmd, client, resource_group_name=None, server_name=No
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):

# Populate desired parameters
location, resource_group_name, server_name = generate_missing_parameters(cmd, location, resource_group_name,
server_name, 'mysql')
# validator
if location is None:
location = DEFAULT_LOCATION_MySQL
sku_info, iops_info, single_az = get_mysql_list_skus_info(cmd, location)
mysql_arguments_validator(tier, sku_name, storage_mb, backup_retention, sku_info, version=version)

Expand All @@ -58,10 +60,6 @@ def flexible_server_create(cmd, client, resource_group_name=None, server_name=No
"and --public_access is invalid. Use either one of them.")

server_result = firewall_id = subnet_id = None

# Populate desired parameters
location, resource_group_name, server_name = generate_missing_parameters(cmd, location, resource_group_name,
server_name, 'mysql')
server_name = server_name.lower()
validate_server_name(cf_mysql_check_resource_availability(cmd.cli_ctx, '_'), server_name, 'Microsoft.DBforMySQL/flexibleServers')

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
from azure.cli.core.azclierror import RequiredArgumentMissingError, ArgumentUsageError
from azure.mgmt.rdbms import postgresql_flexibleservers
from ._client_factory import cf_postgres_flexible_firewall_rules, get_postgresql_flexible_management_client, cf_postgres_flexible_db, cf_postgres_check_resource_availability
from .flexible_server_custom_common import user_confirmation, create_firewall_rule
from .flexible_server_custom_common import create_firewall_rule
from ._flexible_server_util import generate_missing_parameters, resolve_poller, parse_public_access_input, \
generate_password, parse_maintenance_window, get_postgres_list_skus_info, DEFAULT_LOCATION_PG
generate_password, parse_maintenance_window, get_postgres_list_skus_info
from .flexible_server_virtual_network import prepare_private_network, prepare_private_dns_zone
from .validators import pg_arguments_validator, validate_server_name

Expand All @@ -42,8 +42,9 @@ def flexible_server_create(cmd, client,
vnet_address_prefix=None, subnet_address_prefix=None,
private_dns_zone_arguments=None):
# validator
if location is None:
location = DEFAULT_LOCATION_PG
location, resource_group_name, server_name = generate_missing_parameters(cmd, location, resource_group_name,
server_name, 'postgres')

sku_info, single_az = get_postgres_list_skus_info(cmd, location)
pg_arguments_validator(tier, sku_name, storage_mb, sku_info, version=version)
storage_mb *= 1024
Expand All @@ -65,9 +66,6 @@ def flexible_server_create(cmd, client,

server_result = firewall_id = subnet_id = None

# Populate desired parameters
location, resource_group_name, server_name = generate_missing_parameters(cmd, location, resource_group_name,
server_name, 'postgres')
server_name = server_name.lower()
validate_server_name(cf_postgres_check_resource_availability(cmd.cli_ctx, '_'), server_name, 'Microsoft.DBforPostgreSQL/flexibleServers')

Expand Down
Loading

0 comments on commit e89f375

Please sign in to comment.