Skip to content

Commit d2d8aa6

Browse files
yolocsderekbekoe
authored andcommitted
Add az container module (#4081)
* add az container module * added helps to readme * address_feedback * applied updated ContainerInstance python SDK * address Pylint failures * address more pylint failures * use future print fucntion py2 superfluous-parens warning
1 parent 76d5614 commit d2d8aa6

File tree

15 files changed

+1131
-0
lines changed

15 files changed

+1131
-0
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
.. :changelog:
2+
3+
Release History
4+
===============
5+
6+
unreleased
7+
+++++++++++++++++++++
8+
9+
* Preview release.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
include *.rst
Lines changed: 179 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,179 @@
1+
Microsoft Azure CLI 'container' Command Module
2+
==============================================
3+
4+
Commands to manage Azure container instances
5+
+++++++++++++++++++++++++++++++++++++++++++++
6+
::
7+
8+
Group
9+
az container: Manage Azure Container Instances.
10+
11+
Commands:
12+
create: Create a container group.
13+
delete: Delete a container group.
14+
list : List container groups.
15+
logs : Tail the log of a container group.
16+
show : Show the details of a container group.
17+
18+
Commands to create an Azure container group
19+
+++++++++++++++++++++++++++++++++++++++++++++
20+
::
21+
22+
Command
23+
az container create: Create a container group.
24+
25+
Arguments
26+
--image [Required]: The container image name.
27+
--name -n [Required]: The name of the container group.
28+
--resource-group -g [Required]: Name of resource group. You can configure the default group
29+
using `az configure --defaults group=<name>`.
30+
--command-line : The command line to run when the container is started, e.g.
31+
'/bin/bash -c myscript.sh'.
32+
--cpu : The required number of CPU cores of the containers. Default: 1.
33+
--environment-variables -e : A list of environment variable for the container. Space
34+
separated values in 'key=value' format.
35+
--ip-address : The IP address type of the container group. Allowed values:
36+
Public.
37+
--location -l : Location. You can configure the default location using `az
38+
configure --defaults location=<location>`.
39+
--memory : The required memory of the containers in GB. Default: 1.5.
40+
--os-type : The OS type of the containers. Allowed values: Linux, Windows.
41+
Default: Linux.
42+
--port : Default: 80.
43+
44+
Image Registry Arguments
45+
--registry-login-server : The container image registry login server.
46+
--registry-password : The password to log in container image registry server.
47+
--registry-username : The username to log in container image registry server.
48+
49+
Global Arguments
50+
--debug : Increase logging verbosity to show all debug logs.
51+
--help -h : Show this help message and exit.
52+
--output -o : Output format. Allowed values: json, jsonc, table, tsv.
53+
Default: json.
54+
--query : JMESPath query string. See http://jmespath.org/ for more
55+
information and examples.
56+
--verbose : Increase logging verbosity. Use --debug for full debug logs.
57+
58+
Examples
59+
Create a container group and specify resources required.
60+
az container create -g MyResourceGroup --name MyAlpine --image alpine:latest --cpu 1
61+
--memory 1
62+
63+
Create a container group with OS type.
64+
az container create -g MyResourceGroup --name MyWinApp --image winappimage:latest --os-type
65+
Windows
66+
67+
Create a container group with public IP address.
68+
az container create -g MyResourceGroup --name MyAlpine --image alpine:latest --ip-address
69+
public
70+
71+
Create a container group with starting command line.
72+
az container create -g MyResourceGroup --name MyAlpine --image alpine:latest --command-line
73+
"/bin/sh -c '/path to/myscript.sh'"
74+
75+
Create a container group with envrionment variables.
76+
az contanier create -g MyResourceGroup --name MyAlpine --image alpine:latest -e key1=value1
77+
key2=value2
78+
79+
Create a container group using container image from Azure Container Registry.
80+
az container create -g MyResourceGroup --name MyAlpine --image
81+
myAcrRegistry.azurecr.io/alpine:latest --registry-password password
82+
83+
Create a container group using container image from other private container image registry.
84+
az container create -g MyResourceGroup --name MyApp --image myimage:latest --cpu 1 --memory
85+
1.5 --registry-login-server myregistry.com --registry-username username --registry-password
86+
password
87+
88+
Commands to get an Azure container group
89+
+++++++++++++++++++++++++++++++++++++++++++++
90+
::
91+
92+
Command
93+
az container show: Show the details of a container group.
94+
95+
Arguments
96+
97+
Resource Id Arguments
98+
--ids : One or more resource IDs (space delimited). If provided, no other 'Resource
99+
Id' arguments should be specified.
100+
--name -n : The name of the container group.
101+
--resource-group -g: Name of resource group. You can configure the default group using `az
102+
configure --defaults group=<name>`.
103+
104+
Global Arguments
105+
--debug : Increase logging verbosity to show all debug logs.
106+
--help -h : Show this help message and exit.
107+
--output -o : Output format. Allowed values: json, jsonc, table, tsv. Default: json.
108+
--query : JMESPath query string. See http://jmespath.org/ for more information and
109+
examples.
110+
--verbose : Increase logging verbosity. Use --debug for full debug logs.
111+
112+
Commands to tail the logs of a Azure container group
113+
+++++++++++++++++++++++++++++++++++++++++++++
114+
::
115+
116+
Command
117+
az container logs: Tail the log of a container group.
118+
119+
Arguments
120+
--container-name : The container name to tail the logs.
121+
122+
Resource Id Arguments
123+
--ids : One or more resource IDs (space delimited). If provided, no other 'Resource
124+
Id' arguments should be specified.
125+
--name -n : The name of the container group.
126+
--resource-group -g: Name of resource group. You can configure the default group using `az
127+
configure --defaults group=<name>`.
128+
129+
Global Arguments
130+
--debug : Increase logging verbosity to show all debug logs.
131+
--help -h : Show this help message and exit.
132+
--output -o : Output format. Allowed values: json, jsonc, table, tsv. Default: json.
133+
--query : JMESPath query string. See http://jmespath.org/ for more information and
134+
examples.
135+
--verbose : Increase logging verbosity. Use --debug for full debug logs.
136+
137+
Commands to delete an Azure container group
138+
+++++++++++++++++++++++++++++++++++++++++++++
139+
::
140+
141+
Command
142+
az container delete: Delete a container group.
143+
144+
Arguments
145+
--yes -y : Do not prompt for confirmation.
146+
147+
Resource Id Arguments
148+
--ids : One or more resource IDs (space delimited). If provided, no other 'Resource
149+
Id' arguments should be specified.
150+
--name -n : The name of the container group.
151+
--resource-group -g: Name of resource group. You can configure the default group using `az
152+
configure --defaults group=<name>`.
153+
154+
Global Arguments
155+
--debug : Increase logging verbosity to show all debug logs.
156+
--help -h : Show this help message and exit.
157+
--output -o : Output format. Allowed values: json, jsonc, table, tsv. Default: json.
158+
--query : JMESPath query string. See http://jmespath.org/ for more information and
159+
examples.
160+
--verbose : Increase logging verbosity. Use --debug for full debug logs.
161+
162+
Commands to list Azure container groups by resource group
163+
+++++++++++++++++++++++++++++++++++++++++++++
164+
::
165+
166+
Command
167+
az container list: List container groups.
168+
169+
Arguments
170+
--resource-group -g: Name of resource group. You can configure the default group using `az
171+
configure --defaults group=<name>`.
172+
173+
Global Arguments
174+
--debug : Increase logging verbosity to show all debug logs.
175+
--help -h : Show this help message and exit.
176+
--output -o : Output format. Allowed values: json, jsonc, table, tsv. Default: json.
177+
--query : JMESPath query string. See http://jmespath.org/ for more information and
178+
examples.
179+
--verbose : Increase logging verbosity. Use --debug for full debug logs.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# --------------------------------------------------------------------------------------------
2+
# Copyright (c) Microsoft Corporation. All rights reserved.
3+
# Licensed under the MIT License. See License.txt in the project root for license information.
4+
# --------------------------------------------------------------------------------------------
5+
6+
import pkg_resources
7+
pkg_resources.declare_namespace(__name__)
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# --------------------------------------------------------------------------------------------
2+
# Copyright (c) Microsoft Corporation. All rights reserved.
3+
# Licensed under the MIT License. See License.txt in the project root for license information.
4+
# --------------------------------------------------------------------------------------------
5+
6+
import pkg_resources
7+
pkg_resources.declare_namespace(__name__)
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# --------------------------------------------------------------------------------------------
2+
# Copyright (c) Microsoft Corporation. All rights reserved.
3+
# Licensed under the MIT License. See License.txt in the project root for license information.
4+
# --------------------------------------------------------------------------------------------
5+
6+
import pkg_resources
7+
pkg_resources.declare_namespace(__name__)
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# --------------------------------------------------------------------------------------------
2+
# Copyright (c) Microsoft Corporation. All rights reserved.
3+
# Licensed under the MIT License. See License.txt in the project root for license information.
4+
# --------------------------------------------------------------------------------------------
5+
6+
import azure.cli.command_modules.container._help # pylint: disable=unused-import
7+
8+
9+
def load_params(_):
10+
import azure.cli.command_modules.container._params # pylint: disable=redefined-outer-name, unused-variable
11+
12+
13+
def load_commands():
14+
import azure.cli.command_modules.container.commands # pylint: disable=redefined-outer-name, unused-variable
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# --------------------------------------------------------------------------------------------
2+
# Copyright (c) Microsoft Corporation. All rights reserved.
3+
# Licensed under the MIT License. See License.txt in the project root for license information.
4+
# --------------------------------------------------------------------------------------------
5+
6+
7+
def _container_instance_client_factory(_):
8+
from azure.mgmt.containerinstance import ContainerInstanceManagementClient
9+
from azure.cli.core.commands.client_factory import get_mgmt_service_client
10+
return get_mgmt_service_client(ContainerInstanceManagementClient)
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# --------------------------------------------------------------------------------------------
2+
# Copyright (c) Microsoft Corporation. All rights reserved.
3+
# Licensed under the MIT License. See License.txt in the project root for license information.
4+
# --------------------------------------------------------------------------------------------
5+
6+
from azure.cli.core.help_files import helps
7+
8+
helps['container'] = """
9+
type: group
10+
short-summary: (Preview) Manage Azure Container Instances.
11+
"""
12+
13+
helps['container create'] = """
14+
type: command
15+
short-summary: Create a container group.
16+
examples:
17+
- name: Create a container group and specify resources required.
18+
text: az container create -g MyResourceGroup --name MyAlpine --image alpine:latest --cpu 1 --memory 1
19+
- name: Create a container group with OS type.
20+
text: az container create -g MyResourceGroup --name MyWinApp --image winappimage:latest --os-type Windows
21+
- name: Create a container group with public IP address.
22+
text: az container create -g MyResourceGroup --name MyAlpine --image alpine:latest --ip-address public
23+
- name: Create a container group with starting command line.
24+
text: az container create -g MyResourceGroup --name MyAlpine --image alpine:latest --command-line "/bin/sh -c '/path to/myscript.sh'"
25+
- name: Create a container group with envrionment variables.
26+
text: az contanier create -g MyResourceGroup --name MyAlpine --image alpine:latest -e key1=value1 key2=value2
27+
- name: Create a container group using container image from Azure Container Registry.
28+
text: az container create -g MyResourceGroup --name MyAlpine --image myAcrRegistry.azurecr.io/alpine:latest --registry-password password
29+
- name: Create a container group using container image from other private container image registry.
30+
text: az container create -g MyResourceGroup --name MyApp --image myimage:latest --cpu 1 --memory 1.5 --registry-server myregistry.com --registry-username username --registry-password password
31+
"""
32+
33+
helps['container delete'] = """
34+
type: command
35+
short-summary: Delete a container group.
36+
"""
37+
38+
helps['container list'] = """
39+
type: command
40+
short-summary: List container groups.
41+
"""
42+
43+
helps['container show'] = """
44+
type: command
45+
short-summary: Show the details of a container group.
46+
"""
47+
48+
helps['container logs'] = """
49+
type: command
50+
short-summary: Tail the log of a container group.
51+
"""
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# --------------------------------------------------------------------------------------------
2+
# Copyright (c) Microsoft Corporation. All rights reserved.
3+
# Licensed under the MIT License. See License.txt in the project root for license information.
4+
# --------------------------------------------------------------------------------------------
5+
6+
from azure.cli.core.commands import register_cli_argument
7+
from azure.cli.core.commands.parameters import (enum_choice_list,
8+
location_type,
9+
resource_group_name_type)
10+
from azure.cli.core.commands.validators import get_default_location_from_resource_group
11+
from azure.cli.core.util import CLIError
12+
import azure.cli.core.commands.arm # pylint: disable=unused-import
13+
14+
# pylint: disable=line-too-long
15+
16+
IP_ADDRESS_TYPES = ['Public']
17+
OS_TYPES = ['Windows', 'Linux']
18+
19+
20+
def environment_variables_format(value):
21+
"""Space separated values in 'key=value' format."""
22+
try:
23+
env_name, env_value = value.split('=')
24+
except ValueError:
25+
message = ("Incorrectly formatted enviroment settings. "
26+
"Argmuent values should be in the format a=b c=d")
27+
raise CLIError(message)
28+
return {'name': env_name, 'value': env_value}
29+
30+
31+
register_cli_argument('container', 'resource_group_name', resource_group_name_type)
32+
register_cli_argument('container', 'name', options_list=('--name', '-n'), help="The name of the container group", id_part='name')
33+
register_cli_argument('container', 'location', location_type)
34+
35+
register_cli_argument('container create', 'location', location_type, validator=get_default_location_from_resource_group)
36+
register_cli_argument('container create', 'image', help='The container image name')
37+
register_cli_argument('container create', 'cpu', type=int, help='The required number of CPU cores of the containers')
38+
register_cli_argument('container create', 'memory', type=float, help='The required memory of the containers in GB')
39+
register_cli_argument('container create', 'os_type', help='The OS type of the containers', **enum_choice_list(OS_TYPES))
40+
register_cli_argument('container create', 'ip_address', help='The IP address type of the container group', **enum_choice_list(IP_ADDRESS_TYPES))
41+
register_cli_argument('container create', 'command_line', help='The command line to run when the container is started, e.g. \'/bin/bash -c myscript.sh\'')
42+
register_cli_argument('container create', 'environment_variables', nargs='+', options_list=('--environment-variables', '-e'), type=environment_variables_format, help='A list of environment variable for the container. Space separated values in \'key=value\' format.')
43+
register_cli_argument('container create', 'registry_login_server', arg_group='Image Registry', help='The container image registry login server')
44+
register_cli_argument('container create', 'registry_username', arg_group='Image Registry', help='The username to log in container image registry server')
45+
register_cli_argument('container create', 'registry_password', arg_group='Image Registry', help='The password to log in container image registry server')
46+
47+
register_cli_argument('container logs', 'container_name', help='The container name to tail the logs')

0 commit comments

Comments
 (0)