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
4 changes: 2 additions & 2 deletions src/azure-cli/azure/cli/command_modules/cosmosdb/_help.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@
text: az cosmosdb create --name MyCosmosDBDatabaseAccount --resource-group MyResourceGroup --subscription MySubscription
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
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
"""

helps['cosmosdb database'] = """
Expand Down Expand Up @@ -848,5 +848,5 @@
text: az cosmosdb update --capabilities EnableGremlin --name MyCosmosDBDatabaseAccount --resource-group MyResourceGroup
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
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
"""
8 changes: 6 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 @@ -45,7 +45,7 @@ class ThroughputTypes(str, Enum):

def load_arguments(self, _):
from knack.arguments import CLIArgumentType
from azure.mgmt.cosmosdb.models import KeyKind, DefaultConsistencyLevel, DatabaseAccountKind, TriggerType, TriggerOperation, ServerVersion
from azure.mgmt.cosmosdb.models import KeyKind, DefaultConsistencyLevel, DatabaseAccountKind, TriggerType, TriggerOperation, ServerVersion, NetworkAclBypass

with self.argument_context('cosmosdb') as c:
c.argument('account_name', arg_type=name_type, help='Name of the Cosmos DB database account', completer=get_resource_name_completion_list('Microsoft.DocumentDb/databaseAccounts'), id_part='name')
Expand All @@ -55,7 +55,6 @@ def load_arguments(self, _):
c.argument('account_name', completer=None)
c.argument('key_uri', help="The URI of the key vault", is_preview=True)
c.argument('enable_free_tier', arg_type=get_three_state_flag(), help="If enabled the account is free-tier.", is_preview=True)
c.argument('server_version', arg_type=get_enum_type(ServerVersion), help="Valid only for MongoDB accounts.", is_preview=True)

for scope in ['cosmosdb create', 'cosmosdb update']:
with self.argument_context(scope) as c:
Expand All @@ -75,6 +74,11 @@ def load_arguments(self, _):
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('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('enable_analytical_storage', arg_type=get_three_state_flag(), help="Flag to enable log storage on the account.", is_preview=True)
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.")
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('server_version', arg_type=get_enum_type(ServerVersion), help="Valid only for MongoDB accounts.", is_preview=True)

for scope in ['cosmosdb regenerate-key', 'cosmosdb keys regenerate']:
with self.argument_context(scope) as c:
Expand Down
50 changes: 46 additions & 4 deletions src/azure-cli/azure/cli/command_modules/cosmosdb/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@
ThroughputSettingsResource,
ThroughputSettingsUpdateParameters,
AutoscaleSettings,
PeriodicModeBackupPolicy,
PeriodicModeProperties
)

logger = get_logger(__name__)
Expand Down Expand Up @@ -93,7 +95,11 @@ def cli_cosmosdb_create(cmd, client,
enable_public_network=None,
enable_analytical_storage=None,
enable_free_tier=None,
server_version=None):
server_version=None,
network_acl_bypass=None,
network_acl_bypass_resource_ids=None,
backup_interval=None,
backup_retention=None):
"""Create a new Azure Cosmos DB database account."""
consistency_policy = None
if default_consistency_level is not None:
Expand Down Expand Up @@ -122,6 +128,15 @@ def cli_cosmosdb_create(cmd, client,
elif server_version is not None:
raise CLIError('server-version is a valid argument only when kind is MongoDB.')

backup_policy = None
if backup_interval is not None or backup_retention is not None:
backup_policy = PeriodicModeBackupPolicy()
periodic_mode_properties = PeriodicModeProperties(
backup_interval_in_minutes=backup_interval,
backup_retention_interval_in_hours=backup_retention
)
backup_policy.periodic_mode_properties = periodic_mode_properties

params = DatabaseAccountCreateUpdateParameters(
location=resource_group_location,
locations=locations,
Expand All @@ -139,7 +154,10 @@ def cli_cosmosdb_create(cmd, client,
public_network_access=public_network_access,
api_properties=api_properties,
enable_analytical_storage=enable_analytical_storage,
enable_free_tier=enable_free_tier)
enable_free_tier=enable_free_tier,
network_acl_bypass=network_acl_bypass,
network_acl_bypass_resource_ids=network_acl_bypass_resource_ids,
backup_policy=backup_policy)

async_docdb_create = client.create_or_update(resource_group_name, account_name, params)
docdb_account = async_docdb_create.result()
Expand All @@ -164,7 +182,12 @@ def cli_cosmosdb_update(client,
enable_multiple_write_locations=None,
disable_key_based_metadata_write_access=None,
enable_public_network=None,
enable_analytical_storage=None):
enable_analytical_storage=None,
network_acl_bypass=None,
network_acl_bypass_resource_ids=None,
server_version=None,
backup_interval=None,
backup_retention=None):
"""Update an existing Azure Cosmos DB database account. """
existing = client.get(resource_group_name, account_name)

Expand Down Expand Up @@ -193,6 +216,21 @@ def cli_cosmosdb_update(client,
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
if backup_interval is not None or backup_retention is not None:
if isinstance(existing.backup_policy, PeriodicModeBackupPolicy):
periodic_mode_properties = PeriodicModeProperties(
backup_interval_in_minutes=backup_interval,
backup_retention_interval_in_hours=backup_retention
)
backup_policy = existing.backup_policy
backup_policy.periodic_mode_properties = periodic_mode_properties
else:
raise CLIError(
'backup-interval and backup-retention can only be set for accounts with periodic backup policy.')

params = DatabaseAccountUpdateParameters(
locations=locations,
tags=tags,
Expand All @@ -205,7 +243,11 @@ def cli_cosmosdb_update(client,
enable_multiple_write_locations=enable_multiple_write_locations,
disable_key_based_metadata_write_access=disable_key_based_metadata_write_access,
public_network_access=public_network_access,
enable_analytical_storage=enable_analytical_storage)
enable_analytical_storage=enable_analytical_storage,
network_acl_bypass=network_acl_bypass,
network_acl_bypass_resource_ids=network_acl_bypass_resource_ids,
api_properties=api_properties,
backup_policy=backup_policy)

async_docdb_update = client.update(resource_group_name, account_name, params)
docdb_account = async_docdb_update.result()
Expand Down
Loading