Skip to content

Commit

Permalink
Merge pull request #141 from ImMin5/master
Browse files Browse the repository at this point in the history
Fix budget update error because of datasource_id parameter
  • Loading branch information
ImMin5 authored Jan 12, 2024
2 parents 574b61e + d16ef3f commit f5ce250
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 33 deletions.
25 changes: 3 additions & 22 deletions src/spaceone/cost_analysis/manager/budget_usage_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,7 @@ def update_cost_usage(

self._update_monthly_budget_usage(budget_vo, cost_mgr)

def update_budget_usage(
self, domain_id: str, data_source_id: str
):
def update_budget_usage(self, domain_id: str, data_source_id: str):
budget_vos = self.budget_mgr.filter_budgets(
domain_id=domain_id,
data_source_id=data_source_id,
Expand Down Expand Up @@ -325,7 +323,8 @@ def _update_monthly_budget_usage(self, budget_vo: Budget, cost_mgr: CostManager)
else:
budget_usage_vo.update({"cost": 0})

def _make_cost_analyze_query(self, budget_vo: Budget):
@staticmethod
def _make_cost_analyze_query(budget_vo: Budget):
query = {
"granularity": "MONTHLY",
"start": budget_vo.start,
Expand All @@ -342,24 +341,6 @@ def _make_cost_analyze_query(self, budget_vo: Budget):
query["filter"].append(
{"k": "project_id", "v": budget_vo.project_id, "o": "eq"}
)
# else:
# identity_mgr: IdentityManager = self.locator.get_manager("IdentityManager")
#
# project_query = {
# "filter": [
# {"k": "domain_id", "v": budget_vo.domain_id, "o": "eq"},
# {"k": "workspace_id", "v": budget_vo.workspace_id, "o": "eq"},
# ]
# }
# projects_info = identity_mgr.list_projects(
# project_query, budget_vo.domain_id
# )
#
# project_ids = []
# for project_info in projects_info.get("results", []):
# project_ids.append(project_info["project_id"])
#
# query["filter"].append({"k": "project_id", "v": project_ids, "o": "in"})

if budget_vo.provider_filter and budget_vo.provider_filter.state == "ENABLED":
query["filter"].append(
Expand Down
15 changes: 4 additions & 11 deletions src/spaceone/cost_analysis/service/budget_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ def create(self, params):
provider_filter_state = provider_filter.get("state", "DISABLED")
notifications = params.get("notifications", [])
resource_group = params["resource_group"]
# self._check_target(project_id, project_group_id, domain_id)
self._check_time_period(start, end)

identity_mgr: IdentityManager = self.locator.get_manager("IdentityManager")
Expand Down Expand Up @@ -149,9 +148,7 @@ def create(self, params):
"BudgetUsageManager"
)
budget_usage_mgr.create_budget_usages(budget_vo)
budget_usage_mgr.update_cost_usage(
budget_vo=budget_vo, data_source_workspace_id=data_source_vo.workspace_id
)
budget_usage_mgr.update_cost_usage(budget_vo)
budget_usage_mgr.notify_budget_usage(budget_vo)

return budget_vo
Expand Down Expand Up @@ -194,7 +191,6 @@ def update(self, params):
)

# Check limit and Planned Limits

budget_vo = self.budget_mgr.update_budget_by_vo(params, budget_vo)

if "name" in params:
Expand All @@ -206,14 +202,11 @@ def update(self, params):
budget_usage_mgr.update_budget_usage_by_vo(
{"name": params["name"]}, budget_usage_vo
)
# Check DataSource exists
data_source_mgr = self.locator.get_manager("DataSourceManager")
data_source_vo = data_source_mgr.get_data_source(
budget_vo.data_source_id, domain_id
)
data_source_mgr.get_data_source(budget_vo.data_source_id, domain_id)

budget_usage_mgr.update_cost_usage(
budget_vo=budget_vo, data_source_workspace_id=data_source_vo.workspace_id
)
budget_usage_mgr.update_cost_usage(budget_vo)
budget_usage_mgr.notify_budget_usage(budget_vo)

return budget_vo
Expand Down

0 comments on commit f5ce250

Please sign in to comment.