Skip to content

Commit

Permalink
Added zone redundant parameter to CLI commands (#5560)
Browse files Browse the repository at this point in the history
* Add support for zone redundancy for databases and elastic pools
  • Loading branch information
emgu-ms authored and troydai committed Feb 21, 2018
1 parent a23636d commit 69d6e0b
Show file tree
Hide file tree
Showing 10 changed files with 4,008 additions and 576 deletions.
3 changes: 3 additions & 0 deletions src/command_modules/azure-cli-sql/HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
Release History
===============
2.0.22
++++++
* Added zone redundancy support for databases and elastic pools on creation and update.

2.0.21
++++++
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@
helps['sql db create'] = """
type: command
short-summary: Create a database.
examples:
- name: Create database with zone redundancy enabled
text: az sql db create -g mygroup -s myserver -n mydb -z
- name: Create database with zone redundancy explicitly disabled
text: az sql db create -g mygroup -s myserver -n mydb -z false
"""
helps['sql db delete'] = """
type: command
Expand Down Expand Up @@ -60,6 +65,11 @@
helps['sql db update'] = """
type: command
short-summary: Update a database.
examples:
- name: Update database with zone redundancy enabled
text: az sql db update -g mygroup -s myserver -n mypool -z
- name: Update database with zone redundancy explicitly disabled
text: az sql db update -g mygroup -s myserver -n mypool -z false
"""
helps['sql db audit-policy'] = """
type: group
Expand Down Expand Up @@ -245,6 +255,11 @@
helps['sql elastic-pool create'] = """
type: command
short-summary: Create an elastic pool.
examples:
- name: Create elastic pool with zone redundancy enabled
text: az sql elastic-pool create -g mygroup -s myserver -n mypool -z
- name: Create elastic pool with zone redundancy explicitly disabled
text: az sql elastic-pool create -g mygroup -s myserver -n mypool -z false
"""
helps['sql elastic-pool list-editions'] = """
type: command
Expand All @@ -266,6 +281,11 @@
helps['sql elastic-pool update'] = """
type: command
short-summary: Update an elastic pool.
examples:
- name: Update elastic pool with zone redundancy enabled
text: az sql elastic-pool update -g mygroup -s myserver -n mypool -z
- name: Update elastic pool with zone redundancy explicitly disabled
text: az sql elastic-pool update -g mygroup -s myserver -n mypool -z false
"""
helps['sql server'] = """
type: group
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,6 @@ def _configure_db_create_params(
create_mode: Valid CreateMode enum value (e.g. `default`, `copy`, etc)
"""

# This line to be removed when zone redundancy is fully supported in production.
arg_ctx.ignore('zone_redundant')

# DW does not support all create modes. Check that engine and create_mode are consistent.
if engine == Engine.dw and create_mode not in [
CreateMode.default,
Expand Down Expand Up @@ -204,6 +201,11 @@ def load_arguments(self, _):
options_list=['--edition'],
help='The edition of the database.')

c.argument('zone_redundant',
options_list=['--zone-redundant', '-z'],
help='Specifies whether to enable zone redundancy for the database.',
arg_type=get_three_state_flag())

with self.argument_context('sql db create') as c:
_configure_db_create_params(c, Engine.db, CreateMode.default)

Expand Down Expand Up @@ -529,9 +531,6 @@ def _configure_security_policy_storage_params(arg_ctx):
# sql elastic-pool #
###############################################
with self.argument_context('sql elastic-pool') as c:
# This line to be removed when zone redundancy is fully supported in production.
c.ignore('zone_redundant')

c.argument('server_name',
arg_type=server_param_type,
# Allow --ids command line argument. id_part=name is 1st name in uri
Expand Down Expand Up @@ -560,6 +559,11 @@ def _configure_security_policy_storage_params(arg_ctx):
help='The max storage size of the elastic pool. If no unit is specified, defaults'
' to megabytes (MB).')

c.argument('zone_redundant',
options_list=['--zone-redundant', '-z'],
help='Specifies whether to enable zone redundancy for the elastic pool.',
arg_type=get_three_state_flag())

with self.argument_context('sql elastic-pool create') as c:
c.expand('parameters', ElasticPool)
# We have a wrapper function that determines server location so user doesn't need to specify
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,11 @@ def _get_server_location(cli_ctx, server_name, resource_group_name):

_DEFAULT_SERVER_VERSION = "12.0"


###############################################
# sql db #
###############################################


# pylint: disable=too-few-public-methods
class ClientType(Enum):
ado_net = 'ado.net'
Expand Down Expand Up @@ -588,7 +588,8 @@ def db_update(
instance,
elastic_pool_name=None,
max_size_bytes=None,
requested_service_objective_name=None):
requested_service_objective_name=None,
zone_redundant=None):

# Verify edition
if instance.edition.lower() == DatabaseEdition.data_warehouse.value.lower():
Expand Down Expand Up @@ -629,6 +630,8 @@ def db_update(
# Set other properties
instance.max_size_bytes = max_size_bytes or instance.max_size_bytes

instance.zone_redundant = zone_redundant

return instance


Expand Down Expand Up @@ -933,13 +936,15 @@ def elastic_pool_update(
database_dtu_max=None,
database_dtu_min=None,
dtu=None,
storage_mb=None):
storage_mb=None,
zone_redundant=None):

# Apply params to instance
instance.database_dtu_max = database_dtu_max or instance.database_dtu_max
instance.database_dtu_min = database_dtu_min or instance.database_dtu_min
instance.dtu = dtu or instance.dtu
instance.storage_mb = storage_mb or instance.storage_mb
instance.zone_redundant = zone_redundant

return instance

Expand Down
Loading

0 comments on commit 69d6e0b

Please sign in to comment.