@@ -24,7 +24,7 @@ def __init__(self, *args, **kwargs):
24
24
)
25
25
26
26
def get_linked_accounts (
27
- self , options : dict , secret_data : dict , domain_id : str , schema
27
+ self , options : dict , secret_data : dict , domain_id : str , schema
28
28
) -> list :
29
29
self .azure_cm_connector .create_session (options , secret_data , schema )
30
30
billing_account_info = self .azure_cm_connector .get_billing_account ()
@@ -51,11 +51,12 @@ def get_linked_accounts(
51
51
return accounts_info
52
52
53
53
def get_data (
54
- self , options : dict , secret_data : dict , schema , task_options : dict
54
+ self , options : dict , secret_data : dict , schema , task_options : dict
55
55
) -> list :
56
56
self .azure_cm_connector .create_session (options , secret_data , schema )
57
57
self ._check_task_options (task_options )
58
58
59
+ agreement_type : str = task_options .get ("agreement_type" )
59
60
collect_scope : str = task_options ["collect_scope" ]
60
61
tenant_ids : list = self ._get_tenant_ids (task_options , collect_scope )
61
62
start : datetime = self ._get_first_date_of_month (task_options ["start" ])
@@ -85,7 +86,11 @@ def get_data(
85
86
response_stream = self .azure_cm_connector .get_cost_data (blobs , options )
86
87
for results in response_stream :
87
88
yield self ._make_cost_data (
88
- results = results , end = _end , tenant_id = tenant_id , options = options
89
+ results = results ,
90
+ end = _end ,
91
+ tenant_id = tenant_id ,
92
+ options = options ,
93
+ agreement_type = agreement_type ,
89
94
)
90
95
_LOGGER .info (
91
96
f"[get_data] #{ idx + 1 } { tenant_id } tenant collect is done"
@@ -97,7 +102,12 @@ def get_data(
97
102
yield []
98
103
99
104
def _make_cost_data (
100
- self , results : list , end : datetime , options : dict , tenant_id : str = None
105
+ self ,
106
+ results : list ,
107
+ end : datetime ,
108
+ options : dict ,
109
+ tenant_id : str = None ,
110
+ agreement_type : str = None ,
101
111
) -> list :
102
112
"""Source Data Model"""
103
113
@@ -113,7 +123,13 @@ def _make_cost_data(
113
123
if self ._exclude_cost_data_with_options (result , options ):
114
124
continue
115
125
116
- data = self ._make_data_info (result , billed_date , options , tenant_id )
126
+ data = self ._make_data_info (
127
+ result ,
128
+ billed_date ,
129
+ options ,
130
+ tenant_id ,
131
+ agreement_type = agreement_type ,
132
+ )
117
133
costs_data .append (data )
118
134
119
135
except Exception as e :
@@ -123,20 +139,27 @@ def _make_cost_data(
123
139
return costs_data
124
140
125
141
def _make_data_info (
126
- self , result : dict , billed_date : str , options : dict , tenant_id : str = None
142
+ self ,
143
+ result : dict ,
144
+ billed_date : str ,
145
+ options : dict ,
146
+ tenant_id : str = None ,
147
+ agreement_type : str = None ,
127
148
):
128
- additional_info = self ._get_additional_info (result , options , tenant_id )
129
- cost = self ._get_cost_from_result_with_options (result , options )
130
- usage_quantity = self ._convert_str_to_float_format (result .get ("quantity" , 0.0 ))
131
- usage_type = result .get ("metername" , "" )
132
- usage_unit = str (result .get ("unitofmeasure" , "" ))
133
- region_code = self ._get_region_code (result .get ("resourcelocation" , "" ))
134
- product = result .get ("metercategory" , "" )
135
- tags = self ._convert_tags_str_to_dict (result .get ("tags" ))
149
+ additional_info : dict = self ._get_additional_info (result , options , tenant_id )
150
+ cost : float = self ._get_cost_from_result_with_options (result , options )
151
+ usage_quantity : float = self ._convert_str_to_float_format (
152
+ result .get ("quantity" , 0.0 )
153
+ )
154
+ usage_type : str = result .get ("metername" , "" )
155
+ usage_unit : str = str (result .get ("unitofmeasure" , "" ))
156
+ region_code : str = self ._get_region_code (result .get ("resourcelocation" , "" ))
157
+ product : str = result .get ("metercategory" , "" )
158
+ tags : dict = self ._convert_tags_str_to_dict (result .get ("tags" ))
136
159
137
160
aggregate_data = self ._get_aggregate_data (result , options )
138
161
# Set Network Traffic Cost at Additional Info
139
- additional_info = self ._set_network_traffic_cost (
162
+ additional_info : dict = self ._set_network_traffic_cost (
140
163
additional_info , product , usage_type
141
164
)
142
165
@@ -169,7 +192,7 @@ def _get_additional_info(self, result: dict, options: dict, tenant_id: str = Non
169
192
additional_info ["Tenant Id" ] = tenant_id
170
193
additional_info ["Subscription Id" ] = result .get ("subscriptionid" , "Shared" )
171
194
172
- if meter_category == "Virtual Machines" and "Meter" in result :
195
+ if meter_category == "Virtual Machines" :
173
196
additional_info ["Instance Type" ] = result ["metername" ]
174
197
175
198
if result .get ("resourcegroupname" ) != "" and result .get ("resourcegroupname" ):
@@ -188,8 +211,8 @@ def _get_additional_info(self, result: dict, options: dict, tenant_id: str = Non
188
211
additional_info ["Benefit Name" ] = benefit_name
189
212
190
213
if (
191
- result .get ("pricingmodel" ) == "Reservation"
192
- and result ["metercategory" ] == ""
214
+ result .get ("pricingmodel" ) == "Reservation"
215
+ and result ["metercategory" ] == ""
193
216
):
194
217
result ["metercategory" ] = self ._set_product_from_benefit_name (
195
218
benefit_name
@@ -200,14 +223,14 @@ def _get_additional_info(self, result: dict, options: dict, tenant_id: str = Non
200
223
if result .get ("metersubcategory" ) != "" and result .get ("metersubcategory" ):
201
224
additional_info ["Meter SubCategory" ] = result .get ("metersubcategory" )
202
225
if (
203
- result .get ("pricingmodel" ) == "OnDemand"
204
- and result .get ("metercategory" ) == ""
226
+ result .get ("pricingmodel" ) == "OnDemand"
227
+ and result .get ("metercategory" ) == ""
205
228
):
206
229
result ["metercategory" ] = result .get ("metercategory" )
207
230
208
231
if result .get ("customername" ) is None :
209
232
if result .get ("invoicesectionname" ) != "" and result .get (
210
- "invoicesectionname"
233
+ "invoicesectionname"
211
234
):
212
235
additional_info ["Department Name" ] = result .get ("invoicesectionname" )
213
236
elif result .get ("departmentname" ) != "" and result .get ("departmentname" ):
@@ -216,15 +239,15 @@ def _get_additional_info(self, result: dict, options: dict, tenant_id: str = Non
216
239
if result .get ("accountname" ) != "" and result .get ("accountname" ):
217
240
additional_info ["Enrollment Account Name" ] = result ["accountname" ]
218
241
elif result .get ("enrollmentaccountname" ) != "" and result .get (
219
- "enrollmentaccountname"
242
+ "enrollmentaccountname"
220
243
):
221
244
additional_info ["Enrollment Account Name" ] = result ["enrollmentaccountname" ]
222
245
223
246
collect_resource_id = options .get ("collect_resource_id" , False )
224
247
if (
225
- collect_resource_id
226
- and result .get ("resourceid" ) != ""
227
- and result .get ("resourceid" )
248
+ collect_resource_id
249
+ and result .get ("resourceid" ) != ""
250
+ and result .get ("resourceid" )
228
251
):
229
252
additional_info ["Resource Id" ] = result ["resourceid" ]
230
253
additional_info ["Resource Name" ] = result ["resourceid" ].split ("/" )[- 1 ]
@@ -308,10 +331,10 @@ def _get_tenant_ids(task_options: dict, collect_scope: str) -> list:
308
331
309
332
@staticmethod
310
333
def _make_scope (
311
- secret_data : dict ,
312
- task_options : dict ,
313
- collect_scope : str ,
314
- customer_tenant_id : str = None ,
334
+ secret_data : dict ,
335
+ task_options : dict ,
336
+ collect_scope : str ,
337
+ customer_tenant_id : str = None ,
315
338
):
316
339
if collect_scope == "subscription_id" :
317
340
subscription_id = task_options ["subscription_id" ]
@@ -412,7 +435,7 @@ def _convert_date_format_to_utc(date_format: str) -> datetime:
412
435
return datetime .strptime (date_format , "%Y-%m-%d" ).replace (tzinfo = timezone .utc )
413
436
414
437
def _make_monthly_time_period (
415
- self , start_date : datetime , end_date : datetime
438
+ self , start_date : datetime , end_date : datetime
416
439
) -> list :
417
440
monthly_time_period = []
418
441
current_date = end_date
@@ -442,7 +465,7 @@ def _make_monthly_time_period(
442
465
443
466
@staticmethod
444
467
def _get_linked_customer_tenants (
445
- secret_data : dict , billing_accounts_info : list
468
+ secret_data : dict , billing_accounts_info : list
446
469
) -> list :
447
470
customer_tenants = secret_data .get ("customer_tenants" , [])
448
471
if not customer_tenants :
@@ -455,7 +478,7 @@ def _get_linked_customer_tenants(
455
478
456
479
@staticmethod
457
480
def _make_accounts_info_from_customer_tenants (
458
- billing_accounts_info : list , customer_tenants : list
481
+ billing_accounts_info : list , customer_tenants : list
459
482
) -> list :
460
483
accounts_info = []
461
484
for billing_account_info in billing_accounts_info :
@@ -493,7 +516,7 @@ def _exclude_cost_data_with_options(result: dict, options: dict) -> bool:
493
516
494
517
@staticmethod
495
518
def _set_network_traffic_cost (
496
- additional_info : dict , product : str , usage_type : str
519
+ additional_info : dict , product : str , usage_type : str
497
520
) -> dict :
498
521
if product in ["Bandwidth" , "Content Delivery Network" ]:
499
522
additional_info ["Usage Type Details" ] = usage_type
0 commit comments