Пример #1
0
    def _populate_ocp_aws_cost_line_item_project_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

                data = {
                    'cluster_id': self.cluster_id,
                    'cluster_alias': self.cluster_alias,
                    'namespace': row.get('namespace'),
                    'node': row.get('node'),
                    'pod': row.get('pod'),
                    'pod_labels': self.tags,
                    '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,
                    'unit': unit,
                    'usage_amount': usage_amount,
                    'normalized_usage_amount': usage_amount,
                    'pod_cost': Decimal(random.random()) * unblended_cost
                }
                line_item = OCPAWSCostLineItemProjectDailySummary(**data)
                line_item.save()
Пример #2
0
    def _populate_ocp_aws_cost_line_item_project_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

                data = {
                    "cluster_id": self.cluster_id,
                    "cluster_alias": self.cluster_alias,
                    "namespace": row.get("namespace"),
                    "node": row.get("node"),
                    "pod": row.get("pod"),
                    "pod_labels": self.tags,
                    "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,
                    "unit": unit,
                    "usage_amount": usage_amount,
                    "normalized_usage_amount": usage_amount,
                    "pod_cost": Decimal(random.random()) * unblended_cost,
                }
                line_item = OCPAWSCostLineItemProjectDailySummary(**data)
                line_item.save()