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 @@ -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
Expand Down Expand Up @@ -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):
Copy link

@sajayantony sajayantony Sep 19, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure what index means. Do you need arg documentation here? or can you just remove the function if it isn't needed.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed. It is basically a validate and retry function to avoid deployment name conflict. Index is a number added to deployment names.

'''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.
Expand All @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,6 @@
"description": "Name of the storage account"
}
},
"storageAccountLocation": {
"type": "string",
"metadata": {
"description": "Location of the storage account"
}
},
"storageAccountApiVersion": {
"type": "string",
"metadata": {
Expand All @@ -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"
Expand Down