Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
6c7d7b3
validate with list-skus info
DaeunYim Sep 18, 2020
f4aff33
style fixed
DaeunYim Sep 19, 2020
341fbcf
validate with list-skus info
DaeunYim Sep 18, 2020
9207f45
style fixed
DaeunYim Sep 19, 2020
9caa763
move validators to command body to speed up
DaeunYim Sep 22, 2020
8d9f96c
test code for validator and restored mgmt testcode
DaeunYim Sep 23, 2020
72e34f9
resolve conflicts
DaeunYim Sep 23, 2020
27a273b
minor fix
DaeunYim Sep 23, 2020
7848a49
flexible mgmt mysql test
DaeunYim Sep 24, 2020
7e61dad
new test recording files
DaeunYim Sep 29, 2020
490908d
deleting arguments and recording files modified
DaeunYim Sep 29, 2020
33c038f
style fixed, location changed, linter fixed
DaeunYim Sep 29, 2020
b7f7ed0
Adding az {} flexible-server connect capability
mjain2 Sep 29, 2020
6795970
Styling and linter fixes
mjain2 Sep 29, 2020
63add36
Merging with ppbugbash
mjain2 Sep 29, 2020
aa3c7e8
firewall rule name generation and end-ip-address rule changed
DaeunYim Sep 29, 2020
dca3e63
style fixed
DaeunYim Sep 29, 2020
8d16183
restore removed sterling test
DaeunYim Sep 30, 2020
47f489f
Fixing tests for renaming of parameters
mjain2 Sep 30, 2020
5249876
post public preview changes
arde0708 Sep 30, 2020
40d4d76
remove point in time param name change
arde0708 Sep 30, 2020
f1c1396
Merge pull request #2 from DaeunYim/arde/ppplusone
arde0708 Sep 30, 2020
01d284b
Merge branch 'daeunyim/ppbugbash' of https://github.com/DaeunYim/azur…
mjain2 Sep 30, 2020
abaab72
Merge pull request #1 from DaeunYim/mjain2/ppbugbash
mjain2 Sep 30, 2020
98c4775
Fixing linter/style issues and connect libraries in setup.py
mjain2 Sep 30, 2020
adcb404
Removing connect capability due to package issue
mjain2 Sep 30, 2020
307e9aa
Merge with dev
mjain2 Sep 30, 2020
0e3f9c7
Merge pull request #3 from DaeunYim/daeunyim/ppbugbash
mjain2 Sep 30, 2020
4c908e9
Removing connect packages from windows.txt
mjain2 Sep 30, 2020
468dff9
Minor fixes for description
mjain2 Sep 30, 2020
5812e7d
flexible server tests and new recording files
DaeunYim Oct 7, 2020
377a6af
adding create test with different tiers and sku
DaeunYim Oct 8, 2020
6f28532
Merge branch 'dev' into dev
DaeunYim Oct 9, 2020
c9849a7
style issue fixed
DaeunYim Oct 9, 2020
989476d
Trigger pipeline
mjain2 Oct 15, 2020
2e20afd
Trigger pipeline
mjain2 Oct 15, 2020
290ac2e
pulled from original repo
DaeunYim Dec 17, 2020
68b191b
Merge remote-tracking branch 'upstream/dev' into dev
DaeunYim Jan 5, 2021
dee0703
fix delete func
DaeunYim Jan 5, 2021
4478209
merged latest change
DaeunYim Jan 5, 2021
5a59094
logging exception to error
DaeunYim Jan 5, 2021
8884ebd
local context test updated
DaeunYim Jan 7, 2021
247bd53
pulled dev repo
DaeunYim Jan 7, 2021
bcd4aac
Merge branch 'dev' of https://github.com/Azure/azure-cli into s181
DaeunYim Jan 8, 2021
331d77e
fix for CI test
DaeunYim Jan 11, 2021
f485ae8
style fixed
DaeunYim Jan 11, 2021
832280a
comments resolved and moved local context test to another file for pi…
DaeunYim Jan 13, 2021
32eaecb
added copyright
DaeunYim Jan 13, 2021
e0f12a1
trigger pipeline
DaeunYim Jan 13, 2021
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
3 changes: 2 additions & 1 deletion src/azure-cli/azure/cli/command_modules/rdbms/_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,8 @@ def _flexible_server_params(command_group):
c.ignore('database_name')

