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
2 changes: 2 additions & 0 deletions src/azure/cli/_azure_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,15 @@ class ENDPOINT_URLS: #pylint: disable=too-few-public-methods,old-style-class,no-
ACTIVE_DIRECTORY_AUTHORITY = 'active_directory_authority'
ACTIVE_DIRECTORY_GRAPH_RESOURCE_ID = 'active_directory_graph_resource_id'
RESOURCE_MANAGER = 'resource_manager'
STORAGE_END_POINT_SUFFIX = 'storage end point suffix'

_environments = {
ENV_DEFAULT: {
ENDPOINT_URLS.MANAGEMENT: 'https://management.core.windows.net/',
ENDPOINT_URLS.ACTIVE_DIRECTORY_AUTHORITY : 'https://login.windows-ppe.net',
ENDPOINT_URLS.ACTIVE_DIRECTORY_GRAPH_RESOURCE_ID: 'https://graph.ppe.windows.net/',
ENDPOINT_URLS.RESOURCE_MANAGER: 'https://api-dogfood.resources.windows-int.net/',
ENDPOINT_URLS.STORAGE_END_POINT_SUFFIX: 'blob.core.test-cint.azure-test.net/'
}
}

Expand Down
7 changes: 6 additions & 1 deletion src/azure/cli/commands/client_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@
import azure.cli._logging as _logging
from azure.cli.application import APPLICATION

from azure.cli._azure_env import (
get_env,
ENDPOINT_URLS
)

logger = _logging.get_az_logger(__name__)

def get_mgmt_service_client(client_type):
Expand Down Expand Up @@ -40,7 +45,7 @@ def _get_mgmt_service_client(client_type, subscription_bound=True):
profile = Profile()
cred, subscription_id, _ = profile.get_login_credentials()
if subscription_bound:
client = client_type(cred, subscription_id)
client = client_type(cred, subscription_id, base_url=get_env()[ENDPOINT_URLS.RESOURCE_MANAGER])
else:
client = client_type(cred)

Expand Down
194 changes: 194 additions & 0 deletions src/command_modules/azure-cli-registry/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,194 @@
# Microsoft Azure CLI 'registry' Command Module

## Commands to manage Azure container registries
```
Group
az registry: 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 registry 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, tsv, list, table, jsonc. 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 registry list -o table
List container registries in a resource group and show result in a table
az registry list -g <resource-group> -o table
```

## Create a container registry
```
Command
az registry 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 : Key of storage account.
--storage-account-name : 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, tsv, list, table, jsonc.
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 registry create -n <registry-name> -g <resource-group> -l <location>
Create a container registry with dedicated storage account (new or existing)
az registry create -n <registry-name> -g <resource-group> -l <location> --storage-account-
name <storage-account-name>
Create a container registry with your own storage account
az registry create -n <registry-name> -g <resource-group> -l <location> --storage-account-
name <storage-account-name> --storage-account-key <storage-account-key>
```

## Delete a container registry
```
Command
az registry 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, tsv, list, table, jsonc. 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 registry delete -n <registry-name>
```

## Get a container registry
```
Command
az registry 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, tsv, list, table, jsonc. 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 registry show -n <registry-name> -o table
```

## Update a container registry
```
Command
az registry 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, tsv, list, table, jsonc. 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 registry update -n <registry-name> --tags key1=value1;key2=value2 -o table
```

## The catalog of repositories in the specified registry
```
Command
az registry 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, tsv, list, table, jsonc. 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 registry catalog -n <registry-name>
The catalog of repositories in any registry with credentials
az registry catalog -n <registry-name> --username <username> --password <password>
```

## The list of tags for a given repository in the specified registry
```
Command
az registry 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, tsv, list, table, jsonc.
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 registry tags -n <registry-name> --repository <repository>
The list of tags for a given repository in any registry with credentials
az registry tags -n <registry-name> --repository <repository> --username <username>
--password <password>
```
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@
import azure.cli.command_modules.registry._help
import azure.cli.command_modules.registry._params
import azure.cli.command_modules.registry.custom
import azure.cli.command_modules.registry.container
import azure.cli.command_modules.registry.repository
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@

