Skip to content

Commit

Permalink
[BatchAI] BatchAI module Knack conversion (Azure#5120)
Browse files Browse the repository at this point in the history
* BatchAi work

* BatchAI module conversion.

* Fix rebase issues with Backup.
  • Loading branch information
tjprescott authored Dec 18, 2017
1 parent 649ec1f commit 883e96d
Show file tree
Hide file tree
Showing 13 changed files with 374 additions and 313 deletions.
2 changes: 0 additions & 2 deletions .flake8
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,5 @@ exclude =
scripts
doc
build_scripts
src/command_modules/azure-cli-backup
src/command_modules/azure-cli-batchai
src/command_modules/azure-cli-cosmosdb
src/command_modules/azure-cli-monitor
2 changes: 1 addition & 1 deletion scripts/ci/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ EOL
for name in $(ls src/command_modules | grep azure-cli-); do
if [ "$name" == "azure-cli-appservice" ]; then continue; fi
if [ "$name" == "azure-cli-backup" ]; then continue; fi
if [ "$name" == "azure-cli-batchai" ]; then continue; fi
if [ "$name" == "azure-cli-batchai" ]; then continue; fi
if [ "$name" == "azure-cli-cosmosdb" ]; then continue; fi
if [ "$name" == "azure-cli-dla" ]; then continue; fi
if [ "$name" == "azure-cli-dls" ]; then continue; fi
Expand Down
4 changes: 2 additions & 2 deletions scripts/ci/test_static.sh
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ run_style azure.cli.command_modules.acr
run_style azure.cli.command_modules.acs
run_style azure.cli.command_modules.advisor
#run_style azure.cli.command_modules.appservice
#run_style azure.cli.command_modules.backup
run_style azure.cli.command_modules.backup
run_style azure.cli.command_modules.batch
#run_style azure.cli.command_modules.batchai
run_style azure.cli.command_modules.batchai
run_style azure.cli.command_modules.billing
run_style azure.cli.command_modules.cdn
run_style azure.cli.command_modules.cloud
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@
# pylint: disable=line-too-long

from argcomplete.completers import FilesCompleter

from knack.arguments import CLIArgumentType

from azure.cli.core.commands.parameters import \
(get_resource_name_completion_list, file_type, get_location_type, get_three_state_flag,
get_enum_type)
from azure.cli.command_modules.backup._validators import \
(datetime_type)

from knack.arguments import CLIArgumentType

# ARGUMENT DEFINITIONS

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@
import os
from datetime import datetime, timedelta
from six.moves.urllib.parse import urlparse # pylint: disable=import-error

from knack.log import get_logger

from msrest.paging import Paged
from msrestazure.tools import parse_resource_id, is_valid_resource_id

from azure.mgmt.recoveryservices.models import Vault, VaultProperties, Sku, SkuName, BackupStorageConfig
from azure.mgmt.recoveryservicesbackup.models import ProtectedItemResource, AzureIaaSComputeVMProtectedItem, \
Expand All @@ -23,10 +27,6 @@
backup_protectable_items_cf, resources_cf, backup_operation_statuses_cf, job_details_cf, \
protection_container_refresh_operation_results_cf, backup_protection_containers_cf

from knack.log import get_logger

from msrestazure.tools import parse_resource_id, is_valid_resource_id

logger = get_logger(__name__)

fabric_name = "Azure"
Expand Down Expand Up @@ -455,6 +455,7 @@ def _get_storage_account_id(cli_ctx, storage_account_name, storage_account_rg):
return storage_account.id


# pylint: disable=inconsistent-return-statements
def _get_disable_protection_request(item):
if item.properties.workload_type == WorkloadType.vm.value:
vm_item_properties = _get_vm_item_properties_from_vm_id(item.properties.virtual_machine_id)
Expand All @@ -465,13 +466,15 @@ def _get_disable_protection_request(item):
return vm_item


# pylint: disable=inconsistent-return-statements
def _get_vm_item_properties_from_vm_type(vm_type):
if vm_type == 'Microsoft.Compute/virtualMachines':
return AzureIaaSComputeVMProtectedItem()
elif vm_type == 'Microsoft.ClassicCompute/virtualMachines':
return AzureIaaSClassicComputeVMProtectedItem()


# pylint: disable=inconsistent-return-statements
def _get_vm_item_properties_from_vm_id(vm_id):
if 'Microsoft.Compute/virtualMachines' in vm_id:
return AzureIaaSComputeVMProtectedItem()
Expand Down Expand Up @@ -572,9 +575,9 @@ def _get_resource_name_and_rg(resource_group_name, name_or_id):
resource_group = resource_group_name
return name, resource_group

# Tracking Utilities


# Tracking Utilities
# pylint: disable=inconsistent-return-statements
def _track_backup_ilr(cli_ctx, result, vault_name, resource_group):
operation_status = _track_backup_operation(cli_ctx, resource_group, result, vault_name)

Expand All @@ -583,6 +586,7 @@ def _track_backup_ilr(cli_ctx, result, vault_name, resource_group):
return recovery_target.client_scripts


# pylint: disable=inconsistent-return-statements
def _track_backup_job(cli_ctx, result, vault_name, resource_group):
job_details_client = job_details_cf(None)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,28 @@
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------

import azure.cli.command_modules.batchai._help # pylint: disable=unused-import
from azure.cli.core import AzCommandsLoader

from azure.cli.command_modules.batchai._help import helps # pylint: disable=unused-import

def load_params(_):
import azure.cli.command_modules.batchai._params # pylint: disable=redefined-outer-name, unused-variable

class BatchAiCommandsLoader(AzCommandsLoader):

def load_commands():
import azure.cli.command_modules.batchai.commands # pylint: disable=redefined-outer-name, unused-variable
def __init__(self, cli_ctx=None):
from azure.cli.core.commands import CliCommandType
batchai_custom = CliCommandType(operations_tmpl='azure.cli.command_modules.batchai.custom#{}')
super(BatchAiCommandsLoader, self).__init__(cli_ctx=cli_ctx,
min_profile='2017-03-10-profile',
custom_command_type=batchai_custom)

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

def load_arguments(self, command):
from azure.cli.command_modules.batchai._params import load_arguments
load_arguments(self, command)


COMMAND_LOADER_CLS = BatchAiCommandsLoader
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,19 @@
# --------------------------------------------------------------------------------------------


def batchai_client_factory(_=None):
def batchai_client_factory(cli_ctx, _=None):
from azure.mgmt.batchai import BatchAIManagementClient
from azure.cli.core.commands.client_factory import get_mgmt_service_client
return get_mgmt_service_client(BatchAIManagementClient)
return get_mgmt_service_client(cli_ctx, BatchAIManagementClient)


def cluster_client_factory(_):
return batchai_client_factory().clusters
def cluster_client_factory(cli_ctx, _):
return batchai_client_factory(cli_ctx).clusters


def job_client_factory(_):
return batchai_client_factory().jobs
def job_client_factory(cli_ctx, _):
return batchai_client_factory(cli_ctx).jobs


def file_server_client_factory(_):
return batchai_client_factory().file_servers
def file_server_client_factory(cli_ctx, _):
return batchai_client_factory(cli_ctx).file_servers
Loading

0 comments on commit 883e96d

Please sign in to comment.