Skip to content

Commit

Permalink
{RDBMS} az postgres flexible-server create: Sort version number, sk…
Browse files Browse the repository at this point in the history
…u name when displaying the error message (#30549)

* {RDBMS} az postgres flexible-server create: Sort the version number when displaying the error message

* sort sku-name error output

---------

Co-authored-by: Matthew Boentoro <mboentoro@microsoft.com>
  • Loading branch information
mattboentoro and Matthew Boentoro authored Dec 25, 2024
1 parent 658d77b commit 4099a1d
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/azure-cli/azure/cli/command_modules/rdbms/validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------
from dateutil import parser
from functools import cmp_to_key
import re
from knack.prompting import prompt_pass, NoTTYException
from knack.util import CLIError
Expand Down Expand Up @@ -451,6 +452,16 @@ def _pg_tier_validator(tier, sku_info):
raise CLIError('Incorrect value for --tier. Allowed values : {}'.format(tiers))


def compare_sku_names(sku_1, sku_2):
regex_pattern = r"_v(\d)"

sku_1_match = re.search(regex_pattern, sku_1)
sku_2_match = re.search(regex_pattern, sku_2)

return (int(sku_2_match.group(1)) if sku_2_match else 0) - \
(int(sku_1_match.group(1)) if sku_1_match else 0)


def _pg_sku_name_validator(sku_name, sku_info, tier, instance):
if instance is not None:
tier = instance.sku.tier if tier is None else tier
Expand All @@ -459,7 +470,7 @@ def _pg_sku_name_validator(sku_name, sku_info, tier, instance):
if sku_name.lower() not in skus:
raise CLIError('Incorrect value for --sku-name. The SKU name does not match {} tier. '
'Specify --tier if you did not. Or CLI will set GeneralPurpose as the default tier. '
'Allowed values : {}'.format(tier, skus))
'Allowed values : {}'.format(tier, sorted(skus, key=cmp_to_key(compare_sku_names))))


def _pg_storage_performance_tier_validator(performance_tier, sku_info, tier=None, storage_size=None):
Expand All @@ -482,7 +493,7 @@ def _pg_storage_performance_tier_validator(performance_tier, sku_info, tier=None
def _pg_version_validator(version, versions, is_create):
if version:
if version not in versions:
raise CLIError('Incorrect value for --version. Allowed values : {}'.format(versions))
raise CLIError('Incorrect value for --version. Allowed values : {}'.format(sorted(versions)))
if version == '12':
logger.warning("Support for PostgreSQL 12 has officially ended. As a result, "
"the option to select version 12 will be removed in the near future. "
Expand Down

0 comments on commit 4099a1d

Please sign in to comment.