Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ACR] Prefix storage account name with registry name #1417

Merged
merged 1 commit into from
Nov 29, 2016
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 @@ -16,7 +16,8 @@
STORAGE_RESOURCE_TYPE
)
from ._validators import (
validate_resource_group_name
validate_resource_group_name,
validate_registry_name
)

register_cli_argument('acr', 'registry_name',
Expand All @@ -41,7 +42,8 @@
options_list=('--password', '-p'),
help='The password used to log into a container registry')

register_cli_argument('acr create', 'registry_name', completer=None)
register_cli_argument('acr create', 'registry_name', completer=None,
validator=validate_registry_name)
register_cli_argument('acr create', 'resource_group_name',
validator=validate_resource_group_name)
register_cli_argument('acr check-name', 'registry_name', completer=None)
Original file line number Diff line number Diff line change
Expand Up @@ -150,10 +150,20 @@ def _parameters(registry_name,
'registryName': {'value': registry_name},
'registryLocation': {'value': location},
'storageAccountName': {'value': storage_account_name},
'storageAccountType': {'value': 'Standard_LRS'},
'adminUserEnabled': {'value': admin_user_enabled},
}
customized_api_version = get_acr_api_version()
if customized_api_version:
parameters['registryApiVersion'] = {'value': customized_api_version}
return parameters

def random_storage_account_name(registry_name):
from datetime import datetime

client = get_storage_service_client().storage_accounts

while True:
time_stamp_suffix = datetime.utcnow().strftime('%H%M%S')
storage_account_name = ''.join([registry_name[:18], time_stamp_suffix])[:24]
if client.check_name_availability(storage_account_name).name_available: #pylint: disable=no-member
return storage_account_name
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,24 @@

from azure.cli.core._util import CLIError

from ._factory import get_arm_service_client
from ._factory import (
get_arm_service_client,
get_acr_service_client
)

import azure.cli.core._logging as _logging
logger = _logging.get_az_logger(__name__)

def validate_registry_name(namespace):
if namespace.registry_name:
client = get_acr_service_client().registries
registry_name = namespace.registry_name

result = client.check_name_availability(registry_name)

if not result.name_available: #pylint: disable=no-member
raise CLIError(result.message) #pylint: disable=no-member

def validate_resource_group_name(namespace):
if namespace.resource_group_name:
client = get_arm_service_client()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------

import uuid

from azure.cli.core.commands import LongRunningOperation

from azure.mgmt.containerregistry.models import (
Expand All @@ -17,7 +15,8 @@
from ._utils import (
get_access_key_by_storage_account_name,
get_resource_group_name_by_registry_name,
arm_deploy_template
arm_deploy_template,
random_storage_account_name
)

import azure.cli.core._logging as _logging
Expand Down Expand Up @@ -58,7 +57,7 @@ def acr_create(registry_name, #pylint: disable=too-many-arguments
admin_user_enabled = admin_enabled == 'true'

if storage_account_name is None:
storage_account_name = str(uuid.uuid4()).replace('-', '')[:24]
storage_account_name = random_storage_account_name(registry_name)
LongRunningOperation()(
arm_deploy_template(resource_group_name,
registry_name,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
},
"storageAccountType": {
"type": "string",
"defaultValue": "Standard_LRS",
"metadata": {
"description": "Type of the storage account"
}
Expand All @@ -47,6 +48,9 @@
"type": "Microsoft.Storage/storageAccounts",
"location": "[parameters('registryLocation')]",
"apiVersion": "2016-01-01",
"tags": {
"containerregistry": "[parameters('registryName')]"
},
"sku": {
"name": "[parameters('storageAccountType')]"
},
Expand Down
Loading