diff --git a/src/command_modules/azure-cli-batch/azure/cli/command_modules/batch/_client_factory.py b/src/command_modules/azure-cli-batch/azure/cli/command_modules/batch/_client_factory.py index d5c0a545043..bda4787aae7 100644 --- a/src/command_modules/azure-cli-batch/azure/cli/command_modules/batch/_client_factory.py +++ b/src/command_modules/azure-cli-batch/azure/cli/command_modules/batch/_client_factory.py @@ -3,19 +3,70 @@ # Licensed under the MIT License. See License.txt in the project root for license information. # -------------------------------------------------------------------------------------------- -from azure.mgmt.batch import BatchManagementClient -import azure.batch.batch_service_client as batch -import azure.batch.batch_auth as batchauth +def account_mgmt_client_factory(kwargs): + return batch_client_factory(**kwargs).batch_account -from azure.cli.core.commands.client_factory import get_mgmt_service_client + +def application_mgmt_client_factory(kwargs): + return batch_client_factory(**kwargs).application + + +def application_package_client_factory(kwargs): + return batch_client_factory(**kwargs).application_package + + +def location_client_factory(kwargs): + return batch_client_factory(**kwargs).location + + +def application_client_factory(kwargs): + return batch_data_service_factory(kwargs).application + + +def account_client_factory(kwargs): + return batch_data_service_factory(kwargs).account + + +def certificate_client_factory(kwargs): + return batch_data_service_factory(kwargs).certificate + + +def pool_client_factory(kwargs): + return batch_data_service_factory(kwargs).pool + + +def job_client_factory(kwargs): + return batch_data_service_factory(kwargs).job + + +def job_schedule_client_factory(kwargs): + return batch_data_service_factory(kwargs).job_schedule + + +def task_client_factory(kwargs): + return batch_data_service_factory(kwargs).task + + +def file_client_factory(kwargs): + return batch_data_service_factory(kwargs).file + + +def compute_node_client_factory(kwargs): + return batch_data_service_factory(kwargs).compute_node def batch_client_factory(**_): + from azure.mgmt.batch import BatchManagementClient + from azure.cli.core.commands.client_factory import get_mgmt_service_client + return get_mgmt_service_client(BatchManagementClient) def batch_data_service_factory(kwargs): + import azure.batch.batch_service_client as batch + import azure.batch.batch_auth as batchauth + account_name = kwargs.pop('account_name', None) account_key = kwargs.pop('account_key', None) account_endpoint = kwargs.pop('account_endpoint', None) diff --git a/src/command_modules/azure-cli-batch/azure/cli/command_modules/batch/_command_type.py b/src/command_modules/azure-cli-batch/azure/cli/command_modules/batch/_command_type.py index 84c4599871c..c18ecd36fd1 100644 --- a/src/command_modules/azure-cli-batch/azure/cli/command_modules/batch/_command_type.py +++ b/src/command_modules/azure-cli-batch/azure/cli/command_modules/batch/_command_type.py @@ -8,10 +8,6 @@ import re from six import string_types -from argcomplete.completers import ( - FilesCompleter, - DirectoriesCompleter) - from msrest.exceptions import DeserializationError from azure.cli.command_modules.batch import _validators as validators @@ -21,14 +17,11 @@ command_module_map, CliCommand, CliCommandArgument, - get_op_handler, - _user_confirmed) -from azure.cli.core._util import CLIError -from azure.cli.core._config import az_config + get_op_handler) from azure.cli.core.commands._introspection import ( extract_full_summary_from_signature, extract_args_from_signature) -from azure.cli.core.commands.parameters import file_type + # TODO: Enum choice lists @@ -398,7 +391,7 @@ def parse(self, namespace): self.done = True -class AzureDataPlaneCommand(object): +class AzureBatchDataPlaneCommand(object): # pylint:disable=too-many-instance-attributes, too-few-public-methods def __init__(self, module_name, name, operation, factory, transform_result, # pylint:disable=too-many-arguments @@ -428,7 +421,11 @@ def _execute_command(kwargs): from msrest.paging import Paged from msrest.exceptions import ValidationError, ClientRequestError from azure.batch.models import BatchErrorException - if self._cancel_operation(kwargs): + from azure.cli.core._util import CLIError + from azure.cli.core._config import az_config + from azure.cli.core.commands import _user_confirmed + + if self._cancel_operation(kwargs, az_config, _user_confirmed): raise CLIError('Operation cancelled.') try: @@ -501,7 +498,7 @@ def _execute_command(kwargs): get_op_handler(operation)) ) - def _cancel_operation(self, kwargs): + def _cancel_operation(self, kwargs, config, user): """Whether to cancel the current operation because user declined the confirmation prompt. :param dict kwargs: The request arguments. @@ -509,8 +506,8 @@ def _cancel_operation(self, kwargs): """ return self.confirmation \ and not kwargs.get(FORCE_PARAM_NAME) \ - and not az_config.getboolean('core', 'disable_confirm_prompt', fallback=False) \ - and not _user_confirmed(self.confirmation, kwargs) + and not config.getboolean('core', 'disable_confirm_prompt', fallback=False) \ + and not user(self.confirmation, kwargs) def _build_parameters(self, path, kwargs, param, value): """Recursively build request parameter dictionary from command line args. @@ -676,6 +673,9 @@ def _load_transformed_arguments(self, handler): """Load all the command line arguments from the request parameters. :param func handler: The operation function. """ + from azure.cli.core.commands.parameters import file_type + from argcomplete.completers import FilesCompleter, DirectoriesCompleter + self.parser = BatchArgumentTree(self.validator) self._load_options_model(handler) for arg in extract_args_from_signature(handler): @@ -725,11 +725,11 @@ def _load_transformed_arguments(self, handler): help=docstring)) -def cli_data_plane_command(name, operation, client_factory, transform=None, # pylint:disable=too-many-arguments +def cli_batch_data_plane_command(name, operation, client_factory, transform=None, # pylint:disable=too-many-arguments table_transformer=None, flatten=FLATTEN, ignore=None, validator=None): """ Registers an Azure CLI Batch Data Plane command. These commands must respond to a challenge from the service when they make requests. """ - command = AzureDataPlaneCommand(__name__, name, operation, client_factory, + command = AzureBatchDataPlaneCommand(__name__, name, operation, client_factory, transform, table_transformer, flatten, ignore, validator) # add parameters required to create a batch client diff --git a/src/command_modules/azure-cli-batch/azure/cli/command_modules/batch/_validators.py b/src/command_modules/azure-cli-batch/azure/cli/command_modules/batch/_validators.py index 39d8169b5e5..dda6b77c486 100644 --- a/src/command_modules/azure-cli-batch/azure/cli/command_modules/batch/_validators.py +++ b/src/command_modules/azure-cli-batch/azure/cli/command_modules/batch/_validators.py @@ -5,20 +5,12 @@ import os import json -try: - from urllib.parse import urlsplit -except ImportError: - from urlparse import urlsplit # pylint: disable=import-error + +from six.moves.urllib.parse import urlsplit from msrest.serialization import Deserializer from msrest.exceptions import DeserializationError -from azure.mgmt.batch import BatchManagementClient -from azure.mgmt.storage import StorageManagementClient - -from azure.cli.core._config import az_config -from azure.cli.core.commands.client_factory import get_mgmt_service_client - # TYPES VALIDATORS @@ -95,6 +87,9 @@ def validate_required_parameter(ns, parser): def storage_account_id(namespace): """Validate storage account name""" + from azure.mgmt.storage import StorageManagementClient + from azure.cli.core.commands.client_factory import get_mgmt_service_client + if namespace.storage_account_name: if not namespace.storage_account_id: storage_client = get_mgmt_service_client(StorageManagementClient) @@ -110,6 +105,9 @@ def storage_account_id(namespace): def application_enabled(namespace): """Validates account has auto-storage enabled""" + from azure.mgmt.batch import BatchManagementClient + from azure.cli.core.commands.client_factory import get_mgmt_service_client + client = get_mgmt_service_client(BatchManagementClient) acc = client.batch_account.get(namespace.resource_group_name, namespace.account_name) if not acc: @@ -190,6 +188,9 @@ def validate_file_destination(namespace): def validate_client_parameters(namespace): """Retrieves Batch connection parameters from environment variables""" + from azure.mgmt.batch import BatchManagementClient + from azure.cli.core.commands.client_factory import get_mgmt_service_client + from azure.cli.core._config import az_config # simply try to retrieve the remaining variables from environment variables if not namespace.account_name: diff --git a/src/command_modules/azure-cli-batch/azure/cli/command_modules/batch/commands.py b/src/command_modules/azure-cli-batch/azure/cli/command_modules/batch/commands.py index 64196ec9553..f6a24f64b9b 100644 --- a/src/command_modules/azure-cli-batch/azure/cli/command_modules/batch/commands.py +++ b/src/command_modules/azure-cli-batch/azure/cli/command_modules/batch/commands.py @@ -5,10 +5,23 @@ from azure.cli.core.commands import cli_command -from azure.cli.command_modules.batch._client_factory import ( - batch_client_factory, batch_data_service_factory) -from azure.cli.command_modules.batch._command_type import cli_data_plane_command +from azure.cli.command_modules.batch._command_type import cli_batch_data_plane_command from azure.cli.command_modules.batch._validators import validate_pool_settings +from azure.cli.command_modules.batch._client_factory import ( + account_mgmt_client_factory, + account_client_factory, + application_mgmt_client_factory, + application_package_client_factory, + application_client_factory, + certificate_client_factory, + compute_node_client_factory, + file_client_factory, + job_client_factory, + job_schedule_client_factory, + location_client_factory, + pool_client_factory, + task_client_factory) + data_path = 'azure.batch.operations.{}_operations#{}' custom_path = 'azure.cli.command_modules.batch.custom#{}' @@ -17,119 +30,104 @@ # pylint: disable=line-too-long # Mgmt Account Operations -factory = lambda args: batch_client_factory(**args).batch_account -cli_command(__name__, 'batch account list', custom_path.format('list_accounts'), factory) -cli_command(__name__, 'batch account show', mgmt_path.format('batch_account', 'BatchAccountOperations.get'), factory) -cli_command(__name__, 'batch account create', custom_path.format('create_account'), factory) -cli_command(__name__, 'batch account set', custom_path.format('update_account'), factory) -cli_command(__name__, 'batch account delete', mgmt_path.format('batch_account', 'BatchAccountOperations.delete'), factory, confirmation=True) -cli_command(__name__, 'batch account autostorage-keys sync', mgmt_path.format('batch_account', 'BatchAccountOperations.synchronize_auto_storage_keys'), factory) - -cli_command(__name__, 'batch account keys list', mgmt_path.format('batch_account', 'BatchAccountOperations.get_keys'), factory) -cli_command(__name__, 'batch account keys renew', mgmt_path.format('batch_account', 'BatchAccountOperations.regenerate_key'), factory) - -factory = lambda args: batch_client_factory(**args).application -cli_command(__name__, 'batch application list', mgmt_path.format('application', 'ApplicationOperations.list'), factory) -cli_command(__name__, 'batch application show', mgmt_path.format('application', 'ApplicationOperations.get'), factory) -cli_command(__name__, 'batch application create', mgmt_path.format('application', 'ApplicationOperations.create'), factory) -cli_command(__name__, 'batch application set', custom_path.format('update_application'), factory) -cli_command(__name__, 'batch application delete', mgmt_path.format('application', 'ApplicationOperations.delete'), factory) - -factory = lambda args: batch_client_factory(**args).application_package -cli_command(__name__, 'batch application package create', custom_path.format('create_application_package'), factory) -cli_command(__name__, 'batch application package delete', mgmt_path.format('application_package', 'ApplicationPackageOperations.delete'), factory) -cli_command(__name__, 'batch application package show', mgmt_path.format('application_package', 'ApplicationPackageOperations.get'), factory) -cli_command(__name__, 'batch application package activate', mgmt_path.format('application_package', 'ApplicationPackageOperations.activate'), factory) - -factory = lambda args: batch_client_factory(**args).location -cli_command(__name__, 'batch location quotas show', mgmt_path.format('location', 'LocationOperations.get_quotas'), factory) +cli_command(__name__, 'batch account list', custom_path.format('list_accounts'), account_mgmt_client_factory) +cli_command(__name__, 'batch account show', mgmt_path.format('batch_account', 'BatchAccountOperations.get'), account_mgmt_client_factory) +cli_command(__name__, 'batch account create', custom_path.format('create_account'), account_mgmt_client_factory) +cli_command(__name__, 'batch account set', custom_path.format('update_account'), account_mgmt_client_factory) +cli_command(__name__, 'batch account delete', mgmt_path.format('batch_account', 'BatchAccountOperations.delete'), account_mgmt_client_factory, confirmation=True) +cli_command(__name__, 'batch account autostorage-keys sync', mgmt_path.format('batch_account', 'BatchAccountOperations.synchronize_auto_storage_keys'), account_mgmt_client_factory) +cli_command(__name__, 'batch account keys list', mgmt_path.format('batch_account', 'BatchAccountOperations.get_keys'), account_mgmt_client_factory) +cli_command(__name__, 'batch account keys renew', mgmt_path.format('batch_account', 'BatchAccountOperations.regenerate_key'), account_mgmt_client_factory) + +cli_command(__name__, 'batch application list', mgmt_path.format('application', 'ApplicationOperations.list'), application_mgmt_client_factory) +cli_command(__name__, 'batch application show', mgmt_path.format('application', 'ApplicationOperations.get'), application_mgmt_client_factory) +cli_command(__name__, 'batch application create', mgmt_path.format('application', 'ApplicationOperations.create'), application_mgmt_client_factory) +cli_command(__name__, 'batch application set', custom_path.format('update_application'), application_mgmt_client_factory) +cli_command(__name__, 'batch application delete', mgmt_path.format('application', 'ApplicationOperations.delete'), application_mgmt_client_factory) + +cli_command(__name__, 'batch application package create', custom_path.format('create_application_package'), application_package_client_factory) +cli_command(__name__, 'batch application package delete', mgmt_path.format('application_package', 'ApplicationPackageOperations.delete'), application_package_client_factory) +cli_command(__name__, 'batch application package show', mgmt_path.format('application_package', 'ApplicationPackageOperations.get'), application_package_client_factory) +cli_command(__name__, 'batch application package activate', mgmt_path.format('application_package', 'ApplicationPackageOperations.activate'), application_package_client_factory) + +cli_command(__name__, 'batch location quotas show', mgmt_path.format('location', 'LocationOperations.get_quotas'), location_client_factory) # Data Plane Commands -factory = lambda args: batch_data_service_factory(args).application -cli_data_plane_command('batch application summary list', data_path.format('application', 'ApplicationOperations.list'), factory) -cli_data_plane_command('batch application summary show', data_path.format('application', 'ApplicationOperations.get'), factory) - -factory = lambda args: batch_data_service_factory(args).account -cli_data_plane_command('batch pool node-agent-skus list', data_path.format('account', 'AccountOperations.list_node_agent_skus'), factory) - -factory = lambda args: batch_data_service_factory(args).certificate -cli_command(__name__, 'batch certificate create', custom_path.format('create_certificate'), factory) -cli_command(__name__, 'batch certificate delete', custom_path.format('delete_certificate'), factory, confirmation=True) -cli_data_plane_command('batch certificate show', data_path.format('certificate', 'CertificateOperations.get'), factory) -cli_data_plane_command('batch certificate list', data_path.format('certificate', 'CertificateOperations.list'), factory) - -factory = lambda args: batch_data_service_factory(args).pool -cli_data_plane_command('batch pool usage-metrics list', data_path.format('pool', 'PoolOperations.list_pool_usage_metrics'), factory) -cli_data_plane_command('batch pool all-stats show', data_path.format('pool', 'PoolOperations.get_all_pools_lifetime_statistics'), factory) -cli_data_plane_command('batch pool create', data_path.format('pool', 'PoolOperations.add'), factory, validator=validate_pool_settings) -cli_data_plane_command('batch pool list', data_path.format('pool', 'PoolOperations.list'), factory) -cli_data_plane_command('batch pool delete', data_path.format('pool', 'PoolOperations.delete'), factory) -cli_data_plane_command('batch pool show', data_path.format('pool', 'PoolOperations.get'), factory) -cli_data_plane_command('batch pool set', data_path.format('pool', 'PoolOperations.patch'), factory) -cli_command(__name__, 'batch pool reset', custom_path.format('update_pool'), factory) -cli_data_plane_command('batch pool autoscale disable', data_path.format('pool', 'PoolOperations.disable_auto_scale'), factory) -cli_data_plane_command('batch pool autoscale enable', data_path.format('pool', 'PoolOperations.enable_auto_scale'), factory) -cli_data_plane_command('batch pool autoscale evaluate', data_path.format('pool', 'PoolOperations.evaluate_auto_scale'), factory) -cli_command(__name__, 'batch pool resize', custom_path.format('resize_pool'), factory) -cli_data_plane_command('batch pool os upgrade', data_path.format('pool', 'PoolOperations.upgrade_os'), factory) -cli_data_plane_command('batch node delete', data_path.format('pool', 'PoolOperations.remove_nodes'), factory) - -factory = lambda args: batch_data_service_factory(args).job -cli_data_plane_command('batch job all-stats show', data_path.format('job', 'JobOperations.get_all_jobs_lifetime_statistics'), factory) -cli_data_plane_command('batch job create', data_path.format('job', 'JobOperations.add'), factory) -cli_data_plane_command('batch job delete', data_path.format('job', 'JobOperations.delete'), factory) -cli_data_plane_command('batch job show', data_path.format('job', 'JobOperations.get'), factory) -cli_data_plane_command('batch job set', data_path.format('job', 'JobOperations.patch'), factory) -cli_data_plane_command('batch job reset', data_path.format('job', 'JobOperations.update'), factory) -cli_command(__name__, 'batch job list', custom_path.format('list_job'), factory) -cli_data_plane_command('batch job disable', data_path.format('job', 'JobOperations.disable'), factory) -cli_data_plane_command('batch job enable', data_path.format('job', 'JobOperations.enable'), factory) -cli_data_plane_command('batch job stop', data_path.format('job', 'JobOperations.terminate'), factory) -cli_data_plane_command('batch job prep-release-status list', data_path.format('job', 'JobOperations.list_preparation_and_release_task_status'), factory) - -factory = lambda args: batch_data_service_factory(args).job_schedule -cli_data_plane_command('batch job-schedule create', data_path.format('job_schedule', 'JobScheduleOperations.add'), factory) -cli_data_plane_command('batch job-schedule delete', data_path.format('job_schedule', 'JobScheduleOperations.delete'), factory) -cli_data_plane_command('batch job-schedule show', data_path.format('job_schedule', 'JobScheduleOperations.get'), factory) -cli_data_plane_command('batch job-schedule set', data_path.format('job_schedule', 'JobScheduleOperations.patch'), factory) -cli_data_plane_command('batch job-schedule reset', data_path.format('job_schedule', 'JobScheduleOperations.update'), factory) -cli_data_plane_command('batch job-schedule disable', data_path.format('job_schedule', 'JobScheduleOperations.disable'), factory) -cli_data_plane_command('batch job-schedule enable', data_path.format('job_schedule', 'JobScheduleOperations.enable'), factory) -cli_data_plane_command('batch job-schedule stop', data_path.format('job_schedule', 'JobScheduleOperations.terminate'), factory) -cli_data_plane_command('batch job-schedule list', data_path.format('job_schedule', 'JobScheduleOperations.list'), factory) - -factory = lambda args: batch_data_service_factory(args).task -cli_command(__name__, 'batch task create', custom_path.format('create_task'), factory) -cli_data_plane_command('batch task list', data_path.format('task', 'TaskOperations.list'), factory) -cli_data_plane_command('batch task delete', data_path.format('task', 'TaskOperations.delete'), factory) -cli_data_plane_command('batch task show', data_path.format('task', 'TaskOperations.get'), factory) -cli_data_plane_command('batch task reset', data_path.format('task', 'TaskOperations.update'), factory) -cli_data_plane_command('batch task reactivate', data_path.format('task', 'TaskOperations.reactivate'), factory) -cli_data_plane_command('batch task stop', data_path.format('task', 'TaskOperations.terminate'), factory) -cli_data_plane_command('batch task subtask list', data_path.format('task', 'TaskOperations.list_subtasks'), factory) - -factory = lambda args: batch_data_service_factory(args).file -cli_data_plane_command('batch task file delete', data_path.format('file', 'FileOperations.delete_from_task'), factory) -cli_data_plane_command('batch task file download', data_path.format('file', 'FileOperations.get_from_task'), factory) -cli_data_plane_command('batch task file show', data_path.format('file', 'FileOperations.get_node_file_properties_from_task'), factory) -cli_data_plane_command('batch task file list', data_path.format('file', 'FileOperations.list_from_task'), factory) - -factory = lambda args: batch_data_service_factory(args).compute_node -cli_data_plane_command('batch node-user create', data_path.format('compute_node', 'ComputeNodeOperations.add_user'), factory) -cli_data_plane_command('batch node-user delete', data_path.format('compute_node', 'ComputeNodeOperations.delete_user'), factory) -cli_data_plane_command('batch node-user set', data_path.format('compute_node', 'ComputeNodeOperations.update_user'), factory) -cli_data_plane_command('batch node show', data_path.format('compute_node', 'ComputeNodeOperations.get'), factory) -cli_data_plane_command('batch node list', data_path.format('compute_node', 'ComputeNodeOperations.list'), factory) -cli_data_plane_command('batch node reboot', data_path.format('compute_node', 'ComputeNodeOperations.reboot'), factory) -cli_data_plane_command('batch node reimage', data_path.format('compute_node', 'ComputeNodeOperations.reimage'), factory) -cli_data_plane_command('batch node scheduling disable', data_path.format('compute_node', 'ComputeNodeOperations.disable_scheduling'), factory) -cli_data_plane_command('batch node scheduling enable', data_path.format('compute_node', 'ComputeNodeOperations.enable_scheduling'), factory) -cli_data_plane_command('batch node remote-login-settings show', data_path.format('compute_node', 'ComputeNodeOperations.get_remote_login_settings'), factory) -cli_data_plane_command('batch node remote-desktop show', data_path.format('compute_node', 'ComputeNodeOperations.get_remote_desktop'), factory) - -factory = lambda args: batch_data_service_factory(args).file -cli_data_plane_command('batch node file delete', data_path.format('file', 'FileOperations.delete_from_compute_node'), factory) -cli_data_plane_command('batch node file download', data_path.format('file', 'FileOperations.get_from_compute_node'), factory) -cli_data_plane_command('batch node file show', data_path.format('file', 'FileOperations.get_node_file_properties_from_compute_node'), factory) -cli_data_plane_command('batch node file list', data_path.format('file', 'FileOperations.list_from_compute_node'), factory) +cli_batch_data_plane_command('batch application summary list', data_path.format('application', 'ApplicationOperations.list'), application_client_factory) +cli_batch_data_plane_command('batch application summary show', data_path.format('application', 'ApplicationOperations.get'), application_client_factory) + +cli_batch_data_plane_command('batch pool node-agent-skus list', data_path.format('account', 'AccountOperations.list_node_agent_skus'), account_client_factory) + +cli_command(__name__, 'batch certificate create', custom_path.format('create_certificate'), certificate_client_factory) +cli_command(__name__, 'batch certificate delete', custom_path.format('delete_certificate'), certificate_client_factory, confirmation=True) +cli_batch_data_plane_command('batch certificate show', data_path.format('certificate', 'CertificateOperations.get'), certificate_client_factory) +cli_batch_data_plane_command('batch certificate list', data_path.format('certificate', 'CertificateOperations.list'), certificate_client_factory) + +cli_batch_data_plane_command('batch pool usage-metrics list', data_path.format('pool', 'PoolOperations.list_pool_usage_metrics'), pool_client_factory) +cli_batch_data_plane_command('batch pool all-stats show', data_path.format('pool', 'PoolOperations.get_all_pools_lifetime_statistics'), pool_client_factory) +cli_batch_data_plane_command('batch pool create', data_path.format('pool', 'PoolOperations.add'), pool_client_factory, validator=validate_pool_settings) +cli_batch_data_plane_command('batch pool list', data_path.format('pool', 'PoolOperations.list'), pool_client_factory) +cli_batch_data_plane_command('batch pool delete', data_path.format('pool', 'PoolOperations.delete'), pool_client_factory) +cli_batch_data_plane_command('batch pool show', data_path.format('pool', 'PoolOperations.get'), pool_client_factory) +cli_batch_data_plane_command('batch pool set', data_path.format('pool', 'PoolOperations.patch'), pool_client_factory) +cli_command(__name__, 'batch pool reset', custom_path.format('update_pool'), pool_client_factory) +cli_batch_data_plane_command('batch pool autoscale disable', data_path.format('pool', 'PoolOperations.disable_auto_scale'), pool_client_factory) +cli_batch_data_plane_command('batch pool autoscale enable', data_path.format('pool', 'PoolOperations.enable_auto_scale'), pool_client_factory) +cli_batch_data_plane_command('batch pool autoscale evaluate', data_path.format('pool', 'PoolOperations.evaluate_auto_scale'), pool_client_factory) +cli_command(__name__, 'batch pool resize', custom_path.format('resize_pool'), pool_client_factory) +cli_batch_data_plane_command('batch pool os upgrade', data_path.format('pool', 'PoolOperations.upgrade_os'), pool_client_factory) +cli_batch_data_plane_command('batch node delete', data_path.format('pool', 'PoolOperations.remove_nodes'), pool_client_factory) + +cli_batch_data_plane_command('batch job all-stats show', data_path.format('job', 'JobOperations.get_all_jobs_lifetime_statistics'), job_client_factory) +cli_batch_data_plane_command('batch job create', data_path.format('job', 'JobOperations.add'), job_client_factory) +cli_batch_data_plane_command('batch job delete', data_path.format('job', 'JobOperations.delete'), job_client_factory) +cli_batch_data_plane_command('batch job show', data_path.format('job', 'JobOperations.get'), job_client_factory) +cli_batch_data_plane_command('batch job set', data_path.format('job', 'JobOperations.patch'), job_client_factory) +cli_batch_data_plane_command('batch job reset', data_path.format('job', 'JobOperations.update'), job_client_factory) +cli_command(__name__, 'batch job list', custom_path.format('list_job'), job_client_factory) +cli_batch_data_plane_command('batch job disable', data_path.format('job', 'JobOperations.disable'), job_client_factory) +cli_batch_data_plane_command('batch job enable', data_path.format('job', 'JobOperations.enable'), job_client_factory) +cli_batch_data_plane_command('batch job stop', data_path.format('job', 'JobOperations.terminate'), job_client_factory) +cli_batch_data_plane_command('batch job prep-release-status list', data_path.format('job', 'JobOperations.list_preparation_and_release_task_status'), job_client_factory) + +cli_batch_data_plane_command('batch job-schedule create', data_path.format('job_schedule', 'JobScheduleOperations.add'), job_schedule_client_factory) +cli_batch_data_plane_command('batch job-schedule delete', data_path.format('job_schedule', 'JobScheduleOperations.delete'), job_schedule_client_factory) +cli_batch_data_plane_command('batch job-schedule show', data_path.format('job_schedule', 'JobScheduleOperations.get'), job_schedule_client_factory) +cli_batch_data_plane_command('batch job-schedule set', data_path.format('job_schedule', 'JobScheduleOperations.patch'), job_schedule_client_factory) +cli_batch_data_plane_command('batch job-schedule reset', data_path.format('job_schedule', 'JobScheduleOperations.update'), job_schedule_client_factory) +cli_batch_data_plane_command('batch job-schedule disable', data_path.format('job_schedule', 'JobScheduleOperations.disable'), job_schedule_client_factory) +cli_batch_data_plane_command('batch job-schedule enable', data_path.format('job_schedule', 'JobScheduleOperations.enable'), job_schedule_client_factory) +cli_batch_data_plane_command('batch job-schedule stop', data_path.format('job_schedule', 'JobScheduleOperations.terminate'), job_schedule_client_factory) +cli_batch_data_plane_command('batch job-schedule list', data_path.format('job_schedule', 'JobScheduleOperations.list'), job_schedule_client_factory) + +cli_command(__name__, 'batch task create', custom_path.format('create_task'), task_client_factory) +cli_batch_data_plane_command('batch task list', data_path.format('task', 'TaskOperations.list'), task_client_factory) +cli_batch_data_plane_command('batch task delete', data_path.format('task', 'TaskOperations.delete'), task_client_factory) +cli_batch_data_plane_command('batch task show', data_path.format('task', 'TaskOperations.get'), task_client_factory) +cli_batch_data_plane_command('batch task reset', data_path.format('task', 'TaskOperations.update'), task_client_factory) +cli_batch_data_plane_command('batch task reactivate', data_path.format('task', 'TaskOperations.reactivate'), task_client_factory) +cli_batch_data_plane_command('batch task stop', data_path.format('task', 'TaskOperations.terminate'), task_client_factory) +cli_batch_data_plane_command('batch task subtask list', data_path.format('task', 'TaskOperations.list_subtasks'), task_client_factory) + +cli_batch_data_plane_command('batch task file delete', data_path.format('file', 'FileOperations.delete_from_task'), file_client_factory) +cli_batch_data_plane_command('batch task file download', data_path.format('file', 'FileOperations.get_from_task'), file_client_factory) +cli_batch_data_plane_command('batch task file show', data_path.format('file', 'FileOperations.get_node_file_properties_from_task'), file_client_factory) +cli_batch_data_plane_command('batch task file list', data_path.format('file', 'FileOperations.list_from_task'), file_client_factory) + +cli_batch_data_plane_command('batch node-user create', data_path.format('compute_node', 'ComputeNodeOperations.add_user'), compute_node_client_factory) +cli_batch_data_plane_command('batch node-user delete', data_path.format('compute_node', 'ComputeNodeOperations.delete_user'), compute_node_client_factory) +cli_batch_data_plane_command('batch node-user set', data_path.format('compute_node', 'ComputeNodeOperations.update_user'), compute_node_client_factory) +cli_batch_data_plane_command('batch node show', data_path.format('compute_node', 'ComputeNodeOperations.get'), compute_node_client_factory) +cli_batch_data_plane_command('batch node list', data_path.format('compute_node', 'ComputeNodeOperations.list'), compute_node_client_factory) +cli_batch_data_plane_command('batch node reboot', data_path.format('compute_node', 'ComputeNodeOperations.reboot'), compute_node_client_factory) +cli_batch_data_plane_command('batch node reimage', data_path.format('compute_node', 'ComputeNodeOperations.reimage'), compute_node_client_factory) +cli_batch_data_plane_command('batch node scheduling disable', data_path.format('compute_node', 'ComputeNodeOperations.disable_scheduling'), compute_node_client_factory) +cli_batch_data_plane_command('batch node scheduling enable', data_path.format('compute_node', 'ComputeNodeOperations.enable_scheduling'), compute_node_client_factory) +cli_batch_data_plane_command('batch node remote-login-settings show', data_path.format('compute_node', 'ComputeNodeOperations.get_remote_login_settings'), compute_node_client_factory) +cli_batch_data_plane_command('batch node remote-desktop show', data_path.format('compute_node', 'ComputeNodeOperations.get_remote_desktop'), compute_node_client_factory) + +cli_batch_data_plane_command('batch node file delete', data_path.format('file', 'FileOperations.delete_from_compute_node'), file_client_factory) +cli_batch_data_plane_command('batch node file download', data_path.format('file', 'FileOperations.get_from_compute_node'), file_client_factory) +cli_batch_data_plane_command('batch node file show', data_path.format('file', 'FileOperations.get_node_file_properties_from_compute_node'), file_client_factory) +cli_batch_data_plane_command('batch node file list', data_path.format('file', 'FileOperations.list_from_compute_node'), file_client_factory) diff --git a/src/command_modules/azure-cli-batch/azure/cli/command_modules/batch/tests/test_batch_commands.py b/src/command_modules/azure-cli-batch/azure/cli/command_modules/batch/tests/test_batch_commands.py index c41f1111800..e46a7498ece 100644 --- a/src/command_modules/azure-cli-batch/azure/cli/command_modules/batch/tests/test_batch_commands.py +++ b/src/command_modules/azure-cli-batch/azure/cli/command_modules/batch/tests/test_batch_commands.py @@ -409,38 +409,38 @@ def get_client(*args): # pylint: disable=unused-argument creds = SharedKeyCredentials('test1', 'ZmFrZV9hY29jdW50X2tleQ==') return BatchServiceClient(creds, 'https://test1.westus.batch.azure.com/') - self.command_pool = _command_type.AzureDataPlaneCommand( + self.command_pool = _command_type.AzureBatchDataPlaneCommand( 'batch_unit_tests', 'batch_tests_pool', 'azure.batch.operations.pool_operations#PoolOperations.add', get_client, None, None, 3, None, None) - self.command_job = _command_type.AzureDataPlaneCommand( + self.command_job = _command_type.AzureBatchDataPlaneCommand( 'batch_unit_tests', 'batch_tests_job', 'azure.batch.operations.job_operations#JobOperations.add', get_client, None, None, 3, ['job.job_manager_task', 'job.job_preparation_task', 'job.job_release_task'], None) - self.command_task = _command_type.AzureDataPlaneCommand( + self.command_task = _command_type.AzureBatchDataPlaneCommand( 'batch_unit_tests', 'batch_tests_task', 'azure.batch.operations.task_operations#TaskOperations.add', get_client, None, None, 1, None, None) - self.command_file = _command_type.AzureDataPlaneCommand( + self.command_file = _command_type.AzureBatchDataPlaneCommand( 'batch_unit_tests', 'batch_tests_file', 'azure.batch.operations.file_operations#FileOperations.get_from_task', get_client, None, None, 3, None, None) - self.command_list = _command_type.AzureDataPlaneCommand( + self.command_list = _command_type.AzureBatchDataPlaneCommand( 'batch_unit_tests', 'batch_tests_list', 'azure.batch.operations.job_operations#JobOperations.list', get_client, None, None, 3, None, None) - self.command_delete = _command_type.AzureDataPlaneCommand( + self.command_delete = _command_type.AzureBatchDataPlaneCommand( 'batch_unit_tests', 'batch_tests_delete', 'azure.batch.operations.pool_operations#PoolOperations.delete', get_client, None, None, 3, None, None) - self.command_conflicts = _command_type.AzureDataPlaneCommand( + self.command_conflicts = _command_type.AzureBatchDataPlaneCommand( 'batch_unit_tests', 'batch_tests_conflicts', 'azure.batch.operations.job_schedule_operations#JobScheduleOperations.add', @@ -510,10 +510,13 @@ def test_batch_options(self): self.assertEqual(len(options), 4) def test_batch_cancel_operation(self): - self.assertFalse(self.command_job._cancel_operation({})) - self.assertFalse(self.command_job._cancel_operation({'force': True})) - self.assertFalse(self.command_delete._cancel_operation({'force': True})) - self.assertTrue(self.command_delete._cancel_operation({'force': None})) + from azure.cli.core._config import az_config as config + from azure.cli.core.commands import _user_confirmed as user + + self.assertFalse(self.command_job._cancel_operation({}, config, user)) + self.assertFalse(self.command_job._cancel_operation({'force': True}, config, user)) + self.assertFalse(self.command_delete._cancel_operation({'force': True}, config, user)) + self.assertTrue(self.command_delete._cancel_operation({'force': None}, config, user)) def test_batch_should_flatten(self): self.assertFalse(self.command_task._should_flatten('task.depends_on')) @@ -589,7 +592,7 @@ def test_batch_load_arguments(self): def test_batch_execute_command(self): def function_result(client, **kwargs): - # pylint: disable=unused-argument + # pylint: disable=function-redefined,unused-argument raise ValidationError('maximum', 'id', '100') def get_op_handler(operation): diff --git a/src/command_modules/azure-cli-batch/azure/cli/command_modules/batch/tests/test_batch_data_plane_command_base.py b/src/command_modules/azure-cli-batch/azure/cli/command_modules/batch/tests/test_batch_data_plane_command_base.py index 1debd02e870..35183c373ee 100644 --- a/src/command_modules/azure-cli-batch/azure/cli/command_modules/batch/tests/test_batch_data_plane_command_base.py +++ b/src/command_modules/azure-cli-batch/azure/cli/command_modules/batch/tests/test_batch_data_plane_command_base.py @@ -9,6 +9,8 @@ class BatchDataPlaneTestBase(VCRTestBase): + # pylint:disable=too-few-public-methods + def __init__(self, test_file, test_method): super(BatchDataPlaneTestBase, self).__init__(test_file, test_method) self.account_name = 'test1'