Skip to content

Commit

Permalink
refactor: de-duplicate budget target (project_id or project_group_id)
Browse files Browse the repository at this point in the history
  • Loading branch information
whdalsrnt committed Sep 20, 2023
1 parent 3b4eb11 commit d001ef3
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/spaceone/cost_analysis/error/budget.py
Original file line number Diff line number Diff line change
Expand Up @@ -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})'
10 changes: 10 additions & 0 deletions src/spaceone/cost_analysis/service/budget_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit d001ef3

Please sign in to comment.