Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 0 additions & 37 deletions src/azure-cli/azure/cli/command_modules/sql/_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -396,40 +396,3 @@ def _outbound_firewall_rule_table_format(result):
])

return _apply_format(result, _outbound_firewall_rule_table_format)


###############################################
# sql mi #
###############################################


#####
# sql mi transformers for json
#####

def mi_list_transform(results):
'''
Transforms the json response for a list of managed instances.
'''

return [mi_transform(r) for r in results]


def mi_transform(result):
'''
Transforms the json response for a managed instance.
'''

if hasattr(result, 'storage_account_type'):
result.backupStorageRedundancy = _get_external_backup_storage_redundancy(result.storage_account_type)
del result.storage_account_type

return result


def _get_external_backup_storage_redundancy(self):
return {
'lrs': 'Local',
'grs': 'Geo',
'zrs': 'Zone'
}.get(self.lower(), 'Invalid')
2 changes: 2 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 @@ -899,6 +899,8 @@
- name: Move managed instance to another subnet
text: az sql mi update -g myResourceGroup -n myServer -i \\
--subnet /subscriptions/xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/myResourceGroup/providers/Microsoft.ManagedIdentity/userAssignedIdentities/testumi \\
- name: Update mi backup storage redundancy
text: az sql mi update -g mygroup -n myinstance --bsr Local
"""

helps['sql midb'] = """
Expand Down
36 changes: 17 additions & 19 deletions src/azure-cli/azure/cli/command_modules/sql/_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
ServerConnectionType,
ServerKeyType,
StorageKeyType,
TransparentDataEncryptionStatus
TransparentDataEncryptionState
)

from azure.cli.core.commands.parameters import (
Expand Down Expand Up @@ -66,7 +66,6 @@
create_args_for_complex_type,
validate_managed_instance_storage_size,
validate_backup_storage_redundancy,
validate_backup_storage_redundancy_mi,
validate_subnet
)

Expand Down Expand Up @@ -110,14 +109,7 @@ def get_internal_backup_storage_redundancy(self):
'local': 'Local',
'zone': 'Zone',
'geo': 'Geo',
}.get(self.lower(), 'Invalid')


def get_internal_backup_storage_redundancy_mi(self):
return {
'local': 'LRS',
'zone': 'ZRS',
'geo': 'GRS',
'geozone': 'GeoZone',
}.get(self.lower(), 'Invalid')


Expand Down Expand Up @@ -250,9 +242,9 @@ def get_location_type_with_default_from_resource_group(cli_ctx):

backup_storage_redundancy_param_type_mi = CLIArgumentType(
options_list=['--backup-storage-redundancy', '--bsr'],
type=get_internal_backup_storage_redundancy_mi,
help='Backup storage redundancy used to store backups. Allowed values include: Local, Zone, Geo.',
validator=validate_backup_storage_redundancy_mi)
type=get_internal_backup_storage_redundancy,
help='Backup storage redundancy used to store backups. Allowed values include: Local, Zone, Geo, GeoZone.',
validator=validate_backup_storage_redundancy)

grace_period_param_type = CLIArgumentType(
help='Interval in hours before automatic failover is initiated '
Expand Down Expand Up @@ -985,7 +977,7 @@ def _configure_security_policy_storage_params(arg_ctx):
options_list=['--status'],
required=True,
help='Status of the transparent data encryption.',
arg_type=get_enum_type(TransparentDataEncryptionStatus))
arg_type=get_enum_type(TransparentDataEncryptionState))

#####
# sql db ledger-digest-uploads
Expand Down Expand Up @@ -1864,6 +1856,9 @@ def _configure_security_policy_storage_params(arg_ctx):
help='Type of Identity to be used. Possible values are SystemAsssigned,'
'UserAssigned, SystemAssignedUserAssigned and None.')

c.argument('requested_backup_storage_redundancy',
arg_type=backup_storage_redundancy_param_type_mi)

