Skip to content

Commit

Permalink
Merge pull request #32 from ImMin5/feature-azure-billing
Browse files Browse the repository at this point in the history
Modify job_task unit to tenant for CSP
  • Loading branch information
ImMin5 authored Oct 12, 2023
2 parents b21791b + c4130e4 commit 85c6654
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/cloudforet/cost_analysis/manager/cost_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 10 additions & 3 deletions src/cloudforet/cost_analysis/manager/job_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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', '')
Expand Down
6 changes: 3 additions & 3 deletions src/cloudforet/cost_analysis/model/job_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 85c6654

Please sign in to comment.