Skip to content
Closed
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
34 changes: 34 additions & 0 deletions src/azure-cli/azure/cli/command_modules/cosmosdb/_help.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,11 @@
short-summary: Add table names to restore
long-summary: |
Usage: --tables-to-restore tables=table1 [table2 ...]
- name: --backup-retention-lock-expiration-timestamp
short-summary: Set the retention lock expiration timestamp for continuous mode backups.
long-summary: |
Usage: --backup-retention-lock-expiration-timestamp 2030-01-01T00:00:00Z
This option can only be used with a continuous backup policy.
- name: --minimal-tls-version
short-summary: Indicate the minimum allowed TLS version
long-summary: |
Expand All @@ -193,6 +198,11 @@
Usage: --enable-burst-capacity true
Default: false
The accepted values for the enable-burst-capacity are true and false.
- name: --enable-per-partition-automatic-failover
short-summary: Enable per-partition automatic failover for the account.
long-summary: |
Usage: --enable-per-partition-automatic-failover true
The accepted values are true and false.
- name: --enable-prpp-autoscale
short-summary: Flag to Enable/Disable burst capacity feature
long-summary: |
Expand All @@ -205,8 +215,12 @@
crafted: true
- name: Creates a new Azure Cosmos DB database account with two regions. UK South is zone redundant.
text: az cosmosdb create -n myaccount -g mygroup --locations regionName=eastus failoverPriority=0 isZoneRedundant=False --locations regionName=uksouth failoverPriority=1 isZoneRedundant=True --enable-multiple-write-locations --network-acl-bypass AzureServices --network-acl-bypass-resource-ids /subscriptions/subId/resourceGroups/rgName/providers/Microsoft.Synapse/workspaces/wsName
- name: Create an account with per-partition automatic failover enabled.
text: az cosmosdb create -n myaccount -g mygroup --locations regionName=southcentralus failoverPriority=0 --locations regionName=eastus failoverPriority=1 --enable-per-partition-automatic-failover true
- name: Create a new Azure Cosmos DB database account by restoring from an existing account in the given location
text: az cosmosdb create -n restoredaccount -g mygroup --is-restore-request true --restore-source /subscriptions/2296c272-5d55-40d9-bc05-4d56dc2d7588/providers/Microsoft.DocumentDB/locations/westus/restorableDatabaseAccounts/d056a4f8-044a-436f-80c8-cd3edbc94c68 --restore-timestamp 2020-07-13T16:03:41+0000 --locations regionName=westus failoverPriority=0 isZoneRedundant=False
- name: Create an account with a continuous backup retention lock.
text: az cosmosdb create -n myaccount -g mygroup --backup-policy-type Continuous --backup-retention-lock-expiration-timestamp 2030-01-01T00:00:00Z
"""

helps['cosmosdb restore'] = """
Expand Down Expand Up @@ -835,11 +849,17 @@
helps['cosmosdb sql container throughput show'] = """
type: command
short-summary: Get the throughput of the SQL container under an Azure Cosmos DB SQL database.
examples:
- name: Show container throughput settings, including throughput buckets when configured.
text: az cosmosdb sql container throughput show -g mygroup -a myaccount -d mydatabase -n mycontainer
"""

helps['cosmosdb sql container throughput update'] = """
type: command
short-summary: Update the throughput of the SQL container under an Azure Cosmos DB SQL database.
examples:
- name: Update container throughput while preserving configured throughput buckets.
text: az cosmosdb sql container throughput update -g mygroup -a myaccount -d mydatabase -n mycontainer --throughput 400
"""

