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
style fixed
  • Loading branch information
DaeunYim committed May 9, 2021
commit d446fa8b4097c7d1b1c92c715df359a86f4d800f
4 changes: 2 additions & 2 deletions src/azure-cli/azure/cli/command_modules/rdbms/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
# --------------------------------------------------------------------------------------------

from azure.cli.core import AzCommandsLoader

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


# pylint: disable=import-outside-toplevel
class RdbmsCommandsLoader(AzCommandsLoader):

def __init__(self, cli_ctx=None):
Expand All @@ -19,7 +19,7 @@ def __init__(self, cli_ctx=None):
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 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 @@ -3,7 +3,7 @@
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------

# pylint: disable=unused-argument, line-too-long
# pylint: disable=unused-argument, line-too-long, import-outside-toplevel, raise-missing-from
import datetime as dt
from datetime import datetime
import random
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
15 changes: 7 additions & 8 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,26 @@
# 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
# pylint: disable=too-few-public-methods, import-outside-toplevel
class RdbmsArgumentContext(AzArgumentContext):

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 +31,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 +55,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
4 changes: 2 additions & 2 deletions src/azure-cli/azure/cli/command_modules/rdbms/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------

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

from msrestazure.azure_exceptions import CloudError
from msrestazure.tools import resource_id, is_valid_resource_id, parse_resource_id # pylint: disable=import-error
Expand All @@ -30,7 +30,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
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------

# pylint: disable=unused-argument, line-too-long
# pylint: disable=unused-argument, line-too-long, import-outside-toplevel, raise-missing-from

from knack.log import get_logger
from knack.util import CLIError
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------

# pylint: disable=unused-argument, line-too-long
# pylint: disable=unused-argument, line-too-long, raise-missing-from, import-outside-toplevel
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------

# pylint: disable=unused-argument, line-too-long
# pylint: disable=unused-argument, line-too-long, raise-missing-from, import-outside-toplevel
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
Expand Down Expand Up @@ -84,52 +84,52 @@ def flexible_server_create(cmd, client,
private_dns_zone=private_dns_zone_arguments,
subnet_id=subnet_id,
location=location)
# private_dns_zone_arguments = postgresql_flexibleservers.models.ServerPropertiesPrivateDnsZoneArguments(private_dns_zone_arm_resource_id=private_dns_zone_id)
# else:
# delegated_subnet_arguments = None
# private_dns_zone_arguments = None

# administrator_login_password = generate_password(administrator_login_password)
# if server_result is None:
# # Create postgresql
# # 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, subnet_id, assign_identity, delegated_subnet_arguments,
# high_availability, zone, private_dns_zone_arguments)

# # 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 postgres 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_postgresql_connection_string(host, user, administrator_login_password), firewall_id,
# subnet_id)
private_dns_zone_arguments = postgresql_flexibleservers.models.ServerPropertiesPrivateDnsZoneArguments(private_dns_zone_arm_resource_id=private_dns_zone_id)
else:
delegated_subnet_arguments = None
private_dns_zone_arguments = None

administrator_login_password = generate_password(administrator_login_password)
if server_result is None:
# Create postgresql
# 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, subnet_id, assign_identity, delegated_subnet_arguments,
high_availability, zone, private_dns_zone_arguments)

# 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 postgres 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_postgresql_connection_string(host, user, administrator_login_password), firewall_id,
subnet_id)


def flexible_server_restore(cmd, client,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------

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

from msrestazure.tools import is_valid_resource_id, parse_resource_id, is_valid_resource_name, resource_id # pylint: disable=import-error
from knack.log import get_logger
Expand All @@ -19,7 +19,7 @@
DEFAULT_SUBNET_ADDRESS_PREFIX = '10.0.0.0/24'


# pylint: disable=too-many-locals, too-many-statements, too-many-branches
# pylint: disable=too-many-locals, too-many-statements, too-many-branches, import-outside-toplevel
def prepare_private_network(cmd, resource_group_name, server_name, vnet, subnet, location, delegation_service_name, vnet_address_pref, subnet_address_pref):

nw_client = network_client_factory(cmd.cli_ctx)
Expand Down Expand Up @@ -63,15 +63,14 @@ def prepare_private_network(cmd, resource_group_name, server_name, vnet, subnet,
location, server_name, vnet_address_pref, subnet_address_pref)

else:
raise ValidationError("If you pass both --vnet and --subnet, consider passing names instead of IDs. If you want to use exising subnet, please provide the subnet Id (not vnet Id).")
raise ValidationError("If you pass both --vnet and --subnet, consider passing names instead of IDs. If you want to use an existing subnet, please provide the subnet Id only (not vnet Id).")

elif subnet is None and vnet is None:
subnet_result = _create_vnet_subnet_delegation(cmd, nw_client, resource_client, delegation_service_name, resource_group_name, 'Vnet' + server_name[6:], 'Subnet' + server_name[6:],
location, server_name, vnet_address_pref, subnet_address_pref)
else:
return None

print(subnet_result)
return subnet_result.id


Expand Down Expand Up @@ -131,8 +130,6 @@ def _create_vnet_subnet_delegation(cmd, nw_client, resource_client, delegation_s
def _create_subnet_delegation(cmd, nw_client, resource_client, delegation_service_name, resource_group, vnet_name, subnet_name, location, server_name, subnet_address_pref):
Delegation, Subnet = cmd.get_models('Delegation', 'Subnet', resource_type=ResourceType.MGMT_NETWORK)
delegation = Delegation(name=delegation_service_name, service_name=delegation_service_name)
print(resource_group, vnet_name, subnet_name)
print(check_existence(resource_client, subnet_name, resource_group, 'Microsoft.Network', 'subnets', parent_name=vnet_name, parent_type='virtualNetworks'))

# subnet not exist
if not check_existence(resource_client, subnet_name, resource_group, 'Microsoft.Network', 'subnets', parent_name=vnet_name, parent_type='virtualNetworks'):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
logger = get_logger(__name__)


# pylint: disable=import-outside-toplevel, raise-missing-from
def _get_resource_group_from_server_name(cli_ctx, server_name):
"""
Fetch resource group from server name
Expand Down