2020-02-23 23:00:42 +05:00
|
|
|
from rest_framework import viewsets, permissions
|
2020-02-21 20:33:37 +05:00
|
|
|
|
2020-02-23 16:52:30 +01:00
|
|
|
from .models import VM
|
2020-03-17 15:39:24 +01:00
|
|
|
from .serializers import OpenNebulaVMSerializer
|
2020-02-23 15:33:26 +01:00
|
|
|
|
2020-03-17 15:39:24 +01:00
|
|
|
class VMViewSet(viewsets.ModelViewSet):
|
2020-02-23 15:33:26 +01:00
|
|
|
permission_classes = [permissions.IsAuthenticated]
|
2020-03-17 15:39:24 +01:00
|
|
|
serializer_class = OpenNebulaVMSerializer
|
2020-02-23 16:52:30 +01:00
|
|
|
|
2020-03-17 15:39:24 +01: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 16:52:30 +01:00
|
|
|
|
2020-03-17 15:39:24 +01:00
|
|
|
return obj
|