helps['cosmosdb sql container throughput migrate'] = """
Expand Down Expand Up @@ -959,6 +979,11 @@
Default: single region account in the location of the specified resource group.
Failover priority values are 0 for write regions and greater than 0 for read regions. A failover priority value must be unique and less than the total number of regions.
Multiple locations can be specified by using more than one `--locations` argument.
- name: --backup-retention-lock-expiration-timestamp
short-summary: Push forward the retention lock expiration timestamp for continuous mode backups.
long-summary: |
Usage: --backup-retention-lock-expiration-timestamp 2030-06-01T00:00:00Z
This option can only be used with a continuous backup policy.
- name: --minimal-tls-version
short-summary: Indicate the minimum allowed TLS version
long-summary: |
Expand All @@ -972,6 +997,11 @@
Usage: --enable-burst-capacity true
Default: false
The accepted values for the enable-burst-capacity are true and false.
- name: --enable-per-partition-automatic-failover
short-summary: Enable per-partition automatic failover for the account.
long-summary: |
Usage: --enable-per-partition-automatic-failover true
The accepted values are true and false.
- name: --enable-prpp-autoscale
short-summary: Flag to Enable/Disable burst capacity feature
long-summary: |
Expand All @@ -984,6 +1014,10 @@
crafted: true
- name: Creates a new Azure Cosmos DB database account with two regions. UK South is zone redundant.
text: az cosmosdb update -n myaccount -g mygroup --locations regionName=eastus failoverPriority=0 isZoneRedundant=False --locations regionName=uksouth failoverPriority=1 isZoneRedundant=True --enable-multiple-write-locations --network-acl-bypass AzureServices --network-acl-bypass-resource-ids /subscriptions/subId/resourceGroups/rgName/providers/Microsoft.Synapse/workspaces/wsName
- name: Enable per-partition automatic failover on an account.
text: az cosmosdb update -n myaccount -g mygroup --enable-per-partition-automatic-failover true
- name: Push forward a continuous backup retention lock.
text: az cosmosdb update -n myaccount -g mygroup --backup-retention-lock-expiration-timestamp 2030-06-01T00:00:00Z
"""

