Add calculate price function to template

This commit is contained in:
Modulos 2017-05-10 02:36:11 +02:00
commit c1a3f7281f
2 changed files with 19 additions and 0 deletions

View file

@ -14,6 +14,18 @@ class VirtualMachineTemplate(models.Model):
core_price = models.FloatField()
disk_size_price = models.FloatField()
def calculate_price(self):
manager = OpenNebulaManager()
template = manger._get_template(self.opennebula_id).template
price = int(template.vpcu) * self.core_price
price += int(template.memory) / 1024 * self.memory_price
try:
price += int(template.disk.size) / 1024 * self.disk_size_price
except AttributeError:
for disk in template.disks:
price += int(disk.size) / 1024 * self.disk_size_price
return price
class VirtualMachine(models.Model):
"""This class represents an opennebula virtual machine."""