with self.argument_context('sql mi create') as c:
c.argument('location',
arg_type=get_location_type_with_default_from_resource_group(self.cli_ctx))
Expand All @@ -1883,7 +1878,7 @@ def _configure_security_policy_storage_params(arg_ctx):
'public_data_endpoint_enabled',
'timezone_id',
'tags',
'storage_account_type',
'requested_backup_storage_redundancy',
'yes',
'maintenance_configuration_id',
'primary_user_assigned_identity_id',
Expand Down Expand Up @@ -1924,9 +1919,6 @@ def _configure_security_policy_storage_params(arg_ctx):
help='Generate and assign an Azure Active Directory Identity for this managed instance '
'for use with key management services like Azure KeyVault.')

c.argument('storage_account_type',
arg_type=backup_storage_redundancy_param_type_mi)

c.argument('yes',
options_list=['--yes', '-y'],
help='Do not prompt for confirmation.', action='store_true')
Expand Down Expand Up @@ -1957,7 +1949,9 @@ def _configure_security_policy_storage_params(arg_ctx):
create_args_for_complex_type(
c, 'parameters', ManagedInstance, [
'administrator_login_password',
'requested_backup_storage_redundancy',
'tags',
'yes',
])

c.argument('administrator_login_password',
Expand All @@ -1969,6 +1963,10 @@ def _configure_security_policy_storage_params(arg_ctx):
'for use with key management services like Azure KeyVault. '
'If identity is already assigned - do nothing.')

c.argument('yes',
options_list=['--yes', '-y'],
help='Do not prompt for confirmation.', action='store_true')

c.argument('maintenance_configuration_id',
options_list=['--maint-config-id', '-m'],
help='Change maintenance configuration for this managed instance.')
Expand Down Expand Up @@ -2258,7 +2256,7 @@ def _configure_security_policy_storage_params(arg_ctx):
help='The resource id of the long term retention backup to be restored. '
'Use \'az sql midb ltr-backup show\' or \'az sql midb ltr-backup list\' for backup id.')

c.argument('storage_account_type',
c.argument('requested_backup_storage_redundancy',
arg_type=backup_storage_redundancy_param_type_mi)

with self.argument_context('sql midb log-replay start') as c:
Expand Down
4 changes: 0 additions & 4 deletions src/azure-cli/azure/cli/command_modules/sql/_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,6 @@ def get_sql_database_threat_detection_policies_operations(cli_ctx, _):
return get_sql_management_client(cli_ctx).database_security_alert_policies


def get_sql_database_transparent_data_encryption_activities_operations(cli_ctx, _):
return get_sql_management_client(cli_ctx).transparent_data_encryption_activities


def get_sql_database_transparent_data_encryptions_operations(cli_ctx, _):
return get_sql_management_client(cli_ctx).transparent_data_encryptions

Expand Down
16 changes: 2 additions & 14 deletions src/azure-cli/azure/cli/command_modules/sql/_validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,10 @@ def validate_backup_storage_redundancy(namespace):
# Validate if entered backup storage redundancy value is within allowed values
if (not namespace.requested_backup_storage_redundancy or
(namespace.requested_backup_storage_redundancy and
namespace.requested_backup_storage_redundancy in ['Local', 'Zone', 'Geo'])):
namespace.requested_backup_storage_redundancy in ['Local', 'Zone', 'Geo', 'GeoZone'])):
pass
else:
raise CLIError('incorrect usage: --backup-storage-redundancy must be either Local, Zone or Geo')
raise CLIError('incorrect usage: --backup-storage-redundancy must be either Local, Zone, Geo or GeoZone')


###############################################
Expand All @@ -138,15 +138,3 @@ def validate_managed_instance_storage_size(namespace):
pass
else:
raise CLIError('incorrect usage: --storage must be specified in increments of 32 GB')


