Skip to content

Commit

Permalink
[AKS] az aks maintenance_configurations: Fix issue that add subco…
Browse files Browse the repository at this point in the history
…mmand cannot work (#3635)

* fix aks maintenance_configurations command

* add test for maintenanceconfiguration

* remove useless vendored 2020_12_01 SDK & update version
  • Loading branch information
FumingZhang authored Jul 14, 2021
1 parent 42c228a commit 3115390
Show file tree
Hide file tree
Showing 31 changed files with 1,018 additions and 14,455 deletions.
26 changes: 16 additions & 10 deletions src/aks-preview/azext_aks_preview/maintenanceconfiguration.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,34 +4,35 @@
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------

from .vendored_sdks.azure_mgmt_preview_aks.v2020_12_01.models import (MaintenanceConfiguration,
TimeInWeek,
TimeSpan)
from knack.util import CLIError
from knack.log import get_logger
from azure.cli.core.util import get_file_json
from azext_aks_preview._client_factory import CUSTOM_MGMT_AKS_PREVIEW

logger = get_logger(__name__)


def getMaintenanceConfiguration(config_file, weekday, start_hour):
def getMaintenanceConfiguration(cmd, config_file, weekday, start_hour):
if config_file is not None and weekday is not None:
raise CLIError('either config-file or weekday can be supplied.')
if weekday is None and start_hour is not None:
raise CLIError('if maintenance-start-hour is supplied, maintenance-weekday must be supplied too.')
# get models
MaintenanceConfiguration = cmd.get_models('MaintenanceConfiguration', resource_type=CUSTOM_MGMT_AKS_PREVIEW, operation_group='maintenance_configurations')
TimeInWeek = cmd.get_models('TimeInWeek', resource_type=CUSTOM_MGMT_AKS_PREVIEW, operation_group='maintenance_configurations')

if weekday is not None:
dict = {}
dict["day"] = weekday
if start_hour is not None:
dict["hour_slots"] = [start_hour]
timeInWeek = TimeInWeek(**dict)
result = MaintenanceConfiguration
result = MaintenanceConfiguration()
result.time_in_week = [timeInWeek]
result.not_allowed_time = []
return result

return _get_maintenance_config(config_file)
return _get_maintenance_config(cmd, config_file)


def aks_maintenanceconfiguration_update_internal(
Expand All @@ -46,11 +47,16 @@ def aks_maintenanceconfiguration_update_internal(
):
logger.info('resource_group_name: %s, cluster_name: %s, config_name: %s, config_file: %s, weekday: %s, start_hour: %s ', resource_group_name, cluster_name, config_name, config_file, weekday, start_hour)

config = getMaintenanceConfiguration(config_file, weekday, start_hour)
return client.create_or_update(resource_group_name=resource_group_name, resource_name=cluster_name, config_name=config_name, time_in_week=config.time_in_week, not_allowed_time=config.not_allowed_time)
config = getMaintenanceConfiguration(cmd, config_file, weekday, start_hour)
return client.create_or_update(resource_group_name=resource_group_name, resource_name=cluster_name, config_name=config_name, parameters=config)


def _get_maintenance_config(file_path):
def _get_maintenance_config(cmd, file_path):
# get models
MaintenanceConfiguration = cmd.get_models('MaintenanceConfiguration', resource_type=CUSTOM_MGMT_AKS_PREVIEW, operation_group='maintenance_configurations')
TimeInWeek = cmd.get_models('TimeInWeek', resource_type=CUSTOM_MGMT_AKS_PREVIEW, operation_group='maintenance_configurations')
TimeSpan = cmd.get_models('TimeSpan', resource_type=CUSTOM_MGMT_AKS_PREVIEW, operation_group='maintenance_configurations')

maintenance_config = get_file_json(file_path)
logger.info(maintenance_config)
if not isinstance(maintenance_config, dict):
Expand All @@ -69,7 +75,7 @@ def _get_maintenance_config(file_path):
t = TimeSpan(**item)
logger.info('start: %s, end: %s ', t.start, t.end)
not_allowed.append(t)
result = MaintenanceConfiguration
result = MaintenanceConfiguration()
result.time_in_week = week_schedule
result.not_allowed_time = not_allowed
return result
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"timeInWeek": [
{
"day": "Tuesday",
"hour_slots": [
1,
2
]
},
{
"day": "Wednesday",
"hour_slots": [
1,
6
]
}
],
"notAllowedTime": [
{
"start": "2021-11-26T03:00:00Z",
"end": "2021-11-30T12:00:00Z"
},
{
"start": "2021-12-26T03:00:00Z",
"end": "2021-12-26T12:00:00Z"
}
]
}
Loading

0 comments on commit 3115390

Please sign in to comment.