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
4 changes: 3 additions & 1 deletion src/containerapp/HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ upcoming
* 'az containerapp env': --enable-workload-profiles allowed values:true, false
* 'az containerapp auth': support --token-store, --sas-url-secret, --sas-url-secret-name, --yes
* 'az containerapp create'/'az containerapp job create': When --environment is provided and the environmentId value does not exist in --yaml, use the value in --environment as environmentId
* Added 'az containerapp show-custom-domain-verification-id' to show verfication id used for binding custom domain
* 'az containerapp job create': support --environment-type parameter
* 'az containerapp show-custom-domain-verification-id': show verfication id used for binding custom domain
* 'az containerapp list-usages': list usages in subscription
* 'az containerapp env list-usages': list usages in environment

0.3.37
++++++
Expand Down
24 changes: 24 additions & 0 deletions src/containerapp/azext_containerapp/_clients.py
Original file line number Diff line number Diff line change
Expand Up @@ -1538,10 +1538,34 @@ def show_custom_domain_verification_id(cls, cmd):
r = send_raw_request(cmd.cli_ctx, "POST", request_url)
return r.json()

@classmethod
def list_usages(cls, cmd, location):
management_hostname = cmd.cli_ctx.cloud.endpoints.resource_manager
sub_id = get_subscription_id(cmd.cli_ctx)
request_url = f"{management_hostname}subscriptions/{sub_id}/providers/Microsoft.App/locations/{location}/usages?api-version={cls.api_version}"

r = send_raw_request(cmd.cli_ctx, "GET", request_url)
return r.json()


class ManagedEnvironmentPreviewClient(ManagedEnvironmentClient):
api_version = PREVIEW_API_VERSION

@classmethod
def list_usages(cls, cmd, resource_group_name, name):
management_hostname = cmd.cli_ctx.cloud.endpoints.resource_manager
sub_id = get_subscription_id(cmd.cli_ctx)
url_fmt = "{}/subscriptions/{}/resourceGroups/{}/providers/Microsoft.App/managedEnvironments/{}/usages?api-version={}"
request_url = url_fmt.format(
management_hostname.strip('/'),
sub_id,
resource_group_name,
name,
cls.api_version)

r = send_raw_request(cmd.cli_ctx, "GET", request_url)
return r.json()


class AuthPreviewClient(AuthClient):
api_version = PREVIEW_API_VERSION
Expand Down
18 changes: 18 additions & 0 deletions src/containerapp/azext_containerapp/_help.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,24 @@
az containerapp list -g MyResourceGroup
"""

helps['containerapp list-usages'] = """
type: command
short-summary: List usages of subscription level quotas in specific region.
examples:
- name: List usages of quotas in specific region.
text: |
az containerapp list-usages -l eastus
"""

helps['containerapp env list-usages'] = """
type: command
short-summary: List usages of quotas for specific managed environment.
examples:
- name: List usages of quotas for specific managed environment.
text: |
az containerapp env list-usages -n MyEnv -g MyResourceGroup
"""

helps['containerapp exec'] = """
type: command
short-summary: Open an SSH-like interactive shell within a container app replica
Expand Down
13 changes: 13 additions & 0 deletions src/containerapp/azext_containerapp/_transformers.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,16 @@ def transform_job_execution_show_output(execution):

def transform_job_execution_list_output(executions):
return [transform_job_execution_show_output(e) for e in executions]


def transform_usages_output(result):
table_result = []
for item in result["value"]:
value = {
"Name": item["name"]["value"],
"Usage": item["usage"],
"Limit": item["limit"]
}
table_result.append(value)

return table_result
4 changes: 3 additions & 1 deletion src/containerapp/azext_containerapp/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
transform_job_execution_list_output,
transform_job_execution_show_output,
transform_revision_list_output,
transform_revision_output)
transform_revision_output, transform_usages_output)
Comment thread
Juliehzl marked this conversation as resolved.
Outdated


def load_command_table(self, _):
Expand All @@ -27,6 +27,7 @@ def load_command_table(self, _):
g.custom_command('up', 'containerapp_up', supports_no_wait=False, exception_handler=ex_handler_factory())
g.custom_command('browse', 'open_containerapp_in_browser')
g.custom_show_command('show-custom-domain-verification-id', 'show_custom_domain_verification_id')
g.custom_command('list-usages', 'list_usages', table_transformer=transform_usages_output)

with self.command_group('containerapp replica') as g:
g.custom_show_command('show', 'get_replica') # TODO implement the table transformer
Expand All @@ -43,6 +44,7 @@ def load_command_table(self, _):
g.custom_command('create', 'create_managed_environment', supports_no_wait=True, exception_handler=ex_handler_factory())
g.custom_command('delete', 'delete_managed_environment', supports_no_wait=True, confirmation=True, exception_handler=ex_handler_factory())
g.custom_command('update', 'update_managed_environment', supports_no_wait=True, exception_handler=ex_handler_factory())
g.custom_command('list-usages', 'list_environment_usages', table_transformer=transform_usages_output)

with self.command_group('containerapp job') as g:
g.custom_show_command('show', 'show_containerappsjob')
Expand Down
21 changes: 20 additions & 1 deletion src/containerapp/azext_containerapp/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@
ContainerAppPreviewClient,
AuthPreviewClient,
SubscriptionPreviewClient,
ContainerAppsJobPreviewClient
ContainerAppsJobPreviewClient,
ManagedEnvironmentPreviewClient
)
from ._dev_service_utils import DevServiceUtils
from ._github_oauth import get_github_access_token
Expand Down Expand Up @@ -1059,6 +1060,24 @@ def show_custom_domain_verification_id(cmd):
handle_raw_exception(e)


def list_usages(cmd, location):
_validate_subscription_registered(cmd, CONTAINER_APPS_RP)
try:
r = SubscriptionPreviewClient.list_usages(cmd, location)
return r
except CLIError as e:
handle_raw_exception(e)


def list_environment_usages(cmd, resource_group_name, name):
_validate_subscription_registered(cmd, CONTAINER_APPS_RP)
try:
r = ManagedEnvironmentPreviewClient.list_usages(cmd, resource_group_name, name)
return r
except CLIError as e:
handle_raw_exception(e)


def delete_containerapp(cmd, name, resource_group_name, no_wait=False):
raw_parameters = locals()
containerapp_base_decorator = BaseContainerAppDecorator(
Expand Down
Loading