2020-02-23 18:00:42 +00:00
|
|
|
from rest_framework import viewsets, permissions
|
2020-02-21 15:33:37 +00:00
|
|
|
|
2020-02-23 15:52:30 +00:00
|
|
|
from .models import VM
|
2020-03-17 14:39:24 +00:00
|
|
|
from .serializers import OpenNebulaVMSerializer
|
2020-02-23 14:33:26 +00:00
|
|
|
|
2020-03-17 14:39:24 +00:00
|
|
|
class VMViewSet(viewsets.ModelViewSet):
|
2020-02-23 14:33:26 +00:00
|
|
|
permission_classes = [permissions.IsAuthenticated]
|
2020-03-17 14:39:24 +00:00
|
|
|
serializer_class = OpenNebulaVMSerializer
|
2020-02-23 15:52:30 +00:00
|
|
|
|
2020-03-17 14:39:24 +00:00
|
|
|
def get_queryset(self):
|
|
|
|
if self.request.user.is_superuser:
|
|
|
|
obj = VM.objects.all()
|
|
|
|
else:
|
|
|
|
obj = VM.objects.filter(owner=self.request.user)
|
2020-02-23 15:52:30 +00:00
|
|
|
|
2020-03-17 14:39:24 +00:00
|
|
|
return obj
|