-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
42 changed files
with
11,597 additions
and
6 deletions.
There are no files selected for viewing
This file contains 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
Empty file.
32 changes: 32 additions & 0 deletions
32
...tainerapp-preview/azext_containerapp_preview/vendored_sdks/azext_containerapp/__init__.py
This file contains 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,32 @@ | ||
# -------------------------------------------------------------------------------------------- | ||
# Copyright (c) Microsoft Corporation. All rights reserved. | ||
# Licensed under the MIT License. See License.txt in the project root for license information. | ||
# -------------------------------------------------------------------------------------------- | ||
# pylint: disable=super-with-arguments | ||
|
||
from azure.cli.core import AzCommandsLoader | ||
|
||
from azext_containerapp._help import helps # pylint: disable=unused-import | ||
|
||
|
||
class ContainerappCommandsLoader(AzCommandsLoader): | ||
|
||
def __init__(self, cli_ctx=None): | ||
from azure.cli.core.commands import CliCommandType | ||
containerapp_custom = CliCommandType( | ||
operations_tmpl='azext_containerapp.custom#{}', | ||
client_factory=None) | ||
super(ContainerappCommandsLoader, self).__init__(cli_ctx=cli_ctx, | ||
custom_command_type=containerapp_custom) | ||
|
||
def load_command_table(self, args): | ||
from azext_containerapp.commands import load_command_table | ||
load_command_table(self, args) | ||
return self.command_table | ||
|
||
def load_arguments(self, command): | ||
from azext_containerapp._params import load_arguments | ||
load_arguments(self, command) | ||
|
||
|
||
COMMAND_LOADER_CLS = ContainerappCommandsLoader |
112 changes: 112 additions & 0 deletions
112
...p-preview/azext_containerapp_preview/vendored_sdks/azext_containerapp/_acr_run_polling.py
This file contains 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,112 @@ | ||
# -------------------------------------------------------------------------------------------- | ||
# 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, consider-using-f-string | ||
|
||
import time | ||
|
||
from msrest import Deserializer | ||
from msrestazure.azure_exceptions import CloudError | ||
from azure.cli.core.profiles import ResourceType | ||
from azure.cli.command_modules.acr._constants import get_acr_task_models | ||
from azure.core.polling import PollingMethod, LROPoller | ||
|
||
|
||
def get_run_with_polling(cmd, | ||
client, | ||
run_id, | ||
registry_name, | ||
resource_group_name): | ||
deserializer = Deserializer( | ||
{k: v for k, v in get_acr_task_models(cmd).__dict__.items() if isinstance(v, type)}) | ||
|
||
def deserialize_run(response): | ||
return deserializer('Run', response) | ||
|
||
return LROPoller( | ||
client=client, | ||
initial_response=client.get( | ||
resource_group_name, registry_name, run_id, cls=lambda x, y, z: x), | ||
deserialization_callback=deserialize_run, | ||
polling_method=RunPolling( | ||
cmd=cmd, | ||
registry_name=registry_name, | ||
run_id=run_id | ||
)) | ||
|
||
|
||
class RunPolling(PollingMethod): # pylint: disable=too-many-instance-attributes | ||
|
||
def __init__(self, cmd, registry_name, run_id, timeout=30): | ||
self._cmd = cmd | ||
self._registry_name = registry_name | ||
self._run_id = run_id | ||
self._timeout = timeout | ||
self._client = None | ||
self._response = None # Will hold latest received response | ||
self._url = None # The URL used to get the run | ||
self._deserialize = None # The deserializer for Run | ||
self.operation_status = "" | ||
self.operation_result = None | ||
|
||
def initialize(self, client, initial_response, deserialization_callback): | ||
self._client = client._client # pylint: disable=protected-access | ||
self._response = initial_response | ||
self._url = initial_response.http_request.url | ||
self._deserialize = deserialization_callback | ||
|
||
self._set_operation_status(initial_response) | ||
|
||
def run(self): | ||
while not self.finished(): | ||
time.sleep(self._timeout) | ||
self._update_status() | ||
|
||
if self.operation_status not in get_succeeded_run_status(self._cmd): | ||
from knack.util import CLIError | ||
raise CLIError("The run with ID '{}' finished with unsuccessful status '{}'. " | ||
"Show run details by 'az acr task show-run -r {} --run-id {}'. " | ||
"Show run logs by 'az acr task logs -r {} --run-id {}'.".format( | ||
self._run_id, | ||
self.operation_status, | ||
self._registry_name, | ||
self._run_id, | ||
self._registry_name, | ||
self._run_id | ||
)) | ||
|
||
def status(self): | ||
return self.operation_status | ||
|
||
def finished(self): | ||
return self.operation_status in get_finished_run_status(self._cmd) | ||
|
||
def resource(self): | ||
return self.operation_result | ||
|
||
def _set_operation_status(self, response): | ||
if response.http_response.status_code == 200: | ||
self.operation_result = self._deserialize(response) | ||
self.operation_status = self.operation_result.status | ||
return | ||
raise CloudError(response) | ||
|
||
def _update_status(self): | ||
self._response = self._client._pipeline.run( # pylint: disable=protected-access | ||
self._client.get(self._url), stream=False) | ||
self._set_operation_status(self._response) | ||
|
||
|
||
def get_succeeded_run_status(cmd): | ||
RunStatus = cmd.get_models('RunStatus', resource_type=ResourceType.MGMT_CONTAINERREGISTRY, operation_group='task_runs') | ||
return [RunStatus.succeeded.value] | ||
|
||
|
||
def get_finished_run_status(cmd): | ||
RunStatus = cmd.get_models('RunStatus', resource_type=ResourceType.MGMT_CONTAINERREGISTRY, operation_group='task_runs') | ||
return [RunStatus.succeeded.value, | ||
RunStatus.failed.value, | ||
RunStatus.canceled.value, | ||
RunStatus.error.value, | ||
RunStatus.timeout.value] |
Oops, something went wrong.