Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
167 changes: 47 additions & 120 deletions src/command_modules/azure-cli-acr/README.rst
Original file line number Diff line number Diff line change
@@ -1,48 +1,22 @@
Microsoft Azure CLI 'acr' Command Module
==================================

This package has [not] been tested [much] with Python 2.7, 3.4 and 3.5.

Commands to manage Azure container registries
-------------
::

Group
az acr: Commands to manage Azure container registries.

Commands:
catalog: The catalog of repositories in the specified registry.
create : Create a container registry.
delete : Delete a container registry.
list : List container registries.
show : Get a container registry.
tags : The list of tags for a given repository in the specified registry.
update : Update a container registry.

List container registries
-------------
::
Subgroups:
repository

Command
az acr list: List container registries.

Arguments
--resource-group -g: Name of resource group.

Global Arguments
--debug : Increase logging verbosity to show all debug logs.
--help -h : Show this help message and exit.
--output -o : Output format. Allowed values: json, jsonc, list, table, tsv. Default:
json.
--query : JMESPath query string. See http://jmespath.org/ for more information and
examples.
--verbose : Increase logging verbosity. Use --debug for full debug logs.

Examples
List container registries and show result in a table
az acr list -o table
List container registries in a resource group and show result in a table
az acr list -g <resource-group> -o table
Commands:
create : Create a container registry.
delete : Delete a container registry.
list : List container registries.
show : Get a container registry.
update : Update a container registry.

Create a container registry
-------------
Expand All @@ -53,26 +27,17 @@ Create a container registry

Arguments
--location -l [Required]: Location.
--name -n [Required]: The primary resource name.
--name -n [Required]: Name of container registry.
--resource-group -g [Required]: Name of resource group.
--storage-account-key -k : Key of storage account.
--storage-account-name -s : Name of storage account.

Global Arguments
--debug : Increase logging verbosity to show all debug logs.
--help -h : Show this help message and exit.
--output -o : Output format. Allowed values: json, jsonc, list, table, tsv.
Default: json.
--query : JMESPath query string. See http://jmespath.org/ for more
information and examples.
--verbose : Increase logging verbosity. Use --debug for full debug logs.

Examples
Create a container registry with managed storage account
az acr create -n <registry-name> -g <resource-group> -l <location>
Create a container registry with new/existing storage account in the current subscription
az acr create -n <registry-name> -g <resource-group> -l <location> -s <storage-account-name>
Create a container registry with your own storage account
Create a container registry with your own storage account in any subscription
az acr create -n <registry-name> -g <resource-group> -l <location> -s <storage-account-name>
-k <storage-account-key>

Expand All @@ -84,20 +49,23 @@ Delete a container registry
az acr delete: Delete a container registry.

Arguments
--name -n [Required]: The primary resource name.
--name -n [Required]: Name of container registry.

Global Arguments
--debug : Increase logging verbosity to show all debug logs.
--help -h : Show this help message and exit.
--output -o : Output format. Allowed values: json, jsonc, list, table, tsv. Default:
json.
--query : JMESPath query string. See http://jmespath.org/ for more information and
examples.
--verbose : Increase logging verbosity. Use --debug for full debug logs.
List container registries
-------------
::

Command
az acr list: List container registries.

Arguments
--resource-group -g: Name of resource group.

Examples
Delete a container registry
az acr delete -n <registry-name>
List container registries and show result in a table
az acr list -o table
List container registries in a resource group and show result in a table
az acr list -g <resource-group> -o table

Get a container registry
-------------
Expand All @@ -107,20 +75,7 @@ Get a container registry
az acr show: Get a container registry.

Arguments
--name -n [Required]: The primary resource name.

Global Arguments
--debug : Increase logging verbosity to show all debug logs.
--help -h : Show this help message and exit.
--output -o : Output format. Allowed values: json, jsonc, list, table, tsv. Default:
json.
--query : JMESPath query string. See http://jmespath.org/ for more information and
examples.
--verbose : Increase logging verbosity. Use --debug for full debug logs.

