Skip to content

Commit

Permalink
Cumulative Knack work.
Browse files Browse the repository at this point in the history
Compute/RDBMS progress.
  • Loading branch information
tjprescott authored Nov 20, 2017
1 parent 66960dc commit 644e9f8
Show file tree
Hide file tree
Showing 135 changed files with 42,564 additions and 54,367 deletions.
61 changes: 37 additions & 24 deletions azure-cli.pyproj

Large diffs are not rendered by default.

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
19 changes: 11 additions & 8 deletions src/azure-cli-core/azure/cli/core/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ def load_arguments(self, command):

if command_loaders:
for loader in command_loaders:
loader.command_name = command
loader.load_arguments(command)
self.argument_registry.arguments.update(loader.argument_registry.arguments)
self.extra_argument_registry.update(loader.extra_argument_registry)
Expand All @@ -188,19 +189,24 @@ def load_arguments(self, command):
c.argument('location', get_location_type(self.cli_ctx))
c.argument('deployment_name', deployment_name_type)
c.argument('cmd', ignore_type)

super(MainCommandsLoader, self).load_arguments(command)
super(MainCommandsLoader, self).load_arguments(command)


class AzCommandsLoader(CLICommandsLoader):

def __init__(self, cli_ctx=None, min_profile=None, max_profile='latest', **kwargs):
def __init__(self, cli_ctx=None, min_profile=None, max_profile='latest',
command_group_cls=None, argument_context_cls=None,
**kwargs):
from azure.cli.core.commands import AzCliCommand
from azure.cli.core.sdk.util import _CommandGroup, _ParametersContext

super(AzCommandsLoader, self).__init__(cli_ctx=cli_ctx, command_cls=AzCliCommand)
self.module_name = __name__
self.min_profile = min_profile
self.max_profile = max_profile
self.module_kwargs = kwargs
self._command_group_cls = command_group_cls or _CommandGroup
self._argument_context_cls = argument_context_cls or _ParametersContext

def _update_command_definitions(self):
for command_name, command in self.command_table.items():
Expand Down Expand Up @@ -241,7 +247,6 @@ def _apply_doc_string(self, dest, command_kwargs):
raise CLIError("command authoring error: source '{}' not found.".format(doc_string_source))
dest.__doc__ = model.__doc__


def get_api_version(self, resource_type=None):
from azure.cli.core.profiles import get_api_version
resource_type = resource_type or self.module_kwargs.get('resource_type', None)
Expand All @@ -266,18 +271,16 @@ def get_models(self, *attr_args, **kwargs):
return get_sdk(self.cli_ctx, resource_type, *attr_args, mod='models')

def command_group(self, group_name, command_type=None, **kwargs):
from azure.cli.core.sdk.util import _CommandGroup
merged_kwargs = self.module_kwargs.copy()
if command_type:
merged_kwargs['command_type'] = command_type
merged_kwargs.update(kwargs)
return _CommandGroup(self.module_name, self, group_name, **merged_kwargs)
return self._command_group_cls(self.module_name, self, group_name, **merged_kwargs)

def argument_context(self, scope, **kwargs):
from azure.cli.core.sdk.util import _ParametersContext
merged_kwargs = self.module_kwargs.copy()
merged_kwargs.update(kwargs)
return _ParametersContext(self, scope, **merged_kwargs)
return self._argument_context_cls(self, scope, **merged_kwargs)

def _cli_command(self, name, operation=None, handler=None, argument_loader=None, description_loader=None, **kwargs):

Expand Down
39 changes: 38 additions & 1 deletion src/azure-cli-core/azure/cli/core/commands/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

import six

from azure.cli.core import AzCommandsLoader
import azure.cli.core.telemetry as telemetry

logger = get_logger(__name__)
Expand Down Expand Up @@ -134,6 +133,7 @@ def _resolve_default_value_from_cfg_file(self, arg, overrides):
overrides.settings['required'] = False

def load_arguments(self):
from azure.cli.core.commands.validators import DefaultStr, DefaultInt
if self.arguments_loader:
cmd_args = self.arguments_loader()
if self.no_wait_param:
Expand All @@ -146,6 +146,14 @@ def load_arguments(self):
(CONFIRM_PARAM_NAME,
CLICommandArgument(CONFIRM_PARAM_NAME, options_list=['--yes', '-y'], action='store_true',
help='Do not prompt for confirmation.')))
for (arg_name, arg) in cmd_args:
arg_def = arg.type.settings.get('default', None)
if isinstance(arg_def, str):
arg_def = DefaultStr(arg_def)
elif isinstance(arg_def, int):
arg_def = DefaultInt(arg_def)
if arg_def:
arg.type.settings['default'] = arg_def
self.arguments.update(cmd_args)