helps['cosmosdb mongodb role'] = """
Expand Down
2 changes: 2 additions & 0 deletions src/azure-cli/azure/cli/command_modules/cosmosdb/_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,13 +148,15 @@ def load_arguments(self, _):
c.argument('network_acl_bypass_resource_ids', nargs='+', options_list=['--network-acl-bypass-resource-ids', '-i'], help="List of Resource Ids to allow Network Acl Bypass.")
c.argument('backup_interval', type=int, help="the frequency(in minutes) with which backups are taken (only for accounts with periodic mode backups)", arg_group='Backup Policy')
c.argument('backup_retention', type=int, help="the time(in hours) for which each backup is retained (only for accounts with periodic mode backups)", arg_group='Backup Policy')
c.argument('backup_retention_lock_expiration_timestamp', action=UtcDatetimeAction, help="The retention lock expiration timestamp for continuous mode backups.", arg_group='Backup Policy')
c.argument('backup_redundancy', arg_type=get_enum_type(BackupStorageRedundancy), help="The redundancy type of the backup Storage account", arg_group='Backup Policy')
c.argument('server_version', arg_type=get_enum_type(ServerVersion), help="Valid only for MongoDB accounts.")
c.argument('default_identity', help="The primary identity to access key vault in CMK related features. e.g. 'FirstPartyIdentity', 'SystemAssignedIdentity' and more. User-assigned identities are specified in format `UserAssignedIdentity=<resource ID of the user-assigned identity>`.")
c.argument('analytical_storage_schema_type', options_list=['--analytical-storage-schema-type', '--as-schema'], arg_type=get_enum_type(AnalyticalStorageSchemaType), help="Schema type for analytical storage.", arg_group='Analytical Storage Configuration')
c.argument('backup_policy_type', arg_type=get_enum_type(BackupPolicyType), help="The type of backup policy of the account to create", arg_group='Backup Policy')
c.argument('enable_partition_merge', arg_type=get_three_state_flag(), help="Flag to enable partition merge on the account.")
c.argument('enable_burst_capacity', arg_type=get_three_state_flag(), help="Flag to enable burst capacity on the account.")
c.argument('enable_per_partition_automatic_failover', arg_type=get_three_state_flag(), help="Flag to enable per-partition automatic failover on the account.")
c.argument('enable_prpp_autoscale', arg_type=get_three_state_flag(), help="Enable or disable PerRegionPerPartitionAutoscale.")
c.argument('enable_pbe', arg_type=get_three_state_flag(), help="Flag to enable priority based execution on the account.")
c.argument('default_priority_level', arg_type=get_enum_type(DefaultPriorityLevel), help="Default Priority Level of Request if not specified.")
Expand Down
24 changes: 24 additions & 0 deletions src/azure-cli/azure/cli/command_modules/cosmosdb/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ def cli_cosmosdb_create(cmd,
network_acl_bypass_resource_ids=None,
backup_interval=None,
backup_retention=None,
backup_retention_lock_expiration_timestamp=None,
backup_redundancy=None,
assign_identity=None,
default_identity=None,
Expand All @@ -151,6 +152,7 @@ def cli_cosmosdb_create(cmd,
restore_timestamp=None,
enable_partition_merge=None,
enable_burst_capacity=None,
enable_per_partition_automatic_failover=None,
enable_prpp_autoscale=None,
minimal_tls_version=None,
enable_pbe=None,
Expand Down Expand Up @@ -204,12 +206,14 @@ def cli_cosmosdb_create(cmd,
assign_identity=assign_identity,
default_identity=default_identity,
backup_retention=backup_retention,
backup_retention_lock_expiration_timestamp=backup_retention_lock_expiration_timestamp,
databases_to_restore=databases_to_restore,
gremlin_databases_to_restore=gremlin_databases_to_restore,
tables_to_restore=tables_to_restore,
arm_location=resource_group_location,
enable_partition_merge=enable_partition_merge,
enable_burst_capacity=enable_burst_capacity,
enable_per_partition_automatic_failover=enable_per_partition_automatic_failover,
enable_prpp_autoscale=enable_prpp_autoscale,
minimal_tls_version=minimal_tls_version,
enable_pbe=enable_pbe,
Expand Down Expand Up @@ -244,6 +248,7 @@ def _create_database_account(client,
network_acl_bypass_resource_ids=None,
backup_interval=None,
backup_retention=None,
backup_retention_lock_expiration_timestamp=None,
backup_redundancy=None,
assign_identity=None,
default_identity=None,
Expand All @@ -259,6 +264,7 @@ def _create_database_account(client,
arm_location=None,
enable_partition_merge=None,
enable_burst_capacity=None,
enable_per_partition_automatic_failover=None,
enable_prpp_autoscale=None,
minimal_tls_version=None,
disable_ttl=None,
Expand Down Expand Up @@ -359,6 +365,12 @@ def _create_database_account(client,
)
backup_policy.periodic_mode_properties = periodic_mode_properties

if backup_retention_lock_expiration_timestamp is not None:
if not isinstance(backup_policy, ContinuousModeBackupPolicy):
raise CLIError(
'--backup-retention-lock-expiration-timestamp can only be set with continuous backup policy.')
backup_policy.backup_retention_lock_expiration_timestamp = backup_retention_lock_expiration_timestamp

analytical_storage_configuration = None
if analytical_storage_schema_type is not None:
analytical_storage_configuration = AnalyticalStorageConfiguration()
Expand Down Expand Up @@ -421,6 +433,7 @@ def _create_database_account(client,
restore_parameters=restore_parameters,
enable_partition_merge=enable_partition_merge,
enable_burst_capacity=enable_burst_capacity,
per_partition_automatic_failover_enabled=enable_per_partition_automatic_failover,
enable_per_region_per_partition_autoscale=enable_prpp_autoscale,
minimal_tls_version=minimal_tls_version,
enable_priority_based_execution=enable_pbe,
Expand Down Expand Up @@ -472,13 +485,15 @@ def cli_cosmosdb_update(client,
server_version=None,
backup_interval=None,
backup_retention=None,
backup_retention_lock_expiration_timestamp=None,
backup_redundancy=None,
default_identity=None,
analytical_storage_schema_type=None,
backup_policy_type=None,
continuous_tier=None,
enable_partition_merge=None,
enable_burst_capacity=None,
enable_per_partition_automatic_failover=None,
enable_prpp_autoscale=None,
minimal_tls_version=None,
enable_pbe=None,
Expand Down Expand Up @@ -552,6 +567,14 @@ def cli_cosmosdb_update(client,
)
backup_policy.continuous_mode_properties = continuous_mode_properties

if backup_retention_lock_expiration_timestamp is not None:
if backup_policy is None:
backup_policy = existing.backup_policy
if not isinstance(backup_policy, ContinuousModeBackupPolicy):
raise CLIError(
'--backup-retention-lock-expiration-timestamp can only be set with continuous backup policy.')
backup_policy.backup_retention_lock_expiration_timestamp = backup_retention_lock_expiration_timestamp

analytical_storage_configuration = None
if analytical_storage_schema_type is not None:
analytical_storage_configuration = AnalyticalStorageConfiguration()
Expand Down Expand Up @@ -580,6 +603,7 @@ def cli_cosmosdb_update(client,
analytical_storage_configuration=analytical_storage_configuration,
enable_partition_merge=enable_partition_merge,
enable_burst_capacity=enable_burst_capacity,
per_partition_automatic_failover_enabled=enable_per_partition_automatic_failover,
enable_per_region_per_partition_autoscale=enable_prpp_autoscale,
minimal_tls_version=minimal_tls_version,
enable_priority_based_execution=enable_pbe,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# --------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------

from azure.cli.testsdk import ScenarioTest, ResourceGroupPreparer
from azure.cli.testsdk.scenario_tests import AllowLargeResponse


class CosmosdbPerPartitionAutomaticFailoverScenarioTest(ScenarioTest):

@AllowLargeResponse()
@ResourceGroupPreparer(name_prefix='cli_test_cosmosdb_ppaf', location='southcentralus')
def test_cosmosdb_per_partition_automatic_failover(self, resource_group):
self.kwargs.update({
'acc': self.create_random_name(prefix='ppaf-test-', length=20)
})

self.cmd(
'az cosmosdb create -n {acc} -g {rg} '
'--locations regionName=southcentralus failoverPriority=0 '
'--locations regionName=eastus failoverPriority=1 '
'--enable-per-partition-automatic-failover true')
self.cmd('az cosmosdb show -n {acc} -g {rg}', checks=[
self.check('perPartitionAutomaticFailoverEnabled', True),
])

self.cmd(
'az cosmosdb update -n {acc} -g {rg} '
'--enable-per-partition-automatic-failover true')
self.cmd('az cosmosdb show -n {acc} -g {rg}', checks=[
self.check('perPartitionAutomaticFailoverEnabled', True),
])

self.cmd('az cosmosdb delete -n {acc} -g {rg} --yes')
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# --------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------

from azure.cli.testsdk import ScenarioTest, ResourceGroupPreparer
from azure.cli.testsdk.scenario_tests import AllowLargeResponse


class CosmosdbRetentionLockScenarioTest(ScenarioTest):

@AllowLargeResponse()
@ResourceGroupPreparer(name_prefix='cli_test_cosmosdb_retention_lock')
def test_cosmosdb_retention_lock(self, resource_group):
self.kwargs.update({
'acc': self.create_random_name(prefix='retention-lock-', length=25),
'create_timestamp': '2030-01-01T00:00:00Z',
'update_timestamp': '2030-06-01T00:00:00Z'
})

self.cmd(
'az cosmosdb create -n {acc} -g {rg} '
'--backup-policy-type Continuous '
'--backup-retention-lock-expiration-timestamp {create_timestamp}',
checks=[
self.check('backupPolicy.type', 'Continuous'),
self.check('backupPolicy.backupRetentionLockExpirationTimestamp', '{create_timestamp}'),
])
self.cmd('az cosmosdb show -n {acc} -g {rg}', checks=[
self.check('backupPolicy.backupRetentionLockExpirationTimestamp', '{create_timestamp}'),
])

self.cmd(
'az cosmosdb update -n {acc} -g {rg} '
'--backup-retention-lock-expiration-timestamp {update_timestamp}',
checks=[
self.check('backupPolicy.backupRetentionLockExpirationTimestamp', '{update_timestamp}'),
])

self.cmd('az cosmosdb update -n {acc} -g {rg} --tags retention-lock=preserved')
self.cmd('az cosmosdb show -n {acc} -g {rg}', checks=[
self.check('backupPolicy.backupRetentionLockExpirationTimestamp', '{update_timestamp}'),
])

self.cmd('az cosmosdb delete -n {acc} -g {rg} --yes')
Loading
Loading