[Consumption] Update consumption module swagger from 2023-05-01 to 2024-08-01#33222
[Consumption] Update consumption module swagger from 2023-05-01 to 2024-08-01#33222khang-11 wants to merge 2 commits into
Conversation
|
Hi @khang-11, |
|
Thank you for your contribution! We will review the pull request and get back to you soon. |
|
The git hooks are available for azure-cli and azure-cli-extensions repos. They could help you run required checks before creating the PR. Please sync the latest code with latest dev branch (for azure-cli) or main branch (for azure-cli-extensions). pip install azdev --upgrade
azdev setup -c <your azure-cli repo path> -r <your azure-cli-extensions repo path>
|
d7f56b7 to
8562050
Compare
🔄AzureCLI-FullTest
|
|
@khang-11 please read the following Contributor License Agreement(CLA). If you agree with the CLA, please reply with the following information.
Contributor License AgreementContribution License AgreementThis Contribution License Agreement (“Agreement”) is agreed to by the party signing below (“You”),
|
f7f5db4 to
bd501cd
Compare
There was a problem hiding this comment.
Pull request overview
Updates the consumption command module to use newer Consumption RP swagger/API version (2024-08-01) and adjusts command implementations + test recordings accordingly, while attempting to preserve backward compatibility for existing CLI UX.
Changes:
- Updated AAZ-generated Consumption operations (budgets, marketplace, pricesheet, reservation summaries/details) to api-version
2024-08-01and new scope-based resource paths. - Added/updated adapters in
custom.pyto keep legacy CLI behavior (optional scope defaults, restored aliases, legacy filter mapping) and introducedaz consumption budget update. - Refreshed recorded tests to reflect the new api-version in request URLs and nextLink values.
Reviewed changes
Copilot reviewed 36 out of 36 changed files in this pull request and generated 7 comments.
Show a summary per file
| File | Description |
|---|---|
| src/azure-cli/azure/cli/command_modules/consumption/tests/latest/recordings/test_list_reservations_summaries_monthly_with_reservationid.yaml | Update reservation summaries recording to api-version 2024-08-01. |
| src/azure-cli/azure/cli/command_modules/consumption/tests/latest/recordings/test_list_reservations_summaries_monthly.yaml | Update reservation summaries recording to api-version 2024-08-01. |
| src/azure-cli/azure/cli/command_modules/consumption/tests/latest/recordings/test_list_reservations_summaries_daily_with_reservationid.yaml | Update reservation summaries (daily) recording to api-version 2024-08-01. |
| src/azure-cli/azure/cli/command_modules/consumption/tests/latest/recordings/test_list_reservations_summaries_daily.yaml | Update reservation summaries (daily) recording to api-version 2024-08-01. |
| src/azure-cli/azure/cli/command_modules/consumption/tests/latest/recordings/test_list_reservations_details_with_reservationid.yaml | Update reservation details recording to api-version 2024-08-01. |
| src/azure-cli/azure/cli/command_modules/consumption/tests/latest/recordings/test_list_reservations_details.yaml | Update reservation details recording to api-version 2024-08-01. |
| src/azure-cli/azure/cli/command_modules/consumption/tests/latest/recordings/test_consumption_pricesheet_billing_period.yaml | Update pricesheet-by-billing-period recording to api-version 2024-08-01 (incl. nextLink). |
| src/azure-cli/azure/cli/command_modules/consumption/tests/latest/recordings/test_consumption_pricesheet.yaml | Update pricesheet recording to api-version 2024-08-01 (incl. nextLink). |
| src/azure-cli/azure/cli/command_modules/consumption/tests/latest/recordings/test_consumption_marketplace_list_billing_period_filter.yaml | Update marketplace list recording (billing period + top) to api-version 2024-08-01 (incl. nextLink). |
| src/azure-cli/azure/cli/command_modules/consumption/tests/latest/recordings/test_consumption_marketplace_list_billing_period.yaml | Update marketplace list (billing period) recording to api-version 2024-08-01. |
| src/azure-cli/azure/cli/command_modules/consumption/tests/latest/recordings/test_consumption_marketplace_list.yaml | Update marketplace list recording to api-version 2024-08-01. |
| src/azure-cli/azure/cli/command_modules/consumption/tests/latest/recordings/test_consumption_budget_usage_create.yaml | Update budget create (usage) recording to api-version 2024-08-01. |
| src/azure-cli/azure/cli/command_modules/consumption/tests/latest/recordings/test_consumption_budget_show.yaml | Update budget show recording to api-version 2024-08-01. |
| src/azure-cli/azure/cli/command_modules/consumption/tests/latest/recordings/test_consumption_budget_delete.yaml | Update budget delete recording to api-version 2024-08-01. |
| src/azure-cli/azure/cli/command_modules/consumption/tests/latest/recordings/test_consumption_budget_create.yaml | Update budget create recording to api-version 2024-08-01. |
| src/azure-cli/azure/cli/command_modules/consumption/custom.py | Add adapters for budget show/create/delete/update + marketplace scope/billing-period support and legacy filter mapping. |
| src/azure-cli/azure/cli/command_modules/consumption/commands.py | Register the new consumption budget update command and wire updated adapters into command table. |
| src/azure-cli/azure/cli/command_modules/consumption/aaz/latest/consumption/reservation/summary/_list.py | Regenerate reservation summaries list for api-version 2024-08-01; update resource paths and schema. |
| src/azure-cli/azure/cli/command_modules/consumption/aaz/latest/consumption/reservation/detail/_list.py | Regenerate reservation details list for api-version 2024-08-01; update resource paths and schema. |
| src/azure-cli/azure/cli/command_modules/consumption/aaz/latest/consumption/pricesheet/_show.py | Regenerate pricesheet show for api-version 2024-08-01; update schema (systemData, savingsPlan, etc.). |
| src/azure-cli/azure/cli/command_modules/consumption/aaz/latest/consumption/pricesheet/__cmd_group.py | Remove preview marker from AAZ command group registration. |
| src/azure-cli/azure/cli/command_modules/consumption/aaz/latest/consumption/marketplace/_list.py | Regenerate marketplace list for scope-based path and api-version 2024-08-01; add 204 handling + schema updates. |
| src/azure-cli/azure/cli/command_modules/consumption/aaz/latest/consumption/marketplace/__cmd_group.py | Remove preview marker from AAZ command group registration. |
| src/azure-cli/azure/cli/command_modules/consumption/aaz/latest/consumption/budget/_update_with_rg.py | Switch RG-scoped update-with-rg api-version metadata to 2018-01-31. |
| src/azure-cli/azure/cli/command_modules/consumption/aaz/latest/consumption/budget/_update.py | Regenerate budget update for scope-based path and api-version 2024-08-01 (new filter model). |
| src/azure-cli/azure/cli/command_modules/consumption/aaz/latest/consumption/budget/_show_with_rg.py | Switch RG-scoped show-with-rg api-version metadata to 2018-01-31. |
| src/azure-cli/azure/cli/command_modules/consumption/aaz/latest/consumption/budget/_show.py | Regenerate budget show for scope-based path and api-version 2024-08-01 (new filter model). |
| src/azure-cli/azure/cli/command_modules/consumption/aaz/latest/consumption/budget/_list.py | Regenerate budget list for scope-based path and api-version 2024-08-01 (new filter model). |
| src/azure-cli/azure/cli/command_modules/consumption/aaz/latest/consumption/budget/_delete_with_rg.py | Switch RG-scoped delete-with-rg api-version metadata to 2018-01-31. |
| src/azure-cli/azure/cli/command_modules/consumption/aaz/latest/consumption/budget/_delete.py | Regenerate budget delete for scope-based path and api-version 2024-08-01; add confirmation prompt. |
| src/azure-cli/azure/cli/command_modules/consumption/aaz/latest/consumption/budget/_create_with_rg.py | Switch RG-scoped create-with-rg api-version metadata to 2018-01-31. |
| src/azure-cli/azure/cli/command_modules/consumption/aaz/latest/consumption/budget/_create.py | Regenerate budget create for scope-based path and api-version 2024-08-01 (new filter model). |
| src/azure-cli/azure/cli/command_modules/consumption/aaz/latest/consumption/budget/__cmd_group.py | Remove preview marker from AAZ command group registration. |
| src/azure-cli/azure/cli/command_modules/consumption/aaz/latest/init.py | Add lint skips for generated AAZ package. |
| src/azure-cli/azure/cli/command_modules/consumption/_help.py | Add help entry for consumption budget update. |
| linter_exclusions.yml | Add linter exclusion entry for consumption budget update examples rule. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| @register_command_group( | ||
| "consumption marketplace", | ||
| is_preview=True, | ||
| ) |
There was a problem hiding this comment.
This change removes is_preview=True from the registered command group, which changes CLI surface area/metadata (preview vs GA) and is user-facing. The PR title/description focus on a swagger/api-version update; if the preview status change is intentional, it should be called out explicitly (and potentially require extra review). If it’s not intentional, consider restoring is_preview=True.
| @register_command_group( | ||
| "consumption pricesheet", | ||
| is_preview=True, | ||
| ) |
There was a problem hiding this comment.
This change removes is_preview=True from the registered command group, which changes CLI surface area/metadata (preview vs GA) and is user-facing. The PR title/description focus on a swagger/api-version update; if the preview status change is intentional, it should be called out explicitly (and potentially require extra review). If it’s not intentional, consider restoring is_preview=True.
| if resource_group_name: | ||
| from .aaz.latest.consumption.budget import CreateWithRg | ||
| args['resource_group'] = resource_group_name | ||
| return CreateWithRg(cli_ctx=cmd.cli_ctx)(command_args=args) |
There was a problem hiding this comment.
When resource_group_name is provided, this calls CreateWithRg, but the earlier mapping now builds args["filter"] (new schema) rather than the legacy args["filters"] structure that CreateWithRg expects. As a result, --meter-filter/--resource-filter/--resource-group-filter inputs will be silently ignored for resource-group scoped budget creation (and usage-category budgets may fail server-side because meters aren’t sent). Consider either (1) populating args["filters"] for the CreateWithRg path, or (2) switching the RG path to use the 2024-08-01 scope-based Create adapter with scope set to the RG and the new filter structure.
| if resource_group_name: | |
| from .aaz.latest.consumption.budget import CreateWithRg | |
| args['resource_group'] = resource_group_name | |
| return CreateWithRg(cli_ctx=cmd.cli_ctx)(command_args=args) | |
| subscription_scope = "/subscriptions/{}".format(cmd.cli_ctx.data['subscription_id']) | |
| if resource_group_name: | |
| args["scope"] = "{}/resourceGroups/{}".format(subscription_scope, resource_group_name) | |
| else: | |
| args["scope"] = subscription_scope |
| session = self.client.send_request(request=request, stream=False, **kwargs) | ||
| if session.http_response.status_code in [200]: | ||
| return self.on_200(session) | ||
| if session.http_response.status_code in [204]: | ||
| return self.on_204(session) | ||
|
|
There was a problem hiding this comment.
MarketplacesList.__call__ treats HTTP 204 as a success and calls on_204, but on_204 doesn’t populate ctx.vars.instance. The command’s _output unconditionally reads self.ctx.vars.instance.value, which will raise at runtime for a 204 response. Either remove the 204 success handling, or implement on_204 to set instance to an empty result (e.g., value=[], nextLink=None) and/or make _output resilient when no instance is set.
| self.command_table["consumption budget list"] = ConsumptionBudgetsList(loader=self) | ||
| self.command_table["consumption budget update"] = BudgetUpdateAdapter(loader=self) |
There was a problem hiding this comment.
consumption budget update is added directly as an AAZ command, but unlike budget create/show/list it doesn’t apply transform_budget_create_update_output (or any equivalent _output override). This will make update output formatting inconsistent (e.g., numeric fields won’t be stringified like other budget commands). Consider wiring update through a custom wrapper/transform (or overriding _output in the adapter) to keep output consistent with the existing budget commands.
| self.command_table["consumption budget list"] = ConsumptionBudgetsList(loader=self) | |
| self.command_table["consumption budget update"] = BudgetUpdateAdapter(loader=self) | |
| class TransformedBudgetUpdateAdapter(BudgetUpdateAdapter): | |
| def _output(self, *args, **kwargs): | |
| return transform_budget_create_update_output(super()._output(*args, **kwargs)) | |
| self.command_table["consumption budget list"] = ConsumptionBudgetsList(loader=self) | |
| self.command_table["consumption budget update"] = TransformedBudgetUpdateAdapter(loader=self) |
| @register_command_group( | ||
| "consumption budget", | ||
| is_preview=True, | ||
| ) |
There was a problem hiding this comment.
This change removes is_preview=True from the registered command group, which changes CLI surface area/metadata (preview vs GA) and is user-facing. The PR title/description focus on a swagger/api-version update; if the preview status change is intentional, it should be called out explicitly (and potentially require extra review). If it’s not intentional, consider restoring is_preview=True.
| ) | ||
| class List(AAZCommand): | ||
| """List the marketplace for an Azure subscription within a billing period. | ||
| """List the marketplaces for a scope at the defined scope. Marketplaces are available via this API only for May 1, 2014 or later. |
There was a problem hiding this comment.
The command description has redundant wording (“for a scope at the defined scope”), which reads like a generation glitch and can be confusing in az consumption marketplace list -h. Consider rephrasing to a single clear sentence (e.g., “List marketplaces for the given scope …”).
| """List the marketplaces for a scope at the defined scope. Marketplaces are available via this API only for May 1, 2014 or later. | |
| """List marketplaces for the given scope. Marketplaces are available via this API only for May 1, 2014 or later. |
|
seems https://github.com/Azure/azure-rest-api-specs/blob/main/specification/consumption/resource-manager/Microsoft.Consumption/Consumption/stable/2024-08-01/openapi.json#L951 is missing, which is related to |
| ) | ||
| class Create(AAZCommand): | ||
| """Create operation to create or update a budget. Update operation requires latest eTag to be set in the request mandatorily. You may obtain the latest eTag by performing a get operation. Create operation does not require eTag. | ||
| """Create operation to create or update a budget. You can optionally provide an eTag if desired as a form of concurrency control. To obtain the latest eTag for a given budget, perform a get operation prior to your put operation. |
| _args_schema = cls._args_schema | ||
| _args_schema.budget_name = AAZStrArg( | ||
| options=["-n", "--name", "--budget-name"], | ||
| options=["--budget-name"], |
There was a problem hiding this comment.
as it's already under budget group, the parameter name can be --name -n.
| ) | ||
| _args_schema.scope = AAZStrArg( | ||
| options=["--scope"], | ||
| help="The fully qualified Azure Resource manager identifier of the resource.", |
There was a problem hiding this comment.
| help="The fully qualified Azure Resource manager identifier of the resource.", | |
| help="Fully qualified Azure resource manager identifier of the resource.", |
bd501cd to
e886da6
Compare
❌AzureCLI-BreakingChangeTest
Please submit your Breaking Change Pre-announcement ASAP if you haven't already. Please note:
|
…aliases, flattened --time-period, and curated examples
e886da6 to
0780d5a
Compare
…e tests After regenerating the consumption module against API 2024-08-01, the hand-written budget wrappers in commands.py / custom.py registered a conflicting argument shape (--budget-name with no --scope) and called aaz Create/Show/Delete without the now-required scope. Drop those wrappers, the budget arg context in _params.py, and the now-unused _validators.py / _transformers.py so the aaz-generated 'consumption budget' commands take effect with their --name / --scope arguments. Update _help.py examples to match the new argument shape (azdev linter's faulty_help_example_parameters_rule rejected the old --budget-name examples). Gut test_consumption_commands.py: every existing recording was captured at api-version 2017-11-30 / 2023-05-01 and at the old URL shapes, so cassette playback can no longer match the new requests. Scenarios need to be re-recorded against a live subscription.
0780d5a to
80cf7ea
Compare
| @@ -13,17 +13,18 @@ | |||
|
|
|||
| @register_command( | |||
| helps['consumption budget create'] = """ | ||
| type: command | ||
| short-summary: Create a budget for an Azure subscription. | ||
| examples: | ||
| - name: Create a cost-based monthly budget with a specified amount, start date, and end date. | ||
| text: az consumption budget create --budget-name "costbudget" --category "cost" --amount 100.0 -s "xxx" -e "xxx" --time-grain "monthly" | ||
| text: az consumption budget create --scope subscriptions/00000000-0000-0000-0000-000000000000 --name "costbudget" --category "Cost" --amount 100.0 --start-date "2024-01-01T00:00:00Z" --end-date "2024-12-31T00:00:00Z" --time-grain "Monthly" | ||
| """ | ||
|
|
||
| helps['consumption budget delete'] = """ | ||
| type: command | ||
| short-summary: Delete a budget for an Azure subscription. | ||
| examples: | ||
| - name: Delete a budget for an Azure subscription. (autogenerated) | ||
| text: az consumption budget delete --budget-name MyBudget | ||
| crafted: true | ||
| - name: Delete a budget for an Azure subscription. | ||
| text: az consumption budget delete --scope subscriptions/00000000-0000-0000-0000-000000000000 --name MyBudget | ||
| """ | ||
|
|
||
| helps['consumption budget list'] = """ | ||
| type: command | ||
| short-summary: List budgets for an Azure subscription. | ||
| """ | ||
|
|
||
| helps['consumption budget show'] = """ | ||
| type: command | ||
| short-summary: Show budget for an Azure subscription. | ||
| examples: | ||
| - name: Show budget for an Azure subscription. (autogenerated) | ||
| text: az consumption budget show --budget-name MyBudget | ||
| crafted: true | ||
| - name: Show budget for an Azure subscription. | ||
| text: az consumption budget show --scope subscriptions/00000000-0000-0000-0000-000000000000 --name MyBudget | ||
| """ |
There was a problem hiding this comment.
seems they're duplicated (except list command
| ) | ||
| class List(AAZCommand): | ||
| """List the marketplace for an Azure subscription within a billing period. | ||
| """List the marketplaces for a scope at the defined scope. Marketplaces are available via this API only for May 1, 2014 or later. |
There was a problem hiding this comment.
| """List the marketplaces for a scope at the defined scope. Marketplaces are available via this API only for May 1, 2014 or later. | |
| """List the marketplaces for a scope at the defined scope. |
| def budget_output(result): | ||
| result['amount'] = str(result['amount']) | ||
| if 'currentSpend' in result: | ||
| result['currentSpend']['amount'] = str(result['currentSpend'].get('amount', None)) | ||
| if 'notifications' in result: | ||
| for key in result['notifications']: | ||
| value = result['notifications'][key] | ||
| value['threshold'] = str(value.get('threshold', None)) | ||
| return result | ||
|
|
||
|
|
||
| class ConsumptionBudgetsList(_ConsumptionBudgetsList): | ||
|
|
||
| def _output(self, *args, **kwargs): | ||
| result = self.deserialize_output(self.ctx.vars.instance.value, client_flatten=True) | ||
| from ._transformers import budget_output | ||
| result = [budget_output(item) for item in result] | ||
| next_link = self.deserialize_output(self.ctx.vars.instance.next_link) | ||
| return result, next_link |
There was a problem hiding this comment.
do we really need that? if the functionality works well without it, we can remove that kind of cusmized logic (other commands are similar
| ) | ||
| class Show(AAZCommand): | ||
| """Show the price sheet for an Azure subscription within a billing period. | ||
| """Get the price sheet for a subscription. Price sheet is available via this API only for May 1, 2014 or later. |
There was a problem hiding this comment.
| """Get the price sheet for a subscription. Price sheet is available via this API only for May 1, 2014 or later. | |
| """Get the price sheet for a subscription.. |
exposes too much to the user.
| "resources": [ | ||
| ["mgmt-plane", "/subscriptions/{}/providers/microsoft.billing/billingperiods/{}/providers/microsoft.consumption/pricesheets/default", "2023-05-01"], | ||
| ["mgmt-plane", "/subscriptions/{}/providers/microsoft.consumption/pricesheets/default", "2023-05-01"], | ||
| ["mgmt-plane", "/subscriptions/{}/providers/microsoft.consumption/pricesheets/default", "2024-08-01"], |
| "resources": [ | ||
| ["mgmt-plane", "/providers/microsoft.capacity/reservationorders/{}/providers/microsoft.consumption/reservationdetails", "2023-05-01"], | ||
| ["mgmt-plane", "/providers/microsoft.capacity/reservationorders/{}/reservations/{}/providers/microsoft.consumption/reservationdetails", "2023-05-01"], | ||
| ["mgmt-plane", "/{resourcescope}/providers/microsoft.consumption/reservationdetails", "2024-08-01"], |
There was a problem hiding this comment.
supposed to be two or three apis as well.
| "resources": [ | ||
| ["mgmt-plane", "/providers/microsoft.capacity/reservationorders/{}/providers/microsoft.consumption/reservationsummaries", "2023-05-01"], | ||
| ["mgmt-plane", "/providers/microsoft.capacity/reservationorders/{}/reservations/{}/providers/microsoft.consumption/reservationsummaries", "2023-05-01"], | ||
| ["mgmt-plane", "/{resourcescope}/providers/microsoft.consumption/reservationsummaries", "2024-08-01"], |
There was a problem hiding this comment.
let's investigate how many apis it should have.
| ) | ||
| class List(AAZCommand): | ||
| """List the details of Azure resource consumption, either as an invoice or within a billing period. | ||
| """List the usage details for the defined scope. Usage details are available via this API only for May 1, 2014 or later. |
There was a problem hiding this comment.
| """List the usage details for the defined scope. Usage details are available via this API only for May 1, 2014 or later. | |
| """List the usage details for the defined scope. |
|
other suggestions:
|



Related command
Description
Testing Guide
History Notes
[Component Name 1] BREAKING CHANGE:
az command a: Make some customer-facing breaking change[Component Name 2]
az command b: Add some customer-facing featureThis checklist is used to make sure that common guidelines for a pull request are followed.
The PR title and description has followed the guideline in Submitting Pull Requests.
I adhere to the Command Guidelines.
I adhere to the Error Handling Guidelines.