diff --git a/src/cloudforet/cost_analysis/manager/cost_manager.py b/src/cloudforet/cost_analysis/manager/cost_manager.py index 9a94263..4c48ec9 100644 --- a/src/cloudforet/cost_analysis/manager/cost_manager.py +++ b/src/cloudforet/cost_analysis/manager/cost_manager.py @@ -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 * @@ -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) ) @@ -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 @@ -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, diff --git a/src/cloudforet/cost_analysis/manager/data_source_manager.py b/src/cloudforet/cost_analysis/manager/data_source_manager.py index 7334820..7f2349f 100644 --- a/src/cloudforet/cost_analysis/manager/data_source_manager.py +++ b/src/cloudforet/cost_analysis/manager/data_source_manager.py @@ -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" @@ -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), @@ -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):