diff --git a/src/command_modules/azure-cli-acr/README.rst b/src/command_modules/azure-cli-acr/README.rst index b1c99192562..fcb2cf7df76 100644 --- a/src/command_modules/azure-cli-acr/README.rst +++ b/src/command_modules/azure-cli-acr/README.rst @@ -11,9 +11,9 @@ Commands to manage Azure container registries Subgroups: credential: Manage admin user credential for Azure container registries. repository: Manage repositories for Azure container registries. - storage : Manage storage accounts for Azure container registries. Commands: + check-name: Check whether the container registry name is available. create : Create a container registry. delete : Delete a container registry. list : List container registries. @@ -36,9 +36,9 @@ Create a container registry Examples Create a container registry with a new storage account - az acr create -n myRegistry -g myResourceGroup -l southus + az acr create -n myRegistry -g myResourceGroup -l southcentralus Create a container registry with an existing storage account - az acr create -n myRegistry -g myResourceGroup -l southus -s myStorageAccount + az acr create -n myRegistry -g myResourceGroup -l southcentralus -s myStorageAccount Delete a container registry ------------- @@ -86,39 +86,39 @@ Update a container registry az acr update: Update a container registry. Arguments - --name -n [Required]: Name of container registry. - --disable-admin : Disable admin user. - --enable-admin : Enable admin user. - --resource-group -g : Name of resource group. - --tags : Space separated tags in 'key[=value]' format. Use "" to clear existing - tags. - --tenant-id -t : Tenant id for service principal login. Warning: Changing tenant id will - invalidate assigned access of existing service principals. + --name -n [Required]: Name of container registry. + --disable-admin : Disable admin user. + --enable-admin : Enable admin user. + --resource-group -g : Name of resource group. + --storage-account-name -s: Name of an existing storage account. + --tags : Space separated tags in 'key[=value]' format. Use "" to clear + existing tags. Examples Update tags for a container registry - az acr update -n myRegistry --tags key1=value1;key2=value2 + az acr update -n myRegistry --tags key1=value1 key2=value2 + Update storage account for a container registry + az acr update -n myRegistry -s myStorageAccount Enable admin user for a container registry az acr update -n myRegistry --enable-admin -Update storage account for a container registry +Get login credentials for a container registry ------------- :: Command - az acr storage update: Update storage account for a container registry. + az acr credential show: Get login credentials for a container registry. Arguments - --name -n [Required]: Name of container registry. - --storage-account-name -s [Required]: Name of an existing storage account. - --resource-group -g : Name of resource group. + --name -n [Required]: Name of container registry. + --resource-group -g : Name of resource group. -Get admin username and password for a container registry +Regenerate login credentials for a container registry ------------- :: Command - az acr credential show: Get admin username and password for a container registry. + az acr credential renew: Regenerate login credentials for a container registry. Arguments --name -n [Required]: Name of container registry. diff --git a/src/command_modules/azure-cli-acr/azure/cli/command_modules/acr/__init__.py b/src/command_modules/azure-cli-acr/azure/cli/command_modules/acr/__init__.py index 231e89fa929..c80be6ae8c4 100644 --- a/src/command_modules/azure-cli-acr/azure/cli/command_modules/acr/__init__.py +++ b/src/command_modules/azure-cli-acr/azure/cli/command_modules/acr/__init__.py @@ -8,6 +8,5 @@ import azure.cli.command_modules.acr._help import azure.cli.command_modules.acr._params import azure.cli.command_modules.acr.custom -import azure.cli.command_modules.acr.storage import azure.cli.command_modules.acr.credential import azure.cli.command_modules.acr.repository 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 deleted file mode 100644 index 4175aec7f94..00000000000 --- a/src/command_modules/azure-cli-acr/azure/cli/command_modules/acr/_arm_utils.py +++ /dev/null @@ -1,187 +0,0 @@ -#--------------------------------------------------------------------------------------------- -# Copyright (c) Microsoft Corporation. All rights reserved. -# Licensed under the MIT License. See License.txt in the project root for license information. -#--------------------------------------------------------------------------------------------- - -from azure.cli.core._util import CLIError -from azure.cli.core.commands.parameters import ( - get_resources_in_subscription, - get_resources_in_resource_group -) - -from azure.cli.command_modules.acr.mgmt_acr.models import Registry - -from ._constants import ( - RESOURCE_PROVIDER, - RESOURCE_TYPE -) -from ._factory import ( - get_arm_service_client, - get_storage_service_client, - get_acr_api_version -) -from ._utils import get_resource_group_name_by_resource_id - -def arm_get_registries_in_subscription(): - '''Returns the list of container registries in the current subscription. - ''' - result = get_resources_in_subscription(RESOURCE_TYPE) - return [Registry(item.id, item.name, item.location, item.tags) for item in result] - -def arm_get_registries_in_resource_group(resource_group_name): - '''Returns the list of container registries in the resource group. - :param str resource_group_name: The name of resource group - ''' - result = get_resources_in_resource_group(resource_group_name, RESOURCE_TYPE) - return [Registry(item.id, item.name, item.location, item.tags) for item in result] - -def _arm_get_resource_by_name(resource_name, resource_type): - '''Returns the ARM resource in the current subscription with resource_name. - :param str resource_name: The name of resource - :param str resource_type: The type of resource - ''' - result = get_resources_in_subscription(resource_type) - elements = [item for item in result if item.name.lower() == resource_name.lower()] - - if len(elements) == 0: - return None - elif len(elements) == 1: - return elements[0] - else: - raise CLIError( - 'More than one resources with type {} are found with name: {}'.format( - resource_type, resource_name)) - -def arm_get_registry_by_name(registry_name): - '''Returns the named container registry. - :param str registry_name: The name of container registry - ''' - return _arm_get_resource_by_name(registry_name, RESOURCE_TYPE) - -def arm_get_storage_account_by_name(storage_account_name): - '''Returns the named storage account. - :param str storage_account_name: The name of storage account - ''' - return _arm_get_resource_by_name(storage_account_name, 'Microsoft.Storage/storageAccounts') - -def arm_deploy_template(resource_group_name, - registry_name, - location, - storage_account_name, - admin_user_enabled): - '''Deploys ARM template to create/update a container registry. - :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 storage_account_name: The name of storage account - :param bool admin_user_enabled: Enable admin user - ''' - from azure.mgmt.resource.resources.models import DeploymentProperties - from azure.cli.core._util import get_file_json - import os - - parameters = _parameters(registry_name, location, storage_account_name, admin_user_enabled) - storage_account_resource_group, _ = _parse_storage_account(storage_account_name) - - if storage_account_resource_group: - file_path = os.path.join(os.path.dirname(__file__), 'template.existing.json') - parameters['storageAccountResourceGroup'] = {'value': storage_account_resource_group} - else: - file_path = os.path.join(os.path.dirname(__file__), 'template.new.json') - parameters['storageAccountType'] = {'value': 'Standard_LRS'} - - template = get_file_json(file_path) - properties = DeploymentProperties(template=template, parameters=parameters, mode='incremental') - - return _arm_deploy_template( - get_arm_service_client().deployments, resource_group_name, properties) - -def _arm_deploy_template(deployments_client, - resource_group_name, - properties, - index=0): - '''Deploys ARM template to create a container registry. - :param obj deployments_client: ARM deployments service client - :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 - elif index > 9: # Just a number to avoid infinite loops - raise CLIError( - 'The resource group {} has too many deployments'.format(resource_group_name)) - else: - deployment_name = RESOURCE_PROVIDER + '_' + str(index) - - try: - deployments_client.validate( - resource_group_name, deployment_name, properties) - return deployments_client.create_or_update( - resource_group_name, deployment_name, properties) - except: #pylint: disable=bare-except - return _arm_deploy_template( - deployments_client, resource_group_name, properties, index + 1) - -def _parameters(registry_name, - location, - storage_account_name, - admin_user_enabled): - '''Returns a dict of deployment parameters. - :param str registry_name: The name of container registry - :param str location: The name of location - :param str storage_account_name: The name of storage account - :param bool admin_user_enabled: Enable admin user - ''' - parameters = { - 'registryName': {'value': registry_name}, - 'registryLocation': {'value': location}, - 'registryApiVersion': {'value': get_acr_api_version()}, - 'storageAccountName': {'value': storage_account_name}, - 'adminUserEnabled': {'value': admin_user_enabled} - } - return parameters - -def _parse_storage_account(storage_account_name): - '''Returns resource group and tags in the storage account. - :param str storage_account_name: The name of storage account - ''' - storage_account = arm_get_storage_account_by_name(storage_account_name) - - if storage_account: - storage_account_resource_group = get_resource_group_name_by_resource_id(storage_account.id) - return storage_account_resource_group, storage_account.tags - else: - return None, None - -def add_tag_storage_account(storage_account_name, registry_name): - '''Add a new tag (key, value) to the storage account. - :param str storage_account_name: The name of storage account - :param str registry_name: The name of container registry - ''' - from azure.mgmt.storage.models import StorageAccountUpdateParameters - storage_account_resource_group, tags = _parse_storage_account(storage_account_name) - - tags[registry_name.lower()] = 'acr' - client = get_storage_service_client().storage_accounts - - return client.update(storage_account_resource_group, - storage_account_name, - StorageAccountUpdateParameters(tags=tags)) - -def delete_tag_storage_account(storage_account_name, registry_name): - '''Delete a tag (key, value) from the storage account, if value matches registry_name. - :param str storage_account_name: The name of storage account - :param str registry_name: The name of container registry - ''' - from azure.mgmt.storage.models import StorageAccountUpdateParameters - storage_account_resource_group, tags = _parse_storage_account(storage_account_name) - registry_name = registry_name.lower() - - if registry_name in tags and tags[registry_name] == 'acr': - del tags[registry_name] - client = get_storage_service_client().storage_accounts - - return client.update(storage_account_resource_group, - storage_account_name, - StorageAccountUpdateParameters(tags=tags)) 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 89b8403d43d..d543d600dd7 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,5 +3,6 @@ # Licensed under the MIT License. See License.txt in the project root for license information. #--------------------------------------------------------------------------------------------- -RESOURCE_PROVIDER = 'Microsoft.ContainerRegistry' -RESOURCE_TYPE = RESOURCE_PROVIDER + '/registries' +ACR_RESOURCE_PROVIDER = 'Microsoft.ContainerRegistry' +ACR_RESOURCE_TYPE = ACR_RESOURCE_PROVIDER + '/registries' +STORAGE_RESOURCE_TYPE = 'Microsoft.Storage/storageAccounts' 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 6c462fe857a..37d2fb1d9b9 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 @@ -7,7 +7,6 @@ Profile, CLOUD ) -from azure.cli.core.cloud import CloudEndpoint from azure.cli.core._config import az_config from azure.mgmt.resource.resources import ResourceManagementClient from azure.mgmt.storage import StorageManagementClient @@ -18,8 +17,8 @@ ) from azure.cli.command_modules.acr.mgmt_acr import ( - ContainerRegistry, - ContainerRegistryConfiguration, + ContainerRegistryManagementClient, + ContainerRegistryManagementClientConfiguration, VERSION ) @@ -42,12 +41,12 @@ def get_acr_service_client(): profile = Profile() credentials, subscription_id, _ = profile.get_login_credentials() - config = ContainerRegistryConfiguration( - subscription_id, - get_acr_api_version(), + config = ContainerRegistryManagementClientConfiguration( credentials, - base_url=CLOUD.endpoints[CloudEndpoint.RESOURCE_MANAGER]) - client = ContainerRegistry(config) + subscription_id, + api_version=get_acr_api_version(), + base_url=CLOUD.endpoints.resource_manager) + client = ContainerRegistryManagementClient(config) configure_common_settings(client) diff --git a/src/command_modules/azure-cli-acr/azure/cli/command_modules/acr/_format.py b/src/command_modules/azure-cli-acr/azure/cli/command_modules/acr/_format.py index b92402bed0e..cea289e376a 100644 --- a/src/command_modules/azure-cli-acr/azure/cli/command_modules/acr/_format.py +++ b/src/command_modules/azure-cli-acr/azure/cli/command_modules/acr/_format.py @@ -7,14 +7,11 @@ from ._utils import get_resource_group_name_by_resource_id -_basic_map = { +_registry_map = { 'name': 'NAME', 'resourceGroup': 'RESOURCE GROUP', 'location': 'LOCATION', - 'tags': 'TAGS' -} - -_properties_map = { + 'tags': 'TAGS', 'loginServer': 'LOGIN SERVER', 'creationDate': 'CREATION DATE', 'adminUserEnabled': 'ADMIN USER ENABLED' @@ -25,8 +22,8 @@ } _admin_user_map = { - 'userName': 'USERNAME', - 'passWord': 'PASSWORD' + 'username': 'USERNAME', + 'password': 'PASSWORD' } _order_map = { @@ -53,29 +50,22 @@ def _format_registry(item): '''Returns an ordered dictionary of the container registry. :param dict item: The container registry object ''' - basic_info = {_basic_map[key]: str(item[key]) for key in item if key in _basic_map} + registry_info = {_registry_map[key]: str(item[key]) for key in item if key in _registry_map} if 'id' in item and item['id']: resource_group_name = get_resource_group_name_by_resource_id(item['id']) - basic_info['RESOURCE GROUP'] = resource_group_name + registry_info['RESOURCE GROUP'] = resource_group_name - properties_info = {} storage_account_info = {} - if 'properties' in item and item['properties']: - properties = item['properties'] - properties_info = {_properties_map[key]: str(properties[key]) - for key in properties if key in _properties_map} - - if 'storageAccount' in properties and properties['storageAccount']: - storage_account = properties['storageAccount'] - storage_account_info = {_storage_account_map[key]: str(storage_account[key]) - for key in storage_account if key in _storage_account_map} + if 'storageAccount' in item and item['storageAccount']: + storage_account = item['storageAccount'] + storage_account_info = {_storage_account_map[key]: str(storage_account[key]) + for key in storage_account if key in _storage_account_map} admin_user_info = {_admin_user_map[key]: str(item[key]) for key in item if key in _admin_user_map} - all_info = basic_info.copy() - all_info.update(properties_info) + all_info = registry_info.copy() all_info.update(storage_account_info) all_info.update(admin_user_info) diff --git a/src/command_modules/azure-cli-acr/azure/cli/command_modules/acr/_help.py b/src/command_modules/azure-cli-acr/azure/cli/command_modules/acr/_help.py index bdca9e764fe..18d2f977d8b 100644 --- a/src/command_modules/azure-cli-acr/azure/cli/command_modules/acr/_help.py +++ b/src/command_modules/azure-cli-acr/azure/cli/command_modules/acr/_help.py @@ -12,11 +12,6 @@ short-summary: Commands to manage Azure container registries. """ -helps['acr storage'] = """ - type: group - short-summary: Manage storage accounts for Azure container registries. - """ - helps['acr credential'] = """ type: group short-summary: Manage admin user credential for Azure container registries. @@ -43,10 +38,10 @@ examples: - name: Create a container registry with a new storage account text: - az acr create -n myRegistry -g myResourceGroup -l southus + az acr create -n myRegistry -g myResourceGroup -l southcentralus - name: Create a container registry with an existing storage account text: - az acr create -n myRegistry -g myResourceGroup -l southus -s myStorageAccount + az acr create -n myRegistry -g myResourceGroup -l southcentralus -s myStorageAccount """ helps['acr update'] = """ @@ -55,6 +50,9 @@ - name: Update tags for a container registry text: az acr update -n myRegistry --tags key1=value1 key2=value2 + - name: Update storage account for a container registry + text: + az acr update -n myRegistry -s myStorageAccount - name: Enable admin user for a container registry text: az acr update -n myRegistry --enable-admin diff --git a/src/command_modules/azure-cli-acr/azure/cli/command_modules/acr/_params.py b/src/command_modules/azure-cli-acr/azure/cli/command_modules/acr/_params.py index d569b33b184..eb7c31b82ed 100644 --- a/src/command_modules/azure-cli-acr/azure/cli/command_modules/acr/_params.py +++ b/src/command_modules/azure-cli-acr/azure/cli/command_modules/acr/_params.py @@ -11,46 +11,40 @@ get_resource_name_completion_list ) -from ._constants import RESOURCE_TYPE +from ._constants import ( + ACR_RESOURCE_TYPE, + STORAGE_RESOURCE_TYPE +) from ._validators import ( - validate_registry_name_create, - validate_registry_name, - validate_storage_account_name, - validate_resource_group_name + validate_resource_group_name, + validate_admin_user ) register_cli_argument('acr', 'registry_name', options_list=('--name', '-n'), help='Name of container registry', - completer=get_resource_name_completion_list(RESOURCE_TYPE), - validator=validate_registry_name) + completer=get_resource_name_completion_list(ACR_RESOURCE_TYPE)) +register_cli_argument('acr', 'storage_account_name', + options_list=('--storage-account-name', '-s'), + help='Name of an existing storage account', + completer=get_resource_name_completion_list(STORAGE_RESOURCE_TYPE)) register_cli_argument('acr', 'resource_group_name', resource_group_name_type) register_cli_argument('acr', 'location', location_type) register_cli_argument('acr', 'tags', tags_type) -register_cli_argument('acr', 'storage_account_name', - options_list=('--storage-account-name', '-s'), - help='Name of an existing storage account', - completer=get_resource_name_completion_list( - 'Microsoft.Storage/storageAccounts'), - validator=validate_storage_account_name) - register_cli_argument('acr', 'username', options_list=('--username', '-u'), help='Username used to log into a container registry') - register_cli_argument('acr', 'password', options_list=('--password', '-p'), help='Password used to log into a container registry') -register_cli_argument('acr', 'tenant_id', - options_list=('--tenant-id', '-t'), - help='Tenant id for service principal login. ' +\ - 'Warning: Changing tenant id will invalidate ' +\ - 'assigned access of existing service principals.') - -register_cli_argument('acr create', 'registry_name', completer=None, - validator=validate_registry_name_create) +register_cli_argument('acr create', 'registry_name', completer=None) register_cli_argument('acr create', 'resource_group_name', validator=validate_resource_group_name) + +register_cli_argument('acr', 'enable_admin', help='Enable admin user', + validator=validate_admin_user) +register_cli_argument('acr', 'disable_admin', help='Disable admin user', + validator=validate_admin_user) diff --git a/src/command_modules/azure-cli-acr/azure/cli/command_modules/acr/_utils.py b/src/command_modules/azure-cli-acr/azure/cli/command_modules/acr/_utils.py index 23848402cd8..b03cf415612 100644 --- a/src/command_modules/azure-cli-acr/azure/cli/command_modules/acr/_utils.py +++ b/src/command_modules/azure-cli-acr/azure/cli/command_modules/acr/_utils.py @@ -4,35 +4,41 @@ #--------------------------------------------------------------------------------------------- from azure.cli.core._util import CLIError +from azure.cli.core.commands.parameters import get_resources_in_subscription -from ._factory import get_acr_service_client +from ._constants import ( + ACR_RESOURCE_PROVIDER, + ACR_RESOURCE_TYPE, + STORAGE_RESOURCE_TYPE +) +from ._factory import ( + get_storage_service_client, + get_acr_service_client +) -def _get_registries_in_subscription(): - '''Returns the list of container registries in the current subscription. - ''' - client = get_acr_service_client().registries - return client.list().value #pylint: disable=no-member - -def _get_registries_in_resource_group(resource_group_name): - '''Returns the list of container registries in the resource group. - :param str resource_group_name: The name of resource group - ''' - client = get_acr_service_client().registries - return client.list_by_resource_group(resource_group_name).value #pylint: disable=no-member +from ._factory import ( + get_arm_service_client, + get_acr_api_version +) -def get_registry_by_name(registry_name): - '''Returns the container registry that matches the registry name. - :param str registry_name: The name of container registry +def _arm_get_resource_by_name(resource_name, resource_type): + '''Returns the ARM resource in the current subscription with resource_name. + :param str resource_name: The name of resource + :param str resource_type: The type of resource ''' - registries = _get_registries_in_subscription() - elements = [item for item in registries if item.name.lower() == registry_name.lower()] + result = get_resources_in_subscription(resource_type) + elements = [item for item in result if item.name.lower() == resource_name.lower()] if len(elements) == 0: - return None + raise CLIError( + 'No resource with type {} can be found with name: {}'.format( + resource_type, resource_name)) elif len(elements) == 1: return elements[0] else: - raise ValueError('More than one container registries are found with name: ' + registry_name) + raise CLIError( + 'More than one resources with type {} are found with name: {}'.format( + resource_type, resource_name)) def get_resource_group_name_by_resource_id(resource_id): '''Returns the resource group name from parsing the resource id. @@ -43,7 +49,112 @@ def get_resource_group_name_by_resource_id(resource_id): return resource_id[resource_id.index(resource_group_keyword) + len(resource_group_keyword): resource_id.index('/providers/')] -def registry_not_found(registry_name): - raise CLIError( - 'Registry {} cannot be found in the current subscription.'\ - .format(registry_name)) +def get_resource_group_name_by_registry_name(registry_name): + '''Returns the resource group name for the container registry. + :param str registry_name: The name of container registry + ''' + arm_resource = _arm_get_resource_by_name(registry_name, ACR_RESOURCE_TYPE) + return get_resource_group_name_by_resource_id(arm_resource.id) + +def get_resource_group_name_by_storage_account_name(storage_account_name): + '''Returns the resource group name for the storage account. + :param str storage_account_name: The name of storage account + ''' + arm_resource = _arm_get_resource_by_name(storage_account_name, STORAGE_RESOURCE_TYPE) + return get_resource_group_name_by_resource_id(arm_resource.id) + +def get_registry_by_name(registry_name, resource_group_name=None): + '''Returns a tuple of Registry object and resource group name. + :param str registry_name: The name of container registry + :param str resource_group_name: The name of resource group + ''' + if resource_group_name is None: + resource_group_name = get_resource_group_name_by_registry_name(registry_name) + + client = get_acr_service_client().registries + + return client.get_properties(resource_group_name, registry_name), resource_group_name + +def get_access_key_by_storage_account_name(storage_account_name, resource_group_name=None): + '''Returns access key for the storage account. + :param str storage_account_name: The name of storage account + :param str resource_group_name: The name of resource group + ''' + if resource_group_name is None: + resource_group_name = get_resource_group_name_by_storage_account_name(storage_account_name) + + client = get_storage_service_client().storage_accounts + + return client.list_keys(resource_group_name, storage_account_name).keys[0].value #pylint: disable=no-member + +def arm_deploy_template(resource_group_name, + registry_name, + location, + storage_account_name, + admin_user_enabled): + '''Deploys ARM template to create a container registry with a new 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 storage_account_name: The name of storage account + :param bool admin_user_enabled: Enable admin user + ''' + from azure.mgmt.resource.resources.models import DeploymentProperties + from azure.cli.core._util import get_file_json + import os + + parameters = _parameters(registry_name, location, storage_account_name, 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().deployments, resource_group_name, properties) + +def _arm_deploy_template(deployments_client, + resource_group_name, + properties, + index=0): + '''Deploys ARM template to create a container registry. + :param obj deployments_client: ARM deployments service client + :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 = ACR_RESOURCE_PROVIDER + elif index > 9: # Just a number to avoid infinite loops + raise CLIError( + 'The resource group {} has too many deployments'.format(resource_group_name)) + else: + deployment_name = ACR_RESOURCE_PROVIDER + '_' + str(index) + + try: + deployments_client.validate( + resource_group_name, deployment_name, properties) + return deployments_client.create_or_update( + resource_group_name, deployment_name, properties) + except: #pylint: disable=bare-except + return _arm_deploy_template( + deployments_client, resource_group_name, properties, index + 1) + +def _parameters(registry_name, + location, + storage_account_name, + admin_user_enabled): + '''Returns a dict of deployment parameters. + :param str registry_name: The name of container registry + :param str location: The name of location + :param str storage_account_name: The name of storage account + :param bool admin_user_enabled: Enable admin user + ''' + parameters = { + 'registryName': {'value': registry_name}, + 'registryLocation': {'value': location}, + 'registryApiVersion': {'value': get_acr_api_version()}, + 'storageAccountName': {'value': storage_account_name}, + 'storageAccountType': {'value': 'Standard_LRS'}, + 'adminUserEnabled': {'value': admin_user_enabled}, + } + return parameters diff --git a/src/command_modules/azure-cli-acr/azure/cli/command_modules/acr/_validators.py b/src/command_modules/azure-cli-acr/azure/cli/command_modules/acr/_validators.py index 9ffb5c2e79d..70fede37e35 100644 --- a/src/command_modules/azure-cli-acr/azure/cli/command_modules/acr/_validators.py +++ b/src/command_modules/azure-cli-acr/azure/cli/command_modules/acr/_validators.py @@ -3,74 +3,13 @@ # Licensed under the MIT License. See License.txt in the project root for license information. #--------------------------------------------------------------------------------------------- -import re -import uuid - -from azure.cli.command_modules.acr.mgmt_acr.models import RegistryNameCheckRequest - from azure.cli.core._util import CLIError -from azure.cli.command_modules.storage._factory import storage_client_factory -from ._constants import RESOURCE_TYPE -from ._factory import ( - get_acr_service_client, - get_arm_service_client -) -from ._arm_utils import arm_get_storage_account_by_name +from ._factory import get_arm_service_client import azure.cli.core._logging as _logging logger = _logging.get_az_logger(__name__) -def validate_registry_name(namespace): - if namespace.registry_name: - registry_name = namespace.registry_name - if len(registry_name) < 5 or len(registry_name) > 60: - raise CLIError('The registry name must be between 5 and 60 characters.') - - p = re.compile('^([A-Za-z0-9]+)$') - - if not p.match(registry_name): - raise CLIError('The registry name can contain only letters and numbers.') - -def validate_registry_name_create(namespace): - if namespace.registry_name: - client = get_acr_service_client() - - result = client.operation.check_name_availability( - RegistryNameCheckRequest( - namespace.registry_name, - RESOURCE_TYPE - ) - ) - - if not result.name_available: #pylint: disable=no-member - raise CLIError(result.message) #pylint: disable=no-member - -def validate_storage_account_name(namespace): - client = storage_client_factory().storage_accounts - - if namespace.storage_account_name: - storage_account_name = namespace.storage_account_name - if arm_get_storage_account_by_name(storage_account_name) is None: - logger.warning('Command to create a storage account:') - logger.warning( - ' az storage account create ' +\ - '-n -g -l --sku Standard_LRS') - logger.warning( - 'The container registry must be at the same location as the storage account.') - raise CLIError( - 'The storage account {} does not exist in the current subscription.'\ - .format(storage_account_name)) - else: - while True: - storage_account_name = str(uuid.uuid4()).replace('-', '')[:24] - if client.check_name_availability(storage_account_name).name_available is True: #pylint: disable=no-member - namespace.storage_account_name = storage_account_name - logger.warning( - 'New storage account with name %s will be created and used.', - storage_account_name) - return - def validate_resource_group_name(namespace): if namespace.resource_group_name: client = get_arm_service_client() @@ -82,3 +21,8 @@ def validate_resource_group_name(namespace): raise CLIError( 'The resource group {} does not exist in the current subscription.'\ .format(resource_group_name)) + +def validate_admin_user(namespace): + if namespace.enable_admin: + if hasattr(namespace, 'disable_admin') and namespace.disable_admin: + raise CLIError('--disable-admin and --enable-admin should not be specified together.') diff --git a/src/command_modules/azure-cli-acr/azure/cli/command_modules/acr/credential.py b/src/command_modules/azure-cli-acr/azure/cli/command_modules/acr/credential.py index 46dedf23226..3232eee1265 100644 --- a/src/command_modules/azure-cli-acr/azure/cli/command_modules/acr/credential.py +++ b/src/command_modules/azure-cli-acr/azure/cli/command_modules/acr/credential.py @@ -4,39 +4,37 @@ #--------------------------------------------------------------------------------------------- from azure.cli.core.commands import cli_command -from azure.cli.core._util import CLIError from ._factory import get_acr_service_client - -from ._utils import ( - get_registry_by_name, - get_resource_group_name_by_resource_id, - registry_not_found -) - +from ._utils import get_resource_group_name_by_registry_name from ._format import output_format import azure.cli.core._logging as _logging logger = _logging.get_az_logger(__name__) def acr_credential_show(registry_name, resource_group_name=None): - '''Get admin username and password for a container registry. + '''Get login credentials for a container registry. :param str registry_name: The name of container registry :param str resource_group_name: The name of resource group ''' - registry = get_registry_by_name(registry_name) - if registry is None: - registry_not_found(registry_name) + if resource_group_name is None: + resource_group_name = get_resource_group_name_by_registry_name(registry_name) + + client = get_acr_service_client().registries + return client.get_credentials(resource_group_name, registry_name) + +def acr_credential_renew(registry_name, resource_group_name=None): + '''Regenerate login credentials for a container registry. + :param str registry_name: The name of container registry + :param str resource_group_name: The name of resource group + ''' if resource_group_name is None: - resource_group_name = get_resource_group_name_by_resource_id(registry.id) + resource_group_name = get_resource_group_name_by_registry_name(registry_name) client = get_acr_service_client().registries - if registry.properties.admin_user_enabled: - return client.get_credentials(resource_group_name, registry_name) - else: - raise CLIError( - 'Admin user is not enabled for the container registry with name: {}'\ - .format(registry_name)) + + return client.regenerate_credentials(resource_group_name, registry_name) cli_command('acr credential show', acr_credential_show, table_transformer=output_format) +cli_command('acr credential renew', acr_credential_renew, table_transformer=output_format) diff --git a/src/command_modules/azure-cli-acr/azure/cli/command_modules/acr/custom.py b/src/command_modules/azure-cli-acr/azure/cli/command_modules/acr/custom.py index 8e8f90a97fc..3db6589308f 100644 --- a/src/command_modules/azure-cli-acr/azure/cli/command_modules/acr/custom.py +++ b/src/command_modules/azure-cli-acr/azure/cli/command_modules/acr/custom.py @@ -3,30 +3,26 @@ # Licensed under the MIT License. See License.txt in the project root for license information. #--------------------------------------------------------------------------------------------- +import uuid + from azure.cli.core.commands import ( cli_command, LongRunningOperation ) -from azure.cli.core._util import CLIError from azure.cli.command_modules.acr.mgmt_acr.models import ( + Registry, RegistryUpdateParameters, - RegistryPropertiesCreateParameters + StorageAccountProperties, + RegistryNameCheckRequest ) from ._factory import get_acr_service_client -from ._arm_utils import ( - arm_get_registries_in_subscription, - arm_get_registries_in_resource_group, - arm_get_registry_by_name, - arm_deploy_template, - add_tag_storage_account, - delete_tag_storage_account -) from ._utils import ( get_registry_by_name, - get_resource_group_name_by_resource_id, - registry_not_found + get_access_key_by_storage_account_name, + get_resource_group_name_by_registry_name, + arm_deploy_template ) from ._format import output_format @@ -34,14 +30,25 @@ import azure.cli.core._logging as _logging logger = _logging.get_az_logger(__name__) +def acr_check_name(registry_name): + '''Check whether the container registry name is available. + :param str registry_name: The name of container registry + ''' + client = get_acr_service_client().registries + + return client.check_name_availability( + RegistryNameCheckRequest(registry_name)) + def acr_list(resource_group_name=None): '''List container registries. :param str resource_group_name: The name of resource group ''' + client = get_acr_service_client().registries + if resource_group_name: - return arm_get_registries_in_resource_group(resource_group_name) + return client.list_by_resource_group(resource_group_name) else: - return arm_get_registries_in_subscription() + return client.list() def acr_create(registry_name, #pylint: disable=too-many-arguments resource_group_name, @@ -55,18 +62,32 @@ def acr_create(registry_name, #pylint: disable=too-many-arguments :param str storage_account_name: The name of storage account :param bool enable_admin: Enable admin user ''' - # Create a container registry - LongRunningOperation()( - arm_deploy_template(resource_group_name, - registry_name, - location, - storage_account_name, - enable_admin) - ) - client = get_acr_service_client().registries + + if storage_account_name is None: + storage_account_name = str(uuid.uuid4()).replace('-', '')[:24] + LongRunningOperation()( + arm_deploy_template(resource_group_name, + registry_name, + location, + storage_account_name, + enable_admin) + ) + else: + storage_account_key = get_access_key_by_storage_account_name(storage_account_name) + registry = client.create_or_update( + resource_group_name, registry_name, + Registry( + location=location, + storage_account=StorageAccountProperties( + storage_account_name, + storage_account_key + ), + admin_user_enabled=enable_admin + ) + ) + registry = client.get_properties(resource_group_name, registry_name) - add_tag_storage_account(storage_account_name, registry_name) logger.warning('\nCreate a new service principal and assign access:') logger.warning( @@ -84,19 +105,11 @@ def acr_delete(registry_name, resource_group_name=None): :param str registry_name: The name of container registry :param str resource_group_name: The name of resource group ''' - registry = arm_get_registry_by_name(registry_name) - if registry is None: - registry_not_found(registry_name) - if resource_group_name is None: - resource_group_name = get_resource_group_name_by_resource_id(registry.id) + resource_group_name = get_resource_group_name_by_registry_name(registry_name) client = get_acr_service_client().registries - storage_account_name = client.get_properties( #pylint: disable=no-member - resource_group_name, registry_name).properties.storage_account.name - delete_tag_storage_account(storage_account_name, registry_name) - return client.delete(resource_group_name, registry_name) def acr_show(registry_name, resource_group_name=None): @@ -104,12 +117,8 @@ def acr_show(registry_name, resource_group_name=None): :param str registry_name: The name of container registry :param str resource_group_name: The name of resource group ''' - registry = arm_get_registry_by_name(registry_name) - if registry is None: - registry_not_found(registry_name) - if resource_group_name is None: - resource_group_name = get_resource_group_name_by_resource_id(registry.id) + resource_group_name = get_resource_group_name_by_registry_name(registry_name) client = get_acr_service_client().registries @@ -117,29 +126,19 @@ def acr_show(registry_name, resource_group_name=None): def acr_update(registry_name, #pylint: disable=too-many-arguments resource_group_name=None, + storage_account_name=None, tags=None, enable_admin=False, - disable_admin=False, - tenant_id=None): + disable_admin=False): '''Update a container registry. :param str registry_name: The name of container registry :param str resource_group_name: The name of resource group + :param str storage_account_name: The name of storage account :param dict tags: The set of tags :param bool enable_admin: Enable admin user :param bool disable_admin: Disable admin user - :param str tenant_id: Tenant id for service principal login ''' - if disable_admin and enable_admin: - raise CLIError('disable_admin and enable_admin should not be specified together.') - - registry = get_registry_by_name(registry_name) - if registry is None: - registry_not_found(registry_name) - - if resource_group_name is None: - resource_group_name = get_resource_group_name_by_resource_id(registry.id) - - client = get_acr_service_client().registries + registry, resource_group_name = get_registry_by_name(registry_name, resource_group_name) # Set admin_user_enabled admin_user_enabled = None @@ -147,11 +146,9 @@ def acr_update(registry_name, #pylint: disable=too-many-arguments admin_user_enabled = False if enable_admin: admin_user_enabled = True - if admin_user_enabled is None: - admin_user_enabled = registry.properties.admin_user_enabled # Set tags - newTags = registry.tags + newTags = registry.tags #pylint: disable=no-member if isinstance(tags, dict): if tags: for key in tags: @@ -162,17 +159,27 @@ def acr_update(registry_name, #pylint: disable=too-many-arguments else: newTags = {} + # Set storage account + storage_account = None + if storage_account_name: + storage_account_key = get_access_key_by_storage_account_name(storage_account_name) + storage_account = StorageAccountProperties( + storage_account_name, + storage_account_key + ) + + client = get_acr_service_client().registries + return client.update( resource_group_name, registry_name, RegistryUpdateParameters( tags=newTags, - properties=RegistryPropertiesCreateParameters( - tenant_id=tenant_id, - admin_user_enabled=admin_user_enabled - ) + admin_user_enabled=admin_user_enabled, + storage_account=storage_account if storage_account else None ) ) +cli_command('acr check-name', acr_check_name) cli_command('acr list', acr_list, table_transformer=output_format) cli_command('acr create', acr_create, table_transformer=output_format) cli_command('acr delete', acr_delete, table_transformer=output_format) diff --git a/src/command_modules/azure-cli-acr/azure/cli/command_modules/acr/mgmt_acr/__init__.py b/src/command_modules/azure-cli-acr/azure/cli/command_modules/acr/mgmt_acr/__init__.py index ece5117909b..5ae899ee06e 100644 --- a/src/command_modules/azure-cli-acr/azure/cli/command_modules/acr/mgmt_acr/__init__.py +++ b/src/command_modules/azure-cli-acr/azure/cli/command_modules/acr/mgmt_acr/__init__.py @@ -10,12 +10,12 @@ # regenerated. # -------------------------------------------------------------------------- -from .container_registry import ContainerRegistry, ContainerRegistryConfiguration +from .container_registry_management_client import ContainerRegistryManagementClient, ContainerRegistryManagementClientConfiguration from .version import VERSION __all__ = [ - 'ContainerRegistry', - 'ContainerRegistryConfiguration' + 'ContainerRegistryManagementClient', + 'ContainerRegistryManagementClientConfiguration' ] __version__ = VERSION diff --git a/src/command_modules/azure-cli-acr/azure/cli/command_modules/acr/mgmt_acr/container_registry.py b/src/command_modules/azure-cli-acr/azure/cli/command_modules/acr/mgmt_acr/container_registry.py deleted file mode 100644 index 60cb6195786..00000000000 --- a/src/command_modules/azure-cli-acr/azure/cli/command_modules/acr/mgmt_acr/container_registry.py +++ /dev/null @@ -1,94 +0,0 @@ -#--------------------------------------------------------------------------------------------- -# Copyright (c) Microsoft Corporation. All rights reserved. -# Licensed under the MIT License. See License.txt in the project root for license information. -#--------------------------------------------------------------------------------------------- -#pylint: skip-file -# coding=utf-8 -# -------------------------------------------------------------------------- -# Code generated by Microsoft (R) AutoRest Code Generator 0.16.0.0 -# Changes may cause incorrect behavior and will be lost if the code is -# regenerated. -# -------------------------------------------------------------------------- - -from msrest.service_client import ServiceClient -from msrest import Configuration, Serializer, Deserializer -from .version import VERSION -from .operations.operation import Operation -from .operations.registries import Registries -from .operations.subscriptions import Subscriptions -from . import models - - -class ContainerRegistryConfiguration(Configuration): - """Configuration for ContainerRegistry - Note that all parameters used to create this instance are saved as instance - attributes. - - :param subscription_id: Gets subscription credentials which uniquely - identify Microsoft Azure subscription.The subscription ID forms part of - the URI for every service call. - :type subscription_id: str - :param api_version: Client Api Version. - :type api_version: str - :param credentials: Subscription credentials which uniquely identify - client subscription. - :type credentials: :mod:`A msrest Authentication - object` - :param str base_url: Service URL - :param str filepath: Existing config - """ - - def __init__( - self, subscription_id, api_version, credentials, base_url=None, filepath=None): - - if subscription_id is None: - raise ValueError("Parameter 'subscription_id' must not be None.") - if not isinstance(subscription_id, str): - raise TypeError("Parameter 'subscription_id' must be str.") - if api_version is None: - raise ValueError("Parameter 'api_version' must not be None.") - if not isinstance(api_version, str): - raise TypeError("Parameter 'api_version' must be str.") - if credentials is None: - raise ValueError("Parameter 'credentials' must not be None.") - if not base_url: - base_url = 'https://management.azure.com' - - super(ContainerRegistryConfiguration, self).__init__(base_url, filepath) - - self.add_user_agent('containerregistry/{}'.format(VERSION)) - - self.subscription_id = subscription_id - self.api_version = api_version - self.credentials = credentials - - -class ContainerRegistry(object): - """ContainerRegistry - - :param config: Configuration for client. - :type config: ContainerRegistryConfiguration - - :ivar operation: Operation operations - :vartype operation: .operations.Operation - :ivar registries: Registries operations - :vartype registries: .operations.Registries - :ivar subscriptions: Subscriptions operations - :vartype subscriptions: .operations.Subscriptions - """ - - def __init__(self, config): - - self._client = ServiceClient(config.credentials, config) - - client_models = {k: v for k, v in models.__dict__.items() if isinstance(v, type)} - self._serialize = Serializer() - self._deserialize = Deserializer(client_models) - - self.config = config - self.operation = Operation( - self._client, self.config, self._serialize, self._deserialize) - self.registries = Registries( - self._client, self.config, self._serialize, self._deserialize) - self.subscriptions = Subscriptions( - self._client, self.config, self._serialize, self._deserialize) diff --git a/src/command_modules/azure-cli-acr/azure/cli/command_modules/acr/mgmt_acr/container_registry_management_client.py b/src/command_modules/azure-cli-acr/azure/cli/command_modules/acr/mgmt_acr/container_registry_management_client.py new file mode 100644 index 00000000000..33a45279ec0 --- /dev/null +++ b/src/command_modules/azure-cli-acr/azure/cli/command_modules/acr/mgmt_acr/container_registry_management_client.py @@ -0,0 +1,96 @@ +#--------------------------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for license information. +#--------------------------------------------------------------------------------------------- +#pylint: skip-file +# coding=utf-8 +# -------------------------------------------------------------------------- +# Code generated by Microsoft (R) AutoRest Code Generator 0.16.0.0 +# Changes may cause incorrect behavior and will be lost if the code is +# regenerated. +# -------------------------------------------------------------------------- + +from msrest.service_client import ServiceClient +from msrest import Serializer, Deserializer +from msrestazure import AzureConfiguration +from .version import VERSION +from .operations.registries_operations import RegistriesOperations +from . import models + + +class ContainerRegistryManagementClientConfiguration(AzureConfiguration): + """Configuration for ContainerRegistryManagementClient + Note that all parameters used to create this instance are saved as instance + attributes. + + :param credentials: Gets Azure subscription credentials. + :type credentials: :mod:`A msrestazure Credentials + object` + :param subscription_id: Microsoft Azure subscription id. + :type subscription_id: str + :param api_version: Client Api Version. + :type api_version: str + :param accept_language: Gets or sets the preferred language for the + response. + :type accept_language: str + :param long_running_operation_retry_timeout: Gets or sets the retry + timeout in seconds for Long Running Operations. Default value is 30. + :type long_running_operation_retry_timeout: int + :param generate_client_request_id: When set to true a unique + x-ms-client-request-id value is generated and included in each request. + Default is true. + :type generate_client_request_id: bool + :param str base_url: Service URL + :param str filepath: Existing config + """ + + def __init__( + self, credentials, subscription_id, api_version='2016-06-27-preview', accept_language='en-US', long_running_operation_retry_timeout=30, generate_client_request_id=True, base_url=None, filepath=None): + + if credentials is None: + raise ValueError("Parameter 'credentials' must not be None.") + if subscription_id is None: + raise ValueError("Parameter 'subscription_id' must not be None.") + if not isinstance(subscription_id, str): + raise TypeError("Parameter 'subscription_id' must be str.") + if api_version is not None and not isinstance(api_version, str): + raise TypeError("Optional parameter 'api_version' must be str.") + if accept_language is not None and not isinstance(accept_language, str): + raise TypeError("Optional parameter 'accept_language' must be str.") + if not base_url: + base_url = 'https://management.azure.com' + + super(ContainerRegistryManagementClientConfiguration, self).__init__(base_url, filepath) + + self.add_user_agent('containerregistrymanagementclient/{}'.format(VERSION)) + self.add_user_agent('Azure-SDK-For-Python') + + self.credentials = credentials + self.subscription_id = subscription_id + self.api_version = api_version + self.accept_language = accept_language + self.long_running_operation_retry_timeout = long_running_operation_retry_timeout + self.generate_client_request_id = generate_client_request_id + + +class ContainerRegistryManagementClient(object): + """ContainerRegistryManagementClient + + :param config: Configuration for client. + :type config: ContainerRegistryManagementClientConfiguration + + :ivar registries: Registries operations + :vartype registries: .operations.RegistriesOperations + """ + + def __init__(self, config): + + self._client = ServiceClient(config.credentials, config) + + client_models = {k: v for k, v in models.__dict__.items() if isinstance(v, type)} + self._serialize = Serializer() + self._deserialize = Deserializer(client_models) + + self.config = config + self.registries = RegistriesOperations( + self._client, self.config, self._serialize, self._deserialize) diff --git a/src/command_modules/azure-cli-acr/azure/cli/command_modules/acr/mgmt_acr/credentials.py b/src/command_modules/azure-cli-acr/azure/cli/command_modules/acr/mgmt_acr/credentials.py index a3e369522aa..2fc852a1df0 100644 --- a/src/command_modules/azure-cli-acr/azure/cli/command_modules/acr/mgmt_acr/credentials.py +++ b/src/command_modules/azure-cli-acr/azure/cli/command_modules/acr/mgmt_acr/credentials.py @@ -14,3 +14,8 @@ BasicAuthentication, BasicTokenAuthentication, OAuthTokenAuthentication) + +from msrestazure.azure_active_directory import ( + InteractiveCredentials, + ServicePrincipalCredentials, + UserPassCredentials) diff --git a/src/command_modules/azure-cli-acr/azure/cli/command_modules/acr/mgmt_acr/exceptions.py b/src/command_modules/azure-cli-acr/azure/cli/command_modules/acr/mgmt_acr/exceptions.py index 63c04fade09..2e71efa4241 100644 --- a/src/command_modules/azure-cli-acr/azure/cli/command_modules/acr/mgmt_acr/exceptions.py +++ b/src/command_modules/azure-cli-acr/azure/cli/command_modules/acr/mgmt_acr/exceptions.py @@ -20,3 +20,5 @@ HttpOperationError, ValidationError, ) + +from msrestazure.azure_exceptions import CloudError diff --git a/src/command_modules/azure-cli-acr/azure/cli/command_modules/acr/mgmt_acr/models/__init__.py b/src/command_modules/azure-cli-acr/azure/cli/command_modules/acr/mgmt_acr/models/__init__.py index 0f7e4c4bc6d..7ea335685ec 100644 --- a/src/command_modules/azure-cli-acr/azure/cli/command_modules/acr/mgmt_acr/models/__init__.py +++ b/src/command_modules/azure-cli-acr/azure/cli/command_modules/acr/mgmt_acr/models/__init__.py @@ -12,32 +12,20 @@ from .registry_name_check_request import RegistryNameCheckRequest from .registry_name_status import RegistryNameStatus -from .registry_move_request import RegistryMoveRequest from .registry import Registry -from .registry_properties import RegistryProperties -from .storage_account_base_properties import StorageAccountBaseProperties -from .registry_create_parameters import RegistryCreateParameters -from .registry_properties_create_parameters import RegistryPropertiesCreateParameters from .storage_account_properties import StorageAccountProperties from .registry_update_parameters import RegistryUpdateParameters -from .resource_list_registry import ResourceListRegistry from .registry_credentials import RegistryCredentials -from .subscription_notification import SubscriptionNotification -from .subscription_properties import SubscriptionProperties +from .resource import Resource +from .registry_paged import RegistryPaged __all__ = [ 'RegistryNameCheckRequest', 'RegistryNameStatus', - 'RegistryMoveRequest', 'Registry', - 'RegistryProperties', - 'StorageAccountBaseProperties', - 'RegistryCreateParameters', - 'RegistryPropertiesCreateParameters', 'StorageAccountProperties', 'RegistryUpdateParameters', - 'ResourceListRegistry', 'RegistryCredentials', - 'SubscriptionNotification', - 'SubscriptionProperties', + 'Resource', + 'RegistryPaged', ] diff --git a/src/command_modules/azure-cli-acr/azure/cli/command_modules/acr/mgmt_acr/models/registry.py b/src/command_modules/azure-cli-acr/azure/cli/command_modules/acr/mgmt_acr/models/registry.py index 12f9894e0e1..ec4d462b46e 100644 --- a/src/command_modules/azure-cli-acr/azure/cli/command_modules/acr/mgmt_acr/models/registry.py +++ b/src/command_modules/azure-cli-acr/azure/cli/command_modules/acr/mgmt_acr/models/registry.py @@ -10,47 +10,65 @@ # regenerated. # -------------------------------------------------------------------------- -from msrest.serialization import Model +from .resource import Resource -class Registry(Model): - """Registry +class Registry(Resource): + """ + The container registry. Variables are only populated by the server, and will be ignored when sending a request. - :param id: - :type id: str - :param name: - :type name: str - :param location: + :ivar id: Resource Id. + :vartype id: str + :ivar name: Resource name. + :vartype name: str + :ivar type: Resource type. + :vartype type: str + :param location: Resource location. Once the resource has been created, + location cannot be updated. :type location: str - :param tags: + :param tags: Resource tags. :type tags: dict - :ivar type: - :vartype type: str - :param properties: - :type properties: :class:`RegistryProperties - ` + :ivar login_server: The URL to log into the container registry. + :vartype login_server: str + :ivar creation_date: The creation date of the container registry in + ISO8601 format. + :vartype creation_date: datetime + :param admin_user_enabled: The boolean value that indicates whether admin + user is enabled. Default value is false. Default value: False . + :type admin_user_enabled: bool + :param storage_account: The storage account properties. + :type storage_account: :class:`StorageAccountProperties + ` """ _validation = { + 'id': {'readonly': True}, + 'name': {'readonly': True}, 'type': {'readonly': True}, + 'location': {'required': True}, + 'login_server': {'readonly': True}, + 'creation_date': {'readonly': True}, + 'storage_account': {'required': True}, } _attribute_map = { 'id': {'key': 'id', 'type': 'str'}, 'name': {'key': 'name', 'type': 'str'}, + 'type': {'key': 'type', 'type': 'str'}, 'location': {'key': 'location', 'type': 'str'}, 'tags': {'key': 'tags', 'type': '{str}'}, - 'type': {'key': 'type', 'type': 'str'}, - 'properties': {'key': 'properties', 'type': 'RegistryProperties'}, + 'login_server': {'key': 'properties.loginServer', 'type': 'str'}, + 'creation_date': {'key': 'properties.creationDate', 'type': 'iso-8601'}, + 'admin_user_enabled': {'key': 'properties.adminUserEnabled', 'type': 'bool'}, + 'storage_account': {'key': 'properties.storageAccount', 'type': 'StorageAccountProperties'}, } - def __init__(self, id=None, name=None, location=None, tags=None, properties=None): - self.id = id - self.name = name - self.location = location - self.tags = tags - self.type = None - self.properties = properties + def __init__(self, location, storage_account, tags=None, admin_user_enabled=False): + super(Registry, self).__init__(location=location, tags=tags) + self.login_server = None + self.creation_date = None + self.admin_user_enabled = admin_user_enabled + self.storage_account = storage_account diff --git a/src/command_modules/azure-cli-acr/azure/cli/command_modules/acr/mgmt_acr/models/registry_credentials.py b/src/command_modules/azure-cli-acr/azure/cli/command_modules/acr/mgmt_acr/models/registry_credentials.py index abb5423acf5..6234dc808c9 100644 --- a/src/command_modules/azure-cli-acr/azure/cli/command_modules/acr/mgmt_acr/models/registry_credentials.py +++ b/src/command_modules/azure-cli-acr/azure/cli/command_modules/acr/mgmt_acr/models/registry_credentials.py @@ -14,19 +14,20 @@ class RegistryCredentials(Model): - """RegistryCredentials + """ + The result of showing admin user credentials. - :param user_name: - :type user_name: str - :param pass_word: - :type pass_word: str + :param username: Admin username. + :type username: str + :param password: Admin password. + :type password: str """ _attribute_map = { - 'user_name': {'key': 'userName', 'type': 'str'}, - 'pass_word': {'key': 'passWord', 'type': 'str'}, + 'username': {'key': 'username', 'type': 'str'}, + 'password': {'key': 'password', 'type': 'str'}, } - def __init__(self, user_name=None, pass_word=None): - self.user_name = user_name - self.pass_word = pass_word + def __init__(self, username=None, password=None): + self.username = username + self.password = password diff --git a/src/command_modules/azure-cli-acr/azure/cli/command_modules/acr/mgmt_acr/models/registry_move_request.py b/src/command_modules/azure-cli-acr/azure/cli/command_modules/acr/mgmt_acr/models/registry_move_request.py deleted file mode 100644 index 2e36f518931..00000000000 --- a/src/command_modules/azure-cli-acr/azure/cli/command_modules/acr/mgmt_acr/models/registry_move_request.py +++ /dev/null @@ -1,32 +0,0 @@ -#--------------------------------------------------------------------------------------------- -# Copyright (c) Microsoft Corporation. All rights reserved. -# Licensed under the MIT License. See License.txt in the project root for license information. -#--------------------------------------------------------------------------------------------- -#pylint: skip-file -# coding=utf-8 -# -------------------------------------------------------------------------- -# Code generated by Microsoft (R) AutoRest Code Generator 0.16.0.0 -# Changes may cause incorrect behavior and will be lost if the code is -# regenerated. -# -------------------------------------------------------------------------- - -from msrest.serialization import Model - - -class RegistryMoveRequest(Model): - """RegistryMoveRequest - - :param target_resource_group: - :type target_resource_group: str - :param resources: - :type resources: list of str - """ - - _attribute_map = { - 'target_resource_group': {'key': 'targetResourceGroup', 'type': 'str'}, - 'resources': {'key': 'resources', 'type': '[str]'}, - } - - def __init__(self, target_resource_group=None, resources=None): - self.target_resource_group = target_resource_group - self.resources = resources diff --git a/src/command_modules/azure-cli-acr/azure/cli/command_modules/acr/mgmt_acr/models/registry_name_check_request.py b/src/command_modules/azure-cli-acr/azure/cli/command_modules/acr/mgmt_acr/models/registry_name_check_request.py index c78bb196152..c0facbb5608 100644 --- a/src/command_modules/azure-cli-acr/azure/cli/command_modules/acr/mgmt_acr/models/registry_name_check_request.py +++ b/src/command_modules/azure-cli-acr/azure/cli/command_modules/acr/mgmt_acr/models/registry_name_check_request.py @@ -14,19 +14,30 @@ class RegistryNameCheckRequest(Model): - """RegistryNameCheckRequest + """ + The request to check whether the container registry name is available. - :param name: + Variables are only populated by the server, and will be ignored when + sending a request. + + :param name: The container registry name. :type name: str - :param type: - :type type: str + :ivar type: The container registry resource type. Default value: + "Microsoft.ContainerRegistry/registries" . + :vartype type: str """ + _validation = { + 'name': {'required': True}, + 'type': {'required': True, 'constant': True}, + } + _attribute_map = { 'name': {'key': 'name', 'type': 'str'}, 'type': {'key': 'type', 'type': 'str'}, } - def __init__(self, name=None, type=None): + type = "Microsoft.ContainerRegistry/registries" + + def __init__(self, name): self.name = name - self.type = type diff --git a/src/command_modules/azure-cli-acr/azure/cli/command_modules/acr/mgmt_acr/models/registry_name_status.py b/src/command_modules/azure-cli-acr/azure/cli/command_modules/acr/mgmt_acr/models/registry_name_status.py index e36611d0306..559513348ac 100644 --- a/src/command_modules/azure-cli-acr/azure/cli/command_modules/acr/mgmt_acr/models/registry_name_status.py +++ b/src/command_modules/azure-cli-acr/azure/cli/command_modules/acr/mgmt_acr/models/registry_name_status.py @@ -14,13 +14,17 @@ class RegistryNameStatus(Model): - """RegistryNameStatus + """ + The result of checking name availability. - :param name_available: + :param name_available: The boolean value that indicates whether the name + is available. :type name_available: bool - :param reason: + :param reason: The reason that the container registry name could not be + used. :type reason: str - :param message: + :param message: The error message that explains the reason value in more + detail. :type message: str """ diff --git a/src/command_modules/azure-cli-acr/azure/cli/command_modules/acr/mgmt_acr/models/storage_account_base_properties.py b/src/command_modules/azure-cli-acr/azure/cli/command_modules/acr/mgmt_acr/models/registry_paged.py similarity index 66% rename from src/command_modules/azure-cli-acr/azure/cli/command_modules/acr/mgmt_acr/models/storage_account_base_properties.py rename to src/command_modules/azure-cli-acr/azure/cli/command_modules/acr/mgmt_acr/models/registry_paged.py index c9d5bc7651a..2b469a2acc6 100644 --- a/src/command_modules/azure-cli-acr/azure/cli/command_modules/acr/mgmt_acr/models/storage_account_base_properties.py +++ b/src/command_modules/azure-cli-acr/azure/cli/command_modules/acr/mgmt_acr/models/registry_paged.py @@ -10,19 +10,19 @@ # regenerated. # -------------------------------------------------------------------------- -from msrest.serialization import Model +from msrest.paging import Paged -class StorageAccountBaseProperties(Model): - """StorageAccountBaseProperties - - :param name: - :type name: str - """ +class RegistryPaged(Paged): + """ + A paging container for iterating over a list of Registry object + """ _attribute_map = { - 'name': {'key': 'name', 'type': 'str'}, + 'next_link': {'key': 'nextLink', 'type': 'str'}, + 'current_page': {'key': 'value', 'type': '[Registry]'} } - def __init__(self, name=None): - self.name = name + def __init__(self, *args, **kwargs): + + super(RegistryPaged, self).__init__(*args, **kwargs) diff --git a/src/command_modules/azure-cli-acr/azure/cli/command_modules/acr/mgmt_acr/models/registry_properties.py b/src/command_modules/azure-cli-acr/azure/cli/command_modules/acr/mgmt_acr/models/registry_properties.py deleted file mode 100644 index cd4cf71982f..00000000000 --- a/src/command_modules/azure-cli-acr/azure/cli/command_modules/acr/mgmt_acr/models/registry_properties.py +++ /dev/null @@ -1,41 +0,0 @@ -#--------------------------------------------------------------------------------------------- -# Copyright (c) Microsoft Corporation. All rights reserved. -# Licensed under the MIT License. See License.txt in the project root for license information. -#--------------------------------------------------------------------------------------------- -#pylint: skip-file -# coding=utf-8 -# -------------------------------------------------------------------------- -# Code generated by Microsoft (R) AutoRest Code Generator 0.16.0.0 -# Changes may cause incorrect behavior and will be lost if the code is -# regenerated. -# -------------------------------------------------------------------------- - -from msrest.serialization import Model - - -class RegistryProperties(Model): - """RegistryProperties - - :param storage_account: - :type storage_account: :class:`StorageAccountBaseProperties - ` - :param login_server: - :type login_server: str - :param creation_date: - :type creation_date: datetime - :param admin_user_enabled: - :type admin_user_enabled: bool - """ - - _attribute_map = { - 'storage_account': {'key': 'storageAccount', 'type': 'StorageAccountBaseProperties'}, - 'login_server': {'key': 'loginServer', 'type': 'str'}, - 'creation_date': {'key': 'creationDate', 'type': 'iso-8601'}, - 'admin_user_enabled': {'key': 'adminUserEnabled', 'type': 'bool'}, - } - - def __init__(self, storage_account=None, login_server=None, creation_date=None, admin_user_enabled=None): - self.storage_account = storage_account - self.login_server = login_server - self.creation_date = creation_date - self.admin_user_enabled = admin_user_enabled diff --git a/src/command_modules/azure-cli-acr/azure/cli/command_modules/acr/mgmt_acr/models/registry_properties_create_parameters.py b/src/command_modules/azure-cli-acr/azure/cli/command_modules/acr/mgmt_acr/models/registry_properties_create_parameters.py deleted file mode 100644 index ba5a1a9c8ae..00000000000 --- a/src/command_modules/azure-cli-acr/azure/cli/command_modules/acr/mgmt_acr/models/registry_properties_create_parameters.py +++ /dev/null @@ -1,37 +0,0 @@ -#--------------------------------------------------------------------------------------------- -# Copyright (c) Microsoft Corporation. All rights reserved. -# Licensed under the MIT License. See License.txt in the project root for license information. -#--------------------------------------------------------------------------------------------- -#pylint: skip-file -# coding=utf-8 -# -------------------------------------------------------------------------- -# Code generated by Microsoft (R) AutoRest Code Generator 0.16.0.0 -# Changes may cause incorrect behavior and will be lost if the code is -# regenerated. -# -------------------------------------------------------------------------- - -from msrest.serialization import Model - - -class RegistryPropertiesCreateParameters(Model): - """RegistryPropertiesCreateParameters - - :param tenant_id: - :type tenant_id: str - :param admin_user_enabled: - :type admin_user_enabled: bool - :param storage_account: - :type storage_account: :class:`StorageAccountProperties - ` - """ - - _attribute_map = { - 'tenant_id': {'key': 'tenantId', 'type': 'str'}, - 'admin_user_enabled': {'key': 'adminUserEnabled', 'type': 'bool'}, - 'storage_account': {'key': 'storageAccount', 'type': 'StorageAccountProperties'}, - } - - def __init__(self, tenant_id=None, admin_user_enabled=None, storage_account=None): - self.tenant_id = tenant_id - self.admin_user_enabled = admin_user_enabled - self.storage_account = storage_account diff --git a/src/command_modules/azure-cli-acr/azure/cli/command_modules/acr/mgmt_acr/models/registry_update_parameters.py b/src/command_modules/azure-cli-acr/azure/cli/command_modules/acr/mgmt_acr/models/registry_update_parameters.py index 8f4ef8e37fa..088ba42c4d4 100644 --- a/src/command_modules/azure-cli-acr/azure/cli/command_modules/acr/mgmt_acr/models/registry_update_parameters.py +++ b/src/command_modules/azure-cli-acr/azure/cli/command_modules/acr/mgmt_acr/models/registry_update_parameters.py @@ -14,20 +14,26 @@ class RegistryUpdateParameters(Model): - """RegistryUpdateParameters + """ + The parameters for updating a container registry. - :param tags: + :param tags: Resource tags. :type tags: dict - :param properties: - :type properties: :class:`RegistryPropertiesCreateParameters - ` + :param admin_user_enabled: The boolean value that indicates whether admin + user is enabled. Default value is false. + :type admin_user_enabled: bool + :param storage_account: The storage account properties. + :type storage_account: :class:`StorageAccountProperties + ` """ _attribute_map = { 'tags': {'key': 'tags', 'type': '{str}'}, - 'properties': {'key': 'properties', 'type': 'RegistryPropertiesCreateParameters'}, + 'admin_user_enabled': {'key': 'properties.adminUserEnabled', 'type': 'bool'}, + 'storage_account': {'key': 'properties.storageAccount', 'type': 'StorageAccountProperties'}, } - def __init__(self, tags=None, properties=None): + def __init__(self, tags=None, admin_user_enabled=None, storage_account=None): self.tags = tags - self.properties = properties + self.admin_user_enabled = admin_user_enabled + self.storage_account = storage_account diff --git a/src/command_modules/azure-cli-acr/azure/cli/command_modules/acr/mgmt_acr/models/registry_create_parameters.py b/src/command_modules/azure-cli-acr/azure/cli/command_modules/acr/mgmt_acr/models/resource.py similarity index 68% rename from src/command_modules/azure-cli-acr/azure/cli/command_modules/acr/mgmt_acr/models/registry_create_parameters.py rename to src/command_modules/azure-cli-acr/azure/cli/command_modules/acr/mgmt_acr/models/resource.py index 676cafc8570..91330b95d2b 100644 --- a/src/command_modules/azure-cli-acr/azure/cli/command_modules/acr/mgmt_acr/models/registry_create_parameters.py +++ b/src/command_modules/azure-cli-acr/azure/cli/command_modules/acr/mgmt_acr/models/resource.py @@ -13,44 +13,44 @@ from msrest.serialization import Model -class RegistryCreateParameters(Model): - """RegistryCreateParameters +class Resource(Model): + """ + Azure resource. Variables are only populated by the server, and will be ignored when sending a request. - :param id: - :type id: str - :param name: - :type name: str - :param location: + :ivar id: Resource Id. + :vartype id: str + :ivar name: Resource name. + :vartype name: str + :ivar type: Resource type. + :vartype type: str + :param location: Resource location. Once the resource has been created, + location cannot be updated. :type location: str - :param tags: + :param tags: Resource tags. :type tags: dict - :ivar type: - :vartype type: str - :param properties: - :type properties: :class:`RegistryPropertiesCreateParameters - ` """ _validation = { + 'id': {'readonly': True}, + 'name': {'readonly': True}, 'type': {'readonly': True}, + 'location': {'required': True}, } _attribute_map = { 'id': {'key': 'id', 'type': 'str'}, 'name': {'key': 'name', 'type': 'str'}, + 'type': {'key': 'type', 'type': 'str'}, 'location': {'key': 'location', 'type': 'str'}, 'tags': {'key': 'tags', 'type': '{str}'}, - 'type': {'key': 'type', 'type': 'str'}, - 'properties': {'key': 'properties', 'type': 'RegistryPropertiesCreateParameters'}, } - def __init__(self, id=None, name=None, location=None, tags=None, properties=None): - self.id = id - self.name = name + def __init__(self, location, tags=None): + self.id = None + self.name = None + self.type = None self.location = location self.tags = tags - self.type = None - self.properties = properties diff --git a/src/command_modules/azure-cli-acr/azure/cli/command_modules/acr/mgmt_acr/models/resource_list_registry.py b/src/command_modules/azure-cli-acr/azure/cli/command_modules/acr/mgmt_acr/models/resource_list_registry.py deleted file mode 100644 index 6a213c46e37..00000000000 --- a/src/command_modules/azure-cli-acr/azure/cli/command_modules/acr/mgmt_acr/models/resource_list_registry.py +++ /dev/null @@ -1,28 +0,0 @@ -#--------------------------------------------------------------------------------------------- -# Copyright (c) Microsoft Corporation. All rights reserved. -# Licensed under the MIT License. See License.txt in the project root for license information. -#--------------------------------------------------------------------------------------------- -#pylint: skip-file -# coding=utf-8 -# -------------------------------------------------------------------------- -# Code generated by Microsoft (R) AutoRest Code Generator 0.16.0.0 -# Changes may cause incorrect behavior and will be lost if the code is -# regenerated. -# -------------------------------------------------------------------------- - -from msrest.serialization import Model - - -class ResourceListRegistry(Model): - """ResourceListRegistry - - :param value: - :type value: list of :class:`Registry ` - """ - - _attribute_map = { - 'value': {'key': 'value', 'type': '[Registry]'}, - } - - def __init__(self, value=None): - self.value = value diff --git a/src/command_modules/azure-cli-acr/azure/cli/command_modules/acr/mgmt_acr/models/storage_account_properties.py b/src/command_modules/azure-cli-acr/azure/cli/command_modules/acr/mgmt_acr/models/storage_account_properties.py index 7f9f554436c..5623269f5d1 100644 --- a/src/command_modules/azure-cli-acr/azure/cli/command_modules/acr/mgmt_acr/models/storage_account_properties.py +++ b/src/command_modules/azure-cli-acr/azure/cli/command_modules/acr/mgmt_acr/models/storage_account_properties.py @@ -14,27 +14,25 @@ class StorageAccountProperties(Model): - """StorageAccountProperties + """ + The storage account properties. - :param access_key: - :type access_key: str - :param end_point_url: - :type end_point_url: str - :param location: - :type location: str - :param name: + :param name: Storage account name. :type name: str + :param access_key: Storage account access key. + :type access_key: str """ + _validation = { + 'name': {'required': True}, + 'access_key': {'required': True}, + } + _attribute_map = { - 'access_key': {'key': 'accessKey', 'type': 'str'}, - 'end_point_url': {'key': 'endPointUrl', 'type': 'str'}, - 'location': {'key': 'location', 'type': 'str'}, 'name': {'key': 'name', 'type': 'str'}, + 'access_key': {'key': 'accessKey', 'type': 'str'}, } - def __init__(self, access_key=None, end_point_url=None, location=None, name=None): - self.access_key = access_key - self.end_point_url = end_point_url - self.location = location + def __init__(self, name, access_key): self.name = name + self.access_key = access_key diff --git a/src/command_modules/azure-cli-acr/azure/cli/command_modules/acr/mgmt_acr/models/subscription_notification.py b/src/command_modules/azure-cli-acr/azure/cli/command_modules/acr/mgmt_acr/models/subscription_notification.py deleted file mode 100644 index 0b8073c313b..00000000000 --- a/src/command_modules/azure-cli-acr/azure/cli/command_modules/acr/mgmt_acr/models/subscription_notification.py +++ /dev/null @@ -1,38 +0,0 @@ -#--------------------------------------------------------------------------------------------- -# Copyright (c) Microsoft Corporation. All rights reserved. -# Licensed under the MIT License. See License.txt in the project root for license information. -#--------------------------------------------------------------------------------------------- -#pylint: skip-file -# coding=utf-8 -# -------------------------------------------------------------------------- -# Code generated by Microsoft (R) AutoRest Code Generator 0.16.0.0 -# Changes may cause incorrect behavior and will be lost if the code is -# regenerated. -# -------------------------------------------------------------------------- - -from msrest.serialization import Model - - -class SubscriptionNotification(Model): - """SubscriptionNotification - - :param registration_date: - :type registration_date: datetime - :param state: Possible values include: 'NotDefined', 'Registered', - 'Unregistered', 'Warned', 'Suspended', 'Deleted' - :type state: str - :param properties: - :type properties: :class:`SubscriptionProperties - ` - """ - - _attribute_map = { - 'registration_date': {'key': 'registrationDate', 'type': 'iso-8601'}, - 'state': {'key': 'state', 'type': 'str'}, - 'properties': {'key': 'properties', 'type': 'SubscriptionProperties'}, - } - - def __init__(self, registration_date=None, state=None, properties=None): - self.registration_date = registration_date - self.state = state - self.properties = properties diff --git a/src/command_modules/azure-cli-acr/azure/cli/command_modules/acr/mgmt_acr/models/subscription_properties.py b/src/command_modules/azure-cli-acr/azure/cli/command_modules/acr/mgmt_acr/models/subscription_properties.py deleted file mode 100644 index d2227758a3a..00000000000 --- a/src/command_modules/azure-cli-acr/azure/cli/command_modules/acr/mgmt_acr/models/subscription_properties.py +++ /dev/null @@ -1,36 +0,0 @@ -#--------------------------------------------------------------------------------------------- -# Copyright (c) Microsoft Corporation. All rights reserved. -# Licensed under the MIT License. See License.txt in the project root for license information. -#--------------------------------------------------------------------------------------------- -#pylint: skip-file -# coding=utf-8 -# -------------------------------------------------------------------------- -# Code generated by Microsoft (R) AutoRest Code Generator 0.16.0.0 -# Changes may cause incorrect behavior and will be lost if the code is -# regenerated. -# -------------------------------------------------------------------------- - -from msrest.serialization import Model - - -class SubscriptionProperties(Model): - """SubscriptionProperties - - :param tenant_id: - :type tenant_id: str - :param location_placement_id: - :type location_placement_id: str - :param quota_id: - :type quota_id: str - """ - - _attribute_map = { - 'tenant_id': {'key': 'tenantId', 'type': 'str'}, - 'location_placement_id': {'key': 'locationPlacementId', 'type': 'str'}, - 'quota_id': {'key': 'quotaId', 'type': 'str'}, - } - - def __init__(self, tenant_id=None, location_placement_id=None, quota_id=None): - self.tenant_id = tenant_id - self.location_placement_id = location_placement_id - self.quota_id = quota_id diff --git a/src/command_modules/azure-cli-acr/azure/cli/command_modules/acr/mgmt_acr/operations/__init__.py b/src/command_modules/azure-cli-acr/azure/cli/command_modules/acr/mgmt_acr/operations/__init__.py index dd08efaa7d8..896e8304fbe 100644 --- a/src/command_modules/azure-cli-acr/azure/cli/command_modules/acr/mgmt_acr/operations/__init__.py +++ b/src/command_modules/azure-cli-acr/azure/cli/command_modules/acr/mgmt_acr/operations/__init__.py @@ -10,12 +10,8 @@ # regenerated. # -------------------------------------------------------------------------- -from .operation import Operation -from .registries import Registries -from .subscriptions import Subscriptions +from .registries_operations import RegistriesOperations __all__ = [ - 'Operation', - 'Registries', - 'Subscriptions', + 'RegistriesOperations', ] diff --git a/src/command_modules/azure-cli-acr/azure/cli/command_modules/acr/mgmt_acr/operations/operation.py b/src/command_modules/azure-cli-acr/azure/cli/command_modules/acr/mgmt_acr/operations/operation.py deleted file mode 100644 index 21c31075397..00000000000 --- a/src/command_modules/azure-cli-acr/azure/cli/command_modules/acr/mgmt_acr/operations/operation.py +++ /dev/null @@ -1,141 +0,0 @@ -#--------------------------------------------------------------------------------------------- -# Copyright (c) Microsoft Corporation. All rights reserved. -# Licensed under the MIT License. See License.txt in the project root for license information. -#--------------------------------------------------------------------------------------------- -#pylint: skip-file -# coding=utf-8 -# -------------------------------------------------------------------------- -# Code generated by Microsoft (R) AutoRest Code Generator 0.16.0.0 -# Changes may cause incorrect behavior and will be lost if the code is -# regenerated. -# -------------------------------------------------------------------------- - -from msrest.pipeline import ClientRawResponse -from msrest.exceptions import HttpOperationError - -from .. import models - - -class Operation(object): - """Operation operations. - - :param client: Client for service requests. - :param config: Configuration of service client. - :param serializer: An object model serializer. - :param deserializer: An objec model deserializer. - """ - - def __init__(self, client, config, serializer, deserializer): - - self._client = client - self._serialize = serializer - self._deserialize = deserializer - - self.config = config - - def check_name_availability( - self, name_check_request, custom_headers={}, raw=False, **operation_config): - """ - - :param name_check_request: - :type name_check_request: :class:`RegistryNameCheckRequest - ` - :param dict custom_headers: headers that will be added to the request - :param bool raw: returns the direct response alongside the - deserialized response - :param operation_config: :ref:`Operation configuration - overrides`. - :rtype: :class:`RegistryNameStatus - ` - :rtype: :class:`ClientRawResponse` - if raw=true - """ - # Construct URL - url = '/subscriptions/{subscriptionId}/providers/Microsoft.ContainerRegistry/checkNameAvailability' - path_format_arguments = { - 'subscriptionId': self._serialize.url("self.config.subscription_id", self.config.subscription_id, 'str') - } - url = self._client.format_url(url, **path_format_arguments) - - # Construct parameters - query_parameters = {} - query_parameters['api-version'] = self._serialize.query("self.config.api_version", self.config.api_version, 'str') - - # Construct headers - header_parameters = {} - header_parameters['Content-Type'] = 'application/json; charset=utf-8' - if custom_headers: - header_parameters.update(custom_headers) - - # Construct body - body_content = self._serialize.body(name_check_request, 'RegistryNameCheckRequest') - - # Construct and send request - request = self._client.post(url, query_parameters) - response = self._client.send( - request, header_parameters, body_content, **operation_config) - - if response.status_code not in [200]: - raise HttpOperationError(self._deserialize, response) - - deserialized = None - - if response.status_code == 200: - deserialized = self._deserialize('RegistryNameStatus', response) - - if raw: - client_raw_response = ClientRawResponse(deserialized, response) - return client_raw_response - - return deserialized - - def move_resources( - self, resource_group, move_request, custom_headers={}, raw=False, **operation_config): - """ - - :param resource_group: - :type resource_group: str - :param move_request: - :type move_request: :class:`RegistryMoveRequest - ` - :param dict custom_headers: headers that will be added to the request - :param bool raw: returns the direct response alongside the - deserialized response - :param operation_config: :ref:`Operation configuration - overrides`. - :rtype: None - :rtype: :class:`ClientRawResponse` - if raw=true - """ - # Construct URL - url = '/subscriptions/{subscriptionId}/resourcegroups/{resourceGroup}/moveResources' - path_format_arguments = { - 'subscriptionId': self._serialize.url("self.config.subscription_id", self.config.subscription_id, 'str'), - 'resourceGroup': self._serialize.url("resource_group", resource_group, 'str') - } - url = self._client.format_url(url, **path_format_arguments) - - # Construct parameters - query_parameters = {} - query_parameters['api-version'] = self._serialize.query("self.config.api_version", self.config.api_version, 'str') - - # Construct headers - header_parameters = {} - header_parameters['Content-Type'] = 'application/json; charset=utf-8' - if custom_headers: - header_parameters.update(custom_headers) - - # Construct body - body_content = self._serialize.body(move_request, 'RegistryMoveRequest') - - # Construct and send request - request = self._client.post(url, query_parameters) - response = self._client.send( - request, header_parameters, body_content, **operation_config) - - if response.status_code not in [200]: - raise HttpOperationError(self._deserialize, response) - - if raw: - client_raw_response = ClientRawResponse(None, response) - return client_raw_response diff --git a/src/command_modules/azure-cli-acr/azure/cli/command_modules/acr/mgmt_acr/operations/registries.py b/src/command_modules/azure-cli-acr/azure/cli/command_modules/acr/mgmt_acr/operations/registries.py deleted file mode 100644 index 945091678ff..00000000000 --- a/src/command_modules/azure-cli-acr/azure/cli/command_modules/acr/mgmt_acr/operations/registries.py +++ /dev/null @@ -1,414 +0,0 @@ -#--------------------------------------------------------------------------------------------- -# Copyright (c) Microsoft Corporation. All rights reserved. -# Licensed under the MIT License. See License.txt in the project root for license information. -#--------------------------------------------------------------------------------------------- -#pylint: skip-file -# coding=utf-8 -# -------------------------------------------------------------------------- -# Code generated by Microsoft (R) AutoRest Code Generator 0.16.0.0 -# Changes may cause incorrect behavior and will be lost if the code is -# regenerated. -# -------------------------------------------------------------------------- - -from msrest.pipeline import ClientRawResponse -from msrest.exceptions import HttpOperationError - -from .. import models - - -class Registries(object): - """Registries operations. - - :param client: Client for service requests. - :param config: Configuration of service client. - :param serializer: An object model serializer. - :param deserializer: An objec model deserializer. - """ - - def __init__(self, client, config, serializer, deserializer): - - self._client = client - self._serialize = serializer - self._deserialize = deserializer - - self.config = config - - def get_properties( - self, resource_group, registry_name, custom_headers={}, raw=False, **operation_config): - """ - - :param resource_group: - :type resource_group: str - :param registry_name: - :type registry_name: str - :param dict custom_headers: headers that will be added to the request - :param bool raw: returns the direct response alongside the - deserialized response - :param operation_config: :ref:`Operation configuration - overrides`. - :rtype: :class:`Registry ` - :rtype: :class:`ClientRawResponse` - if raw=true - """ - # Construct URL - url = '/subscriptions/{subscriptionId}/resourcegroups/{resourceGroup}/providers/Microsoft.ContainerRegistry/registries/{registryName}' - path_format_arguments = { - 'subscriptionId': self._serialize.url("self.config.subscription_id", self.config.subscription_id, 'str'), - 'resourceGroup': self._serialize.url("resource_group", resource_group, 'str'), - 'registryName': self._serialize.url("registry_name", registry_name, 'str') - } - url = self._client.format_url(url, **path_format_arguments) - - # Construct parameters - query_parameters = {} - query_parameters['api-version'] = self._serialize.query("self.config.api_version", self.config.api_version, 'str') - - # Construct headers - header_parameters = {} - header_parameters['Content-Type'] = 'application/json; charset=utf-8' - if custom_headers: - header_parameters.update(custom_headers) - - # Construct and send request - request = self._client.get(url, query_parameters) - response = self._client.send(request, header_parameters, **operation_config) - - if response.status_code not in [200]: - raise HttpOperationError(self._deserialize, response) - - deserialized = None - - if response.status_code == 200: - deserialized = self._deserialize('Registry', response) - - if raw: - client_raw_response = ClientRawResponse(deserialized, response) - return client_raw_response - - return deserialized - - def create( - self, resource_group, registry_name, registry_parameters, custom_headers={}, raw=False, **operation_config): - """ - - :param resource_group: - :type resource_group: str - :param registry_name: - :type registry_name: str - :param registry_parameters: - :type registry_parameters: :class:`RegistryCreateParameters - ` - :param dict custom_headers: headers that will be added to the request - :param bool raw: returns the direct response alongside the - deserialized response - :param operation_config: :ref:`Operation configuration - overrides`. - :rtype: :class:`RegistryCreateParameters - ` - :rtype: :class:`ClientRawResponse` - if raw=true - """ - # Construct URL - url = '/subscriptions/{subscriptionId}/resourcegroups/{resourceGroup}/providers/Microsoft.ContainerRegistry/registries/{registryName}' - path_format_arguments = { - 'subscriptionId': self._serialize.url("self.config.subscription_id", self.config.subscription_id, 'str'), - 'resourceGroup': self._serialize.url("resource_group", resource_group, 'str'), - 'registryName': self._serialize.url("registry_name", registry_name, 'str') - } - url = self._client.format_url(url, **path_format_arguments) - - # Construct parameters - query_parameters = {} - query_parameters['api-version'] = self._serialize.query("self.config.api_version", self.config.api_version, 'str') - - # Construct headers - header_parameters = {} - header_parameters['Content-Type'] = 'application/json; charset=utf-8' - if custom_headers: - header_parameters.update(custom_headers) - - # Construct body - body_content = self._serialize.body(registry_parameters, 'RegistryCreateParameters') - - # Construct and send request - request = self._client.put(url, query_parameters) - response = self._client.send( - request, header_parameters, body_content, **operation_config) - - if response.status_code not in [200]: - raise HttpOperationError(self._deserialize, response) - - deserialized = None - - if response.status_code == 200: - deserialized = self._deserialize('RegistryCreateParameters', response) - - if raw: - client_raw_response = ClientRawResponse(deserialized, response) - return client_raw_response - - return deserialized - - def delete( - self, resource_group, registry_name, custom_headers={}, raw=False, **operation_config): - """ - - :param resource_group: - :type resource_group: str - :param registry_name: - :type registry_name: str - :param dict custom_headers: headers that will be added to the request - :param bool raw: returns the direct response alongside the - deserialized response - :param operation_config: :ref:`Operation configuration - overrides`. - :rtype: None - :rtype: :class:`ClientRawResponse` - if raw=true - """ - # Construct URL - url = '/subscriptions/{subscriptionId}/resourcegroups/{resourceGroup}/providers/Microsoft.ContainerRegistry/registries/{registryName}' - path_format_arguments = { - 'subscriptionId': self._serialize.url("self.config.subscription_id", self.config.subscription_id, 'str'), - 'resourceGroup': self._serialize.url("resource_group", resource_group, 'str'), - 'registryName': self._serialize.url("registry_name", registry_name, 'str') - } - url = self._client.format_url(url, **path_format_arguments) - - # Construct parameters - query_parameters = {} - query_parameters['api-version'] = self._serialize.query("self.config.api_version", self.config.api_version, 'str') - - # Construct headers - header_parameters = {} - header_parameters['Content-Type'] = 'application/json; charset=utf-8' - if custom_headers: - header_parameters.update(custom_headers) - - # Construct and send request - request = self._client.delete(url, query_parameters) - response = self._client.send(request, header_parameters, **operation_config) - - if response.status_code not in [200]: - raise HttpOperationError(self._deserialize, response) - - if raw: - client_raw_response = ClientRawResponse(None, response) - return client_raw_response - - def update( - self, resource_group, registry_name, registry_update_parameters, custom_headers={}, raw=False, **operation_config): - """ - - :param resource_group: - :type resource_group: str - :param registry_name: - :type registry_name: str - :param registry_update_parameters: - :type registry_update_parameters: :class:`RegistryUpdateParameters - ` - :param dict custom_headers: headers that will be added to the request - :param bool raw: returns the direct response alongside the - deserialized response - :param operation_config: :ref:`Operation configuration - overrides`. - :rtype: :class:`Registry ` - :rtype: :class:`ClientRawResponse` - if raw=true - """ - # Construct URL - url = '/subscriptions/{subscriptionId}/resourcegroups/{resourceGroup}/providers/Microsoft.ContainerRegistry/registries/{registryName}' - path_format_arguments = { - 'subscriptionId': self._serialize.url("self.config.subscription_id", self.config.subscription_id, 'str'), - 'resourceGroup': self._serialize.url("resource_group", resource_group, 'str'), - 'registryName': self._serialize.url("registry_name", registry_name, 'str') - } - url = self._client.format_url(url, **path_format_arguments) - - # Construct parameters - query_parameters = {} - query_parameters['api-version'] = self._serialize.query("self.config.api_version", self.config.api_version, 'str') - - # Construct headers - header_parameters = {} - header_parameters['Content-Type'] = 'application/json; charset=utf-8' - if custom_headers: - header_parameters.update(custom_headers) - - # Construct body - body_content = self._serialize.body(registry_update_parameters, 'RegistryUpdateParameters') - - # Construct and send request - request = self._client.patch(url, query_parameters) - response = self._client.send( - request, header_parameters, body_content, **operation_config) - - if response.status_code not in [200]: - raise HttpOperationError(self._deserialize, response) - - deserialized = None - - if response.status_code == 200: - deserialized = self._deserialize('Registry', response) - - if raw: - client_raw_response = ClientRawResponse(deserialized, response) - return client_raw_response - - return deserialized - - def list_by_resource_group( - self, resource_group, custom_headers={}, raw=False, **operation_config): - """ - - :param resource_group: - :type resource_group: str - :param dict custom_headers: headers that will be added to the request - :param bool raw: returns the direct response alongside the - deserialized response - :param operation_config: :ref:`Operation configuration - overrides`. - :rtype: :class:`ResourceListRegistry - ` - :rtype: :class:`ClientRawResponse` - if raw=true - """ - # Construct URL - url = '/subscriptions/{subscriptionId}/resourcegroups/{resourceGroup}/providers/Microsoft.ContainerRegistry/registries' - path_format_arguments = { - 'subscriptionId': self._serialize.url("self.config.subscription_id", self.config.subscription_id, 'str'), - 'resourceGroup': self._serialize.url("resource_group", resource_group, 'str') - } - url = self._client.format_url(url, **path_format_arguments) - - # Construct parameters - query_parameters = {} - query_parameters['api-version'] = self._serialize.query("self.config.api_version", self.config.api_version, 'str') - - # Construct headers - header_parameters = {} - header_parameters['Content-Type'] = 'application/json; charset=utf-8' - if custom_headers: - header_parameters.update(custom_headers) - - # Construct and send request - request = self._client.get(url, query_parameters) - response = self._client.send(request, header_parameters, **operation_config) - - if response.status_code not in [200]: - raise HttpOperationError(self._deserialize, response) - - deserialized = None - - if response.status_code == 200: - deserialized = self._deserialize('ResourceListRegistry', response) - - if raw: - client_raw_response = ClientRawResponse(deserialized, response) - return client_raw_response - - return deserialized - - def list( - self, custom_headers={}, raw=False, **operation_config): - """ - - :param dict custom_headers: headers that will be added to the request - :param bool raw: returns the direct response alongside the - deserialized response - :param operation_config: :ref:`Operation configuration - overrides`. - :rtype: :class:`ResourceListRegistry - ` - :rtype: :class:`ClientRawResponse` - if raw=true - """ - # Construct URL - url = '/subscriptions/{subscriptionId}/providers/Microsoft.ContainerRegistry/registries' - path_format_arguments = { - 'subscriptionId': self._serialize.url("self.config.subscription_id", self.config.subscription_id, 'str') - } - url = self._client.format_url(url, **path_format_arguments) - - # Construct parameters - query_parameters = {} - query_parameters['api-version'] = self._serialize.query("self.config.api_version", self.config.api_version, 'str') - - # Construct headers - header_parameters = {} - header_parameters['Content-Type'] = 'application/json; charset=utf-8' - if custom_headers: - header_parameters.update(custom_headers) - - # Construct and send request - request = self._client.get(url, query_parameters) - response = self._client.send(request, header_parameters, **operation_config) - - if response.status_code not in [200]: - raise HttpOperationError(self._deserialize, response) - - deserialized = None - - if response.status_code == 200: - deserialized = self._deserialize('ResourceListRegistry', response) - - if raw: - client_raw_response = ClientRawResponse(deserialized, response) - return client_raw_response - - return deserialized - - def get_credentials( - self, resource_group, registry_name, custom_headers={}, raw=False, **operation_config): - """ - - :param resource_group: - :type resource_group: str - :param registry_name: - :type registry_name: str - :param dict custom_headers: headers that will be added to the request - :param bool raw: returns the direct response alongside the - deserialized response - :param operation_config: :ref:`Operation configuration - overrides`. - :rtype: :class:`RegistryCredentials - ` - :rtype: :class:`ClientRawResponse` - if raw=true - """ - # Construct URL - url = '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroup}/providers/Microsoft.ContainerRegistry/registries/{registryName}/GetCredentials' - path_format_arguments = { - 'subscriptionId': self._serialize.url("self.config.subscription_id", self.config.subscription_id, 'str'), - 'resourceGroup': self._serialize.url("resource_group", resource_group, 'str'), - 'registryName': self._serialize.url("registry_name", registry_name, 'str') - } - url = self._client.format_url(url, **path_format_arguments) - - # Construct parameters - query_parameters = {} - query_parameters['api-version'] = self._serialize.query("self.config.api_version", self.config.api_version, 'str') - - # Construct headers - header_parameters = {} - header_parameters['Content-Type'] = 'application/json; charset=utf-8' - if custom_headers: - header_parameters.update(custom_headers) - - # Construct and send request - request = self._client.post(url, query_parameters) - response = self._client.send(request, header_parameters, **operation_config) - - if response.status_code not in [200]: - raise HttpOperationError(self._deserialize, response) - - deserialized = None - - if response.status_code == 200: - deserialized = self._deserialize('RegistryCredentials', response) - - if raw: - client_raw_response = ClientRawResponse(deserialized, response) - return client_raw_response - - return deserialized diff --git a/src/command_modules/azure-cli-acr/azure/cli/command_modules/acr/mgmt_acr/operations/registries_operations.py b/src/command_modules/azure-cli-acr/azure/cli/command_modules/acr/mgmt_acr/operations/registries_operations.py new file mode 100644 index 00000000000..7daa1d62236 --- /dev/null +++ b/src/command_modules/azure-cli-acr/azure/cli/command_modules/acr/mgmt_acr/operations/registries_operations.py @@ -0,0 +1,613 @@ +#--------------------------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for license information. +#--------------------------------------------------------------------------------------------- +#pylint: skip-file +# coding=utf-8 +# -------------------------------------------------------------------------- +# Code generated by Microsoft (R) AutoRest Code Generator 0.16.0.0 +# Changes may cause incorrect behavior and will be lost if the code is +# regenerated. +# -------------------------------------------------------------------------- + +from msrest.pipeline import ClientRawResponse +from msrestazure.azure_exceptions import CloudError +import uuid + +from .. import models + + +class RegistriesOperations(object): + """RegistriesOperations operations. + + :param client: Client for service requests. + :param config: Configuration of service client. + :param serializer: An object model serializer. + :param deserializer: An objec model deserializer. + """ + + def __init__(self, client, config, serializer, deserializer): + + self._client = client + self._serialize = serializer + self._deserialize = deserializer + + self.config = config + + def check_name_availability( + self, registry_name_check_request, custom_headers={}, raw=False, **operation_config): + """ + Checks whether the container registry name is available. + + :param registry_name_check_request: The request to check whether the + container registry name is available. + :type registry_name_check_request: :class:`RegistryNameCheckRequest + ` + :param dict custom_headers: headers that will be added to the request + :param bool raw: returns the direct response alongside the + deserialized response + :param operation_config: :ref:`Operation configuration + overrides`. + :rtype: :class:`RegistryNameStatus + ` + :rtype: :class:`ClientRawResponse` + if raw=true + """ + # Construct URL + url = '/subscriptions/{subscriptionId}/providers/Microsoft.ContainerRegistry/checkNameAvailability' + path_format_arguments = { + 'subscriptionId': self._serialize.url("self.config.subscription_id", self.config.subscription_id, 'str') + } + url = self._client.format_url(url, **path_format_arguments) + + # Construct parameters + query_parameters = {} + query_parameters['api-version'] = self._serialize.query("self.config.api_version", self.config.api_version, 'str') + + # Construct headers + header_parameters = {} + header_parameters['Content-Type'] = 'application/json; charset=utf-8' + if self.config.generate_client_request_id: + header_parameters['x-ms-client-request-id'] = str(uuid.uuid1()) + if custom_headers: + header_parameters.update(custom_headers) + if self.config.accept_language is not None: + header_parameters['accept-language'] = self._serialize.header("self.config.accept_language", self.config.accept_language, 'str') + + # Construct body + body_content = self._serialize.body(registry_name_check_request, 'RegistryNameCheckRequest') + + # Construct and send request + request = self._client.post(url, query_parameters) + response = self._client.send( + request, header_parameters, body_content, **operation_config) + + if response.status_code not in [200]: + exp = CloudError(response) + exp.request_id = response.headers.get('x-ms-request-id') + raise exp + + deserialized = None + + if response.status_code == 200: + deserialized = self._deserialize('RegistryNameStatus', response) + + if raw: + client_raw_response = ClientRawResponse(deserialized, response) + return client_raw_response + + return deserialized + + def get_properties( + self, resource_group_name, registry_name, custom_headers={}, raw=False, **operation_config): + """ + Gets the properties for the specified container registry. + + :param resource_group_name: The resource group name. + :type resource_group_name: str + :param registry_name: The container registry name. + :type registry_name: str + :param dict custom_headers: headers that will be added to the request + :param bool raw: returns the direct response alongside the + deserialized response + :param operation_config: :ref:`Operation configuration + overrides`. + :rtype: :class:`Registry + ` + :rtype: :class:`ClientRawResponse` + if raw=true + """ + # Construct URL + url = '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ContainerRegistry/registries/{registryName}' + path_format_arguments = { + 'subscriptionId': self._serialize.url("self.config.subscription_id", self.config.subscription_id, 'str'), + 'resourceGroupName': self._serialize.url("resource_group_name", resource_group_name, 'str'), + 'registryName': self._serialize.url("registry_name", registry_name, 'str') + } + url = self._client.format_url(url, **path_format_arguments) + + # Construct parameters + query_parameters = {} + query_parameters['api-version'] = self._serialize.query("self.config.api_version", self.config.api_version, 'str') + + # Construct headers + header_parameters = {} + header_parameters['Content-Type'] = 'application/json; charset=utf-8' + if self.config.generate_client_request_id: + header_parameters['x-ms-client-request-id'] = str(uuid.uuid1()) + if custom_headers: + header_parameters.update(custom_headers) + if self.config.accept_language is not None: + header_parameters['accept-language'] = self._serialize.header("self.config.accept_language", self.config.accept_language, 'str') + + # Construct and send request + request = self._client.get(url, query_parameters) + response = self._client.send(request, header_parameters, **operation_config) + + if response.status_code not in [200]: + exp = CloudError(response) + exp.request_id = response.headers.get('x-ms-request-id') + raise exp + + deserialized = None + + if response.status_code == 200: + deserialized = self._deserialize('Registry', response) + + if raw: + client_raw_response = ClientRawResponse(deserialized, response) + return client_raw_response + + return deserialized + + def create_or_update( + self, resource_group_name, registry_name, registry, custom_headers={}, raw=False, **operation_config): + """ + Creates or updates a container registry with the specified parameters. + The storage account provided in this operation should be in the same + location as the container registry. + + :param resource_group_name: The resource group name. + :type resource_group_name: str + :param registry_name: The container registry name. + :type registry_name: str + :param registry: The container registry. + :type registry: :class:`Registry + ` + :param dict custom_headers: headers that will be added to the request + :param bool raw: returns the direct response alongside the + deserialized response + :param operation_config: :ref:`Operation configuration + overrides`. + :rtype: :class:`Registry + ` + :rtype: :class:`ClientRawResponse` + if raw=true + """ + # Construct URL + url = '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ContainerRegistry/registries/{registryName}' + path_format_arguments = { + 'subscriptionId': self._serialize.url("self.config.subscription_id", self.config.subscription_id, 'str'), + 'resourceGroupName': self._serialize.url("resource_group_name", resource_group_name, 'str'), + 'registryName': self._serialize.url("registry_name", registry_name, 'str') + } + url = self._client.format_url(url, **path_format_arguments) + + # Construct parameters + query_parameters = {} + query_parameters['api-version'] = self._serialize.query("self.config.api_version", self.config.api_version, 'str') + + # Construct headers + header_parameters = {} + header_parameters['Content-Type'] = 'application/json; charset=utf-8' + if self.config.generate_client_request_id: + header_parameters['x-ms-client-request-id'] = str(uuid.uuid1()) + if custom_headers: + header_parameters.update(custom_headers) + if self.config.accept_language is not None: + header_parameters['accept-language'] = self._serialize.header("self.config.accept_language", self.config.accept_language, 'str') + + # Construct body + body_content = self._serialize.body(registry, 'Registry') + + # Construct and send request + request = self._client.put(url, query_parameters) + response = self._client.send( + request, header_parameters, body_content, **operation_config) + + if response.status_code not in [200]: + exp = CloudError(response) + exp.request_id = response.headers.get('x-ms-request-id') + raise exp + + deserialized = None + + if response.status_code == 200: + deserialized = self._deserialize('Registry', response) + + if raw: + client_raw_response = ClientRawResponse(deserialized, response) + return client_raw_response + + return deserialized + + def delete( + self, resource_group_name, registry_name, custom_headers={}, raw=False, **operation_config): + """ + Deletes a container registry from the given subscription and resource + group. + + :param resource_group_name: The resource group name. + :type resource_group_name: str + :param registry_name: The container registry name. + :type registry_name: str + :param dict custom_headers: headers that will be added to the request + :param bool raw: returns the direct response alongside the + deserialized response + :param operation_config: :ref:`Operation configuration + overrides`. + :rtype: None + :rtype: :class:`ClientRawResponse` + if raw=true + """ + # Construct URL + url = '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ContainerRegistry/registries/{registryName}' + path_format_arguments = { + 'subscriptionId': self._serialize.url("self.config.subscription_id", self.config.subscription_id, 'str'), + 'resourceGroupName': self._serialize.url("resource_group_name", resource_group_name, 'str'), + 'registryName': self._serialize.url("registry_name", registry_name, 'str') + } + url = self._client.format_url(url, **path_format_arguments) + + # Construct parameters + query_parameters = {} + query_parameters['api-version'] = self._serialize.query("self.config.api_version", self.config.api_version, 'str') + + # Construct headers + header_parameters = {} + header_parameters['Content-Type'] = 'application/json; charset=utf-8' + if self.config.generate_client_request_id: + header_parameters['x-ms-client-request-id'] = str(uuid.uuid1()) + if custom_headers: + header_parameters.update(custom_headers) + if self.config.accept_language is not None: + header_parameters['accept-language'] = self._serialize.header("self.config.accept_language", self.config.accept_language, 'str') + + # Construct and send request + request = self._client.delete(url, query_parameters) + response = self._client.send(request, header_parameters, **operation_config) + + if response.status_code not in [200]: + exp = CloudError(response) + exp.request_id = response.headers.get('x-ms-request-id') + raise exp + + if raw: + client_raw_response = ClientRawResponse(None, response) + return client_raw_response + + def update( + self, resource_group_name, registry_name, registry_update_parameters, custom_headers={}, raw=False, **operation_config): + """ + Updates a container registry with the specified parameters. The + storage account provided in this operation should be in the same + location as the container registry. + + :param resource_group_name: The resource group name. + :type resource_group_name: str + :param registry_name: The container registry name. + :type registry_name: str + :param registry_update_parameters: The parameters for updating a + container registry. + :type registry_update_parameters: :class:`RegistryUpdateParameters + ` + :param dict custom_headers: headers that will be added to the request + :param bool raw: returns the direct response alongside the + deserialized response + :param operation_config: :ref:`Operation configuration + overrides`. + :rtype: :class:`Registry + ` + :rtype: :class:`ClientRawResponse` + if raw=true + """ + # Construct URL + url = '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ContainerRegistry/registries/{registryName}' + path_format_arguments = { + 'subscriptionId': self._serialize.url("self.config.subscription_id", self.config.subscription_id, 'str'), + 'resourceGroupName': self._serialize.url("resource_group_name", resource_group_name, 'str'), + 'registryName': self._serialize.url("registry_name", registry_name, 'str') + } + url = self._client.format_url(url, **path_format_arguments) + + # Construct parameters + query_parameters = {} + query_parameters['api-version'] = self._serialize.query("self.config.api_version", self.config.api_version, 'str') + + # Construct headers + header_parameters = {} + header_parameters['Content-Type'] = 'application/json; charset=utf-8' + if self.config.generate_client_request_id: + header_parameters['x-ms-client-request-id'] = str(uuid.uuid1()) + if custom_headers: + header_parameters.update(custom_headers) + if self.config.accept_language is not None: + header_parameters['accept-language'] = self._serialize.header("self.config.accept_language", self.config.accept_language, 'str') + + # Construct body + body_content = self._serialize.body(registry_update_parameters, 'RegistryUpdateParameters') + + # Construct and send request + request = self._client.patch(url, query_parameters) + response = self._client.send( + request, header_parameters, body_content, **operation_config) + + if response.status_code not in [200]: + exp = CloudError(response) + exp.request_id = response.headers.get('x-ms-request-id') + raise exp + + deserialized = None + + if response.status_code == 200: + deserialized = self._deserialize('Registry', response) + + if raw: + client_raw_response = ClientRawResponse(deserialized, response) + return client_raw_response + + return deserialized + + def list_by_resource_group( + self, resource_group_name, custom_headers={}, raw=False, **operation_config): + """ + Lists all the container registries available under the given resource + group. + + :param resource_group_name: The resource group name. + :type resource_group_name: str + :param dict custom_headers: headers that will be added to the request + :param bool raw: returns the direct response alongside the + deserialized response + :param operation_config: :ref:`Operation configuration + overrides`. + :rtype: :class:`RegistryPaged + ` + """ + def internal_paging(next_link=None, raw=False): + + if not next_link: + # Construct URL + url = '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ContainerRegistry/registries' + path_format_arguments = { + 'subscriptionId': self._serialize.url("self.config.subscription_id", self.config.subscription_id, 'str'), + 'resourceGroupName': self._serialize.url("resource_group_name", resource_group_name, 'str') + } + url = self._client.format_url(url, **path_format_arguments) + + # Construct parameters + query_parameters = {} + query_parameters['api-version'] = self._serialize.query("self.config.api_version", self.config.api_version, 'str') + + else: + url = next_link + query_parameters = {} + + # Construct headers + header_parameters = {} + header_parameters['Content-Type'] = 'application/json; charset=utf-8' + if self.config.generate_client_request_id: + header_parameters['x-ms-client-request-id'] = str(uuid.uuid1()) + if custom_headers: + header_parameters.update(custom_headers) + if self.config.accept_language is not None: + header_parameters['accept-language'] = self._serialize.header("self.config.accept_language", self.config.accept_language, 'str') + + # Construct and send request + request = self._client.get(url, query_parameters) + response = self._client.send( + request, header_parameters, **operation_config) + + if response.status_code not in [200]: + exp = CloudError(response) + exp.request_id = response.headers.get('x-ms-request-id') + raise exp + + return response + + # Deserialize response + deserialized = models.RegistryPaged(internal_paging, self._deserialize.dependencies) + + if raw: + header_dict = {} + client_raw_response = models.RegistryPaged(internal_paging, self._deserialize.dependencies, header_dict) + return client_raw_response + + return deserialized + + def list( + self, custom_headers={}, raw=False, **operation_config): + """ + Lists all the container registries available under the subscription. + + :param dict custom_headers: headers that will be added to the request + :param bool raw: returns the direct response alongside the + deserialized response + :param operation_config: :ref:`Operation configuration + overrides`. + :rtype: :class:`RegistryPaged + ` + """ + def internal_paging(next_link=None, raw=False): + + if not next_link: + # Construct URL + url = '/subscriptions/{subscriptionId}/providers/Microsoft.ContainerRegistry/registries' + path_format_arguments = { + 'subscriptionId': self._serialize.url("self.config.subscription_id", self.config.subscription_id, 'str') + } + url = self._client.format_url(url, **path_format_arguments) + + # Construct parameters + query_parameters = {} + query_parameters['api-version'] = self._serialize.query("self.config.api_version", self.config.api_version, 'str') + + else: + url = next_link + query_parameters = {} + + # Construct headers + header_parameters = {} + header_parameters['Content-Type'] = 'application/json; charset=utf-8' + if self.config.generate_client_request_id: + header_parameters['x-ms-client-request-id'] = str(uuid.uuid1()) + if custom_headers: + header_parameters.update(custom_headers) + if self.config.accept_language is not None: + header_parameters['accept-language'] = self._serialize.header("self.config.accept_language", self.config.accept_language, 'str') + + # Construct and send request + request = self._client.get(url, query_parameters) + response = self._client.send( + request, header_parameters, **operation_config) + + if response.status_code not in [200]: + exp = CloudError(response) + exp.request_id = response.headers.get('x-ms-request-id') + raise exp + + return response + + # Deserialize response + deserialized = models.RegistryPaged(internal_paging, self._deserialize.dependencies) + + if raw: + header_dict = {} + client_raw_response = models.RegistryPaged(internal_paging, self._deserialize.dependencies, header_dict) + return client_raw_response + + return deserialized + + def get_credentials( + self, resource_group_name, registry_name, custom_headers={}, raw=False, **operation_config): + """ + Gets login credentials for the specified container registry. + + :param resource_group_name: The resource group name. + :type resource_group_name: str + :param registry_name: The container registry name. + :type registry_name: str + :param dict custom_headers: headers that will be added to the request + :param bool raw: returns the direct response alongside the + deserialized response + :param operation_config: :ref:`Operation configuration + overrides`. + :rtype: :class:`RegistryCredentials + ` + :rtype: :class:`ClientRawResponse` + if raw=true + """ + # Construct URL + url = '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ContainerRegistry/registries/{registryName}/getCredentials' + path_format_arguments = { + 'subscriptionId': self._serialize.url("self.config.subscription_id", self.config.subscription_id, 'str'), + 'resourceGroupName': self._serialize.url("resource_group_name", resource_group_name, 'str'), + 'registryName': self._serialize.url("registry_name", registry_name, 'str') + } + url = self._client.format_url(url, **path_format_arguments) + + # Construct parameters + query_parameters = {} + query_parameters['api-version'] = self._serialize.query("self.config.api_version", self.config.api_version, 'str') + + # Construct headers + header_parameters = {} + header_parameters['Content-Type'] = 'application/json; charset=utf-8' + if self.config.generate_client_request_id: + header_parameters['x-ms-client-request-id'] = str(uuid.uuid1()) + if custom_headers: + header_parameters.update(custom_headers) + if self.config.accept_language is not None: + header_parameters['accept-language'] = self._serialize.header("self.config.accept_language", self.config.accept_language, 'str') + + # Construct and send request + request = self._client.post(url, query_parameters) + response = self._client.send(request, header_parameters, **operation_config) + + if response.status_code not in [200]: + exp = CloudError(response) + exp.request_id = response.headers.get('x-ms-request-id') + raise exp + + deserialized = None + + if response.status_code == 200: + deserialized = self._deserialize('RegistryCredentials', response) + + if raw: + client_raw_response = ClientRawResponse(deserialized, response) + return client_raw_response + + return deserialized + + def regenerate_credentials( + self, resource_group_name, registry_name, custom_headers={}, raw=False, **operation_config): + """ + Regenerates login credentials for the specified container registry. + + :param resource_group_name: The resource group name. + :type resource_group_name: str + :param registry_name: The container registry name. + :type registry_name: str + :param dict custom_headers: headers that will be added to the request + :param bool raw: returns the direct response alongside the + deserialized response + :param operation_config: :ref:`Operation configuration + overrides`. + :rtype: :class:`RegistryCredentials + ` + :rtype: :class:`ClientRawResponse` + if raw=true + """ + # Construct URL + url = '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ContainerRegistry/registries/{registryName}/regenerateCredentials' + path_format_arguments = { + 'subscriptionId': self._serialize.url("self.config.subscription_id", self.config.subscription_id, 'str'), + 'resourceGroupName': self._serialize.url("resource_group_name", resource_group_name, 'str'), + 'registryName': self._serialize.url("registry_name", registry_name, 'str') + } + url = self._client.format_url(url, **path_format_arguments) + + # Construct parameters + query_parameters = {} + query_parameters['api-version'] = self._serialize.query("self.config.api_version", self.config.api_version, 'str') + + # Construct headers + header_parameters = {} + header_parameters['Content-Type'] = 'application/json; charset=utf-8' + if self.config.generate_client_request_id: + header_parameters['x-ms-client-request-id'] = str(uuid.uuid1()) + if custom_headers: + header_parameters.update(custom_headers) + if self.config.accept_language is not None: + header_parameters['accept-language'] = self._serialize.header("self.config.accept_language", self.config.accept_language, 'str') + + # Construct and send request + request = self._client.post(url, query_parameters) + response = self._client.send(request, header_parameters, **operation_config) + + if response.status_code not in [200]: + exp = CloudError(response) + exp.request_id = response.headers.get('x-ms-request-id') + raise exp + + deserialized = None + + if response.status_code == 200: + deserialized = self._deserialize('RegistryCredentials', response) + + if raw: + client_raw_response = ClientRawResponse(deserialized, response) + return client_raw_response + + return deserialized diff --git a/src/command_modules/azure-cli-acr/azure/cli/command_modules/acr/mgmt_acr/operations/subscriptions.py b/src/command_modules/azure-cli-acr/azure/cli/command_modules/acr/mgmt_acr/operations/subscriptions.py deleted file mode 100644 index 4cb592677f5..00000000000 --- a/src/command_modules/azure-cli-acr/azure/cli/command_modules/acr/mgmt_acr/operations/subscriptions.py +++ /dev/null @@ -1,90 +0,0 @@ -#--------------------------------------------------------------------------------------------- -# Copyright (c) Microsoft Corporation. All rights reserved. -# Licensed under the MIT License. See License.txt in the project root for license information. -#--------------------------------------------------------------------------------------------- -#pylint: skip-file -# coding=utf-8 -# -------------------------------------------------------------------------- -# Code generated by Microsoft (R) AutoRest Code Generator 0.16.0.0 -# Changes may cause incorrect behavior and will be lost if the code is -# regenerated. -# -------------------------------------------------------------------------- - -from msrest.pipeline import ClientRawResponse -from msrest.exceptions import HttpOperationError - -from .. import models - - -class Subscriptions(object): - """Subscriptions operations. - - :param client: Client for service requests. - :param config: Configuration of service client. - :param serializer: An object model serializer. - :param deserializer: An objec model deserializer. - """ - - def __init__(self, client, config, serializer, deserializer): - - self._client = client - self._serialize = serializer - self._deserialize = deserializer - - self.config = config - - def put_subscription( - self, notification, custom_headers={}, raw=False, **operation_config): - """ - - :param notification: - :type notification: :class:`SubscriptionNotification - ` - :param dict custom_headers: headers that will be added to the request - :param bool raw: returns the direct response alongside the - deserialized response - :param operation_config: :ref:`Operation configuration - overrides`. - :rtype: :class:`SubscriptionNotification - ` - :rtype: :class:`ClientRawResponse` - if raw=true - """ - # Construct URL - url = '/subscriptions/{subscriptionId}' - path_format_arguments = { - 'subscriptionId': self._serialize.url("self.config.subscription_id", self.config.subscription_id, 'str') - } - url = self._client.format_url(url, **path_format_arguments) - - # Construct parameters - query_parameters = {} - query_parameters['api-version'] = self._serialize.query("self.config.api_version", self.config.api_version, 'str') - - # Construct headers - header_parameters = {} - header_parameters['Content-Type'] = 'application/json; charset=utf-8' - if custom_headers: - header_parameters.update(custom_headers) - - # Construct body - body_content = self._serialize.body(notification, 'SubscriptionNotification') - - # Construct and send request - request = self._client.put(url, query_parameters) - response = self._client.send( - request, header_parameters, body_content, **operation_config) - - if response.status_code not in [200]: - raise HttpOperationError(self._deserialize, response) - - deserialized = None - - if response.status_code == 200: - deserialized = self._deserialize('SubscriptionNotification', response) - - if raw: - client_raw_response = ClientRawResponse(deserialized, response) - return client_raw_response - - return deserialized diff --git a/src/command_modules/azure-cli-acr/azure/cli/command_modules/acr/repository.py b/src/command_modules/azure-cli-acr/azure/cli/command_modules/acr/repository.py index 0fb39b9b228..4c22df29e2f 100644 --- a/src/command_modules/azure-cli-acr/azure/cli/command_modules/acr/repository.py +++ b/src/command_modules/azure-cli-acr/azure/cli/command_modules/acr/repository.py @@ -8,8 +8,7 @@ from azure.cli.core.commands import cli_command from ._utils import ( - get_registry_by_name, - registry_not_found + get_registry_by_name ) from .credential import acr_credential_show @@ -44,11 +43,8 @@ def _obtain_data_from_registry(login_server, path, resultIndex, username, passwo return resultList def _validate_user_credentials(registry_name, path, resultIndex, username=None, password=None): - registry = get_registry_by_name(registry_name) - if registry is None: - registry_not_found(registry_name) - - login_server = registry.properties.login_server + registry, _ = get_registry_by_name(registry_name) + login_server = registry.login_server #pylint: disable=no-member if username: if not password: @@ -58,8 +54,8 @@ def _validate_user_credentials(registry_name, path, resultIndex, username=None, try: cred = acr_credential_show(registry_name) - username = cred.user_name - password = cred.pass_word + username = cred.username + password = cred.password return _obtain_data_from_registry(login_server, path, resultIndex, username, password) except: #pylint: disable=bare-except pass diff --git a/src/command_modules/azure-cli-acr/azure/cli/command_modules/acr/storage.py b/src/command_modules/azure-cli-acr/azure/cli/command_modules/acr/storage.py deleted file mode 100644 index 746ace9f3c4..00000000000 --- a/src/command_modules/azure-cli-acr/azure/cli/command_modules/acr/storage.py +++ /dev/null @@ -1,58 +0,0 @@ -#--------------------------------------------------------------------------------------------- -# Copyright (c) Microsoft Corporation. All rights reserved. -# Licensed under the MIT License. See License.txt in the project root for license information. -#--------------------------------------------------------------------------------------------- - -from azure.cli.core.commands import ( - cli_command, - LongRunningOperation -) - -from ._factory import get_acr_service_client -from ._arm_utils import ( - arm_deploy_template, - add_tag_storage_account, - delete_tag_storage_account -) -from ._utils import ( - get_registry_by_name, - get_resource_group_name_by_resource_id, - registry_not_found -) -from ._format import output_format - -def acr_storage_update(registry_name, - storage_account_name, - resource_group_name=None): - '''Update storage account for a container registry. - :param str registry_name: The name of container registry - :param str storage_account_name: The name of storage account - :param str resource_group_name: The name of resource group - ''' - registry = get_registry_by_name(registry_name) - if registry is None: - registry_not_found(registry_name) - - if resource_group_name is None: - resource_group_name = get_resource_group_name_by_resource_id(registry.id) - - old_storage_account_name = registry.properties.storage_account.name - - # Update a container registry - LongRunningOperation()( - arm_deploy_template(resource_group_name, - registry_name, - registry.location, - storage_account_name, - registry.properties.admin_user_enabled) - ) - - client = get_acr_service_client().registries - registry = client.get_properties(resource_group_name, registry_name) - - delete_tag_storage_account(old_storage_account_name, registry_name) - add_tag_storage_account(storage_account_name, registry_name) - - return registry - -cli_command('acr storage update', acr_storage_update, table_transformer=output_format) diff --git a/src/command_modules/azure-cli-acr/azure/cli/command_modules/acr/template.existing.json b/src/command_modules/azure-cli-acr/azure/cli/command_modules/acr/template.existing.json deleted file mode 100644 index 98bd399f1ff..00000000000 --- a/src/command_modules/azure-cli-acr/azure/cli/command_modules/acr/template.existing.json +++ /dev/null @@ -1,64 +0,0 @@ -{ - "$schema": "http://schema.management.azure.com/schemas/2014-04-01-preview/deploymentTemplate.json#", - "contentVersion": "1.0.0.0", - "parameters": { - "registryName": { - "type": "string", - "metadata": { - "description": "Name of the registry service" - } - }, - "registryLocation": { - "type": "string", - "metadata": { - "description": "Location of the registry service" - } - }, - "registryApiVersion": { - "type": "string", - "defaultValue": "2016-06-27-preview", - "metadata": { - "description": "Api version of the registry service" - } - }, - "storageAccountName": { - "type": "string", - "metadata": { - "description": "Name of the storage account" - } - }, - "storageAccountResourceGroup": { - "type": "string", - "metadata": { - "description": "Resource group of the storage account" - } - }, - "adminUserEnabled": { - "type": "bool", - "defaultValue": false, - "metadata": { - "description": "Enable admin user" - } - } - }, - "resources": [ - { - "name": "[parameters('registryName')]", - "type": "Microsoft.ContainerRegistry/registries", - "location": "[parameters('registryLocation')]", - "apiVersion": "[parameters('registryApiVersion')]", - "tags": { - "storageaccount": "[parameters('storageAccountName')]" - }, - "properties": { - "tenantId": "[subscription().tenantId]", - "adminUserEnabled": "[parameters('adminUserEnabled')]", - "storageAccount": { - "name": "[parameters('storageAccountName')]", - "accessKey": "[listKeys(resourceId(parameters('storageAccountResourceGroup'), 'Microsoft.Storage/storageAccounts', parameters('storageAccountName')), '2016-01-01').keys[0].value]", - "endPointUrl": "[reference(resourceId(parameters('storageAccountResourceGroup'), 'Microsoft.Storage/storageAccounts', parameters('storageAccountName')), '2016-01-01').primaryEndpoints.blob]" - } - } - } - ] -} \ No newline at end of file diff --git a/src/command_modules/azure-cli-acr/azure/cli/command_modules/acr/template.new.json b/src/command_modules/azure-cli-acr/azure/cli/command_modules/acr/template.json similarity index 87% rename from src/command_modules/azure-cli-acr/azure/cli/command_modules/acr/template.new.json rename to src/command_modules/azure-cli-acr/azure/cli/command_modules/acr/template.json index a5fc188933c..1d4115e69d0 100644 --- a/src/command_modules/azure-cli-acr/azure/cli/command_modules/acr/template.new.json +++ b/src/command_modules/azure-cli-acr/azure/cli/command_modules/acr/template.json @@ -57,19 +57,14 @@ "type": "Microsoft.ContainerRegistry/registries", "location": "[parameters('registryLocation')]", "apiVersion": "[parameters('registryApiVersion')]", - "tags": { - "storageaccount": "[parameters('storageAccountName')]" - }, "dependsOn": [ "[resourceId('Microsoft.Storage/storageAccounts', parameters('storageAccountName'))]" ], "properties": { - "tenantId": "[subscription().tenantId]", "adminUserEnabled": "[parameters('adminUserEnabled')]", "storageAccount": { "name": "[parameters('storageAccountName')]", - "accessKey": "[listKeys(resourceId('Microsoft.Storage/storageAccounts', parameters('storageAccountName')), '2016-01-01').keys[0].value]", - "endPointUrl": "[reference(resourceId('Microsoft.Storage/storageAccounts', parameters('storageAccountName')), '2016-01-01').primaryEndpoints.blob]" + "accessKey": "[listKeys(resourceId('Microsoft.Storage/storageAccounts', parameters('storageAccountName')), '2016-01-01').keys[0].value]" } } } diff --git a/src/command_modules/azure-cli-acr/setup.py b/src/command_modules/azure-cli-acr/setup.py index 294d607005d..07dc93f3253 100644 --- a/src/command_modules/azure-cli-acr/setup.py +++ b/src/command_modules/azure-cli-acr/setup.py @@ -54,5 +54,5 @@ 'azure.cli.command_modules.acr.mgmt_acr.operations', ], install_requires=DEPENDENCIES, - package_data={'azure.cli.command_modules.acr': ['template.new.json', 'template.existing.json']}, + package_data={'azure.cli.command_modules.acr': ['template.json']}, )