Skip to content
Merged
6 changes: 4 additions & 2 deletions src/azure-cli/azure/cli/command_modules/cosmosdb/_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@
CreateLocation, CreateDatabaseRestoreResource, CreateGremlinDatabaseRestoreResource, CreateTableRestoreResource, UtcDatetimeAction, InvokeCommandArgumentsAddAction)
from azure.cli.command_modules.cosmosdb.custom import (
CosmosKeyTypes)

from azure.mgmt.cosmosdb.models import (
ContinuousTier)

SQL_GREMLIN_INDEXING_POLICY_EXAMPLE = """--idx "{\\"indexingMode\\": \\"consistent\\", \\"automatic\\": true, \\"includedPaths\\": [{\\"path\\": \\"/*\\"}], \\"excludedPaths\\": [{ \\"path\\": \\"/headquarters/employees/?\\"}, { \\"path\\": \\"/\\\\"_etag\\\\"/?\\"}]}"
"""
Expand Down Expand Up @@ -105,7 +106,7 @@ def load_arguments(self, _):
c.argument('enable_multiple_write_locations', arg_type=get_three_state_flag(), help="Enable Multiple Write Locations")
c.argument('disable_key_based_metadata_write_access', arg_type=get_three_state_flag(), help="Disable write operations on metadata resources (databases, containers, throughput) via account keys")
c.argument('key_uri', help="The URI of the key vault", is_preview=True)
c.argument('enable_public_network', options_list=['--enable-public-network', '-e'], arg_type=get_three_state_flag(), help="Enable or disable public network access to server.")
c.argument('public_network_access', options_list=['--public-network-access', '-p'], arg_type=get_enum_type(['ENABLED', 'DISABLED', 'SECUREDBYPERIMETER']), help="Sets public network access in server to either Enabled, Disabled, or SecuredByPerimeter.")
c.argument('enable_analytical_storage', arg_type=get_three_state_flag(), help="Flag to enable log storage on the account.")
c.argument('network_acl_bypass', arg_type=get_enum_type(NetworkAclBypass), options_list=['--network-acl-bypass'], help="Flag to enable or disable Network Acl Bypass.")
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.")
Expand All @@ -116,6 +117,7 @@ def load_arguments(self, _):
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>'.", is_preview=True)
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('continuous_tier', arg_type=get_enum_type(ContinuousTier), help="The tier of Continuous backup", arg_group='Backup Policy')

