diff --git a/src/spaceone/cost_analysis/error/budget.py b/src/spaceone/cost_analysis/error/budget.py index d3b7ed84..df5d4830 100644 --- a/src/spaceone/cost_analysis/error/budget.py +++ b/src/spaceone/cost_analysis/error/budget.py @@ -42,3 +42,7 @@ class ERROR_THRESHOLD_IS_WRONG_IN_PERCENT_TYPE(ERROR_INVALID_ARGUMENT): class ERROR_PROVIDER_FILTER_IS_EMPTY(ERROR_INVALID_ARGUMENT): _message = 'Provider filter is empty. (key = provider_filter.providers, value = [])' + + +class ERROR_BUDGET_ALREADY_EXIST(ERROR_INVALID_ARGUMENT): + _message = 'Budget already exist. (data_source_id = {data_source_id}, target = {target})' diff --git a/src/spaceone/cost_analysis/service/budget_service.py b/src/spaceone/cost_analysis/service/budget_service.py index d28cc3ab..5348e41e 100644 --- a/src/spaceone/cost_analysis/service/budget_service.py +++ b/src/spaceone/cost_analysis/service/budget_service.py @@ -98,6 +98,16 @@ def create(self, params): # Check Notifications self._check_notifications(notifications) + # Check Duplicated Budget + budget_vos = self.budget_mgr.filter_budgets( + data_source_id=data_source_id, + project_id=project_id, + project_group_id=project_group_id, + domain_id=domain_id + ) + if budget_vos.count() > 0: + raise ERROR_BUDGET_ALREADY_EXIST(data_source_id=data_source_id, target=project_id or project_group_id) + budget_vo = self.budget_mgr.create_budget(params) # Create budget usages