diff --git a/src/azure-cli/azure/cli/command_modules/postgresql/_client_factory.py b/src/azure-cli/azure/cli/command_modules/postgresql/_client_factory.py index 13f553cb25f..7512079c491 100644 --- a/src/azure-cli/azure/cli/command_modules/postgresql/_client_factory.py +++ b/src/azure-cli/azure/cli/command_modules/postgresql/_client_factory.py @@ -117,6 +117,10 @@ def cf_postgres_flexible_tuning_options(cli_ctx, _): return get_postgresql_flexible_management_client(cli_ctx).tuning_options +def cf_postgres_flexible_maintenance_events(cli_ctx, _): + return get_postgresql_flexible_management_client(cli_ctx).maintenance_events + + def resource_client_factory(cli_ctx, subscription_id=None): return get_mgmt_service_client(cli_ctx, ResourceType.MGMT_RESOURCE_RESOURCES, subscription_id=subscription_id) diff --git a/src/azure-cli/azure/cli/command_modules/postgresql/_help.py b/src/azure-cli/azure/cli/command_modules/postgresql/_help.py index f5819398adb..00e7aa64f6c 100644 --- a/src/azure-cli/azure/cli/command_modules/postgresql/_help.py +++ b/src/azure-cli/azure/cli/command_modules/postgresql/_help.py @@ -320,6 +320,45 @@ text: az postgres flexible-server restore --resource-group testgroup --name testservernew --source-server testserver --storage-type PremiumV2_LRS """ +helps['postgres flexible-server maintenance-event'] = """ +type: group +short-summary: Manage maintenance events for PostgreSQL flexible servers. +""" + +helps['postgres flexible-server maintenance-event list'] = """ +type: command +short-summary: List maintenance events for a flexible server. +examples: + - name: List all maintenance events for a server. + text: az postgres flexible-server maintenance-event list --resource-group testgroup --server-name testserver + - name: List only upcoming maintenance events. + text: az postgres flexible-server maintenance-event list --resource-group testgroup --server-name testserver --maintenance-status Upcoming +""" + +helps['postgres flexible-server maintenance-event show'] = """ +type: command +short-summary: Show details of a maintenance event. +examples: + - name: Get a maintenance event by ID. + text: az postgres flexible-server maintenance-event show --resource-group testgroup --server-name testserver --maintenance-event-id XXXX-111 +""" + +helps['postgres flexible-server maintenance-event reschedule'] = """ +type: command +short-summary: Reschedule a maintenance event to a new UTC datetime. +examples: + - name: Reschedule a maintenance event. + text: az postgres flexible-server maintenance-event reschedule --resource-group testgroup --server-name testserver --maintenance-event-id XXXX-111 --start-time 2026-04-10T10:00:00+00:00 +""" + +helps['postgres flexible-server maintenance-event apply-now'] = """ +type: command +short-summary: Apply a maintenance event immediately. +examples: + - name: Apply a maintenance event now. + text: az postgres flexible-server maintenance-event apply-now --resource-group testgroup --server-name testserver --maintenance-event-id XXXX-111 +""" + helps['postgres flexible-server restart'] = """ type: command short-summary: Restart a flexible server. diff --git a/src/azure-cli/azure/cli/command_modules/postgresql/_params.py b/src/azure-cli/azure/cli/command_modules/postgresql/_params.py index a0d7a6678bf..27a7c2921c1 100644 --- a/src/azure-cli/azure/cli/command_modules/postgresql/_params.py +++ b/src/azure-cli/azure/cli/command_modules/postgresql/_params.py @@ -372,6 +372,23 @@ def _flexible_server_params(command_group): help='The read replicas the virtual endpoints point to.' ) + maintenance_event_id_arg_type = CLIArgumentType( + options_list=['--maintenance-event-id'], + id_part='child_name_1', + help='The maintenance event identifier.' + ) + + maintenance_status_arg_type = CLIArgumentType( + options_list=['--maintenance-status'], + arg_type=get_enum_type(['Upcoming', 'Past']), + help='Filter maintenance events by status.' + ) + + start_time_arg_type = CLIArgumentType( + options_list=['--start-time', '-t'], + help='New UTC start time to target rescheduling maintenance (ISO8601 format), e.g., 2026-04-10T10:00:00+00:00.' + ) + with self.argument_context('{} flexible-server'.format(command_group)) as c: c.argument('resource_group_name', arg_type=resource_group_name_type) c.argument('server_name', arg_type=server_name_arg_type) @@ -634,6 +651,20 @@ def _flexible_server_params(command_group): with self.argument_context('{} flexible-server backup delete'.format(command_group)) as c: c.argument('yes', arg_type=yes_arg_type) + # maintenance-event + with self.argument_context('{} flexible-server maintenance-event'.format(command_group)) as c: + c.argument('server_name', arg_type=server_name_resource_arg_type) + + with self.argument_context('{} flexible-server maintenance-event list'.format(command_group)) as c: + c.argument('maintenance_status', arg_type=maintenance_status_arg_type) + + for scope in ['show', 'reschedule', 'apply-now']: + with self.argument_context('{} flexible-server maintenance-event {}'.format(command_group, scope)) as c: + c.argument('maintenance_event_id', arg_type=maintenance_event_id_arg_type) + + with self.argument_context('{} flexible-server maintenance-event reschedule'.format(command_group)) as c: + c.argument('start_time', arg_type=start_time_arg_type, required=True) + # identity with self.argument_context('{} flexible-server identity'.format(command_group)) as c: c.argument('server_name', arg_type=server_name_resource_arg_type) diff --git a/src/azure-cli/azure/cli/command_modules/postgresql/commands/maintenance_event_commands.py b/src/azure-cli/azure/cli/command_modules/postgresql/commands/maintenance_event_commands.py new file mode 100644 index 00000000000..3f2f164b5bd --- /dev/null +++ b/src/azure-cli/azure/cli/command_modules/postgresql/commands/maintenance_event_commands.py @@ -0,0 +1,44 @@ +# -------------------------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for license information. +# -------------------------------------------------------------------------------------------- + +# pylint: disable=unused-argument, line-too-long +from azure.cli.core.util import sdk_no_wait +from ..utils.validators import validate_resource_group + + +def flexible_server_maintenance_event_list(client, resource_group_name, server_name, maintenance_status=None): + validate_resource_group(resource_group_name) + return client.list(resource_group_name=resource_group_name, + server_name=server_name, + maintenance_status=maintenance_status) + + +def flexible_server_maintenance_event_show(client, resource_group_name, server_name, maintenance_event_id): + validate_resource_group(resource_group_name) + return client.get(resource_group_name=resource_group_name, + server_name=server_name, + maintenance_event_id=maintenance_event_id) + + +def flexible_server_maintenance_event_reschedule(client, resource_group_name, server_name, + maintenance_event_id, start_time, no_wait=False): + validate_resource_group(resource_group_name) + body = {"postponeToDateTime": start_time} + return sdk_no_wait(no_wait, + client.begin_reschedule, + resource_group_name=resource_group_name, + server_name=server_name, + maintenance_event_id=maintenance_event_id, + body=body) + + +def flexible_server_maintenance_event_apply_now(client, resource_group_name, server_name, + maintenance_event_id, no_wait=False): + validate_resource_group(resource_group_name) + return sdk_no_wait(no_wait, + client.begin_apply_now, + resource_group_name=resource_group_name, + server_name=server_name, + maintenance_event_id=maintenance_event_id) diff --git a/src/azure-cli/azure/cli/command_modules/postgresql/flexible_server_commands.py b/src/azure-cli/azure/cli/command_modules/postgresql/flexible_server_commands.py index 3bdf3a3a59c..d7efaf899c7 100644 --- a/src/azure-cli/azure/cli/command_modules/postgresql/flexible_server_commands.py +++ b/src/azure-cli/azure/cli/command_modules/postgresql/flexible_server_commands.py @@ -19,7 +19,8 @@ cf_postgres_flexible_virtual_endpoints, cf_postgres_flexible_server_threat_protection_settings, cf_postgres_flexible_advanced_threat_protection_settings, - cf_postgres_flexible_server_log_files) + cf_postgres_flexible_server_log_files, + cf_postgres_flexible_maintenance_events) from azure.cli.command_modules.postgresql.utils.validators import validate_private_endpoint_connection_id from azure.cli.command_modules.postgresql.utils._transformers import ( table_transform_output, @@ -101,6 +102,11 @@ def load_flexibleserver_command_table(self, _): client_factory=cf_postgres_flexible_server_log_files ) + postgres_flexible_maintenance_events_sdk = CliCommandType( + operations_tmpl='azure.mgmt.postgresqlflexibleservers.operations#MaintenanceEventsOperations.{}', + client_factory=cf_postgres_flexible_maintenance_events + ) + postgres_flexible_server_private_endpoint_connections_sdk = CliCommandType( operations_tmpl='azure.mgmt.postgresqlflexibleservers.operations#PrivateEndpointConnectionsOperations.{}', client_factory=cf_postgres_flexible_private_endpoint_connections @@ -290,6 +296,16 @@ def load_flexibleserver_command_table(self, _): g.custom_command('list', 'flexible_server_list_log_files_with_filter') g.custom_command('download', 'flexible_server_download_log_files') + maintenance_event_commands = CliCommandType( + operations_tmpl='azure.cli.command_modules.postgresql.commands.maintenance_event_commands#{}') + with self.command_group('postgres flexible-server maintenance-event', postgres_flexible_maintenance_events_sdk, + custom_command_type=maintenance_event_commands, + client_factory=cf_postgres_flexible_maintenance_events) as g: + g.custom_command('list', 'flexible_server_maintenance_event_list') + g.custom_command('show', 'flexible_server_maintenance_event_show') + g.custom_command('reschedule', 'flexible_server_maintenance_event_reschedule', supports_no_wait=True) + g.custom_command('apply-now', 'flexible_server_maintenance_event_apply_now', supports_no_wait=True) + private_endpoint_commands = CliCommandType( operations_tmpl='azure.cli.command_modules.postgresql.commands.private_endpoint_commands#{}') with self.command_group('postgres flexible-server private-endpoint-connection', postgres_flexible_server_private_endpoint_connections_sdk,