Skip to content

Commit eb3e2a1

Browse files
committed
feat: add actions spec for routing multiple workspaces
1 parent cb6c605 commit eb3e2a1

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

src/spaceone/cost_analysis/manager/cost_manager.py

+5
Original file line numberDiff line numberDiff line change
@@ -489,11 +489,16 @@ def _change_filter_v_workspace_id(
489489
) = self.data_source_account_mgr.list_data_source_accounts(
490490
ds_account_list_query
491491
)
492+
if not isinstance(value, list):
493+
workspace_ids.append(value)
494+
else:
495+
workspace_ids.extend(value)
492496

493497
if total_count > 0:
494498
for ds_accounts_vo in ds_accounts_vos:
495499
if ds_accounts_vo.workspace_id:
496500
workspace_ids.append(ds_accounts_vo.v_workspace_id)
501+
workspace_ids.remove(ds_accounts_vo.workspace_id)
497502

498503
change_filter.append(
499504
{"k": "workspace_id", "v": workspace_ids, "o": "in"}

src/spaceone/cost_analysis/manager/data_source_rule_manager.py

+8-3
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,11 @@ def _change_cost_data_with_actions(
155155
source = value["source"]
156156
target_key = value.get("target", "service_account_id")
157157
target_value = utils.get_dict_value(cost_data, source)
158+
all_workspaces = value.get("all_workspaces", False)
159+
160+
if all_workspaces:
161+
workspace_id = None
162+
158163
if target_value:
159164
service_account_info = self._get_service_account(
160165
target_key, target_value, domain_id, workspace_id
@@ -179,11 +184,11 @@ def _get_service_account(
179184
self, target_key, target_value, domain_id: str, workspace_id: str = None
180185
):
181186
if (
182-
f"service-account:{domain_id}:{target_key}:{target_value}"
187+
f"service-account:{domain_id}:{target_key}:{target_value}:{workspace_id}"
183188
in self._service_account_info
184189
):
185190
return self._service_account_info[
186-
f"service-account:{domain_id}:{target_key}:{target_value}"
191+
f"service-account:{domain_id}:{target_key}:{target_value}:{workspace_id}"
187192
]
188193

189194
query = {
@@ -207,7 +212,7 @@ def _get_service_account(
207212
service_account_info = results[0]
208213

209214
self._service_account_info[
210-
f"service-account:{domain_id}:{target_key}:{target_value}"
215+
f"service-account:{domain_id}:{target_key}:{target_value}:{workspace_id}"
211216
] = service_account_info
212217
return service_account_info
213218

0 commit comments

Comments
 (0)