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
205 changes: 205 additions & 0 deletions src/command_modules/azure-cli-acr/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,205 @@
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
-------------
::

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

Create a container registry
-------------
::

Command
az acr create: Create a container registry.

Arguments
--location -l [Required]: Location.
--name -n [Required]: The primary resource name.
--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
az acr create -n <registry-name> -g <resource-group> -l <location> -s <storage-account-name>
-k <storage-account-key>

Delete a container registry
-------------
::

Command
az acr delete: Delete 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
Delete a container registry
az acr delete -n <registry-name>

Get a container registry
-------------
::

Command
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

Update a container registry
-------------
::

Command
az acr update: Update a container registry.

Arguments
--name -n [Required]: The primary resource name.
--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
-------------
::

Command
az acr catalog: The catalog of repositories in the specified 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.

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>

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

Command
az acr tags: The list of tags for a given repository in the specified 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.

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>

6 changes: 6 additions & 0 deletions src/command_modules/azure-cli-acr/azure/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#---------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
#---------------------------------------------------------------------------------------------
import pkg_resources
pkg_resources.declare_namespace(__name__)
6 changes: 6 additions & 0 deletions src/command_modules/azure-cli-acr/azure/cli/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#---------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
#---------------------------------------------------------------------------------------------
import pkg_resources
pkg_resources.declare_namespace(__name__)
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#---------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
#---------------------------------------------------------------------------------------------
import pkg_resources
pkg_resources.declare_namespace(__name__)
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#---------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
#---------------------------------------------------------------------------------------------

# pylint: disable=unused-import

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.repository
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
#---------------------------------------------------------------------------------------------
# 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.command_modules.acr.containerregistry.models import RegistryParameters

from ._factory import get_arm_service_client

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

resource_type = 'Microsoft.ContainerRegistry/registries'

def arm_get_registries_in_subscription():
'''Returns the list of container registries in the current subscription.
'''
client = get_arm_service_client()
filter_str = "resourceType eq '{}'".format(resource_type)
result = list(client.resources.list(filter=filter_str))

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

def arm_get_registries_in_resource_group(resource_group):
'''Returns the list of container registries in the resource group.
:param str resource_group: 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))

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

def arm_get_registry_by_name(registry_name):
'''Returns the container registry that matches the registry name.
:param str registry_name: The name of container registry
'''
registries = arm_get_registries_in_subscription()
elements = [item for item in registries if item.name.lower() == registry_name.lower()]

if len(elements) == 0:
return None
elif len(elements) == 1:
return elements[0]
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, deployment_name, mode='incremental'):
'''Deploys ARM template to create a container registry using the storage account in the current subscription.
:param str resource_group: 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 str deployment_name: The name of deployment
:param str mode: The mode of deployment
'''
from azure.mgmt.resource.resources.models import DeploymentProperties
from azure.cli.core._util import get_file_json
import os

file_path = os.path.join(os.path.dirname(__file__), 'template.json')
template = get_file_json(file_path)
parameters = _parameters(registry_name, location, storage_account_name)
properties = DeploymentProperties(template=template, parameters=parameters, mode=mode)

client = get_arm_service_client()

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

def _parameters(registry_name, location, storage_account_name):
'''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
'''
parameters = {
'registryName': {'value': registry_name},
'registryLocation': {'value': location},
'registryApiVersion': {'value': VERSION},
'storageAccountName': {'value': storage_account_name},
'storageAccountLocation': {'value': 'westus'},
'storageAccountApiVersion': {'value': '2015-05-01-preview'}
}
return parameters
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#---------------------------------------------------------------------------------------------
# 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._profile import Profile
from azure.cli.core.commands.client_factory import (
configure_common_settings,
get_mgmt_service_client
)

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

from azure.mgmt.resource.resources import ResourceManagementClient
from azure.storage._constants import SERVICE_HOST_BASE

def get_arm_service_client():
'''Returns the client for managing ARM resources.
'''
return get_mgmt_service_client(ResourceManagementClient)

def get_registry_service_client():
'''Returns the client for managing container registries.
'''
profile = Profile()
credentials, subscription_id, _ = profile.get_login_credentials()

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

configure_common_settings(client)

return client.registries

def get_storage_end_point_suffix():
'''Returns storage account end point suffix
'''
return SERVICE_HOST_BASE
Loading