def update_argument(self, param_name, argtype):
Expand All @@ -155,6 +163,7 @@ def update_argument(self, param_name, argtype):

def __call__(self, *args, **kwargs):

from azure.cli.core import AzCommandsLoader
cmd_args = args[0]

if self.command_source and isinstance(self.command_source, ExtensionCommandSource) and\
Expand Down Expand Up @@ -326,6 +335,34 @@ def execute(self, args):
table_transformer=cmd_tbl[parsed_args.command].table_transformer,
is_query_active=self.data['query_active'])

def _build_kwargs(self, func, ns): # pylint: disable=no-self-use
import inspect
arg_spec = inspect.getargspec(func).args # pylint: disable=deprecated-method
kwargs = {}
if 'cmd' in arg_spec:
kwargs['cmd'] = ns._cmd # pylint: disable=protected-access
if 'namespace' in arg_spec:
kwargs['namespace'] = ns
if 'ns' in arg_spec:
kwargs['ns'] = ns
return kwargs

def _validate_cmd_level(self, ns, cmd_validator): # pylint: disable=no-self-use
if cmd_validator:
cmd_validator(**self._build_kwargs(cmd_validator, ns))
try:
delattr(ns, '_command_validator')
except AttributeError:
pass

def _validate_arg_level(self, ns, **_): # pylint: disable=no-self-use
for validator in getattr(ns, '_argument_validators', []):
validator(**self._build_kwargs(validator, ns))
try:
delattr(ns, '_argument_validators')
except AttributeError:
pass


class LongRunningOperation(object): # pylint: disable=too-few-public-methods

Expand Down
20 changes: 11 additions & 9 deletions src/azure-cli-core/azure/cli/core/commands/arm.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,13 +203,14 @@ def _get_child(parent, collection_name, item_name, collection_key):


def _get_operations_tmpl(cmd):
operations_tmpl = cmd.command_kwargs.get('operations_tmpl', cmd.command_kwargs.get('command_type').settings['operations_tmpl'])
operations_tmpl = cmd.command_kwargs.get('operations_tmpl',
cmd.command_kwargs.get('command_type').settings['operations_tmpl'])
if not operations_tmpl:
raise CLIError("command authoring error: cmd '{}' does not have an operations_tmpl.".format(cmd.name))
return operations_tmpl


def _get_client_factory(name, kwargs):
def _get_client_factory(_, kwargs):
factory = kwargs.get('client_factory', kwargs.get('command_type').settings.get('client_factory', None))
return factory

Expand Down Expand Up @@ -239,7 +240,7 @@ def function_arguments_loader():
return {}

custom_op = context.get_op_handler(custom_function_op)
context._apply_doc_string(custom_op, kwargs)
context._apply_doc_string(custom_op, kwargs) # pylint: disable=protected-access
return dict(extract_args_from_signature(custom_op))

def generic_update_arguments_loader():
Expand Down Expand Up @@ -445,7 +446,8 @@ def handler(args):
client = factory(context.cli_ctx) if factory else None
except TypeError:
client = factory(context.cli_ctx, None) if factory else None
args[client_arg_name] = client
if client:
args[client_arg_name] = client

getter = context.get_op_handler(getter_op)

Expand Down Expand Up @@ -749,7 +751,7 @@ def _find_property(instance, path):
return instance