def validate_backup_storage_redundancy_mi(namespace):
# Differentiating from validate_backup_storage_redundancy while Databases and
# ManagedInstances API use different properties for setting backup storage redundancy
# ie. "requested_backup_storage_redundancy" (Databases) vs. "storage_account_type" (ManagedInstances)
# Validate if entered backup storage redundancy value is within allowed values
if (not namespace.storage_account_type or
(namespace.storage_account_type and namespace.storage_account_type in ['LRS', 'ZRS', 'GRS'])):
pass
else:
raise CLIError('incorrect usage: --backup-storage-redundancy must be either Local, Zone or Geo')
24 changes: 5 additions & 19 deletions src/azure-cli/azure/cli/command_modules/sql/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@
outbound_firewall_rule_table_format,
server_table_format,
usage_table_format,
LongRunningOperationResultTransform,
mi_transform,
mi_list_transform
LongRunningOperationResultTransform
)

from ._util import (
Expand All @@ -37,7 +35,6 @@
get_sql_database_sensitivity_labels_operations,
get_sql_database_operations_operations,
get_sql_database_threat_detection_policies_operations,
get_sql_database_transparent_data_encryption_activities_operations,
get_sql_database_transparent_data_encryptions_operations,
get_sql_database_usages_operations,
get_sql_elastic_pools_operations,
Expand Down Expand Up @@ -217,16 +214,6 @@ def load_command_table(self, _):
g.custom_command('set', 'transparent_data_encryptions_set')
g.custom_show_command('show', 'transparent_data_encryptions_get')

transparent_data_encryption_activities_operations = CliCommandType(
operations_tmpl='azure.mgmt.sql.operations#TransparentDataEncryptionActivitiesOperations.{}',
client_factory=get_sql_database_transparent_data_encryption_activities_operations)

with self.command_group('sql db tde',
transparent_data_encryption_activities_operations,
client_factory=get_sql_database_transparent_data_encryption_activities_operations) as g:

g.custom_command('list-activity', 'tde_list_by_configuration')

replication_links_operations = CliCommandType(
operations_tmpl='azure.mgmt.sql.operations#ReplicationLinksOperations.{}',
client_factory=get_sql_replication_links_operations)
Expand Down Expand Up @@ -706,14 +693,13 @@ def load_command_table(self, _):
managed_instances_operations,
client_factory=get_sql_managed_instances_operations) as g:

g.custom_command('create', 'managed_instance_create', transform=mi_transform, supports_no_wait=True)
g.command('delete', 'begin_delete', transform=mi_transform, confirmation=True, supports_no_wait=True)
g.custom_show_command('show', 'managed_instance_get', transform=mi_transform)
g.custom_command('list', 'managed_instance_list', transform=mi_list_transform)
g.custom_command('create', 'managed_instance_create', supports_no_wait=True)
g.command('delete', 'begin_delete', confirmation=True, supports_no_wait=True)
g.custom_show_command('show', 'managed_instance_get')
g.custom_command('list', 'managed_instance_list')
g.generic_update_command('update',
setter_name='begin_create_or_update',
custom_func_name='managed_instance_update',
transform=mi_transform,
supports_no_wait=True)
g.command('failover', 'begin_failover', supports_no_wait=True)

