From a9aac394866a5df90ac0c3945a5d749631cdc7b0 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Thu, 27 Feb 2020 12:31:20 +0100 Subject: [PATCH] Create a vmsnapshot + associated order --- uncloud/uncloud/urls.py | 2 +- uncloud/uncloud_vm/serializers.py | 7 +------ uncloud/uncloud_vm/views.py | 21 ++++++++++++++++++--- 3 files changed, 20 insertions(+), 10 deletions(-) diff --git a/uncloud/uncloud/urls.py b/uncloud/uncloud/urls.py index a02f24a..d6d3b7d 100644 --- a/uncloud/uncloud/urls.py +++ b/uncloud/uncloud/urls.py @@ -25,7 +25,7 @@ from opennebula import views as oneviews router = routers.DefaultRouter() # user / regular urls -router.register(r'vm/snapshot', vmviews.VMSnapshotProductViewSet, basename='VMSnapshot') +router.register(r'vm/snapshot', vmviews.VMSnapshotProductViewSet, basename='vmsnapshotproduct') router.register(r'vm/vm', vmviews.VMProductViewSet, basename='vmproduct') # Pay diff --git a/uncloud/uncloud_vm/serializers.py b/uncloud/uncloud_vm/serializers.py index 232e954..c1eafe2 100644 --- a/uncloud/uncloud_vm/serializers.py +++ b/uncloud/uncloud_vm/serializers.py @@ -14,12 +14,7 @@ class VMProductSerializer(serializers.HyperlinkedModelSerializer): model = VMProduct fields = '__all__' -class VMSnapshotProductSerializer(serializers.HyperlinkedModelSerializer): - class Meta: - model = VMSnapshotProduct - fields = ['uuid', 'status', 'recurring_price', 'one_time_price' ] - -class VMSnapshotProductCreateSerializer(serializers.HyperlinkedModelSerializer): +class VMSnapshotProductSerializer(serializers.ModelSerializer): class Meta: model = VMSnapshotProduct fields = '__all__' diff --git a/uncloud/uncloud_vm/views.py b/uncloud/uncloud_vm/views.py index c82dff3..53986b4 100644 --- a/uncloud/uncloud_vm/views.py +++ b/uncloud/uncloud_vm/views.py @@ -11,6 +11,8 @@ from uncloud_pay.models import Order from .serializers import VMHostSerializer, VMProductSerializer, VMSnapshotProductSerializer +import datetime + class VMHostViewSet(viewsets.ModelViewSet): serializer_class = VMHostSerializer queryset = VMHost.objects.all() @@ -40,12 +42,25 @@ class VMSnapshotProductViewSet(viewsets.ModelViewSet): return VMSnapshotProduct.objects.filter(owner=self.request.user) def create(self, request): - serializer = VMProductSerializer(data=request.data, context={'request': request}) + serializer = VMSnapshotProductSerializer(data=request.data, context={'request': request}) serializer.is_valid(raise_exception=True) + print(serializer) # Create order - #order = Order() + now = datetime.datetime.now() + order = Order(owner=request.user, + creation_date=now, + starting_date=now, + recurring_price=20, + one_time_price=0, + recurring_period="per_month") + order.save() + print(order) - serializer.save(owner=request.user) + # FIXME: calculate the gb_* values + serializer.save(owner=request.user, + order=order, + gb_ssd=12, + gb_hdd=20) return Response(serializer.data)