From 85b251d2e6a9c984360e56da6ce8386ef6303347 Mon Sep 17 00:00:00 2001 From: PCoder Date: Tue, 9 Apr 2019 07:40:06 +0200 Subject: [PATCH] Check if the template VM serializer object has template attr --- opennebula_api/serializers.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/opennebula_api/serializers.py b/opennebula_api/serializers.py index 1fa1a802..3d451538 100644 --- a/opennebula_api/serializers.py +++ b/opennebula_api/serializers.py @@ -137,12 +137,15 @@ class VirtualMachineSerializer(serializers.Serializer): return price def get_configuration(self, obj): - template_id = obj.template.template_id - template = OpenNebulaManager().get_template(template_id) - if template.name.startswith('public-'): - return template.name.lstrip('public-') + 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 else: - return template.name + return "" def get_ipv4(self, obj): """