Skip to content

Commit 4459771

Browse files
committed
feat: modify extend synced_accounts only with account id from plugin
Signed-off-by: ImMin5 <mino@megazone.com>
1 parent 48bc8d3 commit 4459771

File tree

1 file changed

+52
-47
lines changed

1 file changed

+52
-47
lines changed

src/spaceone/cost_analysis/service/job_service.py

+52-47
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ def get_cost_data(self, params):
260260
is_canceled = False
261261

262262
for costs_data in self.ds_plugin_mgr.get_cost_data(
263-
options, secret_data, schema, task_options, domain_id
263+
options, secret_data, schema, task_options, domain_id
264264
):
265265
results = costs_data.get("results", [])
266266
for cost_data in results:
@@ -370,7 +370,12 @@ def create_cost_job(self, data_source_vo: DataSource, job_options):
370370
)
371371
tasks.extend(single_tasks)
372372
changed.extend(single_changed)
373-
synced_accounts.extend(single_synced_accounts)
373+
synced_accounts.extend(
374+
[
375+
single_synced_account.get("account_id")
376+
for single_synced_account in single_synced_accounts
377+
]
378+
)
374379
except Exception as e:
375380
_LOGGER.error(f"[create_cost_job] get_tasks error: {e}", exc_info=True)
376381

@@ -436,11 +441,11 @@ def create_cost_job(self, data_source_vo: DataSource, job_options):
436441
return job_vo
437442

438443
def _list_secret_ids_from_secret_type(
439-
self,
440-
data_source_vo: DataSource,
441-
secret_type: str,
442-
workspace_id: str,
443-
domain_id: str,
444+
self,
445+
data_source_vo: DataSource,
446+
secret_type: str,
447+
workspace_id: str,
448+
domain_id: str,
444449
):
445450
secret_ids = []
446451

