From 78738e8175c99741fd33e779ae8d80279191358c Mon Sep 17 00:00:00 2001 From: PCoder Date: Tue, 9 Apr 2019 00:16:28 +0200 Subject: [PATCH] Change cores to SerializerMethodField and obtain it from cpu --- opennebula_api/serializers.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/opennebula_api/serializers.py b/opennebula_api/serializers.py index c7418aa5..ec7bd5d5 100644 --- a/opennebula_api/serializers.py +++ b/opennebula_api/serializers.py @@ -46,7 +46,7 @@ class VirtualMachineSerializer(serializers.Serializer): """Serializer to map the virtual machine instance into JSON format.""" name = serializers.SerializerMethodField() - cores = serializers.IntegerField(source='template.vcpu') + cores = serializers.SerializerMethodField() disk = serializers.IntegerField(write_only=True) set_memory = serializers.IntegerField(write_only=True, label='Memory') memory = serializers.SerializerMethodField() @@ -99,6 +99,9 @@ class VirtualMachineSerializer(serializers.Serializer): return manager.get_vm(opennebula_id) + def get_cores(self, obj): + return (obj.template.cpu) * 10 + def get_memory(self, obj): return int(obj.template.memory) / 1024