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
Progress on RDBMS coversion.
  • Loading branch information
tjprescott committed Nov 20, 2017
commit 5cbc697142bafbe4d8888f781b7055835e16fcf0
6 changes: 4 additions & 2 deletions azure-cli2017.pyproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@
<LaunchProvider>Standard Python launcher</LaunchProvider>
<InterpreterId>MSBuild|{54f4b6dc-0859-46dc-99bb-b275c9d0aca3}|$(MSBuildProjectFullPath)</InterpreterId>
<EnableNativeCodeDebugging>False</EnableNativeCodeDebugging>
<CommandLineArguments>
</CommandLineArguments>
<CommandLineArguments>mysql server-logs download -h</CommandLineArguments>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)' == 'Debug'" />
<PropertyGroup Condition="'$(Configuration)' == 'Release'" />
Expand Down Expand Up @@ -423,6 +422,9 @@
<Compile Include="command_modules\azure-cli-rdbms\azure\cli\command_modules\rdbms\custom.py" />
<Compile Include="command_modules\azure-cli-rdbms\azure\cli\command_modules\rdbms\tests\test_rdbms_commands.py" />
<Compile Include="command_modules\azure-cli-rdbms\azure\cli\command_modules\rdbms\validators.py" />
<Compile Include="command_modules\azure-cli-rdbms\azure\cli\command_modules\rdbms\_client_factory.py">
<SubType>Code</SubType>
</Compile>
<Compile Include="command_modules\azure-cli-rdbms\azure\cli\command_modules\rdbms\_help.py" />
<Compile Include="command_modules\azure-cli-rdbms\azure\cli\command_modules\rdbms\_params.py" />
<Compile Include="command_modules\azure-cli-rdbms\azure\cli\command_modules\rdbms\_util.py" />
Expand Down
4 changes: 2 additions & 2 deletions src/azure-cli-core/azure/cli/core/commands/validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,10 @@ def generate_deployment_name(namespace):
'azurecli{}{}'.format(str(time.time()), str(random.randint(1, 100000)))


def get_default_location_from_resource_group(namespace):
def get_default_location_from_resource_group(cmd, namespace):
if not namespace.location:
from azure.cli.core.commands.client_factory import get_mgmt_service_client
resource_client = get_mgmt_service_client(namespace.cmd.cli_ctx, ResourceType.MGMT_RESOURCE_RESOURCES)
resource_client = get_mgmt_service_client(cmd.cli_ctx, ResourceType.MGMT_RESOURCE_RESOURCES)
rg = resource_client.resource_groups.get(namespace.resource_group_name)
namespace.location = rg.location # pylint: disable=no-member
logger.debug("using location '%s' from resource group '%s'", namespace.location, rg.name)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -493,8 +493,8 @@ def process_ag_url_path_map_rule_create_namespace(namespace): # pylint: disable
namespace, 'redirectConfigurations', namespace.redirect_config)


def process_ag_create_namespace(namespace):
get_default_location_from_resource_group(namespace)
def process_ag_create_namespace(cmd, namespace):
get_default_location_from_resource_group(cmd, namespace)

get_servers_validator(camel_case=True)(namespace)

Expand All @@ -517,8 +517,8 @@ def process_auth_create_namespace(namespace):
namespace.authorization_parameters = ExpressRouteCircuitAuthorization()


def process_lb_create_namespace(namespace):
get_default_location_from_resource_group(namespace)
def process_lb_create_namespace(cmd, namespace):
get_default_location_from_resource_group(cmd, namespace)

