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
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -501,16 +498,16 @@ 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.
:returns: bool
"""
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.
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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)
Expand All @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
Loading