diff --git a/src/command_modules/azure-cli-acr/azure/cli/command_modules/acr/_arm_utils.py b/src/command_modules/azure-cli-acr/azure/cli/command_modules/acr/_arm_utils.py index 06fa5addeaa..9393bb1d056 100644 --- a/src/command_modules/azure-cli-acr/azure/cli/command_modules/acr/_arm_utils.py +++ b/src/command_modules/azure-cli-acr/azure/cli/command_modules/acr/_arm_utils.py @@ -5,7 +5,10 @@ from azure.cli.command_modules.acr.mgmt_acr.models import RegistryParameters -from ._constants import RESOURCE_TYPE +from ._constants import ( + RESOURCE_PROVIDER, + RESOURCE_TYPE +) from ._factory import get_arm_service_client from azure.cli.command_modules.acr.mgmt_acr import VERSION @@ -59,10 +62,26 @@ def arm_deploy_template(resource_group_name, registry_name, location, storage_ac parameters = _parameters(registry_name, location, storage_account_name) properties = DeploymentProperties(template=template, parameters=parameters, mode='incremental') + return _arm_deploy_template(resource_group_name, properties) + +def _arm_deploy_template(resource_group_name, properties, index=0): + '''Deploys ARM template to create a container registry. + :param str resource_group_name: The name of resource group + :param DeploymentProperties properties: The properties of a deployment + :param int index: The index added to deployment name to avoid conflict + ''' + if index == 0: + deployment_name = RESOURCE_PROVIDER + else: + deployment_name = RESOURCE_PROVIDER + '_' + str(index) + client = get_arm_service_client() - deployment_name = 'Deployment.' + registry_name - return client.deployments.create_or_update(resource_group_name, deployment_name, properties) + try: + client.deployments.validate(resource_group_name, deployment_name, properties) + return client.deployments.create_or_update(resource_group_name, deployment_name, properties) + except: #pylint: disable=W0702 + return _arm_deploy_template(resource_group_name, properties, index + 1) def _parameters(registry_name, location, storage_account_name): '''Returns a dict of deployment parameters. @@ -75,7 +94,6 @@ def _parameters(registry_name, location, storage_account_name): 'registryLocation': {'value': location}, 'registryApiVersion': {'value': VERSION}, 'storageAccountName': {'value': storage_account_name}, - 'storageAccountLocation': {'value': 'westus'}, 'storageAccountApiVersion': {'value': '2015-05-01-preview'} } return parameters diff --git a/src/command_modules/azure-cli-acr/azure/cli/command_modules/acr/_constants.py b/src/command_modules/azure-cli-acr/azure/cli/command_modules/acr/_constants.py index 9421308ddfb..89b8403d43d 100644 --- a/src/command_modules/azure-cli-acr/azure/cli/command_modules/acr/_constants.py +++ b/src/command_modules/azure-cli-acr/azure/cli/command_modules/acr/_constants.py @@ -3,4 +3,5 @@ # Licensed under the MIT License. See License.txt in the project root for license information. #--------------------------------------------------------------------------------------------- -RESOURCE_TYPE = 'Microsoft.ContainerRegistry/registries' +RESOURCE_PROVIDER = 'Microsoft.ContainerRegistry' +RESOURCE_TYPE = RESOURCE_PROVIDER + '/registries' diff --git a/src/command_modules/azure-cli-acr/azure/cli/command_modules/acr/_factory.py b/src/command_modules/azure-cli-acr/azure/cli/command_modules/acr/_factory.py index a183dd0a316..d33e927cd65 100644 --- a/src/command_modules/azure-cli-acr/azure/cli/command_modules/acr/_factory.py +++ b/src/command_modules/azure-cli-acr/azure/cli/command_modules/acr/_factory.py @@ -6,7 +6,6 @@ from azure.cli.core._profile import Profile from azure.cli.core._config import az_config from azure.mgmt.resource.resources import ResourceManagementClient -from azure.storage._constants import SERVICE_HOST_BASE from azure.cli.core.commands.client_factory import ( configure_common_settings, @@ -45,8 +44,3 @@ def get_registry_service_client(): configure_common_settings(client) return client.registries - -def get_storage_end_point_suffix(): - '''Returns storage account end point suffix. - ''' - return SERVICE_HOST_BASE diff --git a/src/command_modules/azure-cli-acr/azure/cli/command_modules/acr/template.json b/src/command_modules/azure-cli-acr/azure/cli/command_modules/acr/template.json index 4fca20cdbcd..c26aa404346 100644 --- a/src/command_modules/azure-cli-acr/azure/cli/command_modules/acr/template.json +++ b/src/command_modules/azure-cli-acr/azure/cli/command_modules/acr/template.json @@ -26,12 +26,6 @@ "description": "Name of the storage account" } }, - "storageAccountLocation": { - "type": "string", - "metadata": { - "description": "Location of the storage account" - } - }, "storageAccountApiVersion": { "type": "string", "metadata": { @@ -44,7 +38,7 @@ "comments": "# Storage Account", "name": "[parameters('storageAccountName')]", "type": "Microsoft.Storage/storageAccounts", - "location": "[parameters('storageAccountLocation')]", + "location": "[parameters('registryLocation')]", "apiVersion": "[parameters('storageAccountApiVersion')]", "properties": { "accountType": "Standard_LRS"