forked from uncloud/uncloud
27 lines
951 B
Python
27 lines
951 B
Python
from rest_framework import viewsets, permissions
|
|
from rest_framework.response import Response
|
|
from django.shortcuts import get_object_or_404
|
|
|
|
from .models import VM
|
|
from .serializers import VMSerializer, OpenNebulaVMSerializer
|
|
|
|
|
|
class RawVMViewSet(viewsets.ModelViewSet):
|
|
queryset = VM.objects.all()
|
|
serializer_class = VMSerializer
|
|
permission_classes = [permissions.IsAdminUser]
|
|
|
|
|
|
class VMViewSet(viewsets.ViewSet):
|
|
permission_classes = [permissions.IsAuthenticated]
|
|
|
|
def list(self, request):
|
|
queryset = VM.objects.filter(owner=request.user)
|
|
serializer = OpenNebulaVMSerializer(queryset, many=True, context={'request': request})
|
|
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)
|