From c4130e4d3fdbf8607091c7ea6ff281e09baa8c0e Mon Sep 17 00:00:00 2001 From: ImMin5 Date: Thu, 12 Oct 2023 17:05:17 +0900 Subject: [PATCH] feat: modify job_task unit to tenant for CSP(#28) Signed-off-by: ImMin5 --- .../cost_analysis/manager/cost_manager.py | 2 +- src/cloudforet/cost_analysis/manager/job_manager.py | 13 ++++++++++--- src/cloudforet/cost_analysis/model/job_model.py | 6 +++--- 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/src/cloudforet/cost_analysis/manager/cost_manager.py b/src/cloudforet/cost_analysis/manager/cost_manager.py index 853a705..4dcc343 100644 --- a/src/cloudforet/cost_analysis/manager/cost_manager.py +++ b/src/cloudforet/cost_analysis/manager/cost_manager.py @@ -180,7 +180,7 @@ def _get_customer_tenant_id(task_options, collect_scope): if 'tenant_id' in task_options: customer_tenants.append(task_options['tenant_id']) elif collect_scope == 'customer_tenant_id': - customer_tenants.extend(task_options['customer_tenants']) + customer_tenants.append(task_options['customer_tenant']) else: customer_tenants.append('EA Agreement') return customer_tenants diff --git a/src/cloudforet/cost_analysis/manager/job_manager.py b/src/cloudforet/cost_analysis/manager/job_manager.py index b2b3044..001baa7 100644 --- a/src/cloudforet/cost_analysis/manager/job_manager.py +++ b/src/cloudforet/cost_analysis/manager/job_manager.py @@ -28,15 +28,22 @@ def get_tasks(self, options, secret_data, schema, start, last_synchronized_at, d billing_account_agreement_type = getattr(billing_account_info, 'agreement_type', '') if billing_account_agreement_type == 'MicrosoftPartnerAgreement': + tasks = [] + changed = [] customer_tenants = secret_data.get('customer_tenants', self._get_tenants_from_billing_account()) if len(customer_tenants) == 0: raise ERROR_EMPTY_CUSTOMER_TENANTS(customer_tenants=customer_tenants) - tasks = [{'task_options': {'start': start_month, 'account_agreement_type': billing_account_agreement_type, - 'collect_scope': 'customer_tenant_id', 'customer_tenants': customer_tenants}}] + + for customer_tenant in customer_tenants: + tasks.append({'task_options': {'start': start_month, + 'account_agreement_type': billing_account_agreement_type, + 'collect_scope': 'customer_tenant_id', + 'customer_tenant': customer_tenant}}) + changed.append({'start': start_month}) else: tasks = [{'task_options': {'start': start_month, 'account_agreement_type': billing_account_agreement_type, 'collect_scope': 'billing_account_id'}}] - changed = [{'start': start_month}] + changed = [{'start': start_month}] elif secret_type == 'USE_SERVICE_ACCOUNT_SECRET': subscription_id = secret_data.get('subscription_id', '') diff --git a/src/cloudforet/cost_analysis/model/job_model.py b/src/cloudforet/cost_analysis/model/job_model.py index fe6b88d..2c2b491 100644 --- a/src/cloudforet/cost_analysis/model/job_model.py +++ b/src/cloudforet/cost_analysis/model/job_model.py @@ -10,11 +10,11 @@ class TaskOptionsWithSubscription(Model): tenant_id = StringType(serialize_when_none=False) -class TaskOptionsWithCustomerTenants(Model): - customer_tenants = ListType(StringType, serialize_when_none=False) +class TaskOptionsWithCustomerTenant(Model): + customer_tenant = StringType(serialize_when_none=False) -class TaskOptions(TaskOptionsWithSubscription, TaskOptionsWithCustomerTenants): +class TaskOptions(TaskOptionsWithSubscription, TaskOptionsWithCustomerTenant): start = StringType(required=True, max_length=7) collect_scope = StringType(choices=['subscription_id', 'billing_account_id', 'customer_tenant_id'], required=True) account_agreement_type = StringType(choices=['EnterpriseAgreement', 'MicrosoftPartnerAgreement', 'MicrosoftCustomerAgreement','MicrosoftOnlineServicesProgram'], serialize_when_none=False)