Skip to content

Commit

Permalink
Merge pull request #294 from ImMin5/master
Browse files Browse the repository at this point in the history
Modify set default unified cost config method
  • Loading branch information
ImMin5 authored Oct 10, 2024
2 parents 5078749 + d9a0f4d commit 89d51f2
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 10 deletions.
51 changes: 43 additions & 8 deletions src/spaceone/cost_analysis/manager/config_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,31 @@ def get_unified_cost_config(self, domain_id: str) -> dict:
params, token=system_token, x_domain_id=domain_id
)

unified_cost_config = {}
for config_info in response.get("results", []):
if data := config_info.get("data", {}):
unified_cost_config = data.get(
"unified_cost_config", self._get_default_unified_cost_config()
)
results = response.get("results", [])
total_count = response.get("total_count", 0)

if total_count > 0:
domain_config_data = results[0].get("data", {})
unified_cost_config = domain_config_data.get("unified_cost_config", {})
else:
domain_config_data = {}
unified_cost_config = {}

if not unified_cost_config:
unified_cost_config = self._get_default_unified_cost_config()
unified_cost_config = self._set_default_unified_cost_config(
domain_id, data=domain_config_data
)

return unified_cost_config

def set_domain_config(self, domain_id: str, name: str, data: dict) -> dict:
system_token = config.get_global("TOKEN")
params = {"name": name, "data": data}

return self.config_conn.dispatch(
"DomainConfig.set", params, token=system_token, x_domain_id=domain_id
)

def list_domain_configs(
self, params: dict, token: str = None, x_domain_id: str = None
) -> dict:
Expand All @@ -51,7 +65,6 @@ def list_domain_configs(
x_domain_id=x_domain_id,
)

# todo: use method
@staticmethod
def _get_default_unified_cost_config() -> dict:
default_unified_cost_config = {
Expand All @@ -66,3 +79,25 @@ def _get_default_unified_cost_config() -> dict:
"currency": "KRW",
}
return default_unified_cost_config

def _set_default_unified_cost_config(self, domain_id: str, data: dict) -> dict:
default_unified_cost_config = self._get_default_unified_cost_config()

try:
domain_config_name = _AUTH_CONFIG_KEYS[0]
data["unified_cost_config"] = default_unified_cost_config

domain_config_info = self.set_domain_config(
domain_id, domain_config_name, data
)

default_unified_cost_config = domain_config_info["data"][
"unified_cost_config"
]

except Exception as e:
_LOGGER.error(
f"Failed to set default unified cost config: {e}", exc_info=True
)

return default_unified_cost_config
1 change: 0 additions & 1 deletion src/spaceone/cost_analysis/model/unified_cost/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ class UnifiedCost(MongoModel):
max_length=40, generate_id="unified-cost", unique=True
)
cost = DictField(default={})
cost_report_name = StringField(max_length=255)
billed_month = StringField(max_length=40)
billed_year = StringField(max_length=20)
exchange_date = StringField(max_length=40)
Expand Down
1 change: 0 additions & 1 deletion src/spaceone/cost_analysis/service/unified_cost_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ def run_unified_cost(self, params: dict):
"month": 'str', (optional),
}
"""

domain_id = params["domain_id"]
aggregation_month: Union[str, None] = params.get("month")

Expand Down

0 comments on commit 89d51f2

Please sign in to comment.