Check template_id attr exists within template

This commit is contained in:
PCoder 2019-04-09 07:43:06 +02:00
parent 85b251d2e6
commit 6a5a5ed160

View file

@ -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 ""