Examples
Get a container registry and show result in a table
az acr show -n <registry-name> -o table
--name -n [Required]: Name of container registry.

Update a container registry
-------------
Expand All @@ -130,76 +85,48 @@ Update a container registry
az acr update: Update a container registry.

Arguments
--name -n [Required]: The primary resource name.
--name -n [Required]: Name of container registry.
--tags : Multiple semicolon separated tags in 'key[=value]' format. Use "" to
clear existing tags.

Global Arguments
--debug : Increase logging verbosity to show all debug logs.
--help -h : Show this help message and exit.
--output -o : Output format. Allowed values: json, jsonc, list, table, tsv. Default:
json.
--query : JMESPath query string. See http://jmespath.org/ for more information and
examples.
--verbose : Increase logging verbosity. Use --debug for full debug logs.

Examples
Update tags of a container registry and show result in a table
az acr update -n <registry-name> --tags key1=value1;key2=value2 -o table

The catalog of repositories in the specified registry
List repositories in a given container registry
-------------
::

Command
az acr catalog: The catalog of repositories in the specified registry.
az acr repository list: List repositories in a given container registry.

Arguments
--name -n [Required]: The primary resource name.
--password : The password used to log into the container registry.
--username : The username used to log into the container registry.

Global Arguments
--debug : Increase logging verbosity to show all debug logs.
--help -h : Show this help message and exit.
--output -o : Output format. Allowed values: json, jsonc, list, table, tsv. Default:
json.
--query : JMESPath query string. See http://jmespath.org/ for more information and
examples.
--verbose : Increase logging verbosity. Use --debug for full debug logs.
--login-server [Required]: The URL of a container registry login server.
--password : The password used to log into the container registry.
--username : The username used to log into the container registry.

Examples
The catalog of repositories in a registry under the current subscription
az acr catalog -n <registry-name>
The catalog of repositories in any registry with credentials
az acr catalog -n <registry-name> --username <username> --password <password>
List repositories in a given container registry under the current subscription
az acr repository list --login-server <login-server>
List repositories in a given container registry with credentials
az acr repository list --login-server <login-server> --username <username> --password
<password>

The list of tags for a given repository in the specified registry
Show tags of a given repository in a given container registry
-------------
::

Command
az acr tags: The list of tags for a given repository in the specified registry.
az acr repository show-tags: Show tags of a given repository in a given container registry.

Arguments
--name -n [Required]: The primary resource name.
--repository [Required]: The repository to obtain tags from.
--password : The password used to log into the container registry.
--username : The username used to log into the container registry.

Global Arguments
--debug : Increase logging verbosity to show all debug logs.
--help -h : Show this help message and exit.
--output -o : Output format. Allowed values: json, jsonc, list, table, tsv.
Default: json.
--query : JMESPath query string. See http://jmespath.org/ for more information
and examples.
--verbose : Increase logging verbosity. Use --debug for full debug logs.
--login-server [Required]: The URL of a container registry login server.
--repository [Required]: The repository to obtain tags from.
--password : The password used to log into the container registry.
--username : The username used to log into the container registry.

Examples
The list of tags for a given repository in a registry under the current subscription
az acr tags -n <registry-name> --repository <repository>
The list of tags for a given repository in any registry with credentials
az acr tags -n <registry-name> --repository <repository> --username <username> --password
<password>

Show tags of a given repository in a given container registry under the current subscription
az acr repository show-tags --login-server <login-server> --repository <repository>
Show tags of a given repository in a given container registry with credentials
az acr repository show-tags --login-server <login-server> --repository <repository>
--username <username> --password <password>
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
# Licensed under the MIT License. See License.txt in the project root for license information.
#---------------------------------------------------------------------------------------------

from azure.cli.command_modules.acr.containerregistry.models import RegistryParameters
from azure.cli.command_modules.acr.mgmt_acr.models import RegistryParameters

