Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
18 changes: 9 additions & 9 deletions src/azure-cli/azure/cli/command_modules/rdbms/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,13 @@
# --------------------------------------------------------------------------------------------

from azure.cli.core import AzCommandsLoader

from azure.cli.core import ModExtensionSuppress
from azure.cli.core.commands import CliCommandType
from azure.cli.core.profiles import ResourceType
from azure.cli.command_modules.rdbms._util import RdbmsArgumentContext
from azure.cli.command_modules.rdbms.commands import load_command_table
from azure.cli.command_modules.rdbms.flexible_server_commands import load_flexibleserver_command_table
from azure.cli.command_modules.rdbms._params import load_arguments
import azure.cli.command_modules.rdbms._help # pylint: disable=unused-import
import azure.cli.command_modules.rdbms._helptext_pg # pylint: disable=unused-import
import azure.cli.command_modules.rdbms._helptext_mysql # pylint: disable=unused-import
Expand All @@ -13,13 +19,9 @@
class RdbmsCommandsLoader(AzCommandsLoader):

def __init__(self, cli_ctx=None):
from azure.cli.core import ModExtensionSuppress
from azure.cli.core.commands import CliCommandType
from azure.cli.core.profiles import ResourceType
from azure.cli.command_modules.rdbms._util import RdbmsArgumentContext

rdbms_custom = CliCommandType(operations_tmpl='azure.cli.command_modules.rdbms.custom#{}')
super(RdbmsCommandsLoader, self).__init__(
super().__init__(
cli_ctx=cli_ctx,
resource_type=ResourceType.MGMT_RDBMS,
custom_command_type=rdbms_custom,
Expand All @@ -32,14 +34,12 @@ def __init__(self, cli_ctx=None):
recommend_remove=True))

def load_command_table(self, args):
from azure.cli.command_modules.rdbms.commands import load_command_table
from azure.cli.command_modules.rdbms.flexible_server_commands import load_flexibleserver_command_table

load_command_table(self, args)
load_flexibleserver_command_table(self, args)
return self.command_table

def load_arguments(self, command):
from azure.cli.command_modules.rdbms._params import load_arguments
load_arguments(self, command)


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from azure.cli.core.commands.client_factory import get_mgmt_service_client
from azure.cli.core.profiles import ResourceType

# CLIENT FACTORIES
# pylint: disable=import-outside-toplevel

RM_URI_OVERRIDE = 'AZURE_CLI_RDBMS_RM_URI'
SUB_ID_OVERRIDE = 'AZURE_CLI_RDBMS_SUB_ID'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import datetime as dt
from datetime import datetime
import random
import secrets
import string
from knack.log import get_logger
from azure.core.paging import ItemPaged
from azure.cli.core.commands import LongRunningOperation, _is_poller
Expand Down Expand Up @@ -67,8 +69,6 @@ def generate_missing_parameters(cmd, location, resource_group_name, server_name,


def generate_password(administrator_login_password):
import secrets
import string
if administrator_login_password is None:
passwordlength = 16
administrator_login_password = secrets.token_urlsafe(passwordlength)
Expand Down
2 changes: 1 addition & 1 deletion src/azure-cli/azure/cli/command_modules/rdbms/_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ def _flexible_server_params(command_group):
c.argument('public_access', options_list=['--public-access'],
help='Determines the public access. Enter single or range of IP addresses to be included in the allowed list of IPs. IP address ranges must be dash-separated and not contain any spaces. Specifying 0.0.0.0 allows public access from any resources deployed within Azure to access your server. Setting it to "None" sets the server in public access mode but does not create a firewall rule. ',
validator=public_access_validator)
c.argument('high_availability', default="Disabled", options_list=['--high-availability'], help='Enable or disable high availability feature. Default value is Disabled.')
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='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.')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------
# pylint: disable=line-too-long
# pylint: disable=line-too-long, raise-missing-from
from collections import OrderedDict
from azure.cli.core.util import CLIError

