Add get_vm_price_with_vat method
This commit is contained in:
		
					parent
					
						
							
								e9a883bf2e
							
						
					
				
			
			
				commit
				
					
						957cec00a0
					
				
			
		
					 1 changed files with 35 additions and 0 deletions
				
			
		| 
						 | 
					@ -76,3 +76,38 @@ def get_vm_price(cpu, memory, disk_size, hdd_size=0, pricing_name='default'):
 | 
				
			||||||
            (memory * pricing.ram_unit_price) +
 | 
					            (memory * pricing.ram_unit_price) +
 | 
				
			||||||
            (disk_size * pricing.ssd_unit_price) +
 | 
					            (disk_size * pricing.ssd_unit_price) +
 | 
				
			||||||
            (hdd_size * pricing.hdd_unit_price))
 | 
					            (hdd_size * pricing.hdd_unit_price))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					def get_vm_price_with_vat(cpu, memory, disk_size, hdd_size=0,
 | 
				
			||||||
 | 
					                          pricing_name='default'):
 | 
				
			||||||
 | 
					    """
 | 
				
			||||||
 | 
					    A helper function that computes price of a VM from given cpu, ram and
 | 
				
			||||||
 | 
					    ssd, hdd and the pricing parameters
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    :param cpu: Number of cores of the VM
 | 
				
			||||||
 | 
					    :param memory: RAM of the VM
 | 
				
			||||||
 | 
					    :param disk_size: Disk space of the VM (SSD)
 | 
				
			||||||
 | 
					    :param hdd_size: The HDD size
 | 
				
			||||||
 | 
					    :param pricing_name: The pricing name to be used
 | 
				
			||||||
 | 
					    :return: The a tuple containing the price of the VM and the VAT
 | 
				
			||||||
 | 
					    """
 | 
				
			||||||
 | 
					    try:
 | 
				
			||||||
 | 
					        pricing = VMPricing.objects.get(name=pricing_name)
 | 
				
			||||||
 | 
					    except Exception as ex:
 | 
				
			||||||
 | 
					        logger.error(
 | 
				
			||||||
 | 
					            "Error getting VMPricing object for {pricing_name}."
 | 
				
			||||||
 | 
					            "Details: {details}".format(
 | 
				
			||||||
 | 
					                pricing_name=pricing_name, details=str(ex)
 | 
				
			||||||
 | 
					            )
 | 
				
			||||||
 | 
					        )
 | 
				
			||||||
 | 
					        return None
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    price = float((cpu * pricing.cores_unit_price) +
 | 
				
			||||||
 | 
					             (memory * pricing.ram_unit_price) +
 | 
				
			||||||
 | 
					             (disk_size * pricing.ssd_unit_price) +
 | 
				
			||||||
 | 
					             (hdd_size * pricing.hdd_unit_price))
 | 
				
			||||||
 | 
					    if pricing.vat_inclusive:
 | 
				
			||||||
 | 
					        vat = 0
 | 
				
			||||||
 | 
					    else:
 | 
				
			||||||
 | 
					        vat = price * float(pricing.vat_percentage) * 0.01
 | 
				
			||||||
 | 
					    return price, vat
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue