Added VMTemplateSerializer

This commit is contained in:
PCoder 2017-07-27 12:05:01 +05:30
parent 1a6e497e38
commit fca291c6a5
2 changed files with 9 additions and 2 deletions

View file

@ -21,7 +21,7 @@ from datetime import datetime
from membership.models import CustomUser, StripeCustomer
from opennebula_api.models import OpenNebulaManager
from opennebula_api.serializers import VirtualMachineTemplateSerializer, VirtualMachineSerializer
from opennebula_api.serializers import VirtualMachineTemplateSerializer, VirtualMachineSerializer, VMTemplateSerializer
class LandingProgramView(TemplateView):
@ -212,7 +212,8 @@ class IndexView(CreateView):
storage = request.POST.get('storage')
price = request.POST.get('total')
template_id = int(request.POST.get('config'))
template_data = VMTemplate.objects.all()
template = VMTemplate.objects.filter(opennebula_vm_template_id=template_id).first()
template_data = VMTemplateSerializer(template).data
name = request.POST.get('name')
email = request.POST.get('email')

View file

@ -129,6 +129,12 @@ class VirtualMachineSerializer(serializers.Serializer):
return obj.name.strip('public-')
class VMTemplateSerializer(serializers.Serializer):
"""Serializer to map the VMTemplate instance into JSON format."""
id = serializers.IntegerField(read_only=True, source='opennebula_vm_template_id')
name = serializers.CharField(read_only=True)
def hexstr2int(string):
return int(string.replace(':', ''), 16)