from ._constants import RESOURCE_TYPE
from ._factory import get_arm_service_client

from azure.cli.command_modules.acr.containerregistry import VERSION
from azure.cli.command_modules.acr.mgmt_acr import VERSION

def arm_get_registries_in_subscription():
'''Returns the list of container registries in the current subscription.
Expand All @@ -19,13 +19,13 @@ def arm_get_registries_in_subscription():

return [RegistryParameters(item.id, item.name, item.location, item.tags) for item in result]

def arm_get_registries_in_resource_group(resource_group):
def arm_get_registries_in_resource_group(resource_group_name):
'''Returns the list of container registries in the resource group.
:param str resource_group: The name of resource group
:param str resource_group_name: The name of resource group
'''
client = get_arm_service_client()
filter_str = "resourceType eq '{}'".format(RESOURCE_TYPE)
result = list(client.resource_groups.list_resources(resource_group, filter=filter_str))
result = list(client.resource_groups.list_resources(resource_group_name, filter=filter_str))

return [RegistryParameters(item.id, item.name, item.location, item.tags) for item in result]

Expand All @@ -43,9 +43,9 @@ def arm_get_registry_by_name(registry_name):
else:
raise ValueError('More than one container registries are found with name: ' + registry_name)

def arm_deploy_template(resource_group, registry_name, location, storage_account_name):
def arm_deploy_template(resource_group_name, registry_name, location, storage_account_name):
'''Deploys ARM template to create a container registry.
:param str resource_group: The name of resource group
: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
Expand All @@ -62,7 +62,7 @@ def arm_deploy_template(resource_group, registry_name, location, storage_account
client = get_arm_service_client()
deployment_name = 'Deployment.' + registry_name

return client.deployments.create_or_update(resource_group, deployment_name, properties)
return client.deployments.create_or_update(resource_group_name, deployment_name, properties)

def _parameters(registry_name, location, storage_account_name):
'''Returns a dict of deployment parameters.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#---------------------------------------------------------------------------------------------

from azure.cli.core._profile import Profile
from azure.cli.core._config import az_config
from azure.mgmt.resource.resources import ResourceManagementClient
from azure.storage._constants import SERVICE_HOST_BASE

Expand All @@ -12,12 +13,15 @@
get_mgmt_service_client
)

from azure.cli.command_modules.acr.containerregistry import (
from azure.cli.command_modules.acr.mgmt_acr import (
ContainerRegistry,
ContainerRegistryConfiguration,
VERSION
)

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

def get_arm_service_client():
'''Returns the client for managing ARM resources.
'''
Expand All @@ -29,7 +33,13 @@ def get_registry_service_client():
profile = Profile()
credentials, subscription_id, _ = profile.get_login_credentials()

config = ContainerRegistryConfiguration(subscription_id, VERSION, credentials)
customized_api_version = az_config.get('acr', 'apiversion', None)
if customized_api_version:
logger.warning('Customized api-version is used: ' + customized_api_version)

api_version = customized_api_version or VERSION

config = ContainerRegistryConfiguration(subscription_id, api_version, credentials)
client = ContainerRegistry(config)

configure_common_settings(client)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from collections import OrderedDict

from ._constants import RESOURCE_TYPE
from ._utils import get_resource_group_by_registry
from ._utils import get_resource_group_name_by_registry

_basic_map = {
'name': 'NAME',
Expand Down Expand Up @@ -92,9 +92,9 @@ def _format_registry(item):
'''
basic_info = {_basic_map[key]: str(item[key]) for key in item if key in _basic_map}

resource_group = get_resource_group_by_registry(item)
if resource_group:
basic_info['RESOURCE GROUP'] = resource_group
resource_group_name = get_resource_group_name_by_registry(item)
if resource_group_name:
basic_info['RESOURCE GROUP'] = resource_group_name

properties_info = {}
storage_account_info = {}
Expand Down
Loading