Expand Down Expand Up @@ -59,7 +59,7 @@ def table_transform_output_list_skus(result):
new_entry['Tier'] = tier_name
new_entry['vCore'] = key['vCores']
new_entry['Memory'] = str(int(key['supportedMemoryPerVcoreMb']) * int(key['vCores']) // 1024) + " GiB"
new_entry['Max Disk IOPS'] = key['supportedIOPS']
new_entry['Max Disk IOPS'] = key['supportedIops']
table_result.append(new_entry)
except:
raise CLIError("There is no sku available for this location.")
Expand Down
12 changes: 5 additions & 7 deletions src/azure-cli/azure/cli/command_modules/rdbms/_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,25 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------

from datetime import datetime
from knack.arguments import ignore_type
from knack.log import get_logger
from azure.cli.core.commands import AzArgumentContext
from azure.cli.core.util import CLIError
from ._client_factory import cf_mariadb_firewall_rules, cf_postgres_firewall_rules, cf_mysql_firewall_rules
from .validators import get_combined_validator

logger = get_logger(__name__)


class RdbmsArgumentContext(AzArgumentContext): # pylint: disable=too-few-public-methods

def __init__(self, command_loader, scope, **kwargs): # pylint: disable=unused-argument
super(RdbmsArgumentContext, self).__init__(command_loader, scope)
super().__init__(command_loader, scope)
self.validators = []

def expand(self, dest, model_type, group_name=None, patches=None):
super(RdbmsArgumentContext, self).expand(dest, model_type, group_name, patches)

from knack.arguments import ignore_type
super().expand(dest, model_type, group_name, patches)

# Remove the validator and store it into a list
arg = self.command_loader.argument_registry.arguments[self.command_scope].get(dest, None)
Expand All @@ -30,7 +30,6 @@ def expand(self, dest, model_type, group_name=None, patches=None):
self.validators.append(arg.settings['validator'])
dest_option = ['--__{}'.format(dest.upper())]
if dest == 'parameters':
from .validators import get_combined_validator
self.argument(dest,
arg_type=ignore_type,
options_list=dest_option,
Expand All @@ -55,7 +54,6 @@ def parse_public_network_access_input(public_network_access):


def create_firewall_rule(cmd, resource_group_name, server_name, start_ip, end_ip, db_engine):
from datetime import datetime
now = datetime.now()
firewall_name = 'FirewallIPAddress_{}-{}-{}_{}-{}-{}'.format(now.year, now.month, now.day, now.hour, now.minute,
now.second)
Expand Down
20 changes: 8 additions & 12 deletions src/azure-cli/azure/cli/command_modules/rdbms/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,17 @@
# --------------------------------------------------------------------------------------------

# pylint: disable=unused-argument, line-too-long

from datetime import datetime, timedelta
from importlib import import_module
import re
from dateutil.tz import tzutc # pylint: disable=import-error
from msrestazure.azure_exceptions import CloudError
from msrestazure.tools import resource_id, is_valid_resource_id, parse_resource_id # pylint: disable=import-error
from knack.log import get_logger
from knack.util import todict
from six.moves.urllib.request import urlretrieve # pylint: disable=import-error
from azure.core.exceptions import ResourceNotFoundError
from azure.cli.core._profile import Profile
from azure.cli.core.commands.client_factory import get_subscription_id
from azure.cli.core.util import CLIError, sdk_no_wait
from azure.cli.core.local_context import ALL
Expand All @@ -30,7 +36,7 @@
DEFAULT_DB_NAME = 'defaultdb'


# pylint: disable=too-many-locals, too-many-statements
# pylint: disable=too-many-locals, too-many-statements, raise-missing-from
def _server_create(cmd, client, resource_group_name=None, server_name=None, sku_name=None, no_wait=False,
location=None, administrator_login=None, administrator_login_password=None, backup_retention=None,
geo_redundant_backup=None, ssl_enforcement=None, storage_mb=None, tags=None, version=None, auto_grow='Enabled',
Expand Down Expand Up @@ -355,7 +361,6 @@ def _replica_stop(client, resource_group_name, server_name):
if server_object.replication_role.lower() != "replica":
raise CLIError('Server {} is not a replica server.'.format(server_name))

from importlib import import_module
server_module_path = server_object.__module__
module = import_module(server_module_path.replace('server', 'server_update_parameters'))
ServerUpdateParameters = getattr(module, 'ServerUpdateParameters')
Expand All @@ -376,7 +381,6 @@ def _server_update_custom_func(instance,
assign_identity=False,
public_network_access=None,
minimal_tls_version=None):
from importlib import import_module
server_module_path = instance.__module__
module = import_module(server_module_path.replace('server', 'server_update_parameters'))
ServerUpdateParameters = getattr(module, 'ServerUpdateParameters')
Expand Down Expand Up @@ -561,7 +565,6 @@ def _download_log_files(
resource_group_name,
server_name,
file_name):
from six.moves.urllib.request import urlretrieve # pylint: disable=import-error

# list all files
files = client.list_by_server(resource_group_name, server_name)
Expand All @@ -573,9 +576,6 @@ def _download_log_files(

def _list_log_files_with_filter(client, resource_group_name, server_name, filename_contains=None,
file_last_written=None, max_file_size=None):
import re
from datetime import datetime, timedelta
from dateutil.tz import tzutc # pylint: disable=import-error

# list all files
all_files = client.list_by_server(resource_group_name, server_name)
Expand Down Expand Up @@ -688,7 +688,6 @@ def _get_server_key_name_from_uri(uri):
The SQL server key API requires that the server key has a specific name
based on the vault, key and key version.
'''
import re

match = re.match(r'https://(.)+\.(managedhsm.azure.net|managedhsm-preview.azure.net|vault.azure.net|vault-int.azure-int.net|vault.azure.cn|managedhsm.azure.cn|vault.usgovcloudapi.net|managedhsm.usgovcloudapi.net|vault.microsoftazure.de|managedhsm.microsoftazure.de|vault.cloudapi.eaglex.ic.gov|vault.cloudapi.microsoft.scloud)(:443)?\/keys/[^\/]+\/[0-9a-zA-Z]+$', uri)

Expand Down Expand Up @@ -723,8 +722,6 @@ def _get_tenant_id():
'''
Gets tenantId from current subscription.
'''
from azure.cli.core._profile import Profile

profile = Profile()
sub = profile.get_subscription()
return sub['tenantId']
Expand Down Expand Up @@ -761,7 +758,6 @@ def create_database(cmd, resource_group_name, server_name, database_name, engine


def form_response(server_result, password, host, connection_string, database_name=None, firewall_id=None):
from knack.util import todict
result = todict(server_result)
result['connectionString'] = connection_string
result['password'] = password
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@
# --------------------------------------------------------------------------------------------

# pylint: disable=unused-argument, line-too-long

from datetime import datetime
from knack.log import get_logger
from knack.util import CLIError
from knack.prompting import prompt_y_n, NoTTYException

logger = get_logger(__name__)
# pylint: disable=raise-missing-from


# Common functions used by other providers
Expand Down Expand Up @@ -39,7 +41,6 @@ def firewall_rule_create_func(client, resource_group_name, server_name, firewall
logger.warning('Configuring server firewall rule to accept connections from \'%s\'...', start_ip_address)

if firewall_rule_name is None:
from datetime import datetime
now = datetime.now()
firewall_rule_name = 'FirewallIPAddress_{}-{}-{}_{}-{}-{}'.format(now.year, now.month, now.day, now.hour, now.minute,
now.second)
Expand Down Expand Up @@ -129,7 +130,7 @@ def database_delete_func(client, resource_group_name=None, server_name=None, dat
def user_confirmation(message, yes=False):
if yes:
return True
from knack.prompting import prompt_y_n, NoTTYException

try:
if not prompt_y_n(message):
raise CLIError('Operation cancelled.')
Expand Down
Loading