Microsoft Azure Container Service Management Client Library for Python
—
Quality
Pending
Does it follow best practices?
Impact
Pending
No eval scenarios have been run
Scheduled maintenance window management for AKS clusters including automated patching, upgrade scheduling, maintenance event coordination, and operational control over when disruptive operations can occur. This ensures predictable maintenance timing aligned with business requirements and minimizes operational impact.
Create, update, and manage maintenance configurations that define when maintenance operations can occur on AKS clusters.
def create_or_update(
resource_group_name: str,
resource_name: str,
config_name: str,
parameters: MaintenanceConfiguration
) -> MaintenanceConfiguration:
"""
Creates or updates a maintenance configuration for the cluster.
Args:
resource_group_name: Azure resource group name
resource_name: Cluster name
config_name: Maintenance configuration name
parameters: Complete maintenance configuration
Returns:
MaintenanceConfiguration: Created or updated configuration
"""
def delete(
resource_group_name: str,
resource_name: str,
config_name: str
) -> None:
"""
Deletes a maintenance configuration.
Args:
resource_group_name: Azure resource group name
resource_name: Cluster name
config_name: Maintenance configuration name
"""List and retrieve maintenance configurations to understand current maintenance policies.
def list_by_managed_cluster(
resource_group_name: str,
resource_name: str
) -> ItemPaged[MaintenanceConfiguration]:
"""
Lists maintenance configurations for the cluster.
Args:
resource_group_name: Azure resource group name
resource_name: Cluster name
Returns:
ItemPaged[MaintenanceConfiguration]: Paginated configuration list
"""
def get(
resource_group_name: str,
resource_name: str,
config_name: str
) -> MaintenanceConfiguration:
"""
Gets a specific maintenance configuration.
Args:
resource_group_name: Azure resource group name
resource_name: Cluster name
config_name: Maintenance configuration name
Returns:
MaintenanceConfiguration: Complete maintenance configuration
"""class MaintenanceConfiguration:
"""
Maintenance configuration defining maintenance windows and policies.
Attributes:
main_maintenance_window: Primary maintenance window schedule
not_allowed_time: Time periods when maintenance is not allowed
system_data: System metadata (read-only)
name: Configuration name (read-only)
type: Resource type (read-only)
id: Resource ID (read-only)
"""
main_maintenance_window: Optional[MaintenanceWindow]
not_allowed_time: Optional[List[TimeSpan]]
system_data: Optional[SystemData]
name: Optional[str]
type: Optional[str]
id: Optional[str]
class MaintenanceWindow:
"""
Maintenance window definition with scheduling parameters.
Attributes:
schedule: Maintenance schedule configuration
duration_hours: Duration of maintenance window in hours
utc_offset: UTC offset for maintenance window timing
start_date: Start date for maintenance schedule
start_time: Start time for maintenance operations
not_allowed_dates: Specific dates when maintenance is not allowed
"""
schedule: Schedule
duration_hours: int
utc_offset: Optional[str]
start_date: Optional[str]
start_time: Optional[str]
not_allowed_dates: Optional[List[DateSpan]]
class Schedule:
"""
Base schedule class for maintenance timing.
Note: This is a base class. Use specific schedule types:
- DailySchedule for daily maintenance
- WeeklySchedule for weekly maintenance
- AbsoluteMonthlySchedule for monthly (specific date)
- RelativeMonthlySchedule for monthly (relative day)
"""
pass
class DailySchedule(Schedule):
"""
Daily maintenance schedule.
Attributes:
interval_days: Interval between maintenance days
"""
interval_days: int
class WeeklySchedule(Schedule):
"""
Weekly maintenance schedule.
Attributes:
interval_weeks: Interval between maintenance weeks
day_of_week: Day of week for maintenance (Monday=1, Sunday=7)
"""
interval_weeks: int
day_of_week: int
class AbsoluteMonthlySchedule(Schedule):
"""
Monthly maintenance on specific date.
Attributes:
interval_months: Interval between maintenance months
day_of_month: Specific day of month (1-31)
"""
interval_months: int
day_of_month: int
class RelativeMonthlySchedule(Schedule):
"""
Monthly maintenance on relative day (e.g., first Monday).
Attributes:
interval_months: Interval between maintenance months
day_of_week: Day of week (Monday=1, Sunday=7)
week_index: Week of month (First=1, Last=5)
"""
interval_months: int
day_of_week: int
week_index: int
class TimeSpan:
"""
Time period when maintenance is not allowed.
Attributes:
start: Start time of blackout period
end: End time of blackout period
"""
start: str
end: str
class DateSpan:
"""
Date range when maintenance is not allowed.
Attributes:
start: Start date (YYYY-MM-DD format)
end: End date (YYYY-MM-DD format)
"""
start: str
end: strfrom azure.identity import DefaultAzureCredential
from azure.mgmt.containerservice import ContainerServiceClient
from azure.mgmt.containerservice.models import (
MaintenanceConfiguration,
MaintenanceWindow,
WeeklySchedule
)
credential = DefaultAzureCredential()
client = ContainerServiceClient(credential, subscription_id)
# Create weekly maintenance window (Sundays at 2 AM UTC, 4 hours duration)
maintenance_config = MaintenanceConfiguration(
main_maintenance_window=MaintenanceWindow(
schedule=WeeklySchedule(
interval_weeks=1,
day_of_week=7 # Sunday
),
duration_hours=4,
start_time="02:00",
utc_offset="+00:00"
)
)
result = client.maintenance_configurations.create_or_update(
"myResourceGroup",
"myCluster",
"default",
maintenance_config
)
print(f"Maintenance window created: {result.name}")from azure.mgmt.containerservice.models import (
AbsoluteMonthlySchedule,
DateSpan,
TimeSpan
)
# Monthly maintenance on the 15th, with holiday blackouts
monthly_config = MaintenanceConfiguration(
main_maintenance_window=MaintenanceWindow(
schedule=AbsoluteMonthlySchedule(
interval_months=1,
day_of_month=15
),
duration_hours=6,
start_time="01:00",
utc_offset="-08:00", # PST
not_allowed_dates=[
DateSpan(start="2024-12-20", end="2024-01-05"), # Holiday season
DateSpan(start="2024-07-01", end="2024-07-07"), # July 4th week
]
),
not_allowed_time=[
TimeSpan(start="08:00", end="18:00") # No maintenance during business hours
]
)
result = client.maintenance_configurations.create_or_update(
"myResourceGroup",
"myCluster",
"monthly-maintenance",
monthly_config
)from azure.mgmt.containerservice.models import DailySchedule
# Daily maintenance window for development cluster
dev_config = MaintenanceConfiguration(
main_maintenance_window=MaintenanceWindow(
schedule=DailySchedule(
interval_days=1
),
duration_hours=2,
start_time="03:00",
utc_offset="+00:00"
)
)
result = client.maintenance_configurations.create_or_update(
"devResourceGroup",
"devCluster",
"daily-maintenance",
dev_config
)from azure.mgmt.containerservice.models import RelativeMonthlySchedule
# First Saturday of every month
relative_config = MaintenanceConfiguration(
main_maintenance_window=MaintenanceWindow(
schedule=RelativeMonthlySchedule(
interval_months=1,
day_of_week=6, # Saturday
week_index=1 # First week
),
duration_hours=8,
start_time="22:00", # 10 PM
utc_offset="-05:00" # EST
)
)
result = client.maintenance_configurations.create_or_update(
"myResourceGroup",
"myCluster",
"first-saturday",
relative_config
)# List all maintenance configurations
configs = client.maintenance_configurations.list_by_managed_cluster(
"myResourceGroup",
"myCluster"
)
for config in configs:
print(f"Config: {config.name}")
if config.main_maintenance_window:
window = config.main_maintenance_window
print(f" Duration: {window.duration_hours} hours")
print(f" Start time: {window.start_time}")
if isinstance(window.schedule, WeeklySchedule):
print(f" Schedule: Weekly on day {window.schedule.day_of_week}")
elif isinstance(window.schedule, DailySchedule):
print(f" Schedule: Daily every {window.schedule.interval_days} days")
# Get specific configuration
config = client.maintenance_configurations.get(
"myResourceGroup",
"myCluster",
"default"
)
# Update existing configuration
if config.main_maintenance_window:
config.main_maintenance_window.duration_hours = 6 # Extend to 6 hours
updated = client.maintenance_configurations.create_or_update(
"myResourceGroup",
"myCluster",
"default",
config
)
# Delete configuration
client.maintenance_configurations.delete(
"myResourceGroup",
"myCluster",
"old-config"
)# Production cluster with strict maintenance policies
production_config = MaintenanceConfiguration(
main_maintenance_window=MaintenanceWindow(
schedule=WeeklySchedule(
interval_weeks=2, # Bi-weekly
day_of_week=7 # Sunday
),
duration_hours=4,
start_time="01:00",
utc_offset="-05:00",
start_date="2024-01-07", # First Sunday after Jan 1
not_allowed_dates=[
# Block maintenance during critical business periods
DateSpan(start="2024-11-28", end="2024-12-02"), # Thanksgiving week
DateSpan(start="2024-12-23", end="2024-01-02"), # Holiday season
DateSpan(start="2024-03-15", end="2024-03-31"), # Quarter end
DateSpan(start="2024-06-15", end="2024-06-30"), # Quarter end
DateSpan(start="2024-09-15", end="2024-09-30"), # Quarter end
]
),
not_allowed_time=[
# Never during business hours
TimeSpan(start="06:00", end="22:00")
]
)
result = client.maintenance_configurations.create_or_update(
"prodResourceGroup",
"prodCluster",
"production-maintenance",
production_config
)# Coordinate maintenance across multiple regions
regions = ["eastus", "westus", "northeurope"]
maintenance_times = ["01:00", "04:00", "07:00"] # Staggered times
for i, region in enumerate(regions):
config = MaintenanceConfiguration(
main_maintenance_window=MaintenanceWindow(
schedule=WeeklySchedule(
interval_weeks=1,
day_of_week=7 # Sunday
),
duration_hours=3,
start_time=maintenance_times[i],
utc_offset="+00:00"
)
)
result = client.maintenance_configurations.create_or_update(
f"{region}-rg",
f"cluster-{region}",
"regional-maintenance",
config
)
print(f"Configured maintenance for {region} at {maintenance_times[i]} UTC")from azure.core.exceptions import HttpResponseError, ResourceNotFoundError
try:
config = client.maintenance_configurations.get(
"myRG", "myCluster", "nonexistent"
)
except ResourceNotFoundError:
print("Maintenance configuration not found")
except HttpResponseError as e:
print(f"HTTP error: {e.status_code}")
# Validate maintenance window conflicts
try:
result = client.maintenance_configurations.create_or_update(
"myRG", "myCluster", "new-config", config
)
except HttpResponseError as e:
if e.status_code == 400:
print("Invalid maintenance configuration")
print(f"Error details: {e.message}")# Production: Conservative weekly schedule
prod_schedule = WeeklySchedule(
interval_weeks=1,
day_of_week=7 # Sunday
)
# Staging: More frequent for testing
staging_schedule = WeeklySchedule(
interval_weeks=1,
day_of_week=6 # Saturday
)
# Development: Daily for rapid iteration
dev_schedule = DailySchedule(
interval_days=1
)
# Consider time zones for global deployments
regional_configs = {
"eastus": "+00:00", # UTC
"westus": "-08:00", # PST
"westeurope": "+01:00", # CET
"eastasia": "+08:00" # CST
}# Common blackout periods for enterprise environments
common_blackouts = [
DateSpan(start="2024-11-28", end="2024-11-29"), # Thanksgiving
DateSpan(start="2024-12-24", end="2024-01-01"), # Winter holidays
DateSpan(start="2024-07-04", end="2024-07-04"), # Independence Day
DateSpan(start="2024-05-27", end="2024-05-27"), # Memorial Day
DateSpan(start="2024-09-02", end="2024-09-02"), # Labor Day
]
# Quarter-end blackouts for financial applications
quarter_ends = [
DateSpan(start="2024-03-29", end="2024-04-02"), # Q1 end
DateSpan(start="2024-06-28", end="2024-07-02"), # Q2 end
DateSpan(start="2024-09-27", end="2024-10-01"), # Q3 end
DateSpan(start="2024-12-27", end="2024-12-31"), # Q4 end
]Install with Tessl CLI
npx tessl i tessl/pypi-azure-mgmt-containerservice