Skip to content
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------

from azure.cli.core.breaking_change import register_argument_deprecate
from azure.cli.core.breaking_change import register_argument_deprecate, register_command_group_deprecate

register_argument_deprecate('postgres flexible-server create', '--high-availability', redirect='--zonal-resiliency')
register_argument_deprecate('postgres flexible-server update', '--high-availability', redirect='--zonal-resiliency')
register_command_group_deprecate(command_group='postgres flexible-server index-tuning',
redirect='postgres flexible-server autonomous-tuning',
message='Index tuning feature has now expanded its capabilities to support '
'other automatically generated recommendations which are covered by the '
'new command.')
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def _postgres_parse_list_capability(result, is_offer_restriction_check_required=
restricted = offer_restricted[0].status if offer_restricted else None
zone_redundant = [feature for feature in supported_features if feature.name == "ZoneRedundantHa"]
geo_backup = [feature for feature in supported_features if feature.name == "GeoBackup"]
index_tuning = [feature for feature in supported_features if feature.name == "IndexTuning"]
autonomous_tuning = [feature for feature in supported_features if feature.name == "IndexTuning"]

if restricted == "Enabled" and not is_offer_restriction_check_required:
raise InvalidArgumentValueError("The location is restricted for provisioning of flexible servers. Please try using another region.")
Expand All @@ -63,7 +63,7 @@ def _postgres_parse_list_capability(result, is_offer_restriction_check_required=

single_az = zone_redundant[0].status != "Enabled" if zone_redundant else True
geo_backup_supported = geo_backup[0].status == "Enabled" if geo_backup else False
index_tuning_supported = index_tuning[0].status == "Enabled" if index_tuning else False
autonomous_tuning_supported = autonomous_tuning[0].status == "Enabled" if autonomous_tuning else False

tiers = result[0].supported_server_editions
tiers_dict = {}
Expand Down Expand Up @@ -112,7 +112,7 @@ def _postgres_parse_list_capability(result, is_offer_restriction_check_required=
'zones': zones,
'server_versions': versions,
'supported_server_versions': supported_server_versions,
'index_tuning_supported': index_tuning_supported
'autonomous_tuning_supported': autonomous_tuning_supported
}


Expand Down
63 changes: 63 additions & 0 deletions src/azure-cli/azure/cli/command_modules/rdbms/_helptext_pg.py
Original file line number Diff line number Diff line change
Expand Up @@ -1225,3 +1225,66 @@
- name: Get tuning index recommendations for a PostgreSQL flexible server. Filter by selected type.
text: az postgres flexible-server index-tuning list-recommendations -g testgroup -s testsvr --recommendation-type CreateIndex
"""

helps['postgres flexible-server autonomous-tuning'] = """
type: group
short-summary: Autonomous tuning analyzes read queries captured in query store and recommends operations on tables or index changes to optimize these queries.
"""

helps['postgres flexible-server autonomous-tuning update'] = """
type: command
short-summary: Update autonomous tuning to be enabled/disabled for a PostgreSQL flexible server.
examples:
- name: Update autonomous tuning to be enabled for a PostgreSQL flexible server.
text: az postgres flexible-server autonomous-tuning update -g testgroup -s testsvr --enabled True
- name: Update autonomous tuning to be disabled for a PostgreSQL flexible server.
text: az postgres flexible-server autonomous-tuning update -g testgroup -s testsvr --enabled False
"""

helps['postgres flexible-server autonomous-tuning show'] = """
type: command
short-summary: Show state of autonomous tuning for a PostgreSQL flexible server.
examples:
- name: Show state of autonomous tuning for a PostgreSQL flexible server.
text: az postgres flexible-server autonomous-tuning show -g testgroup -s testsvr
"""

helps['postgres flexible-server autonomous-tuning list-settings'] = """
type: command
short-summary: Get autonomous tuning settings associated to a PostgreSQL flexible server.
examples:
- name: Get autonomous tuning settings for a PostgreSQL flexible server.
text: az postgres flexible-server autonomous-tuning list-settings -g testgroup -s testsvr
"""

helps['postgres flexible-server autonomous-tuning show-settings'] = """
type: command
short-summary: Get an autonomous tuning setting for a PostgreSQL flexible server.
examples:
- name: Get an autonomous tuning setting for a PostgreSQL flexible server.
text: az postgres flexible-server autonomous-tuning show-settings -g testgroup -s testsvr --name setting-name
"""

helps['postgres flexible-server autonomous-tuning set-settings'] = """
type: command
short-summary: Update an autonomous tuning setting for a PostgreSQL flexible server.
examples:
- name: Update an autonomous tuning setting for a PostgreSQL flexible server.
text: az postgres flexible-server autonomous-tuning set-settings -g testgroup -s testsvr --name setting-name --value setting-value
"""

helps['postgres flexible-server autonomous-tuning list-index-recommendations'] = """
type: command
short-summary: Get available autonomous tuning index recommendations associated with a PostgreSQL flexible server.
examples:
- name: Get autonomous tuning index recommendations for a PostgreSQL flexible server. Filter by selected type.
text: az postgres flexible-server autonomous-tuning list-index-recommendations -g testgroup -s testsvr --recommendation-type CreateIndex
"""

helps['postgres flexible-server autonomous-tuning list-table-recommendations'] = """
type: command
short-summary: Get available autonomous tuning table recommendations associated with a PostgreSQL flexible server.
examples:
- name: Get autonomous tuning table recommendations for a PostgreSQL flexible server. Filter by selected type.
text: az postgres flexible-server autonomous-tuning list-table-recommendations -g testgroup -s testsvr --recommendation-type AnalyzeTable
"""
43 changes: 40 additions & 3 deletions src/azure-cli/azure/cli/command_modules/rdbms/_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
from .randomname.generate import generate_username
from ._flexible_server_util import get_current_time
from argcomplete.completers import FilesCompleter
from ._util import get_index_tuning_settings_map
from ._util import get_autonomous_tuning_settings_map


def load_arguments(self, _): # pylint: disable=too-many-statements, too-many-locals
Expand Down Expand Up @@ -1077,19 +1077,56 @@ def _flexible_server_params(command_group):
c.argument('recommendation_type',
options_list=['--recommendation-type', '-r'],
help='Retrieve recommendations based on type.',
arg_type=get_enum_type(['CreateIndex', 'DropIndex']))
arg_type=get_enum_type(['CreateIndex', 'DropIndex', 'ReIndex']))

for scope in ['show-settings', 'set-settings']:
argument_context_string = '{} flexible-server index-tuning {}'.format(command_group, scope)
with self.argument_context(argument_context_string) as c:
c.argument('setting_name', options_list=['--name', '-n'], required=True,
arg_type=get_enum_type(get_index_tuning_settings_map().keys()),
arg_type=get_enum_type(get_autonomous_tuning_settings_map().keys()),
help='The name of the tuning setting.')

with self.argument_context('{} flexible-server index-tuning set-settings'.format(command_group)) as c:
c.argument('value', options_list=['--value', '-v'],
help='Value of the tuning setting.')

# autonomous tuning
if command_group == 'postgres':
for scope in ['update', 'show', 'list-settings', 'show-settings', 'set-settings', 'list-table-recommendations', 'list-index-recommendations']:
argument_context_string = '{} flexible-server autonomous-tuning {}'.format(command_group, scope)
with self.argument_context(argument_context_string) as c:
c.argument('server_name', options_list=['--server-name', '-s'], arg_type=server_name_arg_type)

with self.argument_context('{} flexible-server autonomous-tuning update'.format(command_group)) as c:
c.argument('autonomous_tuning_enabled',
options_list=['--enabled'],
required=True,
help='Enable or disable autonomous tuning feature.',
arg_type=get_enum_type(['True', 'False']))

with self.argument_context('{} flexible-server autonomous-tuning list-index-recommendations'.format(command_group)) as c:
c.argument('recommendation_type',
options_list=['--recommendation-type', '-r'],
help='Retrieve recommendations based on type.',
arg_type=get_enum_type(['CreateIndex', 'DropIndex', 'ReIndex']))

with self.argument_context('{} flexible-server autonomous-tuning list-table-recommendations'.format(command_group)) as c:
c.argument('recommendation_type',
options_list=['--recommendation-type', '-r'],
help='Retrieve recommendations based on type.',
arg_type=get_enum_type(['AnalyzeTable', 'VacuumTable']))

for scope in ['show-settings', 'set-settings']:
argument_context_string = '{} flexible-server autonomous-tuning {}'.format(command_group, scope)
with self.argument_context(argument_context_string) as c:
c.argument('setting_name', options_list=['--name', '-n'], required=True,
arg_type=get_enum_type(get_autonomous_tuning_settings_map().keys()),
help='The name of the tuning setting.')

with self.argument_context('{} flexible-server autonomous-tuning set-settings'.format(command_group)) as c:
c.argument('value', options_list=['--value', '-v'],
help='Value of the tuning setting.')

# GTID
if command_group == 'mysql':
with self.argument_context('{} flexible-server gtid reset'.format(command_group)) as c:
Expand Down
2 changes: 1 addition & 1 deletion src/azure-cli/azure/cli/command_modules/rdbms/_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ def call(*args, **kwargs):
return decorate


def get_index_tuning_settings_map():
def get_autonomous_tuning_settings_map():
return {
'analysis_interval': 'index_tuning.analysis_interval',
'max_columns_per_index': 'index_tuning.max_columns_per_index',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -296,4 +296,14 @@ def load_flexibleserver_command_table(self, _):
g.custom_command('list-settings', 'index_tuning_settings_list', custom_command_type=flexible_servers_custom_postgres)
g.custom_command('show-settings', 'index_tuning_settings_get', custom_command_type=flexible_servers_custom_postgres)
g.custom_command('set-settings', 'index_tuning_settings_set', custom_command_type=flexible_servers_custom_postgres)
g.custom_command('list-recommendations', 'recommendations_list', custom_command_type=flexible_servers_custom_postgres)
g.custom_command('list-recommendations', 'index_tuning_recommendations_list', custom_command_type=flexible_servers_custom_postgres)

with self.command_group('postgres flexible-server autonomous-tuning', postgres_flexible_config_sdk,
client_factory=cf_postgres_flexible_config) as g:
g.custom_command('update', 'autonomous_tuning_update', custom_command_type=flexible_servers_custom_postgres)
g.custom_show_command('show', 'autonomous_tuning_show', custom_command_type=flexible_servers_custom_postgres)
g.custom_command('list-settings', 'autonomous_tuning_settings_list', custom_command_type=flexible_servers_custom_postgres)
g.custom_command('show-settings', 'autonomous_tuning_settings_get', custom_command_type=flexible_servers_custom_postgres)
g.custom_command('set-settings', 'autonomous_tuning_settings_set', custom_command_type=flexible_servers_custom_postgres)
g.custom_command('list-table-recommendations', 'autonomous_tuning_table_recommendations_list', custom_command_type=flexible_servers_custom_postgres)
g.custom_command('list-index-recommendations', 'autonomous_tuning_index_recommendations_list', custom_command_type=flexible_servers_custom_postgres)
Loading
Loading