for scope in ['cosmosdb regenerate-key', 'cosmosdb keys regenerate']:
with self.argument_context(scope) as c:
Expand Down
48 changes: 35 additions & 13 deletions src/azure-cli/azure/cli/command_modules/cosmosdb/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
AnalyticalStorageConfiguration,
RestoreParameters,
ContinuousModeBackupPolicy,
ContinuousModeProperties,
ContinuousBackupRestoreLocation,
CreateMode,
ManagedServiceIdentityUserAssignedIdentity,
Expand Down Expand Up @@ -114,7 +115,7 @@ def cli_cosmosdb_create(cmd,
enable_multiple_write_locations=None,
disable_key_based_metadata_write_access=None,
key_uri=None,
enable_public_network=None,
public_network_access=None,
enable_analytical_storage=None,
enable_free_tier=None,
server_version=None,
Expand All @@ -127,6 +128,7 @@ def cli_cosmosdb_create(cmd,
default_identity=None,
analytical_storage_schema_type=None,
backup_policy_type=None,
continuous_tier=None,
databases_to_restore=None,
gremlin_databases_to_restore=None,
tables_to_restore=None,
Expand Down Expand Up @@ -164,7 +166,7 @@ def cli_cosmosdb_create(cmd,
enable_multiple_write_locations=enable_multiple_write_locations,
disable_key_based_metadata_write_access=disable_key_based_metadata_write_access,
key_uri=key_uri,
enable_public_network=enable_public_network,
public_network_access=public_network_access,
enable_analytical_storage=enable_analytical_storage,
enable_free_tier=enable_free_tier,
server_version=server_version,
Expand All @@ -175,6 +177,7 @@ def cli_cosmosdb_create(cmd,
restore_timestamp=restore_timestamp_utc,
analytical_storage_schema_type=analytical_storage_schema_type,
backup_policy_type=backup_policy_type,
continuous_tier=continuous_tier,
backup_interval=backup_interval,
backup_redundancy=backup_redundancy,
assign_identity=assign_identity,
Expand Down Expand Up @@ -205,7 +208,7 @@ def _create_database_account(client,
enable_multiple_write_locations=None,
disable_key_based_metadata_write_access=None,
key_uri=None,
enable_public_network=None,
public_network_access=None,
enable_analytical_storage=None,
enable_free_tier=None,
server_version=None,
Expand All @@ -217,6 +220,7 @@ def _create_database_account(client,
assign_identity=None,
default_identity=None,
backup_policy_type=None,
continuous_tier=None,
analytical_storage_schema_type=None,
databases_to_restore=None,
gremlin_databases_to_restore=None,
Expand All @@ -236,10 +240,6 @@ def _create_database_account(client,
locations = []
locations.append(Location(location_name=arm_location, failover_priority=0, is_zone_redundant=False))

public_network_access = None
if enable_public_network is not None:
public_network_access = 'Enabled' if enable_public_network else 'Disabled'

managed_service_identity = None
SYSTEM_ID = '[system]'
enable_system = False
Expand Down Expand Up @@ -288,6 +288,15 @@ def _create_database_account(client,
backup_policy.periodic_mode_properties = periodic_mode_properties
elif backup_policy_type.lower() == 'continuous':
backup_policy = ContinuousModeBackupPolicy()
if continuous_tier is not None:
continuous_mode_properties = ContinuousModeProperties(
tier=continuous_tier
)
else:
continuous_mode_properties = ContinuousModeProperties(
tier='Continuous30Days'
)
backup_policy.continuous_mode_properties = continuous_mode_properties
else:
raise CLIError('backup-policy-type argument is invalid.')
elif backup_interval is not None or backup_retention is not None or backup_redundancy is not None:
Expand Down Expand Up @@ -376,7 +385,7 @@ def cli_cosmosdb_update(client,
enable_multiple_write_locations=None,
disable_key_based_metadata_write_access=None,
key_uri=None,
enable_public_network=None,
public_network_access=None,
enable_analytical_storage=None,
network_acl_bypass=None,
network_acl_bypass_resource_ids=None,
Expand All @@ -386,7 +395,8 @@ def cli_cosmosdb_update(client,
backup_redundancy=None,
default_identity=None,
analytical_storage_schema_type=None,
backup_policy_type=None):
backup_policy_type=None,
continuous_tier=None):
"""Update an existing Azure Cosmos DB database account. """
existing = client.get(resource_group_name, account_name)

Expand Down Expand Up @@ -419,10 +429,6 @@ def cli_cosmosdb_update(client,
max_staleness_prefix=max_staleness_prefix,
max_interval_in_seconds=max_interval)

public_network_access = None
if enable_public_network is not None:
public_network_access = 'Enabled' if enable_public_network else 'Disabled'

api_properties = {'ServerVersion': server_version}

backup_policy = None
Expand All @@ -443,6 +449,22 @@ def cli_cosmosdb_update(client,
elif backup_policy_type is not None and backup_policy_type.lower() == 'continuous':
if isinstance(existing.backup_policy, PeriodicModeBackupPolicy):
backup_policy = ContinuousModeBackupPolicy()
if continuous_tier is not None:
continuous_mode_properties = ContinuousModeProperties(
tier=continuous_tier
)
else:
continuous_mode_properties = ContinuousModeProperties(
tier='Continuous30Days'
)
backup_policy.continuous_mode_properties = continuous_mode_properties
else:
backup_policy = existing.backup_policy
if continuous_tier is not None:
continuous_mode_properties = ContinuousModeProperties(
tier=continuous_tier
)
backup_policy.continuous_mode_properties = continuous_mode_properties

analytical_storage_configuration = None
if analytical_storage_schema_type is not None:
Expand Down
Loading