with self.argument_context('{} flexible-server delete'.format(command_group)) as c:
c.argument('server_name', id_part='name', options_list=['--name', '-n'], arg_type=server_name_getter_arg_type)
c.argument('resource_group_name', required=True)
c.argument('server_name', id_part='name', options_list=['--name', '-n'], required=True, arg_type=server_name_getter_arg_type)
c.argument('yes', options_list=['--yes', '-y'], action='store_true',
help='Do not prompt for confirmation.')

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from azure.cli.core.util import CLIError, sdk_no_wait
from azure.cli.core.local_context import ALL
from ._client_factory import get_mysql_flexible_management_client, cf_mysql_flexible_firewall_rules, \
cf_mysql_flexible_db, cf_mysql_check_resource_availability
cf_mysql_flexible_db
from ._flexible_server_util import resolve_poller, generate_missing_parameters, create_firewall_rule, \
parse_public_access_input, generate_password, parse_maintenance_window, get_mysql_list_skus_info, \
DEFAULT_LOCATION_MySQL
Expand Down Expand Up @@ -41,98 +41,88 @@ def flexible_server_create(cmd, client, resource_group_name=None, server_name=No
storage_mb *= 1024

from azure.mgmt.rdbms import mysql_flexibleservers
try:
db_context = DbContext(
azure_sdk=mysql_flexibleservers, cf_firewall=cf_mysql_flexible_firewall_rules, cf_db=cf_mysql_flexible_db,
logging_name='MySQL', command_group='mysql', server_client=client)

# Raise error when user passes values for both parameters
if subnet_arm_resource_id is not None and public_access is not None:
raise CLIError("Incorrect usage : A combination of the parameters --subnet "
"and --public_access is invalid. Use either one of them.")

# When address space parameters are passed, the only valid combination is : --vnet, --subnet, --vnet-address-prefix, --subnet-address-prefix
# pylint: disable=too-many-boolean-expressions
if (vnet_address_prefix is not None) or (subnet_address_prefix is not None):
if (((vnet_address_prefix is not None) and (subnet_address_prefix is None)) or
((vnet_address_prefix is None) and (subnet_address_prefix is not None)) or
((vnet_address_prefix is not None) and (subnet_address_prefix is not None) and
((vnet_resource_id is None) or (subnet_arm_resource_id is None)))):
raise CLIError("Incorrect usage : "
"--vnet, --subnet, --vnet-address-prefix, --subnet-address-prefix must be supplied together.")

server_result = firewall_id = subnet_id = None

# Check availability for server name if it is supplied by the user
if server_name is not None:
check_name_client = cf_mysql_check_resource_availability(cmd.cli_ctx, None)
server_availability = check_name_client.execute(server_name, DELEGATION_SERVICE_NAME)
if not server_availability.name_available:
raise CLIError(server_availability.message)

# 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()

# Handle Vnet scenario
if (subnet_arm_resource_id is not None) or (vnet_resource_id is not None):
subnet_id = prepare_vnet(cmd, server_name, vnet_resource_id, subnet_arm_resource_id, resource_group_name,
location, DELEGATION_SERVICE_NAME, vnet_address_prefix, subnet_address_prefix)
delegated_subnet_arguments = mysql_flexibleservers.models.DelegatedSubnetArguments(
subnet_arm_resource_id=subnet_id)
elif public_access is None and subnet_arm_resource_id is None and vnet_resource_id is None:
subnet_id = create_vnet(cmd, server_name, location, resource_group_name,
DELEGATION_SERVICE_NAME)
delegated_subnet_arguments = mysql_flexibleservers.models.DelegatedSubnetArguments(
subnet_arm_resource_id=subnet_id)
else:
delegated_subnet_arguments = None

administrator_login_password = generate_password(administrator_login_password)
if server_result is None:
# Create mysql server
# Note : passing public_access has no effect as the accepted values are 'Enabled' and 'Disabled'. So the value ends up being ignored.
server_result = _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_access,
high_availability, zone)

# Adding firewall rule
if public_access is not None and str(public_access).lower() != 'none':
if str(public_access).lower() == 'all':
start_ip, end_ip = '0.0.0.0', '255.255.255.255'
else:
start_ip, end_ip = parse_public_access_input(public_access)
firewall_id = create_firewall_rule(db_context, cmd, resource_group_name, server_name, start_ip, end_ip)

# Create mysql database if it does not exist
if database_name is None:
database_name = DEFAULT_DB_NAME
_create_database(db_context, cmd, resource_group_name, server_name, database_name)

user = server_result.administrator_login
server_id = server_result.id
loc = server_result.location
version = server_result.version
sku = server_result.sku.name
host = server_result.fully_qualified_domain_name

logger.warning('Make a note of your password. If you forget, you would have to reset your password with'
'\'az mysql flexible-server update -n %s -g %s -p <new-password>\'.',
server_name, resource_group_name)

_update_local_contexts(cmd, server_name, resource_group_name, location, user)

return _form_response(user, sku, loc, server_id, host, version,
administrator_login_password if administrator_login_password is not None else '*****',
_create_mysql_connection_string(host, database_name, user, administrator_login_password),
database_name, firewall_id, subnet_id)

