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
23 changes: 18 additions & 5 deletions src/cloudforet/cost_analysis/manager/cost_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import logging
import time
from datetime import datetime, timezone
from typing import Union, Generator, Any
from typing import Any, Generator, Union

import pandas as pd
from spaceone.core.error import *
Expand Down Expand Up @@ -193,7 +193,16 @@ def _make_data_info(
if billing_tenant_id:
additional_info["Billing Tenant Id"] = billing_tenant_id

cost: float = self._get_cost_from_result_with_options(result, options)
aggregate_data = self._get_aggregate_data(result, options)

if options.get("custom_cost_adjustment_percent"):
cost_adjustment_factor = (
1 + options.get("custom_cost_adjustment_percent") / 100
)
cost = aggregate_data["Actual Cost"] * cost_adjustment_factor
else:
cost: float = self._get_cost_from_result_with_options(result, options)

usage_quantity: float = self._convert_str_to_float_format(
result.get("quantity", 0.0)
)
Expand All @@ -203,8 +212,6 @@ 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 = self._get_aggregate_data(result, options)

# Set Network Traffic Cost at Additional Info
additional_info: dict = self._set_network_traffic_cost(
additional_info, result, usage_type
Expand Down Expand Up @@ -473,7 +480,13 @@ def _make_benefit_cost_info(
# TODO: Add logic to show Actual Cost RI/SP as retail
pass
else:
cost = actual_cost
if options.get("custom_cost_adjustment_percent"):
cost_adjustment_factor = (
1 + options.get("custom_cost_adjustment_percent") / 100
)
cost = actual_cost * cost_adjustment_factor
else:
cost = actual_cost

data = {
"cost": cost,
Expand Down
10 changes: 9 additions & 1 deletion src/cloudforet/cost_analysis/manager/data_source_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ def init_response(options: dict, domain_id: str) -> dict:
"include_credit_cost(bool)": False,
"include_reservation_cost_at_payg(str)": "ActualCost",
"show_reservation_cost_as_retail(bool): False,
"custom_cost_adjustment_percent(float)": 15,
"cost_info(dict)": {
"name" :"PayAsYouGo",
"unit" :"KRW"
Expand Down Expand Up @@ -123,7 +124,9 @@ 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": None,
# "include_reservation_cost_at_payg": None,
# "show_reservation_cost_as_retail": False,
# "custom_cost_adjustment_percent": 0.0,
"cost_info": {},
"data_info": {},
"additional_info": copy.deepcopy(_DEFAULT_METADATA_ADDITIONAL_INFO),
Expand Down Expand Up @@ -176,6 +179,11 @@ def init_response(options: dict, domain_id: str) -> dict:
if options.get("show_reservation_cost_as_retail"):
plugin_metadata["show_reservation_cost_as_retail"] = True

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

return {"metadata": plugin_metadata}

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