From 6a5a5ed1609abe5de0c60111e8b6c86450f88ad6 Mon Sep 17 00:00:00 2001 From: PCoder Date: Tue, 9 Apr 2019 07:43:06 +0200 Subject: [PATCH] Check template_id attr exists within template --- opennebula_api/serializers.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/opennebula_api/serializers.py b/opennebula_api/serializers.py index 3d451538..69c593fb 100644 --- a/opennebula_api/serializers.py +++ b/opennebula_api/serializers.py @@ -138,12 +138,13 @@ class VirtualMachineSerializer(serializers.Serializer): def get_configuration(self, obj): if hasattr(obj, 'template'): - template_id = obj.template.template_id - template = OpenNebulaManager().get_template(template_id) - if template.name.startswith('public-'): - return template.name.lstrip('public-') - else: - return template.name + if hasattr(obj, 'template.template_id'): + template_id = obj.template.template_id + template = OpenNebulaManager().get_template(template_id) + if template.name.startswith('public-'): + return template.name.lstrip('public-') + else: + return template.name else: return ""