From 43999d803a8a3deb67bc7b94f359ce2a9f808097 Mon Sep 17 00:00:00 2001 From: PCoder Date: Wed, 3 Jan 2018 08:43:57 +0100 Subject: [PATCH] Add sdd_size, hdd_size to VirtualMachineSerializer --- opennebula_api/serializers.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/opennebula_api/serializers.py b/opennebula_api/serializers.py index 662b2fb6..07506a8b 100644 --- a/opennebula_api/serializers.py +++ b/opennebula_api/serializers.py @@ -49,6 +49,8 @@ class VirtualMachineSerializer(serializers.Serializer): memory = serializers.SerializerMethodField() disk_size = serializers.SerializerMethodField() + hdd_size = serializers.SerializerMethodField() + sdd_size = serializers.SerializerMethodField() ipv4 = serializers.SerializerMethodField() ipv6 = serializers.SerializerMethodField() vm_id = serializers.IntegerField(read_only=True, source='id') @@ -102,6 +104,22 @@ class VirtualMachineSerializer(serializers.Serializer): disk_size += int(disk.size) return disk_size / 1024 + def get_sdd_size(self, obj): + template = obj.template + disk_size = 0 + for disk in template.disks: + if disk.datastore == 'cephds': + disk_size += int(disk.size) + return disk_size / 1024 + + def get_hdd_size(self, obj): + template = obj.template + disk_size = 0 + for disk in template.disks: + if disk.datastore == 'ceph_hdd_ds': + disk_size += int(disk.size) + return disk_size / 1024 + def get_price(self, obj): template = obj.template price = float(template.vcpu) * 5.0