diff --git a/src/cloudforet/cost_analysis/connector/azure_cost_mgmt_connector.py b/src/cloudforet/cost_analysis/connector/azure_cost_mgmt_connector.py index aa082a8..1454714 100644 --- a/src/cloudforet/cost_analysis/connector/azure_cost_mgmt_connector.py +++ b/src/cloudforet/cost_analysis/connector/azure_cost_mgmt_connector.py @@ -120,6 +120,8 @@ def get_cost_data(self, blobs: list, options: dict) -> list: offset = _PAGE_SIZE * page_num yield costs_data[offset : offset + _PAGE_SIZE] + del df + def list_by_billing_account(self): billing_account_name = self.billing_account_id return self.billing_client.billing_subscriptions.list_by_billing_account( diff --git a/src/cloudforet/cost_analysis/manager/cost_manager.py b/src/cloudforet/cost_analysis/manager/cost_manager.py index 5db318a..d67604d 100644 --- a/src/cloudforet/cost_analysis/manager/cost_manager.py +++ b/src/cloudforet/cost_analysis/manager/cost_manager.py @@ -24,7 +24,7 @@ def __init__(self, *args, **kwargs): ) def get_linked_accounts( - self, options: dict, secret_data: dict, domain_id: str, schema + self, options: dict, secret_data: dict, domain_id: str, schema ) -> list: self.azure_cm_connector.create_session(options, secret_data, schema) billing_account_info = self.azure_cm_connector.get_billing_account() @@ -51,7 +51,7 @@ def get_linked_accounts( return accounts_info def get_data( - self, options: dict, secret_data: dict, schema, task_options: dict + self, options: dict, secret_data: dict, schema, task_options: dict ) -> list: self.azure_cm_connector.create_session(options, secret_data, schema) self._check_task_options(task_options) @@ -102,12 +102,12 @@ def get_data( yield [] def _make_cost_data( - self, - results: list, - end: datetime, - options: dict, - tenant_id: str = None, - agreement_type: str = None, + self, + results: list, + end: datetime, + options: dict, + tenant_id: str = None, + agreement_type: str = None, ) -> list: """Source Data Model""" @@ -139,12 +139,12 @@ def _make_cost_data( return costs_data def _make_data_info( - self, - result: dict, - billed_date: str, - options: dict, - tenant_id: str = None, - agreement_type: str = None, + self, + result: dict, + billed_date: str, + options: dict, + tenant_id: str = None, + agreement_type: str = None, ): additional_info: dict = self._get_additional_info(result, options, tenant_id) cost: float = self._get_cost_from_result_with_options(result, options) @@ -158,6 +158,7 @@ def _make_data_info( tags: dict = self._convert_tags_str_to_dict(result.get("tags")) aggregate_data = self._get_aggregate_data(result, options) + # Set Network Traffic Cost at Additional Info additional_info: dict = self._set_network_traffic_cost( additional_info, product, usage_type @@ -211,8 +212,8 @@ def _get_additional_info(self, result: dict, options: dict, tenant_id: str = Non additional_info["Benefit Name"] = benefit_name if ( - result.get("pricingmodel") == "Reservation" - and result["metercategory"] == "" + result.get("pricingmodel") == "Reservation" + and result["metercategory"] == "" ): result["metercategory"] = self._set_product_from_benefit_name( benefit_name @@ -223,14 +224,14 @@ def _get_additional_info(self, result: dict, options: dict, tenant_id: str = Non if result.get("metersubcategory") != "" and result.get("metersubcategory"): additional_info["Meter SubCategory"] = result.get("metersubcategory") if ( - result.get("pricingmodel") == "OnDemand" - and result.get("metercategory") == "" + result.get("pricingmodel") == "OnDemand" + and result.get("metercategory") == "" ): result["metercategory"] = result.get("metercategory") if result.get("customername") is None: if result.get("invoicesectionname") != "" and result.get( - "invoicesectionname" + "invoicesectionname" ): additional_info["Department Name"] = result.get("invoicesectionname") elif result.get("departmentname") != "" and result.get("departmentname"): @@ -239,15 +240,15 @@ def _get_additional_info(self, result: dict, options: dict, tenant_id: str = Non if result.get("accountname") != "" and result.get("accountname"): additional_info["Enrollment Account Name"] = result["accountname"] elif result.get("enrollmentaccountname") != "" and result.get( - "enrollmentaccountname" + "enrollmentaccountname" ): additional_info["Enrollment Account Name"] = result["enrollmentaccountname"] collect_resource_id = options.get("collect_resource_id", False) if ( - collect_resource_id - and result.get("resourceid") != "" - and result.get("resourceid") + collect_resource_id + and result.get("resourceid") != "" + and result.get("resourceid") ): additional_info["Resource Id"] = result["resourceid"] additional_info["Resource Name"] = result["resourceid"].split("/")[-1] @@ -331,10 +332,10 @@ def _get_tenant_ids(task_options: dict, collect_scope: str) -> list: @staticmethod def _make_scope( - secret_data: dict, - task_options: dict, - collect_scope: str, - customer_tenant_id: str = None, + secret_data: dict, + task_options: dict, + collect_scope: str, + customer_tenant_id: str = None, ): if collect_scope == "subscription_id": subscription_id = task_options["subscription_id"] @@ -435,7 +436,7 @@ def _convert_date_format_to_utc(date_format: str) -> datetime: return datetime.strptime(date_format, "%Y-%m-%d").replace(tzinfo=timezone.utc) def _make_monthly_time_period( - self, start_date: datetime, end_date: datetime + self, start_date: datetime, end_date: datetime ) -> list: monthly_time_period = [] current_date = end_date @@ -465,7 +466,7 @@ def _make_monthly_time_period( @staticmethod def _get_linked_customer_tenants( - secret_data: dict, billing_accounts_info: list + secret_data: dict, billing_accounts_info: list ) -> list: customer_tenants = secret_data.get("customer_tenants", []) if not customer_tenants: @@ -478,7 +479,7 @@ def _get_linked_customer_tenants( @staticmethod def _make_accounts_info_from_customer_tenants( - billing_accounts_info: list, customer_tenants: list + billing_accounts_info: list, customer_tenants: list ) -> list: accounts_info = [] for billing_account_info in billing_accounts_info: @@ -516,7 +517,7 @@ def _exclude_cost_data_with_options(result: dict, options: dict) -> bool: @staticmethod def _set_network_traffic_cost( - additional_info: dict, product: str, usage_type: str + additional_info: dict, product: str, usage_type: str ) -> dict: if product in ["Bandwidth", "Content Delivery Network"]: additional_info["Usage Type Details"] = usage_type