except Exception as ex: # pylint: disable=broad-except
logger.error(ex)
# try:
db_context = DbContext(
azure_sdk=mysql_flexibleservers, cf_firewall=cf_mysql_flexible_firewall_rules, cf_db=cf_mysql_flexible_db,
logging_name='MySQL', command_group='mysql', server_client=client)

# Raise error when user passes values for both parameters
if subnet_arm_resource_id is not None and public_access is not None:
raise CLIError("Incorrect usage : A combination of the parameters --subnet "
"and --public_access is invalid. Use either one of them.")

# When address space parameters are passed, the only valid combination is : --vnet, --subnet, --vnet-address-prefix, --subnet-address-prefix
# pylint: disable=too-many-boolean-expressions
if (vnet_address_prefix is not None) or (subnet_address_prefix is not None):
if (((vnet_address_prefix is not None) and (subnet_address_prefix is None)) or
((vnet_address_prefix is None) and (subnet_address_prefix is not None)) or
((vnet_address_prefix is not None) and (subnet_address_prefix is not None) and
((vnet_resource_id is None) or (subnet_arm_resource_id is None)))):
raise CLIError("Incorrect usage : "
"--vnet, --subnet, --vnet-address-prefix, --subnet-address-prefix must be supplied together.")

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()

# Handle Vnet scenario
if (subnet_arm_resource_id is not None) or (vnet_resource_id is not None):
subnet_id = prepare_vnet(cmd, server_name, vnet_resource_id, subnet_arm_resource_id, resource_group_name,
location, DELEGATION_SERVICE_NAME, vnet_address_prefix, subnet_address_prefix)
delegated_subnet_arguments = mysql_flexibleservers.models.DelegatedSubnetArguments(
subnet_arm_resource_id=subnet_id)
elif public_access is None and subnet_arm_resource_id is None and vnet_resource_id is None:
subnet_id = create_vnet(cmd, server_name, location, resource_group_name,
DELEGATION_SERVICE_NAME)
delegated_subnet_arguments = mysql_flexibleservers.models.DelegatedSubnetArguments(
subnet_arm_resource_id=subnet_id)
else:
delegated_subnet_arguments = None

administrator_login_password = generate_password(administrator_login_password)
if server_result is None:
# Create mysql server
# Note : passing public_access has no effect as the accepted values are 'Enabled' and 'Disabled'. So the value ends up being ignored.
server_result = _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_access,
high_availability, zone)

# Adding firewall rule
if public_access is not None and str(public_access).lower() != 'none':
if str(public_access).lower() == 'all':
start_ip, end_ip = '0.0.0.0', '255.255.255.255'
else:
start_ip, end_ip = parse_public_access_input(public_access)
firewall_id = create_firewall_rule(db_context, cmd, resource_group_name, server_name, start_ip, end_ip)

# Create mysql database if it does not exist
if database_name is None:
database_name = DEFAULT_DB_NAME
_create_database(db_context, cmd, resource_group_name, server_name, database_name)

user = server_result.administrator_login
server_id = server_result.id
loc = server_result.location
version = server_result.version
sku = server_result.sku.name
host = server_result.fully_qualified_domain_name

logger.warning('Make a note of your password. If you forget, you would have to reset your password with'
'\'az mysql flexible-server update -n %s -g %s -p <new-password>\'.',
server_name, resource_group_name)

_update_local_contexts(cmd, server_name, resource_group_name, location, user)

return _form_response(user, sku, loc, server_id, host, version,
administrator_login_password if administrator_login_password is not None else '*****',
_create_mysql_connection_string(host, database_name, user, administrator_login_password),
database_name, firewall_id, subnet_id)


def flexible_server_restore(cmd, client, resource_group_name, server_name, source_server, restore_point_in_time, location=None, no_wait=False):
Expand Down Expand Up @@ -258,6 +248,7 @@ def flexible_server_update_custom_func(cmd, instance,
def server_delete_func(cmd, client, resource_group_name=None, server_name=None, yes=None):
confirm = yes
result = None # default return value

if not yes:
confirm = user_confirmation(
"Are you sure you want to delete the server '{0}' in resource group '{1}'".format(server_name,
Expand All @@ -269,8 +260,12 @@ def server_delete_func(cmd, client, resource_group_name=None, server_name=None,
if cmd.cli_ctx.local_context.is_on:
local_context_file = cmd.cli_ctx.local_context._get_local_context_file() # pylint: disable=protected-access
local_context_file.remove_option('mysql flexible-server', 'server_name')
local_context_file.remove_option('mysql flexible-server', 'administrator_login')
local_context_file.remove_option('mysql flexible-server', 'database_name')

except Exception as ex: # pylint: disable=broad-except
logger.error(ex)
raise CLIError(ex)
return result


Expand Down
Loading