From f80496a10390c806101f85a162303e4ec8abd56f Mon Sep 17 00:00:00 2001 From: Modulos Date: Sun, 14 May 2017 01:21:10 +0200 Subject: [PATCH] Quick fix remove cpu_cost etc. --- opennebula_api/serializers.py | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/opennebula_api/serializers.py b/opennebula_api/serializers.py index 17793178..48cdd7b6 100644 --- a/opennebula_api/serializers.py +++ b/opennebula_api/serializers.py @@ -17,9 +17,6 @@ class VirtualMachineTemplateSerializer(serializers.Serializer): disk_size = serializers.SerializerMethodField() set_memory = serializers.IntegerField(write_only=True, label='Memory') memory = serializers.SerializerMethodField() - core_price = serializers.FloatField(source='template.cpu_cost') - disk_size_price = serializers.FloatField(source='template.disk_cost') - memory_price = serializers.FloatField(source='template.memory_cost') price = serializers.SerializerMethodField() def create(self, validated_data): @@ -30,9 +27,6 @@ class VirtualMachineTemplateSerializer(serializers.Serializer): name = data.pop('name') disk_size = data.pop('disk') memory = template.pop('memory') - core_price = template.pop('cpu_cost') - memory_price = template.pop('memory_cost') - disk_size_price = template.pop('disk_cost') manager = OpenNebulaManager() try: @@ -57,12 +51,16 @@ class VirtualMachineTemplateSerializer(serializers.Serializer): except: return 0 + def get_price(self, obj): template = obj.template - price = float(template.cpu) * float(template.cpu_cost) - price += (int(template.memory)/1024 * float(template.memory_cost)) - for disk in template.disks: - price += int(disk.size)/1024 * float(template.disk_cost) + price = float(template.cpu) * 5.0 + price += (int(template.memory)/1024 * 2.0) + try: + for disk in template.disks: + price += int(disk.size)/1024 * 0.6 + except: + pass return price def get_memory(self, obj): @@ -137,8 +135,8 @@ class VirtualMachineSerializer(serializers.Serializer): def get_price(self, obj): template = obj.template - price = float(template.cpu) * float(template.cpu_cost) - price += (int(template.memory)/1024 * float(template.memory_cost)) + price = float(template.cpu) * 5.0 + price += (int(template.memory)/1024 * 2.0) for disk in template.disks: - price += int(disk.size)/1024 * float(template.disk_cost) + price += int(disk.size)/1024 * 0.6 return price