@@ -461,7 +466,7 @@ def _list_secret_ids_from_secret_type(
461466
return secret_ids
462467

463468
def _list_secret_ids_from_secret_filter(
464-
self, secret_filter, provider: str, workspace_id: str, domain_id: str
469+
self, secret_filter, provider: str, workspace_id: str, domain_id: str
465470
):
466471
secret_manager: SecretManager = self.locator.get_manager(SecretManager)
467472

@@ -476,7 +481,7 @@ def _list_secret_ids_from_secret_filter(
476481

477482
@staticmethod
478483
def _set_secret_filter(
479-
secret_filter, provider: str, workspace_id: str, domain_id: str
484+
secret_filter, provider: str, workspace_id: str, domain_id: str
480485
):
481486
_filter = [{"k": "domain_id", "v": domain_id, "o": "eq"}]
482487

@@ -491,8 +496,8 @@ def _set_secret_filter(
491496
{"k": "secret_id", "v": secret_filter["secrets"], "o": "in"}
492497
)
493498
if (
494-
"service_accounts" in secret_filter
495-
and secret_filter["service_accounts"]
499+
"service_accounts" in secret_filter
500+
and secret_filter["service_accounts"]
496501
):
497502
_filter.append(
498503
{
@@ -588,10 +593,10 @@ def _create_cost_data(self, cost_data, job_task_vo, cost_options):
588593
self.cost_mgr.create_cost(cost_data, execute_rollback=False)
589594

590595
def _is_job_failed(
591-
self,
592-
job_id: str,
593-
domain_id: str,
594-
workspace_id: str,
596+
self,
597+
job_id: str,
598+
domain_id: str,
599+
workspace_id: str,
595600
):
596601
job_vo: Job = self.job_mgr.get_job(job_id, domain_id, workspace_id)
597602

@@ -601,14 +606,14 @@ def _is_job_failed(
601606
return False
602607

603608
def _close_job(
604-
self,
605-
job_id: str,
606-
data_source_id: str,
607-
domain_id: str,
608-
data_keys: list,
609-
additional_info_keys: list,
610-
tag_keys: list,
611-
workspace_id: str = None,
609+
self,
610+
job_id: str,
611+
data_source_id: str,
612+
domain_id: str,
613+
data_keys: list,
614+
additional_info_keys: list,
615+
tag_keys: list,
616+
workspace_id: str = None,
612617
) -> None:
613618
job_vo: Job = self.job_mgr.get_job(job_id, domain_id, workspace_id)
614619
no_preload_cache = job_vo.options.get("no_preload_cache", False)
@@ -762,7 +767,7 @@ def _delete_old_cost_data(self, data_source_id: str, domain_id: str):
762767
monthly_cost_vos.delete()
763768

764769
def _delete_changed_cost_data(
765-
self, job_vo: Job, start, end, change_filter, domain_id
770+
self, job_vo: Job, start, end, change_filter, domain_id
766771
):
767772
query = {
768773
"filter": [
@@ -798,7 +803,7 @@ def _delete_changed_cost_data(
798803
)
799804

800805
def _aggregate_cost_data(
801-
self, job_vo: Job, data_keys: list, additional_info_keys: list, tag_keys: list
806+
self, job_vo: Job, data_keys: list, additional_info_keys: list, tag_keys: list
802807
):
803808
data_source_id = job_vo.data_source_id
804809
domain_id = job_vo.domain_id
@@ -807,7 +812,7 @@ def _aggregate_cost_data(
807812

808813
for job_task_id in job_task_ids:
809814
for billed_month in self._distinct_billed_month(
810-
domain_id, data_source_id, job_id, job_task_id
815+
domain_id, data_source_id, job_id, job_task_id
811816
):
812817
self._aggregate_monthly_cost_data(
813818
data_source_id,
@@ -821,7 +826,7 @@ def _aggregate_cost_data(
821826
)
822827

823828
def _distinct_billed_month(
824-
self, domain_id: str, data_source_id: str, job_id: str, job_task_id: str
829+
self, domain_id: str, data_source_id: str, job_id: str, job_task_id: str
825830
):
826831
query = {
827832
"distinct": "billed_month",
@@ -842,15 +847,15 @@ def _distinct_billed_month(
842847
return values
843848

844849
def _aggregate_monthly_cost_data(
845-
self,
846-
data_source_id: str,
847-
domain_id: str,
848-
job_id: str,
849-
job_task_id: str,
850-
billed_month: str,
851-
data_keys: list,
852-
additional_info_keys: list,
853-
tag_keys: list,
850+
self,
851+
data_source_id: str,
852+
domain_id: str,
853+
job_id: str,
854+
job_task_id: str,
855+
billed_month: str,
856+
data_keys: list,
857+
additional_info_keys: list,
858+
tag_keys: list,
854859
):
855860
query = {
856861
"group_by": [
@@ -946,7 +951,7 @@ def _get_all_data_sources(self):
946951
)
947952

948953
def _check_duplicate_job(
949-
self, data_source_id: str, domain_id: str, this_job_vo: Job
954+
self, data_source_id: str, domain_id: str, this_job_vo: Job
950955
):
951956
query = {
952957
"filter": [
@@ -984,11 +989,11 @@ def _get_job_task_ids(self, job_id, domain_id):
984989
return job_task_ids
985990

986991
def _get_data_source_account_map(
987-
self,
988-
data_source_id: str,
989-
domain_id: str,
990-
workspace_id: str,
991-
resource_group: str,
992+
self,
993+
data_source_id: str,
994+
domain_id: str,
995+
workspace_id: str,
996+
resource_group: str,
992997
) -> Dict[str, DataSourceAccount]:
993998
data_source_account_map = {}
994999
conditions = {
@@ -1010,11 +1015,11 @@ def _get_data_source_account_map(
10101015
return data_source_account_map
10111016

10121017
def _get_linked_accounts_from_data_source_vo(
1013-
self,
1014-
data_source_vo: DataSource,
1015-
options: dict,
1016-
secret_data: dict,
1017-
schema: dict = None,
1018+
self,
1019+
data_source_vo: DataSource,
1020+
options: dict,
1021+
secret_data: dict,
1022+
schema: dict = None,
10181023
) -> list:
10191024
linked_accounts = []
10201025

0 commit comments

Comments
 (0)