def assign_implict_identity(getter, setter, identity_role=None, identity_scope=None):
def assign_implict_identity(cli_ctx, getter, setter, identity_role=None, identity_scope=None):
import time
from azure.mgmt.authorization import AuthorizationManagementClient
from azure.mgmt.authorization.models import RoleAssignmentProperties
Expand All @@ -766,8 +768,8 @@ def assign_implict_identity(getter, setter, identity_role=None, identity_scope=N
if identity_scope:
principal_id = resource.identity.principal_id

identity_role_id = resolve_role_id(identity_role, identity_scope)
assignments_client = get_mgmt_service_client(AuthorizationManagementClient).role_assignments
identity_role_id = resolve_role_id(cli_ctx, identity_role, identity_scope)
assignments_client = get_mgmt_service_client(cli_ctx, AuthorizationManagementClient).role_assignments
properties = RoleAssignmentProperties(identity_role_id, principal_id)

logger.info("Creating an assignment with a role '%s' on the scope of '%s'", identity_role_id, identity_scope)
Expand All @@ -791,10 +793,10 @@ def assign_implict_identity(getter, setter, identity_role=None, identity_scope=N
return resource


def resolve_role_id(role, scope):
def resolve_role_id(cli_ctx, role, scope):
import uuid
from azure.mgmt.authorization import AuthorizationManagementClient
client = get_mgmt_service_client(AuthorizationManagementClient).role_definitions
client = get_mgmt_service_client(cli_ctx, AuthorizationManagementClient).role_definitions

role_id = None
if re.match(r'/subscriptions/[^/]+/providers/Microsoft.Authorization/roleDefinitions/',
Expand Down
19 changes: 12 additions & 7 deletions src/azure-cli-core/azure/cli/core/commands/parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,16 @@ def get_resources_in_subscription(cli_ctx, resource_type=None):
return list(rcf.resources.list(filter=filter_str))


def get_resource_name_completion_list(cli_ctx, resource_type=None):
def completer(prefix, action, parsed_args, **kwargs): # pylint: disable=unused-argument
if getattr(parsed_args, 'resource_group_name', None):
rg = parsed_args.resource_group_name
return [r.name for r in get_resources_in_resource_group(cli_ctx, rg, resource_type=resource_type)]
return [r.name for r in get_resources_in_subscription(cli_ctx, resource_type)]
def get_resource_name_completion_list(resource_type=None):
from azure.cli.core.decorators import Completer

@Completer
def completer(cmd, prefix, namespace, **kwargs): # pylint: disable=unused-argument
rg = getattr(namespace, 'resource_group_name', None)
if rg:
return [r.name for r in get_resources_in_resource_group(cmd.cli_ctx, rg, resource_type=resource_type)]
return [r.name for r in get_resources_in_subscription(cmd.cli_ctx, resource_type)]

return completer


Expand Down Expand Up @@ -144,11 +148,12 @@ def _type(value):

default_value = None
if default:
from azure.cli.core.commands.validators import DefaultStr
default_value = next((x for x in choices if x.lower() == default.lower()), None)
if not default_value:
raise CLIError("Command authoring exception: urecognized default '{}' from choices '{}'"
.format(default, choices))
arg_type = CLIArgumentType(choices=CaseInsensitiveList(choices), type=_type, default=default_value)
arg_type = CLIArgumentType(choices=CaseInsensitiveList(choices), type=_type, default=DefaultStr(default_value))
else:
arg_type = CLIArgumentType(choices=CaseInsensitiveList(choices), type=_type)
return arg_type
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
13 changes: 13 additions & 0 deletions src/azure-cli-core/azure/cli/core/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,19 @@
is_diagnostics_mode = False


# pylint: disable=too-few-public-methods
class Completer(object):

def __init__(self, func):
self.func = func

def __call__(self, **kwargs):
namespace = kwargs['parsed_args']
prefix = kwargs['prefix']
cmd = namespace._cmd # pylint: disable=protected-access
return self.func(cmd, prefix, namespace)


# internal functions

def _should_raise(raise_in_diagnostics):
Expand Down
1 change: 1 addition & 0 deletions src/azure-cli-core/azure/cli/core/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ def load_command_table(self, cmd_tbl):
command_parser.set_defaults(
func=metadata,
command=command_name,
_cmd=metadata,
_command_validator=command_validator,
_argument_validators=argument_validators,
_parser=command_parser)
Expand Down
2 changes: 1 addition & 1 deletion src/azure-cli-testsdk/azure/cli/testsdk/preparers.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def create_resource(self, name, **kwargs):

if not self.dev_setting_name:
template = 'az storage account create -n {} -g {} -l {} --sku {}'
execute(template.format(name, group, self.location, self.sku))
execute(self.cli_ctx, template.format(name, group, self.location, self.sku))
else:
name = self.dev_setting_name

Expand Down
81 changes: 0 additions & 81 deletions src/command_modules/azure-cli-component/HISTORY.rst

This file was deleted.

1 change: 0 additions & 1 deletion src/command_modules/azure-cli-component/MANIFEST.in

This file was deleted.

Loading

0 comments on commit 644e9f8

Please sign in to comment.