Skip to content

Commit

Permalink
[ACR] Improve resource creation performance and error handling (Azure…
Browse files Browse the repository at this point in the history
…#6195)

* Improve resource creation performance and error handling

* Record tests for appservice
  • Loading branch information
djyou authored and derekbekoe committed Apr 25, 2018
1 parent a74fce7 commit d556df4
Show file tree
Hide file tree
Showing 9 changed files with 872 additions and 1,055 deletions.
1 change: 1 addition & 0 deletions src/command_modules/azure-cli-acr/HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Release History

2.0.24
++++++
* Improve resource creation performance and error handling.
* Improve acr login in non-standard consoles and WSL.
* Improve repository commands error messages.
* Update table columns and ordering.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,39 +84,6 @@ def get_registry_by_name(cli_ctx, registry_name, resource_group_name=None):
return client.get(resource_group_name, registry_name), resource_group_name


def arm_deploy_template_managed_storage(cli_ctx,
resource_group_name,
registry_name,
location,
sku,
admin_user_enabled,
deployment_name=None):
"""Deploys ARM template to create a container registry with managed storage account.
:param str resource_group_name: The name of resource group
:param str registry_name: The name of container registry
:param str location: The name of location
:param str sku: The SKU of the container registry
:param bool admin_user_enabled: Enable admin user
:param str deployment_name: The name of the deployment
"""
from azure.mgmt.resource.resources.models import DeploymentProperties
from azure.cli.core.util import get_file_json
import os

parameters = _parameters(
registry_name=registry_name,
location=location,
sku=sku,
admin_user_enabled=admin_user_enabled)

file_path = os.path.join(os.path.dirname(__file__), 'template.json')
template = get_file_json(file_path)
properties = DeploymentProperties(template=template, parameters=parameters, mode='incremental')

return _arm_deploy_template(
get_arm_service_client(cli_ctx).deployments, resource_group_name, deployment_name, properties)


def arm_deploy_template_new_storage(cli_ctx,
resource_group_name,
registry_name,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from azure.cli.core.commands import LongRunningOperation

from azure.mgmt.containerregistry.v2017_10_01.models import (
Registry,
RegistryUpdateParameters,
StorageAccountProperties,
SkuName,
Expand All @@ -19,7 +20,6 @@
from ._utils import (
arm_deploy_template_new_storage,
arm_deploy_template_existing_storage,
arm_deploy_template_managed_storage,
random_storage_account_name,
get_registry_by_name,
validate_managed_registry,
Expand Down Expand Up @@ -91,23 +91,14 @@ def acr_create(cmd,
admin_user_enabled,
deployment_name)
)
return client.get(resource_group_name, registry_name)
else:
if storage_account_name:
logger.warning(
"The registry '%s' in '%s' SKU is a managed registry. The specified storage account will be ignored.",
registry_name, sku)
LongRunningOperation(cmd.cli_ctx)(
arm_deploy_template_managed_storage(
cmd.cli_ctx,
resource_group_name,
registry_name,
location,
sku,
admin_user_enabled,
deployment_name)
)

return client.get(resource_group_name, registry_name)
registry = Registry(location=location, sku=Sku(name=sku), admin_user_enabled=admin_user_enabled)
return client.create(resource_group_name, registry_name, registry)


def acr_delete(cmd, client, registry_name, resource_group_name=None):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,18 @@ def acr_replication_create(cmd,
normalized_location = "".join(location.split()).lower()
if registry.location == normalized_location:
raise CLIError('Replication could not be created in the same location as the registry.')
return client.create(
resource_group_name=resource_group_name,
registry_name=registry_name,
replication_name=replication_name or normalized_location,
location=location,
tags=tags
)

from msrest.exceptions import ValidationError
try:
return client.create(
resource_group_name=resource_group_name,
registry_name=registry_name,
replication_name=replication_name or normalized_location,
location=location,
tags=tags
)
except ValidationError as e:
raise CLIError(e)


def acr_replication_delete(cmd,
Expand Down

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

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

from azure.cli.core.util import CLIError

from azure.mgmt.containerregistry.v2017_10_01.models import (
WebhookCreateParameters,
WebhookUpdateParameters
Expand Down Expand Up @@ -37,20 +39,25 @@ def acr_webhook_create(cmd,
tags=None):
registry, resource_group_name = validate_managed_registry(
cmd.cli_ctx, registry_name, resource_group_name, WEBHOOKS_NOT_SUPPORTED)
return client.create(
resource_group_name,
registry_name,
webhook_name,
WebhookCreateParameters(
location=location or registry.location,
service_uri=uri,
actions=actions,
custom_headers=headers,
status=status,
scope=scope,
tags=tags

from msrest.exceptions import ValidationError
try:
return client.create(
resource_group_name,
registry_name,
webhook_name,
WebhookCreateParameters(
location=location or registry.location,
service_uri=uri,
actions=actions,
custom_headers=headers,
status=status,
scope=scope,
tags=tags
)
)
)
except ValidationError as e:
raise CLIError(e)


def acr_webhook_delete(cmd,
Expand Down
Loading

0 comments on commit d556df4

Please sign in to comment.