diff --git a/src/spaceone/cost_analysis/manager/budget_usage_manager.py b/src/spaceone/cost_analysis/manager/budget_usage_manager.py index 66ed5ab7..5a8d6801 100644 --- a/src/spaceone/cost_analysis/manager/budget_usage_manager.py +++ b/src/spaceone/cost_analysis/manager/budget_usage_manager.py @@ -108,9 +108,9 @@ def _update_monthly_budget_usage(self, budget_vo: Budget, cost_mgr: CostManager) budget_usage_vos = self.budget_usage_model.filter(budget_id=budget_vo.budget_id) for budget_usage_vo in budget_usage_vos: if budget_usage_vo.date in update_data: - budget_usage_vo.update({'usd_cost': update_data[budget_usage_vo.date]}) + budget_usage_vo.update({'cost': update_data[budget_usage_vo.date]}) else: - budget_usage_vo.update({'usd_cost': 0}) + budget_usage_vo.update({'cost': 0}) def _make_cost_analyze_query(self, budget_vo: Budget): query = { @@ -125,6 +125,7 @@ def _make_cost_analyze_query(self, budget_vo: Budget): }, 'filter': [ {'k': 'domain_id', 'v': budget_vo.domain_id, 'o': 'eq'}, + {'k': 'data_source_id', 'v': budget_vo.data_source_id, 'o': 'eq'}, ] } @@ -142,7 +143,7 @@ def _make_cost_analyze_query(self, budget_vo: Budget): query['filter'].append({'k': 'project_id', 'v': project_ids, 'o': 'in'}) - if budget_vo.provider_filter.state == 'ENABLED': + if budget_vo.provider_filter and budget_vo.provider_filter.state == 'ENABLED': query['filter'].append({'k': 'provider', 'v': budget_vo.provider_filter.providers, 'o': 'in'}) return query diff --git a/src/spaceone/cost_analysis/service/budget_service.py b/src/spaceone/cost_analysis/service/budget_service.py index fe3bb956..6f3a49a0 100644 --- a/src/spaceone/cost_analysis/service/budget_service.py +++ b/src/spaceone/cost_analysis/service/budget_service.py @@ -71,11 +71,14 @@ def create(self, params): if len(provider_filter.get('providers', [])) == 0: raise ERROR_PROVIDER_FILTER_IS_EMPTY() else: - params['provider_filter']['providers'] = [] + params['provider_filter'] = { + 'state': 'DISABLED', + 'providers': [] + } data_source_mgr: DataSourceManager = self.locator.get_manager('DataSourceManager') data_source_vo: DataSource = data_source_mgr.get_data_source(data_source_id, domain_id) - data_source_metadata = data_source_vo.plugin_info.get('metadata', {}) + data_source_metadata = data_source_vo.plugin_info.metadata params['currency'] = data_source_metadata['currency'] if time_unit == 'TOTAL': diff --git a/src/spaceone/cost_analysis/service/job_service.py b/src/spaceone/cost_analysis/service/job_service.py index 4cc21721..a6a0bbfe 100644 --- a/src/spaceone/cost_analysis/service/job_service.py +++ b/src/spaceone/cost_analysis/service/job_service.py @@ -442,12 +442,13 @@ def _close_job(self, job_id, domain_id, data_source_id): self.job_mgr.change_error_status(job_vo, e) raise e - self.budget_usage_mgr.update_budget_usage(domain_id, data_source_id) self.cost_mgr.remove_stat_cache(domain_id, data_source_id) if not no_preload_cache: self.job_mgr.preload_cost_stat_queries(domain_id, data_source_id) + self.budget_usage_mgr.update_budget_usage(domain_id, data_source_id) + self._update_last_sync_time(job_vo) self.job_mgr.change_success_status(job_vo)