Exemple #1
0
    def _populate_aws_daily_table(self):
        included_fields = [
            'cost_entry_product_id', 'cost_entry_pricing_id',
            'cost_entry_reservation_id', 'line_item_type', 'usage_account_id',
            'usage_type', 'operation', 'availability_zone', 'resource_id',
            'tax_type', 'product_code', 'tags'
        ]
        annotations = {
            'usage_start': Cast('usage_start', DateTimeField()),
            'usage_end': Cast('usage_start', DateTimeField()),
            'usage_amount': Sum('usage_amount'),
            'normalization_factor': Max('normalization_factor'),
            'normalized_usage_amount': Sum('normalized_usage_amount'),
            'currency_code': Max('currency_code'),
            'unblended_rate': Max('unblended_rate'),
            'unblended_cost': Sum('unblended_cost'),
            'blended_rate': Max('blended_rate'),
            'blended_cost': Sum('blended_cost'),
            'public_on_demand_cost': Sum('public_on_demand_cost'),
            'public_on_demand_rate': Max('public_on_demand_rate')
        }

        entries = AWSCostEntryLineItem.objects\
            .values(*included_fields)\
            .annotate(**annotations)
        for entry in entries:
            daily = AWSCostEntryLineItemDaily(**entry)
            daily.save()
Exemple #2
0
    def _populate_aws_daily_table(self):
        included_fields = [
            "cost_entry_bill_id",
            "cost_entry_product_id",
            "cost_entry_pricing_id",
            "cost_entry_reservation_id",
            "line_item_type",
            "usage_account_id",
            "usage_type",
            "operation",
            "availability_zone",
            "resource_id",
            "tax_type",
            "product_code",
            "tags",
        ]
        annotations = {
            "usage_start": Cast("usage_start", DateTimeField()),
            "usage_end": Cast("usage_start", DateTimeField()),
            "usage_amount": Sum("usage_amount"),
            "normalization_factor": Max("normalization_factor"),
            "normalized_usage_amount": Sum("normalized_usage_amount"),
            "currency_code": Max("currency_code"),
            "unblended_rate": Max("unblended_rate"),
            "unblended_cost": Sum("unblended_cost"),
            "blended_rate": Max("blended_rate"),
            "blended_cost": Sum("blended_cost"),
            "public_on_demand_cost": Sum("public_on_demand_cost"),
            "public_on_demand_rate": Max("public_on_demand_rate"),
        }

        entries = AWSCostEntryLineItem.objects.values(*included_fields).annotate(**annotations)
        for entry in entries:
            daily = AWSCostEntryLineItemDaily(**entry)
            daily.save()