Expand Down
47 changes: 23 additions & 24 deletions src/azure-cli/azure/cli/command_modules/sql/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -4105,7 +4105,7 @@ def ledger_digest_uploads_enable(

kwargs['digest_storage_endpoint'] = endpoint

return client.create_or_update(
return client.begin_create_or_update(
resource_group_name=resource_group_name,
server_name=server_name,
database_name=database_name,
Expand All @@ -4122,7 +4122,7 @@ def ledger_digest_uploads_disable(
Disables ledger storage target
'''

return client.disable(
return client.begin_disable(
resource_group_name=resource_group_name,
server_name=server_name,
database_name=database_name,
Expand Down Expand Up @@ -4264,15 +4264,15 @@ def managed_instance_create(
kwargs['maintenance_configuration_id'] = _complete_maintenance_configuration_id(cmd.cli_ctx, kwargs['maintenance_configuration_id'])

if not kwargs['yes'] and kwargs['location'].lower() in ['southeastasia', 'brazilsouth', 'eastasia']:
if kwargs['storage_account_type'] == 'GRS':
if kwargs['requested_backup_storage_redundancy'] == 'Geo':
confirmation = prompt_y_n("""Selected value for backup storage redundancy is geo-redundant storage.
Note that database backups will be geo-replicated to the paired region.
To learn more about Azure Paired Regions visit https://aka.ms/azure-ragrs-regions.
Do you want to proceed?""")
if not confirmation:
return

if not kwargs['storage_account_type']:
if not kwargs['requested_backup_storage_redundancy']:
confirmation = prompt_y_n("""You have not specified the value for backup storage redundancy
which will default to geo-redundant storage. Note that database backups will be geo-replicated
to the paired region. To learn more about Azure Paired Regions visit https://aka.ms/azure-ragrs-regions.
Expand Down Expand Up @@ -4360,9 +4360,11 @@ def managed_instance_update(
maintenance_configuration_id=None,
primary_user_assigned_identity_id=None,
key_id=None,
requested_backup_storage_redundancy=None,
identity_type=None,
user_assigned_identity_id=None,
virtual_network_subnet_id=None):
virtual_network_subnet_id=None,
yes=None):
'''
Updates a managed instance. Custom update function to apply parameters to instance.
'''
Expand Down Expand Up @@ -4398,6 +4400,18 @@ def managed_instance_update(
instance.location,
instance.sku)

if not yes and _should_show_backup_storage_redundancy_warnings(instance.location) and requested_backup_storage_redundancy == 'Geo':
confirmation = prompt_y_n("""Selected value for backup storage redundancy is geo-redundant storage.
Note that database backups will be geo-replicated to the paired region.
To learn more about Azure Paired Regions visit https://aka.ms/azure-ragrs-regions.
Do you want to proceed?""")
if not confirmation:
return

if requested_backup_storage_redundancy is not None:
instance.requested_backup_storage_redundancy = requested_backup_storage_redundancy
instance.zone_redundant = None

if public_data_endpoint_enabled is not None:
instance.public_data_endpoint_enabled = public_data_endpoint_enabled

Expand Down Expand Up @@ -5455,7 +5469,7 @@ def update_conn_policy(
'''
Updates a connectin policy
'''
return client.create_or_update(
return client.begin_create_or_update(
resource_group_name=resource_group_name,
server_name=server_name,
connection_policy_name=ConnectionPolicyName.DEFAULT,
Expand All @@ -5478,13 +5492,13 @@ def transparent_data_encryptions_set(
'''
Sets a Transparent Data Encryption
'''
kwargs['status'] = status
kwargs['state'] = status

return client.create_or_update(
resource_group_name=resource_group_name,
server_name=server_name,
database_name=database_name,
transparent_data_encryption_name=TransparentDataEncryptionName.CURRENT,
tde_name=TransparentDataEncryptionName.CURRENT,
parameters=kwargs)


Expand All @@ -5501,24 +5515,9 @@ def transparent_data_encryptions_get(
resource_group_name=resource_group_name,
server_name=server_name,
database_name=database_name,
transparent_data_encryption_name=TransparentDataEncryptionName.CURRENT)
tde_name=TransparentDataEncryptionName.CURRENT)


def tde_list_by_configuration(
client,
resource_group_name,
server_name,
database_name):
'''
Lists Transparent Data Encryption
'''

return client.list_by_configuration(
resource_group_name=resource_group_name,
server_name=server_name,
database_name=database_name,
transparent_data_encryption_name=TransparentDataEncryptionName.CURRENT)

###############################################
# sql server vnet-rule #
###############################################
Expand Down
Loading