-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Add Maintenance Config Support #8190
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
Changes from all commits
14feb57
197987b
b0d2b8b
9b194f5
30bb735
23d7579
51ccb81
3d7ad05
b6fed57
d84acdb
1881544
cbd3699
c53b3d3
211b54f
f3c0370
8a7eef4
1e80f38
57b5731
d99e801
3c3aec5
219c8c6
03ee910
58be1d7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,101 @@ | ||
| # 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 copy import deepcopy | ||
| 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 ._models import MaintenanceConfiguration as MaintenanceConfigurationModel | ||
| from ._client_factory import handle_raw_exception, handle_non_404_status_code_exception | ||
|
|
||
| logger = get_logger(__name__) | ||
|
|
||
|
|
||
| class ContainerappEnvMaintenanceConfigDecorator(BaseResource): | ||
| def __init__(self, cmd: AzCliCommand, client: Any, raw_parameters: Dict, models: str): | ||
| super().__init__(cmd, client, raw_parameters, models) | ||
| self.maintenance_config_def = deepcopy(MaintenanceConfigurationModel) | ||
| self.existing_maintenance_config_def = None | ||
|
|
||
| def get_argument_environment_name(self): | ||
| return self.get_param('env_name') | ||
|
|
||
| def get_argument_resource_group_name(self): | ||
| return self.get_param('resource_group_name') | ||
|
|
||
| def get_argument_weekday(self): | ||
| return self.get_param('weekday') | ||
|
|
||
| def get_argument_start_hour_utc(self): | ||
| return self.get_param('start_hour_utc') | ||
|
|
||
| def get_argument_duration(self): | ||
| return self.get_param('duration') | ||
|
|
||
|
|
||
| class ContainerAppEnvMaintenanceConfigPreviewDecorator(ContainerappEnvMaintenanceConfigDecorator): | ||
| def validate_arguments(self): | ||
| if self.get_argument_start_hour_utc() is not None: | ||
| if not (0 <= int(self.get_argument_start_hour_utc()) <= 23): | ||
| raise ValidationError("Start hour must be an integer from 0 to 23") | ||
|
|
||
| if self.get_argument_duration() is not None: | ||
| if not (8 <= int(self.get_argument_duration()) <= 24): | ||
| raise ValidationError("Duration must be an integer from 8 to 24") | ||
|
|
||
| if self.get_argument_weekday() is not None: | ||
| if self.get_argument_weekday().lower() not in ["monday", "tuesday", "wednesday", "thursday", "friday", "saturday", "sunday"]: | ||
| raise ValidationError("Weekday must be a day of the week") | ||
|
|
||
| def construct_payload(self, forUpdate=False): | ||
| if forUpdate: | ||
| self.existing_maintenance_config_def = self.client.list( | ||
| cmd=self.cmd, | ||
| resource_group_name=self.get_argument_resource_group_name(), | ||
| environment_name=self.get_argument_environment_name()) | ||
|
|
||
| self.maintenance_config_def = deepcopy(self.existing_maintenance_config_def) | ||
|
|
||
| if self.get_argument_start_hour_utc() is not None: | ||
| self.maintenance_config_def["properties"]["scheduledEntries"][0]["startHourUtc"] = self.get_argument_start_hour_utc() | ||
| if self.get_argument_duration() is not None: | ||
| self.maintenance_config_def["properties"]["scheduledEntries"][0]["durationHours"] = self.get_argument_duration() | ||
| if self.get_argument_weekday() is not None: | ||
| self.maintenance_config_def["properties"]["scheduledEntries"][0]["weekDay"] = self.get_argument_weekday() | ||
|
|
||
| def create_or_update(self): | ||
| try: | ||
| return self.client.create_or_update( | ||
| cmd=self.cmd, | ||
| resource_group_name=self.get_argument_resource_group_name(), | ||
| environment_name=self.get_argument_environment_name(), | ||
| maintenance_config_envelope=self.maintenance_config_def) | ||
| except Exception as e: | ||
| handle_raw_exception(e) | ||
|
|
||
| def remove(self): | ||
| try: | ||
| return self.client.remove( | ||
| cmd=self.cmd, | ||
| resource_group_name=self.get_argument_resource_group_name(), | ||
| environment_name=self.get_argument_environment_name()) | ||
| except Exception as e: | ||
| handle_raw_exception(e) | ||
|
|
||
| def list(self): | ||
| try: | ||
| return self.client.list( | ||
| cmd=self.cmd, | ||
| resource_group_name=self.get_argument_resource_group_name(), | ||
| environment_name=self.get_argument_environment_name()) | ||
| except Exception as e: | ||
| handle_non_404_status_code_exception(e) | ||
| return "" |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -84,6 +84,7 @@ | |
| from .containerapp_sessionpool_decorator import SessionPoolPreviewDecorator, SessionPoolCreateDecorator, SessionPoolUpdateDecorator | ||
| from .containerapp_session_code_interpreter_decorator import SessionCodeInterpreterCommandsPreviewDecorator | ||
| from .containerapp_job_registry_decorator import ContainerAppJobRegistryPreviewSetDecorator | ||
| from .containerapp_env_maintenance_config_decorator import ContainerAppEnvMaintenanceConfigPreviewDecorator | ||
| from .dotnet_component_decorator import DotNetComponentDecorator | ||
| from ._client_factory import handle_raw_exception, handle_non_404_status_code_exception | ||
| from ._clients import ( | ||
|
|
@@ -102,7 +103,8 @@ | |
| JavaComponentPreviewClient, | ||
| SessionPoolPreviewClient, | ||
| SessionCodeInterpreterPreviewClient, | ||
| DotNetComponentPreviewClient | ||
| DotNetComponentPreviewClient, | ||
| MaintenanceConfigPreviewClient | ||
| ) | ||
| from ._dev_service_utils import DevServiceUtils | ||
| from ._models import ( | ||
|
|
@@ -3262,3 +3264,57 @@ def set_registry_job(cmd, name, resource_group_name, server, username=None, pass | |
| containerapp_job_registry_set_decorator.construct_payload() | ||
| r = containerapp_job_registry_set_decorator.set() | ||
| return r | ||
|
|
||
|
|
||
| # maintenance config | ||
| def add_maintenance_config(cmd, resource_group_name, env_name, duration, start_hour_utc, weekday): | ||
p-bouchon marked this conversation as resolved.
Show resolved
Hide resolved
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will you support customized name in the future? Current design is not very flexible for extensibility. Consider adding
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hi @Juliehzl only one maintenance config of name "default" is allowed.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @p-bouchon please correct me if I am wrong
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We currently have no plans to allow for non default names for maintenance configuration. If any were to be added, they would be specific non-customizable names to specify upgrades on specific aspects of the service |
||
| raw_parameters = locals() | ||
| maintenance_config_decorator = ContainerAppEnvMaintenanceConfigPreviewDecorator( | ||
| cmd=cmd, | ||
| client=MaintenanceConfigPreviewClient, | ||
| raw_parameters=raw_parameters, | ||
| models=CONTAINER_APPS_SDK_MODELS | ||
| ) | ||
| maintenance_config_decorator.construct_payload() | ||
| maintenance_config_decorator.validate_arguments() | ||
| r = maintenance_config_decorator.create_or_update() | ||
| return r | ||
|
|
||
|
|
||
| def update_maintenance_config(cmd, resource_group_name, env_name, duration=None, start_hour_utc=None, weekday=None): | ||
| raw_parameters = locals() | ||
| maintenance_config_decorator = ContainerAppEnvMaintenanceConfigPreviewDecorator( | ||
| cmd=cmd, | ||
| client=MaintenanceConfigPreviewClient, | ||
| raw_parameters=raw_parameters, | ||
| models=CONTAINER_APPS_SDK_MODELS | ||
| ) | ||
| forUpdate = True | ||
| maintenance_config_decorator.construct_payload(forUpdate) | ||
| maintenance_config_decorator.validate_arguments() | ||
| r = maintenance_config_decorator.create_or_update() | ||
| return r | ||
|
|
||
|
|
||
| def remove_maintenance_config(cmd, resource_group_name, env_name): | ||
| raw_parameters = locals() | ||
| maintenance_config_decorator = ContainerAppEnvMaintenanceConfigPreviewDecorator( | ||
| cmd=cmd, | ||
| client=MaintenanceConfigPreviewClient, | ||
| raw_parameters=raw_parameters, | ||
| models=CONTAINER_APPS_SDK_MODELS | ||
| ) | ||
| r = maintenance_config_decorator.remove() | ||
| return r | ||
|
|
||
|
|
||
| def list_maintenance_config(cmd, resource_group_name, env_name): | ||
| raw_parameters = locals() | ||
| maintenance_config_decorator = ContainerAppEnvMaintenanceConfigPreviewDecorator( | ||
| cmd=cmd, | ||
| client=MaintenanceConfigPreviewClient, | ||
| raw_parameters=raw_parameters, | ||
| models=CONTAINER_APPS_SDK_MODELS | ||
| ) | ||
| r = maintenance_config_decorator.list() | ||
| return r | ||
Uh oh!
There was an error while loading. Please reload this page.