Create a vmsnapshot + associated order

This commit is contained in:
Nico Schottelius 2020-02-27 12:31:20 +01:00
parent 41a5eae879
commit a9aac39486
3 changed files with 20 additions and 10 deletions

View file

@ -25,7 +25,7 @@ from opennebula import views as oneviews
router = routers.DefaultRouter() router = routers.DefaultRouter()
# user / regular urls # 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') router.register(r'vm/vm', vmviews.VMProductViewSet, basename='vmproduct')
# Pay # Pay

View file

@ -14,12 +14,7 @@ class VMProductSerializer(serializers.HyperlinkedModelSerializer):
model = VMProduct model = VMProduct
fields = '__all__' fields = '__all__'
class VMSnapshotProductSerializer(serializers.HyperlinkedModelSerializer): class VMSnapshotProductSerializer(serializers.ModelSerializer):
class Meta:
model = VMSnapshotProduct
fields = ['uuid', 'status', 'recurring_price', 'one_time_price' ]
class VMSnapshotProductCreateSerializer(serializers.HyperlinkedModelSerializer):
class Meta: class Meta:
model = VMSnapshotProduct model = VMSnapshotProduct
fields = '__all__' fields = '__all__'

View file

@ -11,6 +11,8 @@ from uncloud_pay.models import Order
from .serializers import VMHostSerializer, VMProductSerializer, VMSnapshotProductSerializer from .serializers import VMHostSerializer, VMProductSerializer, VMSnapshotProductSerializer
import datetime
class VMHostViewSet(viewsets.ModelViewSet): class VMHostViewSet(viewsets.ModelViewSet):
serializer_class = VMHostSerializer serializer_class = VMHostSerializer
queryset = VMHost.objects.all() queryset = VMHost.objects.all()
@ -40,12 +42,25 @@ 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 = VMSnapshotProductSerializer(data=request.data, context={'request': request})
serializer.is_valid(raise_exception=True) serializer.is_valid(raise_exception=True)
print(serializer)
# Create order # 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) return Response(serializer.data)