Skip to content

Commit 3209b95

Browse files
authored
[SQL] az sql db create/update: Add --use-free-limit and --free-limit-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
1 parent f9a4685 commit 3209b95

File tree

5 files changed

+3242
-7
lines changed

5 files changed

+3242
-7
lines changed

src/azure-cli/azure/cli/command_modules/sql/_help.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,8 @@
129129
text: az sql db create -g mygroup -s myserver -n mydb -e GeneralPurpose --backup-storage-redundancy Local
130130
- name: Create a database with VBS enclave enabled.
131131
text: az sql db create -g mygroup -s myserver -n mydb --preferred-enclave-type VBS
132+
- name: Create a database with free limit applied
133+
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
132134
"""
133135

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

src/azure-cli/azure/cli/command_modules/sql/_params.py

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,8 @@
6161
ServicePrincipalType,
6262
SqlServerMinimalTlsVersionType,
6363
SqlManagedInstanceMinimalTlsVersionType,
64-
AuthenticationType
64+
AuthenticationType,
65+
FreeLimitExhaustionBehavior
6566
)
6667

6768
from ._validators import (
@@ -260,6 +261,19 @@ def get_location_type_with_default_from_resource_group(cli_ctx):
260261
options_list=['--availability-zone'],
261262
help='Availability zone')
262263

264+
database_use_free_limit = CLIArgumentType(
265+
options_list=['--use-free-limit', '--free-limit'],
266+
help='Whether or not the database uses free monthly limits. Allowed on one database in a subscription.',
267+
arg_type=get_three_state_flag())
268+
269+
database_free_limit_exhaustion_behavior = CLIArgumentType(
270+
options_list=['--free-limit-exhaustion-behavior', '--exhaustion-behavior', '--fleb'],
271+
help='Specifies the behavior when monthly free limits are exhausted for the free database.'
272+
'AutoPause: The database will be auto paused upon exhaustion of free limits for remainder of the month.'
273+
'BillForUsage: The database will continue to be online upon exhaustion of free limits'
274+
'and any overage will be billed.',
275+
arg_type=get_enum_type(FreeLimitExhaustionBehavior))
276+
263277
managed_instance_param_type = CLIArgumentType(
264278
options_list=['--managed-instance', '--mi'],
265279
help='Name of the Azure SQL Managed Instance.')
@@ -382,7 +396,7 @@ def get_location_type_with_default_from_resource_group(cli_ctx):
382396
help='The name of the event hub. If none is specified '
383397
'when providing event_hub_authorization_rule_id, the default event hub will be selected.')
384398

385-
db_service_objective_examples = 'Basic, S0, P1, GP_Gen4_1, GP_Gen5_S_8, BC_Gen5_2, HS_Gen5_32.'
399+
db_service_objective_examples = 'Basic, S0, P1, GP_Gen4_1, GP_S_Gen5_8, BC_Gen5_2, HS_Gen5_32.'
386400
dw_service_objective_examples = 'DW100, DW1000c'
387401

388402

@@ -486,6 +500,12 @@ def _configure_db_dw_params(arg_ctx):
486500
arg_ctx.argument('availability_zone',
487501
arg_type=database_availability_zone_param_type)
488502

503+
arg_ctx.argument('use_free_limit',
504+
arg_type=database_use_free_limit)
505+
506+
arg_ctx.argument('free_limit_exhaustion_behavior',
507+
arg_type=database_free_limit_exhaustion_behavior)
508+
489509
arg_ctx.argument('encryption_protector_auto_rotation',
490510
arg_type=database_encryption_protector_auto_rotation_param_type)
491511

@@ -589,7 +609,9 @@ def _configure_db_dw_create_params(
589609
'user_assigned_identity_id',
590610
'federated_client_id',
591611
'availability_zone',
592-
'encryption_protector_auto_rotation'
612+
'encryption_protector_auto_rotation',
613+
'use_free_limit',
614+
'free_limit_exhaustion_behavior'
593615
])
594616

595617
# Create args that will be used to build up the Database's Sku object
@@ -651,6 +673,8 @@ def _configure_db_dw_create_params(
651673
arg_ctx.ignore('catalog_collation')
652674
arg_ctx.ignore('maintenance_configuration_id')
653675
arg_ctx.ignore('is_ledger_on')
676+
arg_ctx.ignore('use_free_limit')
677+
arg_ctx.ignore('free_limit_exhaustion_behavior')
654678

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

739+
# Free limit parameters are not applicable to DataWarehouse
740+
arg_ctx.ignore('use_free_limit')
741+
arg_ctx.ignore('free_limit_exhaustion_behavior')
742+
715743
# ReadScale properties are not valid for DataWarehouse
716744
# --read-replica-count was accidentally included in previous releases and
717745
# therefore is hidden using `deprecate_info` instead of `ignore`
718746
arg_ctx.ignore('read_scale')
719747
arg_ctx.ignore('high_availability_replica_count')
748+
720749
arg_ctx.argument('read_replica_count',
721750
options_list=['--read-replica-count'],
722751
deprecate_info=arg_ctx.deprecate(hide=True))
@@ -905,6 +934,12 @@ def load_arguments(self, _):
905934
c.argument('availability_zone',
906935
arg_type=database_availability_zone_param_type)
907936

937+
c.argument('use_free_limit',
938+
arg_type=database_use_free_limit)
939+
940+
c.argument('free_limit_exhaustion_behavior',
941+
arg_type=database_free_limit_exhaustion_behavior)
942+
908943
with self.argument_context('sql db export') as c:
909944
# Create args that will be used to build up the ExportDatabaseDefinition object
910945
create_args_for_complex_type(

src/azure-cli/azure/cli/command_modules/sql/custom.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -677,6 +677,11 @@ class ComputeModelType(str, Enum):
677677
serverless = "Serverless"
678678

679679

680+
class FreeLimitExhaustionBehavior(str, Enum):
681+
auto_pause = "AutoPause"
682+
bill_over_usage = "BillOverUsage"
683+
684+
680685
class AlwaysEncryptedEnclaveType(str, Enum):
681686

682687
default = "Default"
@@ -1729,7 +1734,9 @@ def db_update( # pylint: disable=too-many-locals
17291734
encryption_protector=None,
17301735
federated_client_id=None,
17311736
keys_to_remove=None,
1732-
encryption_protector_auto_rotation=None):
1737+
encryption_protector_auto_rotation=None,
1738+
use_free_limit=None,
1739+
free_limit_exhaustion_behavior=None):
17331740
'''
17341741
Applies requested parameters to a db resource instance for a DB update.
17351742
'''
@@ -1834,9 +1841,8 @@ def db_update( # pylint: disable=too-many-locals
18341841
#####
18351842
# Per DB CMK properties
18361843
#####
1837-
if assign_identity:
1838-
if user_assigned_identity_id is not None:
1839-
instance.identity = _get_database_identity(user_assigned_identity_id)
1844+
if assign_identity and (user_assigned_identity_id is not None):
1845+
instance.identity = _get_database_identity(user_assigned_identity_id)
18401846

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

1861+
if use_free_limit is not None:
1862+
instance.use_free_limit = use_free_limit
1863+
1864+
if free_limit_exhaustion_behavior:
1865+
instance.free_limit_exhaustion_behavior = free_limit_exhaustion_behavior
1866+
18551867
return instance
18561868

18571869

0 commit comments

Comments
 (0)