Versionise API and cleanups
This commit is contained in:
parent
eea654a9f8
commit
927fb20671
5 changed files with 32 additions and 34 deletions
|
@ -35,10 +35,10 @@ router = routers.DefaultRouter()
|
|||
router.register(r'beta/vm', vmviews.NicoVMProductViewSet, basename='nicovmproduct')
|
||||
|
||||
# VM
|
||||
router.register(r'vm/snapshot', vmviews.VMSnapshotProductViewSet, basename='vmsnapshotproduct')
|
||||
router.register(r'vm/diskimage', vmviews.VMDiskImageProductViewSet, basename='vmdiskimageproduct')
|
||||
router.register(r'vm/disk', vmviews.VMDiskProductViewSet, basename='vmdiskproduct')
|
||||
router.register(r'vm/vm', vmviews.VMProductViewSet, basename='vmproduct')
|
||||
router.register(r'v1/vm/snapshot', vmviews.VMSnapshotProductViewSet, basename='vmsnapshotproduct')
|
||||
router.register(r'v1/vm/diskimage', vmviews.VMDiskImageProductViewSet, basename='vmdiskimageproduct')
|
||||
router.register(r'v1/vm/disk', vmviews.VMDiskProductViewSet, basename='vmdiskproduct')
|
||||
router.register(r'v1/vm/vm', vmviews.VMProductViewSet, basename='vmproduct')
|
||||
|
||||
|
||||
# creates VM from os image
|
||||
|
@ -47,35 +47,35 @@ router.register(r'vm/vm', vmviews.VMProductViewSet, basename='vmproduct')
|
|||
#router.register(r'vm/dualstackvm', vmviews.VMProductViewSet, basename='vmproduct')
|
||||
|
||||
# Services
|
||||
router.register(r'service/matrix', serviceviews.MatrixServiceProductViewSet, basename='matrixserviceproduct')
|
||||
router.register(r'service/generic', serviceviews.GenericServiceProductViewSet, basename='genericserviceproduct')
|
||||
router.register(r'v1/service/matrix', serviceviews.MatrixServiceProductViewSet, basename='matrixserviceproduct')
|
||||
router.register(r'v1/service/generic', serviceviews.GenericServiceProductViewSet, basename='genericserviceproduct')
|
||||
|
||||
|
||||
# Net
|
||||
router.register(r'net/vpn', netviews.VPNNetworkViewSet, basename='vpnnet')
|
||||
router.register(r'net/vpnreservation', netviews.VPNNetworkReservationViewSet, basename='vpnnetreservation')
|
||||
router.register(r'v1/net/vpn', netviews.VPNNetworkViewSet, basename='vpnnet')
|
||||
router.register(r'v1/admin/vpnreservation', netviews.VPNNetworkReservationViewSet, basename='vpnnetreservation')
|
||||
|
||||
|
||||
# Pay
|
||||
router.register(r'address', payviews.BillingAddressViewSet, basename='address')
|
||||
router.register(r'bill', payviews.BillViewSet, basename='bill')
|
||||
router.register(r'order', payviews.OrderViewSet, basename='order')
|
||||
router.register(r'payment', payviews.PaymentViewSet, basename='payment')
|
||||
router.register(r'payment-method', payviews.PaymentMethodViewSet, basename='payment-method')
|
||||
router.register(r'v1/my/address', payviews.BillingAddressViewSet, basename='address')
|
||||
router.register(r'v1/my/bill', payviews.BillViewSet, basename='bill')
|
||||
router.register(r'v1/my/order', payviews.OrderViewSet, basename='order')
|
||||
router.register(r'v1/my/payment', payviews.PaymentViewSet, basename='payment')
|
||||
router.register(r'v1/my/payment-method', payviews.PaymentMethodViewSet, basename='payment-method')
|
||||
|
||||
|
||||
# admin/staff urls
|
||||
router.register(r'admin/bill', payviews.AdminBillViewSet, basename='admin/bill')
|
||||
router.register(r'admin/payment', payviews.AdminPaymentViewSet, basename='admin/payment')
|
||||
router.register(r'admin/order', payviews.AdminOrderViewSet, basename='admin/order')
|
||||
router.register(r'admin/vmhost', vmviews.VMHostViewSet)
|
||||
router.register(r'admin/vmcluster', vmviews.VMClusterViewSet)
|
||||
router.register(r'admin/vpnpool', netviews.VPNPoolViewSet)
|
||||
router.register(r'admin/opennebula', oneviews.VMViewSet, basename='opennebula')
|
||||
router.register(r'v1/admin/bill', payviews.AdminBillViewSet, basename='admin/bill')
|
||||
router.register(r'v1/admin/payment', payviews.AdminPaymentViewSet, basename='admin/payment')
|
||||
router.register(r'v1/admin/order', payviews.AdminOrderViewSet, basename='admin/order')
|
||||
router.register(r'v1/admin/vmhost', vmviews.VMHostViewSet)
|
||||
router.register(r'v1/admin/vmcluster', vmviews.VMClusterViewSet)
|
||||
router.register(r'v1/admin/vpnpool', netviews.VPNPoolViewSet)
|
||||
router.register(r'v1/admin/opennebula', oneviews.VMViewSet, basename='opennebula')
|
||||
|
||||
# User/Account
|
||||
router.register(r'user', authviews.UserViewSet, basename='user')
|
||||
router.register(r'admin/user', authviews.AdminUserViewSet, basename='useradmin')
|
||||
router.register(r'v1/my/user', authviews.UserViewSet, basename='user')
|
||||
router.register(r'v1/admin/user', authviews.AdminUserViewSet, basename='useradmin')
|
||||
|
||||
urlpatterns = [
|
||||
path('', include(router.urls)),
|
||||
|
|
|
@ -825,7 +825,11 @@ class Order(models.Model):
|
|||
|
||||
# Trigger initial bill generation at order creation.
|
||||
def save(self, *args, **kwargs):
|
||||
super(Order, self).save(*args, **kwargs)
|
||||
if self.ending_date and self.ending_date < self.starting_date:
|
||||
raise ValidationError("End date cannot be before starting date")
|
||||
|
||||
super().save(*args, **kwargs)
|
||||
|
||||
Bill.generate_for(self.starting_date.year, self.starting_date.month, self.owner)
|
||||
|
||||
@property
|
||||
|
|
|
@ -69,9 +69,6 @@ class VMProduct(Product):
|
|||
cores = models.IntegerField()
|
||||
ram_in_gb = models.FloatField()
|
||||
|
||||
# Optional disk
|
||||
primary_disk = models.ForeignKey('VMDiskProduct', on_delete=models.CASCADE, null=True)
|
||||
|
||||
# Default recurring price is PER_MONTH, see uncloud_pay.models.Product.
|
||||
@property
|
||||
def recurring_price(self):
|
||||
|
@ -175,6 +172,7 @@ class VMDiskProduct(Product):
|
|||
super().save(*args, **kwargs)
|
||||
|
||||
|
||||
|
||||
class VMNetworkCard(models.Model):
|
||||
vm = models.ForeignKey(VMProduct, on_delete=models.CASCADE)
|
||||
|
||||
|
|
|
@ -121,22 +121,17 @@ class OrderVMProductSerializer(VMProductSerializer):
|
|||
# Nico's playground.
|
||||
|
||||
class NicoVMProductSerializer(serializers.ModelSerializer):
|
||||
primary_disk = CreateVMDiskProductSerializer()
|
||||
snapshots = VMSnapshotProductSerializer(many=True, read_only=True)
|
||||
disks = VMDiskProductSerializer(many=True, read_only=True)
|
||||
|
||||
class Meta:
|
||||
model = VMProduct
|
||||
read_only_fields = ['uuid', 'order', 'owner', 'status',
|
||||
'vmhost', 'vmcluster',
|
||||
'vmhost', 'vmcluster', 'snapshots',
|
||||
'extra_data' ]
|
||||
fields = read_only_fields + [ 'name',
|
||||
'cores',
|
||||
'ram_in_gb',
|
||||
'primary_disk',
|
||||
'snapshots',
|
||||
'disks' ]
|
||||
|
||||
'ram_in_gb'
|
||||
]
|
||||
|
||||
|
||||
class DCLVMProductSerializer(serializers.HyperlinkedModelSerializer):
|
||||
|
|
|
@ -195,6 +195,7 @@ class NicoVMProductViewSet(ProductViewSet):
|
|||
# Extract serializer data.
|
||||
serializer = self.get_serializer(data=request.data)
|
||||
serializer.is_valid(raise_exception=True)
|
||||
|
||||
order_recurring_period = serializer.validated_data.pop("recurring_period")
|
||||
order_billing_address = serializer.validated_data.pop("billing_address")
|
||||
|
||||
|
|
Loading…
Reference in a new issue