Skip to content

Add options for add reservation cost at payg #101

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

Merged
merged 1 commit into from
Sep 20, 2024
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
3 changes: 2 additions & 1 deletion src/cloudforet/cost_analysis/conf/cost_conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@
}
BENEFIT_GROUPING = [
{"type": "Dimension", "name": "PricingModel"},
{"type": "Dimension", "name": "Frequency"},
{"type": "Dimension", "name": "SubscriptionId"},
{"type": "Dimension", "name": "SubscriptionName"},
{"type": "Dimension", "name": "BenefitId"},
{"type": "Dimension", "name": "BenefitName"},
{"type": "Dimension", "name": "ReservationId"},
Expand Down
46 changes: 33 additions & 13 deletions src/cloudforet/cost_analysis/manager/cost_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,9 +197,7 @@ def _make_data_info(
product: str = self._get_product_from_result(result)
tags: dict = self._convert_tags_str_to_dict(result.get("tags"))

aggregate_data, additional_info = self._get_aggregate_data(
result, options, additional_info
)
aggregate_data = self._get_aggregate_data(result, options)

# Set Network Traffic Cost at Additional Info
additional_info: dict = self._set_network_traffic_cost(
Expand Down Expand Up @@ -410,8 +408,6 @@ def _make_benefit_cost_data(

def _make_benefit_cost_info(self, result: dict, billed_at: str) -> dict:
additional_info = {
"Tenant Id": result.get("CustomerTenantId"),
"Customer Name": result.get("CustomerName"),
"Pricing Model": result.get("PricingModel"),
"Frequency": result.get("BillingFrequency"),
"Benefit Id": result.get("BenefitId"),
Expand All @@ -420,6 +416,26 @@ def _make_benefit_cost_info(self, result: dict, billed_at: str) -> dict:
"Reservation Name": result.get("ReservationName"),
"Charge Type": result.get("ChargeType"),
}

if result.get("SubscriptionId"):
additional_info["Subscription Id"] = result.get("SubscriptionId")

if result.get("CustomerName"):
additional_info["Customer Name"] = result.get("CustomerName")

if result.get("CustomerTenantId"):
additional_info["Tenant Id"] = result.get("CustomerTenantId")
elif result.get("TenantId"):
additional_info["Tenant Id"] = result.get("TenantId")

if result.get("DepartmentName"):
additional_info["Department Name"] = result.get("DepartmentName")

if result.get("EnrollmentAccountName"):
additional_info["Enrollment Account Name"] = result.get(
"EnrollmentAccountName"
)

usage_quantity = self._convert_str_to_float_format(
result.get("UsageQuantity", 0.0)
)
Expand Down Expand Up @@ -464,10 +480,6 @@ def _make_credit_data(
return credits_data

def _get_cost_from_result_with_options(self, result: dict, options: dict) -> float:
cost = self.get_pay_as_you_go_cost(result)
return cost

def get_pay_as_you_go_cost(self, result: dict) -> float:
if "paygcostinbillingcurrency" in result:
cost_pay_as_you_go = result.get("paygcostinbillingcurrency", 0.0)
elif "paygprice" in result:
Expand All @@ -482,11 +494,19 @@ def get_pay_as_you_go_cost(self, result: dict) -> float:
else:
cost_pay_as_you_go = 0.0

if options.get("include_reservation_cost_at_payg", False):
pricing_model = result.get("pricingmodel")
charge_type = result.get("chargetype")

if (
pricing_model in ["Reservation", "SavingsPlan"]
and charge_type == "Purchase"
):
cost_pay_as_you_go = result.get("costinbillingcurrency", 0.0)

return cost_pay_as_you_go

def _get_aggregate_data(
self, result: dict, options: dict, additional_info: dict
) -> Tuple[dict, dict]:
def _get_aggregate_data(self, result: dict, options: dict) -> dict:
aggregate_data = {}

if not options.get("pay_as_you_go", False):
Expand Down Expand Up @@ -518,7 +538,7 @@ def _get_aggregate_data(
else:
aggregate_data["Actual Cost"] = cost_in_billing_currency

return aggregate_data, additional_info
return aggregate_data

def _get_saved_cost(self, result: dict, cost: float) -> float:
exchange_rate = 1.0
Expand Down
5 changes: 5 additions & 0 deletions src/cloudforet/cost_analysis/manager/data_source_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ def init_response(options: dict, domain_id: str) -> dict:
"use_account_routing(bool)": False,
"exclude_license_cost(bool)": False,
"include_credit_cost(bool)": False,
"include_reservation_cost_at_payg(bool)": False,
"cost_info(dict)": {
"name" :"PayAsYouGo",
"unit" :"KRW"
Expand Down Expand Up @@ -117,6 +118,7 @@ def init_response(options: dict, domain_id: str) -> dict:
"use_account_routing": False,
"exclude_license_cost": False,
"include_credit_cost": False,
"include_reservation_cost_at_payg": False,
"cost_info": {},
"data_info": {},
"additional_info": copy.deepcopy(_DEFAULT_METADATA_ADDITIONAL_INFO),
Expand Down Expand Up @@ -161,6 +163,9 @@ def init_response(options: dict, domain_id: str) -> dict:
if options.get("include_credit_cost"):
plugin_metadata["include_credit_cost"] = True

if options.get("include_reservation_cost_at_payg"):
plugin_metadata["include_reservation_cost_at_payg"] = True

return {"metadata": plugin_metadata}

def verify_plugin(self, options, secret_data, schema):
Expand Down
Loading