Skip to content

Commit ac2828a

Browse files
mattboentoroMatthew Boentoro
andauthored
[RDBMS] az postgres flexible-server create: Change database name field's default value to None (#32587)
Co-authored-by: Matthew Boentoro <mboentoro@microsoft.com>
1 parent 2a6319e commit ac2828a

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

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

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
get_enum_type, file_type,
1515
resource_group_name_type,
1616
get_three_state_flag)
17-
from azure.cli.command_modules.rdbms.validators import configuration_value_validator, validate_subnet, \
17+
from azure.cli.command_modules.rdbms.validators import configuration_value_validator, db_renaming_cluster_validator, validate_subnet, \
1818
tls_validator, public_access_validator, maintenance_window_validator, ip_address_validator, \
1919
retention_validator, validate_identity, validate_byok_identity, validate_identities, \
2020
virtual_endpoint_name_validator, node_count_validator, postgres_firewall_rule_name_validator
@@ -285,6 +285,16 @@ def _flexible_server_params(command_group):
285285
actions=[LocalContextAction.GET, LocalContextAction.SET],
286286
scopes=['{} flexible-server'.format(command_group)]))
287287

288+
database_name_arg_type_cluster = CLIArgumentType(
289+
metavar='NAME',
290+
options_list=['--database-name', '-d'],
291+
help='The default database name for an elastic cluster. Only applicable when --cluster-option is set to ElasticCluster.',
292+
local_context_attribute=LocalContextAttribute(
293+
name='database_name',
294+
actions=[LocalContextAction.GET, LocalContextAction.SET],
295+
scopes=['{} flexible-server'.format(command_group)]),
296+
validator=db_renaming_cluster_validator)
297+
288298
tier_arg_type = CLIArgumentType(
289299
options_list=['--tier'],
290300
help='Compute tier of the server. Accepted values: Burstable, GeneralPurpose, MemoryOptimized '
@@ -628,7 +638,7 @@ def _flexible_server_params(command_group):
628638
c.argument('cluster_size', default=None, arg_type=create_node_count_arg_type)
629639
c.argument('zonal_resiliency', arg_type=zonal_resiliency_arg_type, default="Disabled")
630640
c.argument('allow_same_zone', arg_type=allow_same_zone_arg_type, default=False)
631-
c.argument('database_name', arg_type=database_name_create_arg_type)
641+
c.argument('database_name', default=None, arg_type=database_name_arg_type_cluster)
632642
elif command_group == 'mysql':
633643
c.argument('tier', default='Burstable', arg_type=tier_arg_type)
634644
c.argument('sku_name', default='Standard_B1ms', arg_type=sku_name_arg_type)

src/azure-cli/azure/cli/command_modules/rdbms/validators.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,12 @@ def node_count_validator(ns):
101101
raise CLIError('incorrect usage: --node-count. Range is 1 to 10 for an elastic cluster.')
102102

103103

104+
def db_renaming_cluster_validator(ns):
105+
if ns.database_name is not None and ns.create_cluster != 'ElasticCluster':
106+
raise ArgumentUsageError('incorrect usage: --database-name can only be '
107+
'used when --cluster-option is set to ElasticCluster.')
108+
109+
104110
# Validates if a subnet id or name have been given by the user. If subnet id is given, vnet-name should not be provided.
105111
def validate_subnet(cmd, namespace):
106112

0 commit comments

Comments
 (0)