if namespace.subnet and namespace.public_ip_address:
raise ValueError(
Expand Down Expand Up @@ -558,17 +558,17 @@ def process_lb_frontend_ip_namespace(namespace):
get_public_ip_validator()(namespace)


def process_local_gateway_create_namespace(namespace):
def process_local_gateway_create_namespace(cmd, namespace):
ns = namespace
get_default_location_from_resource_group(ns)
get_default_location_from_resource_group(cmd, ns)
use_bgp_settings = any([ns.asn or ns.bgp_peering_address or ns.peer_weight])
if use_bgp_settings and (not ns.asn or not ns.bgp_peering_address):
raise ValueError(
'incorrect usage: --bgp-peering-address IP --asn ASN [--peer-weight WEIGHT]')


def process_nic_create_namespace(namespace):
get_default_location_from_resource_group(namespace)
def process_nic_create_namespace(cmd, namespace):
get_default_location_from_resource_group(cmd, namespace)

validate_address_pool_id_list(namespace)
validate_inbound_nat_rule_id_list(namespace)
Expand All @@ -580,13 +580,13 @@ def process_nic_create_namespace(namespace):
get_nsg_validator(has_type_field=False, allow_none=True, default_none=True)(namespace)


def process_public_ip_create_namespace(namespace):
get_default_location_from_resource_group(namespace)
def process_public_ip_create_namespace(cmd, namespace):
get_default_location_from_resource_group(cmd, namespace)


def process_route_table_create_namespace(namespace):
def process_route_table_create_namespace(cmd, namespace):
RouteTable = namespace.cmd.get_models('RouteTable')
get_default_location_from_resource_group(namespace)
get_default_location_from_resource_group(cmd, namespace)
validate_tags(namespace)
namespace.parameters = RouteTable(location=namespace.location, tags=namespace.tags)

Expand Down Expand Up @@ -648,8 +648,8 @@ def process_tm_endpoint_create_namespace(namespace):
raise CLIError(error_message)


def process_vnet_create_namespace(namespace):
get_default_location_from_resource_group(namespace)
def process_vnet_create_namespace(cmd, namespace):
get_default_location_from_resource_group(cmd, namespace)
validate_tags(namespace)

if namespace.subnet_prefix and not namespace.subnet_name:
Expand All @@ -665,9 +665,9 @@ def process_vnet_create_namespace(namespace):
namespace.subnet_prefix = '{}/{}'.format(address, subnet_mask)


def process_vnet_gateway_create_namespace(namespace):
def process_vnet_gateway_create_namespace(cmd, namespace):
ns = namespace
get_default_location_from_resource_group(ns)
get_default_location_from_resource_group(cmd, ns)
get_virtual_network_validator()(ns)

get_public_ip_validator()(ns)
Expand All @@ -692,9 +692,9 @@ def process_vnet_gateway_update_namespace(namespace):
'public IPs to create an active-active gateway.')


def process_vpn_connection_create_namespace(namespace):
def process_vpn_connection_create_namespace(cmd, namespace):
from msrestazure.tools import is_valid_resource_id, resource_id
get_default_location_from_resource_group(namespace)
get_default_location_from_resource_group(cmd, namespace)

