From b8df86342adb0bd8aff8b2ae18f8b0e03e71339c Mon Sep 17 00:00:00 2001 From: Modulos Date: Sun, 14 May 2017 01:02:22 +0200 Subject: [PATCH] Add try and except for template disks It turns out that some templates don't need a disk size if they use a image. --- opennebula_api/serializers.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/opennebula_api/serializers.py b/opennebula_api/serializers.py index 600f6fc3..17793178 100644 --- a/opennebula_api/serializers.py +++ b/opennebula_api/serializers.py @@ -50,9 +50,12 @@ class VirtualMachineTemplateSerializer(serializers.Serializer): def get_disk_size(self, obj): template = obj.template disk_size = 0 - for disk in template.disks: - disk_size += int(disk.size) - return disk_size / 1024 + try: + for disk in template.disks: + disk_size += int(disk.size) + return disk_size / 1024 + except: + return 0 def get_price(self, obj): template = obj.template