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

{Consumption} az consumption: Migrate to atomic commands #27152

Merged
merged 6 commits into from
Aug 18, 2023
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
11 changes: 11 additions & 0 deletions src/azure-cli/azure/cli/command_modules/consumption/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,17 @@ def __init__(self, cli_ctx=None):

def load_command_table(self, args):
from azure.cli.command_modules.consumption.commands import load_command_table
from azure.cli.core.aaz import load_aaz_command_table
try:
from . import aaz
except ImportError:
aaz = None
if aaz:
load_aaz_command_table(
loader=self,
aaz_pkg_name=aaz.__name__,
args=args
)
load_command_table(self, args)
return self.command_table

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,91 +4,17 @@
# --------------------------------------------------------------------------------------------


def transform_usage_output(result):
result.usage_start = result.usage_start.strftime("%Y-%m-%dT%H:%M:%SZ")
result.usage_end = result.usage_end.strftime("%Y-%m-%dT%H:%M:%SZ")
result.usage_quantity = str(result.usage_quantity)
result.billable_quantity = str(result.billable_quantity)
result.pretax_cost = str(result.pretax_cost)
if result.meter_details:
result.meter_details.total_included_quantity = str(result.meter_details.total_included_quantity)
result.meter_details.pretax_standard_rate = str(result.meter_details.pretax_standard_rate)
return result


def transform_usage_list_output(result):
return [transform_usage_output(item) for item in result]


def reservation_summary_output(result):

result.reserved_hours = str(result.reserved_hours)
result.usage_date = result.usage_date.strftime("%Y-%m-%dT%H:%M:%SZ")
result.used_hours = str(result.used_hours)
result.max_utilization_percentage = str(result.max_utilization_percentage)
result.min_utilization_percentage = str(result.min_utilization_percentage)
result.avg_utilization_percentage = str(result.avg_utilization_percentage)
return result


def transform_reservation_summary_list_output(result):
return [reservation_summary_output(item) for item in result]


def reservation_detail_output(result):

result.reserved_hours = str(result.reserved_hours)
result.usage_date = result.usage_date.strftime("%Y-%m-%dT%H:%M:%SZ")
result.used_hours = str(result.used_hours)
result.total_reserved_quantity = str(result.total_reserved_quantity)
return result


def transform_reservation_detail_list_output(result):
return [reservation_detail_output(item) for item in result]


def pricesheet_show_properties(result):
result.unit_of_measure = str(result.unit_of_measure)
result.included_quantity = str(result.included_quantity)
result.unit_price = str(result.unit_price)
if result.meter_details:
result.meter_details.total_included_quantity = str(result.meter_details.total_included_quantity)
result.meter_details.pretax_standard_rate = str(result.meter_details.pretax_standard_rate)
return result


def transform_pricesheet_show_output(result):
result.pricesheets = [pricesheet_show_properties(item) for item in result.pricesheets]
return result


def marketplace_list_output(result):
result.pretax_cost = str(result.pretax_cost)
result.consumed_quantity = str(result.consumed_quantity)
result.resource_rate = str(result.resource_rate)
return result


def transform_marketplace_list_output(result):
return [marketplace_list_output(item) for item in result]


def budget_output(result):
result.amount = str(result.amount)
if result.current_spend:
result.current_spend.amount = str(result.current_spend.amount)
if result.notifications:
for key in result.notifications:
value = result.notifications[key]
value.threshold = str(value.threshold)
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


def transform_budget_list_output(result):
return [budget_output(item) for item in result]


def transform_budget_show_output(result):
return budget_output(result)

Expand Down
15 changes: 0 additions & 15 deletions src/azure-cli/azure/cli/command_modules/consumption/_validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,21 +27,6 @@ def decimal_type(string):
raise ValueError("the value passed cannot be converted to decimal")


def validate_both_start_end_dates(namespace):
"""Validates the existence of both start and end dates in the parameter or neither"""
if bool(namespace.start_date) != bool(namespace.end_date):
raise CLIError("usage error: Both --start-date and --end-date need to be supplied or neither.")


def validate_reservation_summary(namespace):
"""lowercase the data grain for comparison"""
data_grain = namespace.grain.lower()
if data_grain not in ('daily', 'monthly'):
raise CLIError("usage error: --grain can be either daily or monthly.")
if data_grain == 'daily' and (not namespace.start_date or not namespace.end_date):
raise CLIError("usage error: Both --start-date and --end-date need to be supplied for daily grain.")


def validate_budget_parameters(namespace):
if namespace.amount < 0:
raise CLIError("usage error: --amount must be greater than 0")
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# --------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
#
# Code generated by aaz-dev-tools
# --------------------------------------------------------------------------------------------
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# --------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
#
# Code generated by aaz-dev-tools
# --------------------------------------------------------------------------------------------
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# --------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
#
# Code generated by aaz-dev-tools
# --------------------------------------------------------------------------------------------

# pylint: skip-file
# flake8: noqa

from azure.cli.core.aaz import *


@register_command_group(
"consumption",
)
class __CMDGroup(AAZCommandGroup):
"""Manage consumption of Azure resources.
"""
pass


__all__ = ["__CMDGroup"]
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
# --------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
#
# Code generated by aaz-dev-tools
# --------------------------------------------------------------------------------------------

from knack.util import CLIError
# pylint: skip-file
# flake8: noqa


def consumption_exception_handler(ex):
from azure.mgmt.consumption.models import ErrorResponseException
if isinstance(ex, ErrorResponseException):
message = ex.message
raise CLIError(message)
raise ex
from .__cmd_group import *
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# --------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
#
# Code generated by aaz-dev-tools
# --------------------------------------------------------------------------------------------

# pylint: skip-file
# flake8: noqa

from azure.cli.core.aaz import *


@register_command_group(
"consumption budget",
is_preview=True,
)
class __CMDGroup(AAZCommandGroup):
"""Manage budgets for an Azure subscription.
"""
pass


__all__ = ["__CMDGroup"]
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# --------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
#
# Code generated by aaz-dev-tools
# --------------------------------------------------------------------------------------------

# pylint: skip-file
# flake8: noqa

from .__cmd_group import *
from ._create import *
from ._create_with_rg import *
from ._delete import *
from ._delete_with_rg import *
from ._list import *
from ._show import *
from ._show_with_rg import *
from ._update import *
from ._update_with_rg import *
Loading