Skip to content

Commit

Permalink
{AKS} Use default serialization for maintenanceconfiguration commands (
Browse files Browse the repository at this point in the history
…Azure#4362)

* Use msrest deserilizer

* fix as per comments

* remove the import

Co-authored-by: Allan Zhang <xiazhan@microsoft.com>
  • Loading branch information
xiazhan and allan-xiazhan authored Jan 29, 2022
1 parent 7ce423e commit cd4d6fc
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 37 deletions.
8 changes: 4 additions & 4 deletions src/aks-preview/azext_aks_preview/_help.py
Original file line number Diff line number Diff line change
Expand Up @@ -819,14 +819,14 @@
"timeInWeek": [
{
"day": "Tuesday",
"hour_slots": [
"hourSlots": [
1,
2
]
},
{
"day": "Wednesday",
"hour_slots": [
"hourSlots": [
1,
6
]
Expand Down Expand Up @@ -876,14 +876,14 @@
"timeInWeek": [
{
"day": "Tuesday",
"hour_slots": [
"hourSlots": [
1,
2
]
},
{
"day": "Wednesday",
"hour_slots": [
"hourSlots": [
1,
6
]
Expand Down
34 changes: 3 additions & 31 deletions src/aks-preview/azext_aks_preview/maintenanceconfiguration.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ def getMaintenanceConfiguration(cmd, config_file, weekday, start_hour):
result.not_allowed_time = []
return result

return _get_maintenance_config(cmd, config_file)
maintenance_config = get_file_json(config_file)
logger.info(maintenance_config)
return maintenance_config


def aks_maintenanceconfiguration_update_internal(
Expand All @@ -49,33 +51,3 @@ def aks_maintenanceconfiguration_update_internal(

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(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):
raise CLIError("Error reading maintenance configuration at {}.".format(file_path))
time_in_week = maintenance_config["timeInWeek"]
not_allowed_time = maintenance_config["notAllowedTime"]
week_schedule = []
if time_in_week is not None:
for item in time_in_week:
w = TimeInWeek(**item)
logger.info('day: %s, time slots: %s ', w.day, w.hour_slots)
week_schedule.append(w)
not_allowed = []
if not_allowed_time is not None:
for item in not_allowed_time:
t = TimeSpan(**item)
logger.info('start: %s, end: %s ', t.start, t.end)
not_allowed.append(t)
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
Expand Up @@ -2,14 +2,14 @@
"timeInWeek": [
{
"day": "Tuesday",
"hour_slots": [
"hourSlots": [
1,
2
]
},
{
"day": "Wednesday",
"hour_slots": [
"hourSlots": [
1,
6
]
Expand Down

0 comments on commit cd4d6fc

Please sign in to comment.