Exemplo n.º 1
0
 def get_name(self, source):
     return '{name} ({cores} CPU, {ram} GB RAM, {disk} GB disk)'.format(
         name=source.name,
         cores=source.cores,
         ram=mb_to_gb(source.ram),
         disk=mb_to_gb(source.total_disk),
     )
Exemplo n.º 2
0
    def _create_item(self, source, invoice, start, end):
        try:
            resource = marketplace_models.Resource.objects.get(scope=source)
            plan = resource.plan
            if not plan:
                logger.warning(
                    'Skipping VMware item invoice creation because '
                    'billing plan is not defined for resource. '
                    'Resource ID: %s',
                    resource.id,
                )
                return
        except marketplace_models.Resource.DoesNotExist:
            logger.warning(
                'Skipping VMware item invoice creation because '
                'marketplace resource is not available for VMware resource. '
                'Resource ID: %s',
                source.id,
            )
            return

        components_map = {
            plan_component.component.type: plan_component.price
            for plan_component in plan.components.all()
        }

        missing_components = {'cpu', 'ram', 'disk'} - set(
            components_map.keys())
        if missing_components:
            logger.warning(
                'Skipping VMware item invoice creation because plan components are missing. '
                'Plan ID: %s. Missing components: %s',
                plan.id,
                ', '.join(missing_components),
            )
            return

        cores_price = components_map['cpu'] * source.cores
        ram_price = components_map['ram'] * mb_to_gb(source.ram)
        disk_price = components_map['disk'] * mb_to_gb(source.total_disk)
        total_price = cores_price + ram_price + disk_price

        start = invoices_models.adjust_invoice_items(invoice, source, start,
                                                     total_price, plan.unit)

        details = self.get_details(source)
        item = invoices_models.InvoiceItem.objects.create(
            scope=source,
            project=_get_project(source),
            unit_price=total_price,
            unit=plan.unit,
            product_code=plan.product_code,
            article_code=plan.article_code,
            invoice=invoice,
            start=start,
            end=end,
            details=details,
        )
        self.init_details(item)
Exemplo n.º 3
0
 def get_name(self, source):
     return '{resource} ({offering} / VPC {cores} CPU - {ram} GB RAM - {disk} GB storage)'.format(
         resource=source.name,
         offering=source.offering.name,
         cores=source.limits.get(CORES_TYPE),
         ram=int(mb_to_gb(source.limits.get(RAM_TYPE, 0))),
         disk=int(mb_to_gb(source.limits.get(STORAGE_TYPE, 0))),
     )
Exemplo n.º 4
0
 def format_storage_description(self, source):
     if STORAGE_TYPE in source.limits:
         return '{disk} GB storage'.format(
             disk=int(mb_to_gb(source.limits.get(STORAGE_TYPE, 0))))
     else:
         parts = []
         for (k, v) in source.limits.items():
             if k.startswith('gigabytes_') and v:
                 parts.append('{size} GB {type} storage'.format(
                     size=int(mb_to_gb(v)),
                     type=k.replace('gigabytes_', '')))
         return ' - '.join(parts)
Exemplo n.º 5
0
 def get_name(self, source):
     return '{resource} ({offering} / VPC {cores} CPU - {ram} GB RAM - {storage})'.format(
         resource=source.name,
         offering=source.offering.name,
         cores=int(source.limits.get(CORES_TYPE, 0)),
         ram=int(mb_to_gb(source.limits.get(RAM_TYPE, 0))),
         storage=self.format_storage_description(source),
     )