Skip to content

Commit

Permalink
[SQL] az sql failover-group create/update: Add parameter `--seconda…
Browse files Browse the repository at this point in the history
…ry-type` to support creation of geo/standby replica on partner server (#30060)

* enable secondary type for failover group

* add test case to check secondary-type

* fix build errors

* remove breaking change
  • Loading branch information
saljain0101 authored Oct 24, 2024
1 parent ee10466 commit 8dfb199
Show file tree
Hide file tree
Showing 4 changed files with 5,050 additions and 926 deletions.
5 changes: 4 additions & 1 deletion src/azure-cli/azure/cli/command_modules/sql/_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@
SqlServerMinimalTlsVersionType,
SqlManagedInstanceMinimalTlsVersionType,
AuthenticationType,
FreeLimitExhaustionBehavior
FreeLimitExhaustionBehavior,
FailoverGroupDatabasesSecondaryType
)

from ._validators import (
Expand Down Expand Up @@ -1719,6 +1720,8 @@ def _configure_security_policy_storage_params(arg_ctx):
arg_type=allow_data_loss_param_type)
c.argument('try_planned_before_forced_failover',
arg_type=try_planned_before_forced_failover_param_type)
c.argument('secondary_type', help="Databases secondary type on partner server",
arg_type=get_enum_type(FailoverGroupDatabasesSecondaryType))

###############################################
# sql instance pool #
Expand Down
31 changes: 23 additions & 8 deletions src/azure-cli/azure/cli/command_modules/sql/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -643,6 +643,11 @@ class FailoverPolicyType(Enum):
manual = 'Manual'


class FailoverGroupDatabasesSecondaryType(Enum):
geo = 'Geo'
standby = 'Standby'


class SqlServerMinimalTlsVersionType(Enum):
tls_1_0 = "1.0"
tls_1_1 = "1.1"
Expand Down Expand Up @@ -6425,6 +6430,7 @@ def failover_group_create(
server_name,
failover_group_name,
partner_server,
secondary_type=None,
partner_resource_group=None,
failover_policy=FailoverPolicyType.automatic.value,
grace_period=1,
Expand Down Expand Up @@ -6461,25 +6467,32 @@ def failover_group_create(
add_db,
[])

failover_group_params = FailoverGroup(
partner_servers=[partner_server],
databases=databases,
read_write_endpoint=FailoverGroupReadWriteEndpoint(
failover_policy=failover_policy,
failover_with_data_loss_grace_period_minutes=grace_period),
read_only_endpoint=FailoverGroupReadOnlyEndpoint(
failover_policy="Disabled")
)

if secondary_type is not None:
failover_group_params.secondary_type = secondary_type

return client.begin_create_or_update(
resource_group_name=resource_group_name,
server_name=server_name,
failover_group_name=failover_group_name,
parameters=FailoverGroup(
partner_servers=[partner_server],
databases=databases,
read_write_endpoint=FailoverGroupReadWriteEndpoint(
failover_policy=failover_policy,
failover_with_data_loss_grace_period_minutes=grace_period),
read_only_endpoint=FailoverGroupReadOnlyEndpoint(
failover_policy="Disabled")))
parameters=failover_group_params)


def failover_group_update(
cmd,
instance,
resource_group_name,
server_name,
secondary_type=None,
failover_policy=None,
grace_period=None,
add_db=None,
Expand Down Expand Up @@ -6508,6 +6521,8 @@ def failover_group_update(
remove_db)

instance.databases = databases
if secondary_type is not None:
instance.secondary_type = secondary_type

return instance

Expand Down
Loading

0 comments on commit 8dfb199

Please sign in to comment.