Skip to content

Commit

Permalink
az containerapp revision restart, activate, deactivate
Browse files Browse the repository at this point in the history
  • Loading branch information
calvinsID committed Mar 1, 2022
1 parent d895d8b commit 411e61d
Show file tree
Hide file tree
Showing 4 changed files with 117 additions and 4 deletions.
50 changes: 50 additions & 0 deletions src/containerapp/azext_containerapp/_clients.py
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,56 @@ def show_revision(cls, cmd, resource_group_name, container_app_name, name):
r = send_raw_request(cmd.cli_ctx, "GET", request_url)
return r.json()

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

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

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

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

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

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

class ManagedEnvironmentClient():
@classmethod
Expand Down
35 changes: 34 additions & 1 deletion src/containerapp/azext_containerapp/_help.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,12 @@
az containerapp list -g MyResourceGroup
"""

# Revision Commands
helps['containerapp revision'] = """
type: group
short-summary: Commands to manage a Containerapp's revisions.
"""

helps['containerapp revision show'] = """
type: command
short-summary: Show details of a Containerapp's revision.
Expand All @@ -153,7 +159,34 @@
examples:
- name: List a Containerapp's revisions.
text: |
az containerapp revision list -n MyContainerapp -g MyResourceGroup
az containerapp revision list --revision-name MyContainerapp -g MyResourceGroup
"""

helps['containerapp revision restart'] = """
type: command
short-summary: Restart a Containerapps's revision.
examples:
- name: Restart a Containerapp's revision.
text: |
az containerapp revision restart --revision-name MyContainerappRevision -g MyResourceGroup
"""

helps['containerapp revision activate'] = """
type: command
short-summary: Activates Containerapp's revision.
examples:
- name: Activate a Containerapp's revision.
text: |
az containerapp revision activate --revision-name MyContainerappRevision -g MyResourceGroup
"""

helps['containerapp revision deactivate'] = """
type: command
short-summary: Deactivates Containerapp's revision.
examples:
- name: Deactivate a Containerapp's revision.
text: |
az containerapp revision deactivate --revision-name MyContainerappRevision -g MyResourceGroup
"""

# Environment Commands
Expand Down
6 changes: 3 additions & 3 deletions src/containerapp/azext_containerapp/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ def load_command_table(self, _):
g.custom_command('delete', 'delete_managed_environment', supports_no_wait=True, confirmation=True, exception_handler=ex_handler_factory())

with self.command_group('containerapp revision') as g:
# g.custom_command('activate', 'activate_revision')
# g.custom_command('deactivate', 'deactivate_revision')
g.custom_command('activate', 'activate_revision')
g.custom_command('deactivate', 'deactivate_revision')
g.custom_command('list', 'list_revisions', table_transformer=transform_revision_list_output, exception_handler=ex_handler_factory())
# g.custom_command('restart', 'restart_revision')
g.custom_command('restart', 'restart_revision')
g.custom_command('show', 'show_revision', table_transformer=transform_revision_output, exception_handler=ex_handler_factory())
30 changes: 30 additions & 0 deletions src/containerapp/azext_containerapp/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -909,3 +909,33 @@ def show_revision(cmd, resource_group_name, revision_name, name=None):
return ContainerAppClient.show_revision(cmd=cmd, resource_group_name=resource_group_name, container_app_name=name, name=revision_name)
except CLIError as e:
handle_raw_exception(e)


def restart_revision(cmd, resource_group_name, revision_name, name=None):
if not name:
name = _get_app_from_revision(revision_name)

try:
return ContainerAppClient.restart_revision(cmd=cmd, resource_group_name=resource_group_name, container_app_name=name, name=revision_name)
except CLIError as e:
handle_raw_exception(e)


def activate_revision(cmd, resource_group_name, revision_name, name=None):
if not name:
name = _get_app_from_revision(revision_name)

try:
return ContainerAppClient.activate_revision(cmd=cmd, resource_group_name=resource_group_name, container_app_name=name, name=revision_name)
except CLIError as e:
handle_raw_exception(e)

def deactivate_revision(cmd, resource_group_name, revision_name, name=None):
if not name:
name = _get_app_from_revision(revision_name)

try:
return ContainerAppClient.deactivate_revision(cmd=cmd, resource_group_name=resource_group_name, container_app_name=name, name=revision_name)
except CLIError as e:
handle_raw_exception(e)

0 comments on commit 411e61d

Please sign in to comment.