2020-02-23 14:33:26 +00:00
|
|
|
from rest_framework import viewsets, generics, permissions
|
2020-02-23 15:52:30 +00:00
|
|
|
from rest_framework.response import Response
|
2020-02-21 15:33:37 +00:00
|
|
|
|
2020-02-23 15:52:30 +00:00
|
|
|
from django.contrib.auth import get_user_model
|
2020-02-23 14:33:26 +00:00
|
|
|
|
2020-02-23 15:52:30 +00:00
|
|
|
from .models import VM
|
|
|
|
from .serializers import VMSerializer, OpenNebulaVMSerializer
|
2020-02-23 14:33:26 +00:00
|
|
|
|
|
|
|
class RawVMViewSet(viewsets.ModelViewSet):
|
2020-02-21 15:33:37 +00:00
|
|
|
queryset = VM.objects.all()
|
|
|
|
serializer_class = VMSerializer
|
2020-02-23 15:52:30 +00:00
|
|
|
permission_classes = [permissions.IsAdminUser]
|
2020-02-21 15:33:37 +00:00
|
|
|
|
|
|
|
|
2020-02-23 14:33:26 +00:00
|
|
|
class VMViewSet(viewsets.ModelViewSet):
|
|
|
|
permission_classes = [permissions.IsAuthenticated]
|
2020-02-23 15:52:30 +00:00
|
|
|
|
|
|
|
def list(self, request):
|
|
|
|
queryset = VM.objects.filter(owner=request.user)
|
|
|
|
serializer = OpenNebulaVMSerializer(queryset, many=True)
|
|
|
|
return Response(serializer.data)
|
|
|
|
|
|
|
|
def retrieve(self, request, pk=None):
|
|
|
|
queryset = VM.objects.filter(owner=request.user)
|
|
|
|
user = get_object_or_404(queryset, pk=pk)
|
|
|
|
serializer = OpenNebulaVMSerializer(queryset)
|
|
|
|
return Response(serializer.data)
|