Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CosmosDB] API Version 2024-12-01-preview #8323

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
Prev Previous commit
Next Next commit
Added throughput bucket param
  • Loading branch information
Achint-Agrawal authored and pjohari-ms committed Dec 3, 2024
commit fefa25a3f91d252e3e6d9fa7c315c8689275bada
7 changes: 7 additions & 0 deletions src/cosmosdb-preview/azext_cosmosdb_preview/_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,12 @@
}"
"""

SQL_THROUGHPUT_BUCKETS_EXAMPLE = """--tb "[
{ \\"id\\": 1, \\"maxThroughputPercentage\\" : 10 },
{ \\"id\\": 2, \\"maxThroughputPercentage\\" : 20 }
]"
"""

class ThroughputTypes(str, Enum):
autoscale = "autoscale"
manual = "manual"
Expand Down Expand Up @@ -571,6 +577,7 @@ def load_arguments(self, _):
c.argument('container_name', options_list=['--name', '-n'], help="Container name")
c.argument('throughput', type=int, help='The throughput of SQL container (RU/s).')
c.argument('max_throughput', max_throughput_type)
c.argument('throughput_buckets', options_list=['--throughput-buckets', '-tb'], type=shell_safe_json_parse, completer=FilesCompleter(), help='Throughput Buckets, you can enter it as a string or as a file, e.g., --tb @throughput-buckets-file.json or ' + SQL_THROUGHPUT_BUCKETS_EXAMPLE)

for scope in ['sql container throughput migrate']:
with self.argument_context('cosmosdb {}'.format(scope)) as c:
Expand Down
15 changes: 10 additions & 5 deletions src/cosmosdb-preview/azext_cosmosdb_preview/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -2362,9 +2362,12 @@ def cli_cosmosdb_sql_container_throughput_update(client,
database_name,
container_name,
throughput=None,
max_throughput=None):
max_throughput=None,
throughput_buckets=None):
"""Update an Azure Cosmos DB SQL container throughput"""
throughput_update_resource = _get_throughput_settings_update_parameters(throughput, max_throughput)
throughput_update_resource = _get_throughput_settings_update_parameters(throughput=throughput,
max_throughput = max_throughput,
throughput_buckets = throughput_buckets)
return client.begin_update_sql_container_throughput(resource_group_name,
account_name,
database_name,
Expand All @@ -2384,14 +2387,16 @@ def cli_cosmosdb_sql_container_throughput_migrate(client,
return client.begin_migrate_sql_container_to_manual_throughput(resource_group_name, account_name,
database_name, container_name)

def _get_throughput_settings_update_parameters(throughput=None, max_throughput=None):
def _get_throughput_settings_update_parameters(throughput=None, max_throughput=None, throughput_buckets=None):
throughput_resource = None
if throughput and max_throughput:
raise CLIError("Please provide max-throughput if your resource is autoscale enabled otherwise provide throughput.")
if throughput:
throughput_resource = ThroughputSettingsResource(throughput=throughput)
throughput_resource = ThroughputSettingsResource(throughput=throughput, throughput_buckets=throughput_buckets)
elif max_throughput:
throughput_resource = ThroughputSettingsResource(autoscale_settings=AutoscaleSettings(max_throughput=max_throughput))
throughput_resource = ThroughputSettingsResource(
autoscale_settings=AutoscaleSettings(max_throughput=max_throughput),
throughput_buckets=throughput_buckets)

return ThroughputSettingsUpdateParameters(resource=throughput_resource)

Expand Down
Loading
Loading