Skip to content

Commit

Permalink
[SQL] az sql db create/update: Add --use-free-limit and `--free-l…
Browse files Browse the repository at this point in the history
…imit-exhaustion-behavior` arguments (#27553)

* Add free limit parameters to Database create and update

* Add test for free limit params and fix db update logic

* Fix pylint issues

* Fix test and lint errors

* Add abreviated parameter version for free-limit-exhaustion-behavior

* Fix type

* Fix remaining linter errors

* trigger checks
  • Loading branch information
mykolian committed Oct 18, 2023
1 parent f9a4685 commit 3209b95
Show file tree
Hide file tree
Showing 5 changed files with 3,242 additions and 7 deletions.
4 changes: 4 additions & 0 deletions src/azure-cli/azure/cli/command_modules/sql/_help.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,8 @@
text: az sql db create -g mygroup -s myserver -n mydb -e GeneralPurpose --backup-storage-redundancy Local
- name: Create a database with VBS enclave enabled.
text: az sql db create -g mygroup -s myserver -n mydb --preferred-enclave-type VBS
- name: Create a database with free limit applied
text: az sql db create -g mygroup -s myserver -n mydb -e GeneralPurpose -f Gen5 -c 2 --compute-model Serverless --use-free-limit --free-limit-exhaustion-behavior AutoPause
"""

helps['sql db delete'] = """
Expand Down Expand Up @@ -535,6 +537,8 @@
text: az sql db update -g mygroup -s myserver -n mydb --backup-storage-redundancy Local
- name: Update database with VBS enclave enabled.
text: az sql db update -g mygroup -s myserver -n mydb --preferred-enclave-type VBS
- name: Update exhaustion behavior of free limit database to BillOverUsage
text: az sql db update -g mygroup -s myserver -n mydb --free-limit-exhaustion-behavior BillOverUsage
"""

Expand Down
41 changes: 38 additions & 3 deletions src/azure-cli/azure/cli/command_modules/sql/_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@
ServicePrincipalType,
SqlServerMinimalTlsVersionType,
SqlManagedInstanceMinimalTlsVersionType,
AuthenticationType
AuthenticationType,
FreeLimitExhaustionBehavior
)

from ._validators import (
Expand Down Expand Up @@ -260,6 +261,19 @@ def get_location_type_with_default_from_resource_group(cli_ctx):
options_list=['--availability-zone'],
help='Availability zone')

database_use_free_limit = CLIArgumentType(
options_list=['--use-free-limit', '--free-limit'],
help='Whether or not the database uses free monthly limits. Allowed on one database in a subscription.',
arg_type=get_three_state_flag())

database_free_limit_exhaustion_behavior = CLIArgumentType(
options_list=['--free-limit-exhaustion-behavior', '--exhaustion-behavior', '--fleb'],
help='Specifies the behavior when monthly free limits are exhausted for the free database.'
'AutoPause: The database will be auto paused upon exhaustion of free limits for remainder of the month.'
'BillForUsage: The database will continue to be online upon exhaustion of free limits'
'and any overage will be billed.',
arg_type=get_enum_type(FreeLimitExhaustionBehavior))

managed_instance_param_type = CLIArgumentType(
options_list=['--managed-instance', '--mi'],
help='Name of the Azure SQL Managed Instance.')
Expand Down Expand Up @@ -382,7 +396,7 @@ def get_location_type_with_default_from_resource_group(cli_ctx):
help='The name of the event hub. If none is specified '
'when providing event_hub_authorization_rule_id, the default event hub will be selected.')

db_service_objective_examples = 'Basic, S0, P1, GP_Gen4_1, GP_Gen5_S_8, BC_Gen5_2, HS_Gen5_32.'
db_service_objective_examples = 'Basic, S0, P1, GP_Gen4_1, GP_S_Gen5_8, BC_Gen5_2, HS_Gen5_32.'
dw_service_objective_examples = 'DW100, DW1000c'


Expand Down Expand Up @@ -486,6 +500,12 @@ def _configure_db_dw_params(arg_ctx):
arg_ctx.argument('availability_zone',
arg_type=database_availability_zone_param_type)

arg_ctx.argument('use_free_limit',
arg_type=database_use_free_limit)

arg_ctx.argument('free_limit_exhaustion_behavior',
arg_type=database_free_limit_exhaustion_behavior)

arg_ctx.argument('encryption_protector_auto_rotation',
arg_type=database_encryption_protector_auto_rotation_param_type)

Expand Down Expand Up @@ -589,7 +609,9 @@ def _configure_db_dw_create_params(
'user_assigned_identity_id',
'federated_client_id',
'availability_zone',
'encryption_protector_auto_rotation'
'encryption_protector_auto_rotation',
'use_free_limit',
'free_limit_exhaustion_behavior'
])

# Create args that will be used to build up the Database's Sku object
Expand Down Expand Up @@ -651,6 +673,8 @@ def _configure_db_dw_create_params(
arg_ctx.ignore('catalog_collation')
arg_ctx.ignore('maintenance_configuration_id')
arg_ctx.ignore('is_ledger_on')
arg_ctx.ignore('use_free_limit')
arg_ctx.ignore('free_limit_exhaustion_behavior')

# Only applicable to point in time restore or deleted restore create mode.
if create_mode not in [CreateMode.restore, CreateMode.point_in_time_restore]:
Expand Down Expand Up @@ -712,11 +736,16 @@ def _configure_db_dw_create_params(
arg_ctx.ignore('min_capacity')
arg_ctx.ignore('compute_model')

# Free limit parameters are not applicable to DataWarehouse
arg_ctx.ignore('use_free_limit')
arg_ctx.ignore('free_limit_exhaustion_behavior')

# ReadScale properties are not valid for DataWarehouse
# --read-replica-count was accidentally included in previous releases and
# therefore is hidden using `deprecate_info` instead of `ignore`
arg_ctx.ignore('read_scale')
arg_ctx.ignore('high_availability_replica_count')

arg_ctx.argument('read_replica_count',
options_list=['--read-replica-count'],
deprecate_info=arg_ctx.deprecate(hide=True))
Expand Down Expand Up @@ -905,6 +934,12 @@ def load_arguments(self, _):
c.argument('availability_zone',
arg_type=database_availability_zone_param_type)

c.argument('use_free_limit',
arg_type=database_use_free_limit)

c.argument('free_limit_exhaustion_behavior',
arg_type=database_free_limit_exhaustion_behavior)

with self.argument_context('sql db export') as c:
# Create args that will be used to build up the ExportDatabaseDefinition object
create_args_for_complex_type(
Expand Down
20 changes: 16 additions & 4 deletions src/azure-cli/azure/cli/command_modules/sql/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -677,6 +677,11 @@ class ComputeModelType(str, Enum):
serverless = "Serverless"


class FreeLimitExhaustionBehavior(str, Enum):
auto_pause = "AutoPause"
bill_over_usage = "BillOverUsage"


class AlwaysEncryptedEnclaveType(str, Enum):

default = "Default"
Expand Down Expand Up @@ -1729,7 +1734,9 @@ def db_update( # pylint: disable=too-many-locals
encryption_protector=None,
federated_client_id=None,
keys_to_remove=None,
encryption_protector_auto_rotation=None):
encryption_protector_auto_rotation=None,
use_free_limit=None,
free_limit_exhaustion_behavior=None):
'''
Applies requested parameters to a db resource instance for a DB update.
'''
Expand Down Expand Up @@ -1834,9 +1841,8 @@ def db_update( # pylint: disable=too-many-locals
#####
# Per DB CMK properties
#####
if assign_identity:
if user_assigned_identity_id is not None:
instance.identity = _get_database_identity(user_assigned_identity_id)
if assign_identity and (user_assigned_identity_id is not None):
instance.identity = _get_database_identity(user_assigned_identity_id)

if keys is not None or keys_to_remove is not None:
instance.keys = _get_database_keys_for_update(keys, keys_to_remove)
Expand All @@ -1852,6 +1858,12 @@ def db_update( # pylint: disable=too-many-locals
if encryption_protector_auto_rotation is not None:
instance.encryption_protector_auto_rotation = encryption_protector_auto_rotation

if use_free_limit is not None:
instance.use_free_limit = use_free_limit

if free_limit_exhaustion_behavior:
instance.free_limit_exhaustion_behavior = free_limit_exhaustion_behavior

return instance


Expand Down

0 comments on commit 3209b95

Please sign in to comment.