Skip to content

Commit 2768685

Browse files
authored
[Container] Update container cmdlets to use 2024-05-01-preview version API (#30260)
1 parent 259c264 commit 2768685

31 files changed

+7511
-6347
lines changed

linter_exclusions.yml

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1413,6 +1413,47 @@ consumption pricesheet show:
14131413
rule_exclusions:
14141414
- option_length_too_long
14151415
container create:
1416+
parameters:
1417+
azure_file_volume_account_key:
1418+
rule_exclusions:
1419+
- option_length_too_long
1420+
azure_file_volume_account_name:
1421+
rule_exclusions:
1422+
- option_length_too_long
1423+
azure_file_volume_mount_path:
1424+
rule_exclusions:
1425+
- option_length_too_long
1426+
azure_file_volume_share_name:
1427+
rule_exclusions:
1428+
- option_length_too_long
1429+
log_analytics_workspace:
1430+
rule_exclusions:
1431+
- option_length_too_long
1432+
log_analytics_workspace_key:
1433+
rule_exclusions:
1434+
- option_length_too_long
1435+
registry_login_server:
1436+
rule_exclusions:
1437+
- option_length_too_long
1438+
secure_environment_variables:
1439+
rule_exclusions:
1440+
- option_length_too_long
1441+
subnet_address_prefix:
1442+
rule_exclusions:
1443+
- option_length_too_long
1444+
container_group_profile_id:
1445+
rule_exclusions:
1446+
- option_length_too_long
1447+
fail_container_group_create_on_reuse_failure:
1448+
rule_exclusions:
1449+
- option_length_too_long
1450+
standby_pool_profile_id:
1451+
rule_exclusions:
1452+
- option_length_too_long
1453+
container_group_profile_revision:
1454+
rule_exclusions:
1455+
- option_length_too_long
1456+
container container-group-profile create:
14161457
parameters:
14171458
azure_file_volume_account_key:
14181459
rule_exclusions:

src/azure-cli/azure/cli/command_modules/container/_client_factory.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,3 +55,11 @@ def cf_msi(cli_ctx):
5555
from azure.mgmt.msi import ManagedServiceIdentityClient
5656
from azure.cli.core.commands.client_factory import get_mgmt_service_client
5757
return get_mgmt_service_client(cli_ctx, ManagedServiceIdentityClient)
58+
59+
60+
def cf_container_group_profiles(cli_ctx, *_):
61+
return _container_instance_client_factory(cli_ctx).container_group_profiles
62+
63+
64+
def cf_container_group_profile(cli_ctx, *_):
65+
return _container_instance_client_factory(cli_ctx).container_group_profile

src/azure-cli/azure/cli/command_modules/container/_format.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,3 +79,19 @@ def transform_container_group(result):
7979
def transform_container_group_list(result):
8080
"""Transform a container group list to table output. """
8181
return [transform_container_group(container_group) for container_group in result]
82+
83+
84+
def transform_container_group_profile(result):
85+
"""Transform a container group profile to table output. """
86+
return OrderedDict([('Name', result['name']),
87+
('ResourceGroup', result['resourceGroup']),
88+
('Image', _get_images(result)),
89+
('IP:ports', _format_ip_address(result)),
90+
('CPU/Memory', _format_cpu_memory(result)),
91+
('OsType', result.get('osType')),
92+
('Location', result['location'])])
93+
94+
95+
def transform_container_group_profile_list(result):
96+
"""Transform a container group profile list to table output. """
97+
return [transform_container_group_profile(container_group_profile) for container_group_profile in result]

src/azure-cli/azure/cli/command_modules/container/_help.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,3 +106,40 @@
106106
text: az container show --name MyContainerGroup --resource-group MyResourceGroup
107107
crafted: true
108108
"""
109+
110+
helps['container container-group-profile'] = """
111+
type: group
112+
short-summary: Manage Azure Container Instance Container Group Profile.
113+
"""
114+
115+
helps['container container-group-profile create'] = """
116+
type: command
117+
short-summary: Create a container group profile.
118+
examples:
119+
- name: Create a container group profile.
120+
text: az container container-group-profile create --resource-group MyResourceGroup --name myapp --image myimage:latest --cpu 1 --memory 1
121+
"""
122+
123+
helps['container container-group-profile show'] = """
124+
type: command
125+
short-summary: Get a container group profile.
126+
examples:
127+
- name: Get a container group profile.
128+
text: az container container-group-profile show --resource-group MyResourceGroup --name mycgprofile
129+
"""
130+
131+
helps['container container-group-profile show-revision'] = """
132+
type: command
133+
short-summary: Show a container group profile revision.
134+
examples:
135+
- name: Show a container group profile.
136+
text: az container container-group-profile show-revision --resource-group MyResourceGroup --name mycgprofile -r 1
137+
"""
138+
139+
helps['container container-group-profile delete'] = """
140+
type: command
141+
short-summary: Delete a container group profile.
142+
examples:
143+
- name: Delete a container group profile.
144+
text: az container container-group-profile delete --resource-group MyResourceGroup --name mycgprofile
145+
"""

src/azure-cli/azure/cli/command_modules/container/_params.py

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,17 @@ def _secure_environment_variables_type(value):
4141
raise CLIError(message)
4242

4343

44+
def _config_map_type(key_value_pair):
45+
"""Space-separated values in 'key=value' format."""
46+
try:
47+
key, value = key_value_pair.split('=', 1)
48+
return {'key': key, 'value': value}
49+
except ValueError:
50+
message = ("Incorrectly formatted config map key-value pairs. "
51+
"Argument values should be in the format a=b c=d")
52+
raise CLIError(message)
53+
54+
4455
secrets_type = CLIArgumentType(
4556
validator=validate_secrets,
4657
help="space-separated secrets in 'key=value' format.",
@@ -61,6 +72,7 @@ def load_arguments(self, _):
6172
c.argument('image', validator=validate_image, help='The container image name')
6273
c.argument('cpu', type=float, help='The required number of CPU cores of the containers, accurate to one decimal place')
6374
c.argument('memory', type=float, help='The required memory of the containers in GB, accurate to one decimal place')
75+
c.argument('config_map', nargs='+', type=_config_map_type, help='A list of config map key-value pairs for the container. Space-separated values in \'key=value\' format.')
6476
c.argument('os_type', arg_type=get_enum_type(OperatingSystemTypes), help='The OS type of the containers')
6577
c.argument('ip_address', arg_type=get_enum_type(IP_ADDRESS_TYPES), help='The IP address type of the container group')
6678
c.argument('ports', type=int, nargs='+', default=[80], help='A list of ports to open. Space-separated list of ports')
@@ -116,6 +128,14 @@ def load_arguments(self, _):
116128
c.argument('log_analytics_workspace', help='The Log Analytics workspace name or id. Use the current subscription or use --subscription flag to set the desired subscription.')
117129
c.argument('log_analytics_workspace_key', help='The Log Analytics workspace key.')
118130

131+
with self.argument_context('container create', arg_group='Container Group Profile Reference') as c:
132+
c.argument('container_group_profile_id', help='The reference container group profile ARM resource id.')
133+
c.argument('container_group_profile_revision', help='The reference container group profile revision.')
134+
135+
with self.argument_context('container create', arg_group='Standby Pool Profile') as c:
136+
c.argument('standby_pool_profile_id', help='The standby pool profile ARM resource id from which the container will be reused.')
137+
c.argument('fail_container_group_create_on_reuse_failure', help='The flag indicating whether to fail the container group creation if the standby pool reuse failed.', action='store_true')
138+
119139
with self.argument_context('container create', arg_group='Git Repo Volume') as c:
120140
c.argument('gitrepo_url', help='The URL of a git repository to be mounted as a volume')
121141
c.argument('gitrepo_dir', validator=validate_gitrepo_directory, help="The target directory path in the git repository. Must not contain '..'.")
@@ -137,3 +157,64 @@ def load_arguments(self, _):
137157

138158
with self.argument_context('container attach') as c:
139159
c.argument('container_name', help='The container to attach to. If omitted, the first container in the container group will be chosen')
160+
161+
with self.argument_context('container container-group-profile') as c:
162+
c.argument('resource_group_name', arg_type=resource_group_name_type)
163+
c.argument('container_group_profile_name', options_list=['--name', '-n'], help="The name of the container group profile.")
164+
c.argument('location', arg_type=get_location_type(self.cli_ctx))
165+
166+
with self.argument_context('container container-group-profile create') as c:
167+
c.argument('location', arg_type=get_location_type(self.cli_ctx), validator=get_default_location_from_resource_group)
168+
c.argument('image', validator=validate_image, help='The container image name')
169+
c.argument('cpu', type=float, help='The required number of CPU cores of the containers, accurate to one decimal place')
170+
c.argument('memory', type=float, help='The required memory of the containers in GB, accurate to one decimal place')
171+
c.argument('config_map', nargs='+', type=_config_map_type, help='A list of config map key-value pairs for the container. Space-separated values in \'key=value\' format.')
172+
c.argument('os_type', arg_type=get_enum_type(OperatingSystemTypes), help='The OS type of the containers')
173+
c.argument('ip_address', arg_type=get_enum_type(IP_ADDRESS_TYPES), help='The IP address type of the container group')
174+
c.argument('ports', type=int, nargs='+', default=[80], help='A list of ports to open. Space-separated list of ports')
175+
c.argument('protocol', arg_type=get_enum_type(ContainerNetworkProtocol), help='The network protocol to use')
176+
c.argument('restart_policy', arg_type=get_enum_type(ContainerGroupRestartPolicy), help='Restart policy for all containers within the container group')
177+
c.argument('command_line', help='The command line to run when the container is started, e.g. \'/bin/bash -c myscript.sh\'')
178+
c.argument('environment_variables', nargs='+', options_list=['--environment-variables', '-e'], type=_environment_variables_type, help='A list of environment variable for the container. Space-separated values in \'key=value\' format.')
179+
c.argument('secure_environment_variables', nargs='+', type=_secure_environment_variables_type, help='A list of secure environment variable for the container. Space-separated values in \'key=value\' format.')
180+
c.argument('secrets', secrets_type)
181+
c.argument('secrets_mount_path', validator=validate_volume_mount_path, help="The path within the container where the secrets volume should be mounted. Must not contain colon ':'.")
182+
c.argument('file', options_list=['--file', '-f'], help="The path to the input file.")
183+
c.argument('zone', help="The zone to place the container group.")
184+
c.argument('priority', help='The priority of the container group')
185+
c.argument('sku', help="The SKU of the container group")
186+
187+
with self.argument_context('container container-group-profile create', arg_group='Confidential Container Group') as c:
188+
c.argument('cce_policy', help="The CCE policy for the confidential container group")
189+
c.argument('allow_privilege_escalation', options_list=['--allow-escalation'], help="Allow whether a process can gain more privileges than its parent process.", action='store_true')
190+
c.argument('privileged', help='The flag to determine if the container permissions is elevated to Privileged', action='store_true')
191+
c.argument('run_as_user', help="Set the User GID for the container")
192+
c.argument('run_as_group', help="Set the User UID for the container")
193+
c.argument('seccomp_profile', help="A base64 encoded string containing the contents of the JSON in the seccomp profile")
194+
c.argument('add_capabilities', nargs='+', help="A List of security context capabilities to be added")
195+
c.argument('drop_capabilities', nargs='+', help="A List of security context capabilities to be dropped")
196+
197+
with self.argument_context('container container-group-profile create', arg_group='Image Registry') as c:
198+
c.argument('registry_login_server', help='The container image registry login server')
199+
c.argument('registry_username', help='The username to log in container image registry server')
200+
c.argument('registry_password', help='The password to log in container image registry server')
201+
c.argument('acr_identity', help='The identity with access to the container registry')
202+
203+
with self.argument_context('container container-group-profile create', arg_group='Azure File Volume') as c:
204+
c.argument('azure_file_volume_share_name', help='The name of the Azure File share to be mounted as a volume')
205+
c.argument('azure_file_volume_account_name', help='The name of the storage account that contains the Azure File share')
206+
c.argument('azure_file_volume_account_key', help='The storage account access key used to access the Azure File share')
207+
c.argument('azure_file_volume_mount_path', validator=validate_volume_mount_path, help="The path within the container where the azure file volume should be mounted. Must not contain colon ':'.")
208+
209+
with self.argument_context('container container-group-profile create', arg_group='Log Analytics') as c:
210+
c.argument('log_analytics_workspace', help='The Log Analytics workspace name or id. Use the current subscription or use --subscription flag to set the desired subscription.')
211+
c.argument('log_analytics_workspace_key', help='The Log Analytics workspace key.')
212+
213+
with self.argument_context('container container-group-profile create', arg_group='Git Repo Volume') as c:
214+
c.argument('gitrepo_url', help='The URL of a git repository to be mounted as a volume')
215+
c.argument('gitrepo_dir', validator=validate_gitrepo_directory, help="The target directory path in the git repository. Must not contain '..'.")
216+
c.argument('gitrepo_revision', help='The commit hash for the specified revision')
217+
c.argument('gitrepo_mount_path', validator=validate_volume_mount_path, help="The path within the container where the git repo volume should be mounted. Must not contain colon ':'.")
218+
219+
with self.argument_context('container container-group-profile show-revision') as c:
220+
c.argument('revision', options_list=['-r'], help="The revision of the container group profile.")

src/azure-cli/azure/cli/command_modules/container/commands.py

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@
44
# --------------------------------------------------------------------------------------------
55

66
from azure.cli.core.commands import CliCommandType
7-
from ._client_factory import cf_container_groups, cf_container
8-
from ._format import transform_container_group_list, transform_container_group
7+
from ._client_factory import cf_container_groups, cf_container, cf_container_group_profiles, cf_container_group_profile
8+
from ._format import (transform_container_group_list, transform_container_group,
9+
transform_container_group_profile_list, transform_container_group_profile)
910

1011

1112
container_group_sdk = CliCommandType(
@@ -30,3 +31,19 @@ def load_command_table(self, _):
3031
g.command('restart', 'begin_restart', supports_no_wait=True)
3132
g.command('stop', 'stop')
3233
g.command('start', 'begin_start', supports_no_wait=True)
34+
35+
with self.command_group('container container-group-profile',
36+
client_factory=cf_container_group_profiles) as g:
37+
g.custom_command('list', 'list_container_group_profiles',
38+
table_transformer=transform_container_group_profile_list)
39+
g.custom_command('create', 'create_container_group_profile',
40+
supports_no_wait=True, table_transformer=transform_container_group_profile)
41+
g.custom_show_command('show', 'get_container_group_profile',
42+
table_transformer=transform_container_group_profile)
43+
g.custom_command('delete', 'delete_container_group_profile', confirmation=True)
44+
45+
with self.command_group('container container-group-profile', client_factory=cf_container_group_profile) as g:
46+
g.custom_command('list-revisions', 'list_container_group_profile_revisions',
47+
table_transformer=transform_container_group_profile_list)
48+
g.custom_show_command('show-revision', 'get_container_group_profile_revision',
49+
table_transformer=transform_container_group_profile)

0 commit comments

Comments
 (0)