-
Notifications
You must be signed in to change notification settings - Fork 1.6k
[Containerapp] az containerapp session stop: Add stop session feature
#9140
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
f211806
add history info
cba7def
add command
a21ca85
add param
a176b54
add help info
48c2966
add client
63e9a74
Refine logic
922e330
add test
34b14f4
update
ed4d917
fix
f20d636
update
407b33e
fix comments
6727f74
fix comment
2250f7c
update test
a38bfdb
fix style check
a0a229f
fix comment
3566df4
fix style issue
ca01307
fix comments
7b2eae1
fix comment
758720e
fix issue
dffd3ff
Merge branch 'main' into shiqiu/supportStopSession
Greedygre File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
src/containerapp/azext_containerapp/containerapp_session_custom_container_decorator.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| # coding=utf-8 | ||
| # -------------------------------------------------------------------------------------------- | ||
| # Copyright (c) Microsoft Corporation. All rights reserved. | ||
| # Licensed under the MIT License. See License.txt in the project root for license information. | ||
| # -------------------------------------------------------------------------------------------- | ||
| # pylint: disable=line-too-long, broad-except, logging-format-interpolation | ||
|
|
||
|
|
||
| from knack.log import get_logger | ||
| from typing import Any, Dict | ||
|
|
||
| from azure.cli.core.azclierror import ValidationError | ||
| from azure.cli.core.commands import AzCliCommand | ||
| from azure.cli.command_modules.containerapp.base_resource import BaseResource | ||
| from azure.cli.command_modules.containerapp._utils import safe_get | ||
| from ._clients import SessionPoolPreviewClient | ||
|
|
||
| from ._models import SessionCodeInterpreterExecution as SessionCodeInterpreterExecutionPreviewModel | ||
| from ._client_factory import handle_raw_exception | ||
| from .containerapp_sessionpool_decorator import ContainerType | ||
|
|
||
| logger = get_logger(__name__) | ||
|
|
||
|
|
||
| class SessionCustomContainerPreviewDecorator(BaseResource): | ||
| def __init__(self, cmd: AzCliCommand, client: Any, raw_parameters: Dict, models: str): | ||
| super().__init__(cmd, client, raw_parameters, models) | ||
| self.session_code_interpreter_def = SessionCodeInterpreterExecutionPreviewModel | ||
| self.session_pool_client = SessionPoolPreviewClient | ||
|
|
||
| def get_argument_name(self): | ||
| return self.get_param('name') | ||
|
|
||
| def get_argument_resource_group_name(self): | ||
| return self.get_param('resource_group_name') | ||
|
|
||
| def get_argument_identifier(self): | ||
| return self.get_param('identifier') | ||
|
|
||
| def get_sessionpool(self): | ||
| return self.session_pool_client.show(cmd=self.cmd, | ||
| resource_group_name=self.get_argument_resource_group_name(), | ||
| name=self.get_argument_name()) | ||
|
|
||
|
|
||
| class SessionCustomContainerCommandsPreviewDecorator(SessionCustomContainerPreviewDecorator): | ||
| def stop_session(self): | ||
| try: | ||
| existing_pool_def = self.get_sessionpool() | ||
| if safe_get(existing_pool_def, "properties", "containerType").lower() != ContainerType.CustomContainer.name.lower(): | ||
| raise ValidationError("Stop session operation is only supported for session pools with type 'CustomContainer'.") | ||
|
|
||
| return self.client.stop_session( | ||
| cmd=self.cmd, | ||
| identifier=self.get_argument_identifier(), | ||
| session_pool_endpoint=existing_pool_def["properties"]["poolManagementEndpoint"]) | ||
| except Exception as e: | ||
| handle_raw_exception(e) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.