args = [a for a in [namespace.express_route_circuit2,
namespace.local_gateway2,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,33 @@
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------

from azure.cli.core import AzCommandsLoader

import azure.cli.command_modules.rdbms._help # pylint: disable=unused-import

__all__ = ['load_params', 'load_commands']

class RdbmsCommandsLoader(AzCommandsLoader):

def __init__(self, cli_ctx=None):
from azure.cli.core.sdk.util import CliCommandType
from azure.cli.command_modules.rdbms._util import _PolyParametersContext
rdbms_custom = CliCommandType(operations_tmpl='azure.cli.command_modules.rdbms.custom#{}')
super(RdbmsCommandsLoader, self).__init__(cli_ctx=cli_ctx,
min_profile='2017-03-10-profile',
custom_command_type=rdbms_custom,
argument_context_cls=_PolyParametersContext)
self.module_name = __name__

def load_command_table(self, args):
super(RdbmsCommandsLoader, self).load_command_table(args)
from azure.cli.command_modules.rdbms.commands import load_command_table
load_command_table(self, args)
return self.command_table

def load_params(_):
import azure.cli.command_modules.rdbms._params # pylint: disable=redefined-outer-name, unused-variable
def load_arguments(self, command):
super(RdbmsCommandsLoader, self).load_arguments(command)
from azure.cli.command_modules.rdbms._params import load_arguments
load_arguments(self, command)


def load_commands():
import azure.cli.command_modules.rdbms.commands # pylint: disable=redefined-outer-name, unused-variable
COMMAND_LOADER_CLS = RdbmsCommandsLoader
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
# --------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------

from azure.cli.core.commands.client_factory import get_mgmt_service_client

# CLIENT FACTORIES

RM_URI_OVERRIDE = 'AZURE_CLI_RDBMS_RM_URI'
SUB_ID_OVERRIDE = 'AZURE_CLI_RDBMS_SUB_ID'
CLIENT_ID = 'AZURE_CLIENT_ID'
TENANT_ID = 'AZURE_TENANT_ID'
CLIENT_SECRET = 'AZURE_CLIENT_SECRET'


def get_mysql_management_client(cli_ctx, **_):
from os import getenv
from azure.mgmt.rdbms.mysql import MySQLManagementClient

# Allow overriding resource manager URI using environment variable
# for testing purposes. Subscription id is also determined by environment
# variable.
rm_uri_override = getenv(RM_URI_OVERRIDE)
if rm_uri_override:
client_id = getenv(CLIENT_ID)
if client_id:
from azure.common.credentials import ServicePrincipalCredentials
credentials = ServicePrincipalCredentials(
client_id=client_id,
secret=getenv(CLIENT_SECRET),
tenant=getenv(TENANT_ID))
else:
from msrest.authentication import Authentication
credentials = Authentication()

return MySQLManagementClient(
subscription_id=getenv(SUB_ID_OVERRIDE),
base_url=rm_uri_override,
credentials=credentials)
else:
# Normal production scenario.
return get_mgmt_service_client(cli_ctx, MySQLManagementClient)


def get_postgresql_management_client(cli_ctx, **_):
from os import getenv
from azure.mgmt.rdbms.postgresql import PostgreSQLManagementClient

# Allow overriding resource manager URI using environment variable
# for testing purposes. Subscription id is also determined by environment
# variable.
rm_uri_override = getenv(RM_URI_OVERRIDE)
if rm_uri_override:
client_id = getenv(CLIENT_ID)
if client_id:
from azure.common.credentials import ServicePrincipalCredentials
credentials = ServicePrincipalCredentials(
client_id=client_id,
secret=getenv(CLIENT_SECRET),
tenant=getenv(TENANT_ID))
else:
from msrest.authentication import Authentication
credentials = Authentication()

return PostgreSQLManagementClient(
subscription_id=getenv(SUB_ID_OVERRIDE),
base_url=rm_uri_override,
credentials=credentials)
else:
# Normal production scenario.
return get_mgmt_service_client(cli_ctx, PostgreSQLManagementClient)


def cf_mysql_servers(cli_ctx, _):
return get_mysql_management_client(cli_ctx).servers


def cf_postgres_servers(cli_ctx, _):
return get_postgresql_management_client(cli_ctx).servers


def cf_mysql_firewall_rules(cli_ctx, _):
return get_mysql_management_client(cli_ctx).firewall_rules


def cf_postgres_firewall_rules(cli_ctx, _):
return get_postgresql_management_client(cli_ctx).firewall_rules


def cf_mysql_config(cli_ctx, _):
return get_mysql_management_client(cli_ctx).configurations


def cf_postgres_config(cli_ctx, _):
return get_postgresql_management_client(cli_ctx).configurations


def cf_mysql_log(cli_ctx, _):
return get_mysql_management_client(cli_ctx).log_files


def cf_postgres_log(cli_ctx, _):
return get_postgresql_management_client(cli_ctx).log_files


def cf_mysql_db(cli_ctx, _):
return get_mysql_management_client(cli_ctx).databases


def cf_postgres_db(cli_ctx, _):
return get_postgresql_management_client(cli_ctx).databases
Loading