from azure.cli.command_modules.registry.mgmt_cr.models import RegistryParameters

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

from azure.cli.command_modules.registry.mgmt_cr import VERSION

resource_type = 'Microsoft.Krater/registries'

Expand Down Expand Up @@ -42,37 +47,80 @@ 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,
deployment_name, mode='incremental'):
'''Deploys ARM template to create a container registry.
def arm_deploy_template_dedicated(resource_group, registry_name, location,
storage_account_name, deployment_name):
'''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
'''
parameters = _parameters_dedicated(registry_name, location, storage_account_name)
return _arm_deploy_template(resource_group, deployment_name, 'template.dedicated.json', parameters)

def arm_deploy_template_byos(resource_group, registry_name, location,
storage_account_name, storage_account_key, deployment_name):
'''Deploys ARM template to create a container registry using the user's own storage account.
: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 storage_account_key: The key of storage account
:param str deployment_name: The name of deployment
'''
parameters = _parameters_byos(registry_name, location, storage_account_name, storage_account_key)
return _arm_deploy_template(resource_group, deployment_name, 'template.byos.json', parameters)

def _arm_deploy_template(resource_group, deployment_name, template_path, parameters, mode='incremental'):
'''Deploys ARM template to create a container registry.
:param str resource_group: The name of resource group
:param str deployment_name: The name of deployment
:param str template_path: The template file path
:param dict parameters: The parameters for this deployment
:param str mode: The mode of deployment
'''
from azure.mgmt.resource.resources.models import DeploymentProperties
from azure.cli._util import get_file_json
import os

file_path = os.path.join(os.path.dirname(__file__), 'template.json')
file_path = os.path.join(os.path.dirname(__file__), template_path)
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):
def _parameters_dedicated(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

def _parameters_byos(registry_name, location, storage_account_name, storage_account_key):
'''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 str storage_account_key: The key of storage account
'''
parameters = {
'registryName': {'value': registry_name},
'location': {'value': location},
'storageAccountName': {'value': storage_account_name}
'registryLocation': {'value': location},
'registryApiVersion': {'value': VERSION},
'storageAccountName': {'value': storage_account_name},
'storageAccountKey': {'value': storage_account_key},
'storageEndPointUrl': {'value': get_storage_end_point_url(storage_account_name)}
}
return parameters
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@
#---------------------------------------------------------------------------------------------

from azure.cli._profile import Profile
from azure.cli.commands.client_factory import configure_common_settings
from azure.cli.commands.client_factory import (
configure_common_settings,
get_mgmt_service_client
)

from azure.cli._azure_env import (
get_env,
Expand All @@ -20,18 +23,11 @@
from azure.mgmt.resource.resources import ResourceManagementClient

def get_arm_service_client():
'''Returns the client for managing resource.
'''Returns the client for managing ARM resources.
'''
profile = Profile()
cred, subscription_id, _ = profile.get_login_credentials()
return get_mgmt_service_client(ResourceManagementClient)

client = ResourceManagementClient(cred, subscription_id, base_url=get_env()[ENDPOINT_URLS.RESOURCE_MANAGER])

configure_common_settings(client)

return client

def get_mgmt_service_client():
def get_registry_service_client():
'''Returns the client for managing container registries.
'''
profile = Profile()
Expand All @@ -43,3 +39,9 @@ def get_mgmt_service_client():
configure_common_settings(client)

return client.registries

def get_storage_end_point_url(storage_account_name):
'''Returns the end point url for the storage account name
:param str storage_account_name: The name of storage account
'''
return 'https://' + storage_account_name + '.' + get_env()[ENDPOINT_URLS.STORAGE_END_POINT_SUFFIX]
Loading