From edab311d6291982dbacb7bbec45d5b077095f907 Mon Sep 17 00:00:00 2001 From: Modulos Date: Sat, 13 May 2017 17:32:55 +0200 Subject: [PATCH] Fix memory MB to GB --- opennebula_api/models.py | 1 - opennebula_api/serializers.py | 8 ++++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/opennebula_api/models.py b/opennebula_api/models.py index c2bdb9f7..eb6d64a2 100644 --- a/opennebula_api/models.py +++ b/opennebula_api/models.py @@ -203,7 +203,6 @@ class OpenNebulaManager(): try: template_pool = oca.VmTemplatePool(self.oneadmin_client) template_pool.info() - #TODO: Replace with logger except ConnectionRefusedError: logger.info('Could not connect to host: {host} via protocol {protocol}'.format( host=settings.OPENNEBULA_DOMAIN, diff --git a/opennebula_api/serializers.py b/opennebula_api/serializers.py index ccf64677..600f6fc3 100644 --- a/opennebula_api/serializers.py +++ b/opennebula_api/serializers.py @@ -10,10 +10,12 @@ from .models import OpenNebulaManager class VirtualMachineTemplateSerializer(serializers.Serializer): """Serializer to map the virtual machine template instance into JSON format.""" id = serializers.IntegerField(read_only=True) + set_name = serializers.CharField(read_only=True, label='Name') name = serializers.SerializerMethodField() cores = serializers.IntegerField(source='template.vcpu') disk = serializers.IntegerField(write_only=True) 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') @@ -64,6 +66,7 @@ class VirtualMachineTemplateSerializer(serializers.Serializer): return int(obj.template.memory)/1024 def get_name(self, obj): + # TODO: Filter public- away return obj.name class VirtualMachineSerializer(serializers.Serializer): @@ -72,7 +75,8 @@ class VirtualMachineSerializer(serializers.Serializer): name = serializers.CharField(read_only=True) cores = serializers.IntegerField(source='template.vcpu') disk = serializers.IntegerField(write_only=True) - memory = serializers.IntegerField(source='template.memory') + set_memory = serializers.IntegerField(write_only=True, label='Memory') + memory = serializers.SerializerMethodField() disk_size = serializers.SerializerMethodField() @@ -95,7 +99,7 @@ class VirtualMachineSerializer(serializers.Serializer): owner = validated_data['owner'] ssh_key = validated_data['ssh_key'] cores = validated_data['template']['vcpu'] - memory = validated_data['template']['memory'] + memory = validated_data['set_memory'] disk = validated_data['disk'] template_id = validated_data['template']['template_id']