forked from uncloud/uncloud
++cleanup
Signed-off-by: Nico Schottelius <nico@nico-notebook.schottelius.org>
This commit is contained in:
parent
11d629bb51
commit
fd648ade65
2 changed files with 9 additions and 37 deletions
|
@ -60,7 +60,6 @@ INSTALLED_APPS = [
|
||||||
'django.contrib.messages',
|
'django.contrib.messages',
|
||||||
'django.contrib.staticfiles',
|
'django.contrib.staticfiles',
|
||||||
'rest_framework',
|
'rest_framework',
|
||||||
'uncloud_api',
|
|
||||||
'uncloud_auth',
|
'uncloud_auth',
|
||||||
'uncloud_vm',
|
'uncloud_vm',
|
||||||
'opennebula'
|
'opennebula'
|
||||||
|
|
|
@ -6,7 +6,9 @@ from django.shortcuts import get_object_or_404
|
||||||
from rest_framework import viewsets, permissions
|
from rest_framework import viewsets, permissions
|
||||||
from rest_framework.response import Response
|
from rest_framework.response import Response
|
||||||
|
|
||||||
from .models import VMHost, VMProduct
|
from .models import VMHost, VMProduct. VMSnapshotProduct
|
||||||
|
from uncloud_pay.models import Order
|
||||||
|
|
||||||
from .serializers import VMHostSerializer, VMProductSerializer
|
from .serializers import VMHostSerializer, VMProductSerializer
|
||||||
|
|
||||||
class VMHostViewSet(viewsets.ModelViewSet):
|
class VMHostViewSet(viewsets.ModelViewSet):
|
||||||
|
@ -14,6 +16,7 @@ class VMHostViewSet(viewsets.ModelViewSet):
|
||||||
queryset = VMHost.objects.all()
|
queryset = VMHost.objects.all()
|
||||||
permission_classes = [permissions.IsAdminUser]
|
permission_classes = [permissions.IsAdminUser]
|
||||||
|
|
||||||
|
|
||||||
class VMProductViewSet(viewsets.ModelViewSet):
|
class VMProductViewSet(viewsets.ModelViewSet):
|
||||||
permission_classes = [permissions.IsAuthenticated]
|
permission_classes = [permissions.IsAuthenticated]
|
||||||
serializer_class = VMProductSerializer
|
serializer_class = VMProductSerializer
|
||||||
|
@ -37,43 +40,13 @@ class VMSnapshotProductViewSet(viewsets.ModelViewSet):
|
||||||
return VMSnapshotProduct.objects.filter(owner=self.request.user)
|
return VMSnapshotProduct.objects.filter(owner=self.request.user)
|
||||||
|
|
||||||
def create(self, request):
|
def create(self, request):
|
||||||
|
|
||||||
serializer = VMProductSerializer(data=request.data, context={'request': request})
|
serializer = VMProductSerializer(data=request.data, context={'request': request})
|
||||||
serializer.is_valid(raise_exception=True)
|
serializer.is_valid(raise_exception=True)
|
||||||
|
|
||||||
|
# Create order
|
||||||
|
order = Order()
|
||||||
|
|
||||||
serializer.save(owner=request.user)
|
serializer.save(owner=request.user)
|
||||||
|
|
||||||
return Response(serializer.data)
|
return Response(serializer.data)
|
||||||
|
|
||||||
|
|
||||||
class VMSnapshotProductView(viewsets.ViewSet):
|
|
||||||
permission_classes = [permissions.IsAuthenticated]
|
|
||||||
|
|
||||||
def list(self, request):
|
|
||||||
queryset = VMSnapshotProduct.objects.filter(owner=request.user)
|
|
||||||
serializer = VMSnapshotSerializer(queryset, many=True, context={'request': request})
|
|
||||||
return Response(serializer.data)
|
|
||||||
|
|
||||||
def retrieve(self, request, pk=None):
|
|
||||||
queryset = VMSnapshotProduct.objects.filter(owner=request.user)
|
|
||||||
vm = get_object_or_404(queryset, pk=pk)
|
|
||||||
serializer = VMSnapshotSerializer(vm, context={'request': request})
|
|
||||||
return Response(serializer.data)
|
|
||||||
|
|
||||||
def create(self, request):
|
|
||||||
print(request.data)
|
|
||||||
serializer = VMSnapshotCreateSerializer(data=request.data)
|
|
||||||
|
|
||||||
serializer.gb_ssd = 12
|
|
||||||
serializer.gb_hdd = 120
|
|
||||||
print("F")
|
|
||||||
serializer.is_valid(raise_exception=True)
|
|
||||||
|
|
||||||
print(serializer)
|
|
||||||
print("A")
|
|
||||||
serializer.save()
|
|
||||||
print("B")
|
|
||||||
|
|
||||||
|
|
||||||
# snapshot = VMSnapshotProduct(owner=request.user,
|
|
||||||
# **serialzer.data)
|
|
||||||
|
|
||||||
return Response(serializer.data)
|
|
||||||
|
|
Loading…
Reference in a new issue