def _populate_ocp_aws_cost_line_item_daily_summary(self, report_date): """Create OCP hourly usage line items.""" for row in self.ocp_aws_summary_line_items: for aws_service in self.AWS_SERVICE_CHOICES: resource_prefix = "i-" unit = "Hrs" instance_type = random.choice( self.aws_info.SOME_INSTANCE_TYPES) if aws_service == "ebs": resource_prefix = "vol-" unit = "GB-Mo" instance_type = None aws_product = self.aws_info._products.get(aws_service) region = random.choice(self.aws_info.SOME_REGIONS) az = region + random.choice(["a", "b", "c"]) usage_amount = Decimal(random.uniform(0, 100)) unblended_cost = Decimal(random.uniform(0, 10)) * usage_amount project_costs = { row.get("namespace"): float(Decimal(random.random()) * unblended_cost) } bill, _ = AWSCostEntryBill.objects.get_or_create( **self.aws_info.bill) data = { "cost_entry_bill_id": bill.id, "cluster_id": self.cluster_id, "cluster_alias": self.cluster_alias, "namespace": [row.get("namespace")], "pod": [row.get("pod")], "node": row.get("node"), "resource_id": resource_prefix + row.get("resource_id"), "usage_start": report_date, "usage_end": report_date, "product_code": aws_product.get("service_code"), "product_family": aws_product.get("product_family"), "instance_type": instance_type, "usage_account_id": self.usage_account_id, "account_alias": None, "availability_zone": az, "region": region, "tags": self.tags, "unit": unit, "usage_amount": usage_amount, "normalized_usage_amount": usage_amount, "unblended_cost": unblended_cost, "markup_cost": unblended_cost * Decimal(0.1), "project_costs": project_costs, } line_item = OCPAWSCostLineItemDailySummary(**data) line_item.save()
def _populate_ocp_aws_cost_line_item_daily_summary(self, report_date): """Create OCP hourly usage line items.""" for row in self.ocp_aws_summary_line_items: for aws_service in self.AWS_SERVICE_CHOICES: resource_prefix = 'i-' unit = 'Hrs' instance_type = random.choice( self.aws_info.SOME_INSTANCE_TYPES) if aws_service == 'ebs': resource_prefix = 'vol-' unit = 'GB-Mo' instance_type = None aws_product = self.aws_info._products.get(aws_service) region = random.choice(self.aws_info.SOME_REGIONS) az = region + random.choice(['a', 'b', 'c']) usage_amount = Decimal(random.uniform(0, 100)) unblended_cost = Decimal(random.uniform(0, 10)) * usage_amount project_costs = { row.get('namespace'): float(Decimal(random.random()) * unblended_cost) } data = { 'cluster_id': self.cluster_id, 'cluster_alias': self.cluster_alias, 'namespace': [row.get('namespace')], 'pod': [row.get('pod')], 'node': row.get('node'), 'resource_id': resource_prefix + row.get('resource_id'), 'usage_start': report_date, 'usage_end': report_date, 'product_code': aws_product.get('service_code'), 'product_family': aws_product.get('product_family'), 'instance_type': instance_type, 'usage_account_id': self.usage_account_id, 'account_alias': None, 'availability_zone': az, 'region': region, 'tags': self.tags, 'unit': unit, 'usage_amount': usage_amount, 'normalized_usage_amount': usage_amount, 'unblended_cost': unblended_cost, 'markup_cost': unblended_cost * Decimal(0.1), 'project_costs': project_costs, } line_item = OCPAWSCostLineItemDailySummary(**data) line_item.save()