Skip to content

Commit d553c85

Browse files
authored
Merge pull request #120 from lhhyung/master
Add custom cost adjustment in cost
2 parents 9c4c186 + edbcfe2 commit d553c85

File tree

2 files changed

+27
-6
lines changed

2 files changed

+27
-6
lines changed

src/cloudforet/cost_analysis/manager/cost_manager.py

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import logging
44
import time
55
from datetime import datetime, timezone
6-
from typing import Union, Generator, Any
6+
from typing import Any, Generator, Union
77

88
import pandas as pd
99
from spaceone.core.error import *
@@ -193,7 +193,16 @@ def _make_data_info(
193193
if billing_tenant_id:
194194
additional_info["Billing Tenant Id"] = billing_tenant_id
195195

196-
cost: float = self._get_cost_from_result_with_options(result, options)
196+
aggregate_data = self._get_aggregate_data(result, options)
197+
198+
if options.get("custom_cost_adjustment_percent"):
199+
cost_adjustment_factor = (
200+
1 + options.get("custom_cost_adjustment_percent") / 100
201+
)
202+
cost = aggregate_data["Actual Cost"] * cost_adjustment_factor
203+
else:
204+
cost: float = self._get_cost_from_result_with_options(result, options)
205+
197206
usage_quantity: float = self._convert_str_to_float_format(
198207
result.get("quantity", 0.0)
199208
)
@@ -203,8 +212,6 @@ def _make_data_info(
203212
product: str = self._get_product_from_result(result)
204213
tags: dict = self._convert_tags_str_to_dict(result.get("tags"))
205214

206-
aggregate_data = self._get_aggregate_data(result, options)
207-
208215
# Set Network Traffic Cost at Additional Info
209216
additional_info: dict = self._set_network_traffic_cost(
210217
additional_info, result, usage_type
@@ -473,7 +480,13 @@ def _make_benefit_cost_info(
473480
# TODO: Add logic to show Actual Cost RI/SP as retail
474481
pass
475482
else:
476-
cost = actual_cost
483+
if options.get("custom_cost_adjustment_percent"):
484+
cost_adjustment_factor = (
485+
1 + options.get("custom_cost_adjustment_percent") / 100
486+
)
487+
cost = actual_cost * cost_adjustment_factor
488+
else:
489+
cost = actual_cost
477490

478491
data = {
479492
"cost": cost,

src/cloudforet/cost_analysis/manager/data_source_manager.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ def init_response(options: dict, domain_id: str) -> dict:
9595
"include_credit_cost(bool)": False,
9696
"include_reservation_cost_at_payg(str)": "ActualCost",
9797
"show_reservation_cost_as_retail(bool): False,
98+
"custom_cost_adjustment_percent(float)": 15,
9899
"cost_info(dict)": {
99100
"name" :"PayAsYouGo",
100101
"unit" :"KRW"
@@ -123,7 +124,9 @@ def init_response(options: dict, domain_id: str) -> dict:
123124
"use_account_routing": False,
124125
"exclude_license_cost": False,
125126
"include_credit_cost": False,
126-
"include_reservation_cost_at_payg": None,
127+
# "include_reservation_cost_at_payg": None,
128+
# "show_reservation_cost_as_retail": False,
129+
# "custom_cost_adjustment_percent": 0.0,
127130
"cost_info": {},
128131
"data_info": {},
129132
"additional_info": copy.deepcopy(_DEFAULT_METADATA_ADDITIONAL_INFO),
@@ -176,6 +179,11 @@ def init_response(options: dict, domain_id: str) -> dict:
176179
if options.get("show_reservation_cost_as_retail"):
177180
plugin_metadata["show_reservation_cost_as_retail"] = True
178181

182+
if options.get("custom_cost_adjustment_percent"):
183+
plugin_metadata["custom_cost_adjustment_percent"] = options.get(
184+
"custom_cost_adjustment_percent"
185+
)
186+
179187
return {"metadata": plugin_metadata}
180188

181189
def verify_plugin(self, options, secret_data, schema):

0 commit comments

Comments
 (0)