++update
Signed-off-by: Nico Schottelius <nico@nico-notebook.schottelius.org>
This commit is contained in:
parent
bd6008462d
commit
288a65f219
5 changed files with 83 additions and 9 deletions
18
uncloud/uncloud_pay/migrations/0002_auto_20200227_1230.py
Normal file
18
uncloud/uncloud_pay/migrations/0002_auto_20200227_1230.py
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
# Generated by Django 3.0.3 on 2020-02-27 12:30
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('uncloud_pay', '0001_initial'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='payment',
|
||||||
|
name='source',
|
||||||
|
field=models.CharField(choices=[('wire', 'Wire Transfer'), ('stripe', 'Stripe'), ('voucher', 'Voucher'), ('referral', 'Referral'), ('unknown', 'Unknown')], default='unknown', max_length=256),
|
||||||
|
),
|
||||||
|
]
|
36
uncloud/uncloud_vm/migrations/0005_auto_20200227_1230.py
Normal file
36
uncloud/uncloud_vm/migrations/0005_auto_20200227_1230.py
Normal file
|
@ -0,0 +1,36 @@
|
||||||
|
# Generated by Django 3.0.3 on 2020-02-27 12:30
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
import django.db.models.deletion
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('uncloud_pay', '0002_auto_20200227_1230'),
|
||||||
|
('uncloud_vm', '0004_vmsnapshotproduct'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.RemoveField(
|
||||||
|
model_name='vmsnapshotproduct',
|
||||||
|
name='vm_uuid',
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='vmproduct',
|
||||||
|
name='order',
|
||||||
|
field=models.ForeignKey(default=0, editable=False, on_delete=django.db.models.deletion.CASCADE, to='uncloud_pay.Order'),
|
||||||
|
preserve_default=False,
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='vmproduct',
|
||||||
|
name='status',
|
||||||
|
field=models.CharField(choices=[('pending', 'Pending'), ('being_created', 'Being created'), ('active', 'Active'), ('deleted', 'Deleted')], default='pending', max_length=256),
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='vmsnapshotproduct',
|
||||||
|
name='vm',
|
||||||
|
field=models.ForeignKey(default=0, on_delete=django.db.models.deletion.CASCADE, to='uncloud_vm.VMProduct'),
|
||||||
|
preserve_default=False,
|
||||||
|
),
|
||||||
|
]
|
|
@ -32,13 +32,7 @@ class VMHost(models.Model):
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class VMProduct(models.Model):
|
class VMProduct(Product):
|
||||||
uuid = models.UUIDField(primary_key=True,
|
|
||||||
default=uuid.uuid4,
|
|
||||||
editable=False)
|
|
||||||
owner = models.ForeignKey(get_user_model(),
|
|
||||||
on_delete=models.CASCADE,
|
|
||||||
editable=False)
|
|
||||||
vmhost = models.ForeignKey(VMHost,
|
vmhost = models.ForeignKey(VMHost,
|
||||||
on_delete=models.CASCADE,
|
on_delete=models.CASCADE,
|
||||||
editable=False,
|
editable=False,
|
||||||
|
@ -72,8 +66,12 @@ class OperatingSystemDisk(VMDiskProduct):
|
||||||
|
|
||||||
class VMNetworkCard(models.Model):
|
class VMNetworkCard(models.Model):
|
||||||
vm = models.ForeignKey(VMProduct, on_delete=models.CASCADE)
|
vm = models.ForeignKey(VMProduct, on_delete=models.CASCADE)
|
||||||
|
|
||||||
mac_address = models.IntegerField()
|
mac_address = models.IntegerField()
|
||||||
|
|
||||||
|
ip_address = models.GenericIPAddressField(blank=True,
|
||||||
|
null=True)
|
||||||
|
|
||||||
|
|
||||||
class VMSnapshotProduct(Product):
|
class VMSnapshotProduct(Product):
|
||||||
price_per_gb_ssd = 0.35
|
price_per_gb_ssd = 0.35
|
||||||
|
@ -83,7 +81,8 @@ class VMSnapshotProduct(Product):
|
||||||
gb_ssd = models.FloatField(editable=False)
|
gb_ssd = models.FloatField(editable=False)
|
||||||
gb_hdd = models.FloatField(editable=False)
|
gb_hdd = models.FloatField(editable=False)
|
||||||
|
|
||||||
vm_uuid = models.UUIDField()
|
vm = models.ForeignKey(VMProduct, on_delete=models.CASCADE)
|
||||||
|
#vm_uuid = models.UUIDField()
|
||||||
|
|
||||||
# Need to setup recurring_price and one_time_price and recurring period
|
# Need to setup recurring_price and one_time_price and recurring period
|
||||||
|
|
||||||
|
|
|
@ -14,7 +14,17 @@ class VMProductSerializer(serializers.HyperlinkedModelSerializer):
|
||||||
model = VMProduct
|
model = VMProduct
|
||||||
fields = '__all__'
|
fields = '__all__'
|
||||||
|
|
||||||
|
|
||||||
|
# def create(self, validated_data):
|
||||||
|
# return VMSnapshotProduct()
|
||||||
|
|
||||||
class VMSnapshotProductSerializer(serializers.ModelSerializer):
|
class VMSnapshotProductSerializer(serializers.ModelSerializer):
|
||||||
class Meta:
|
class Meta:
|
||||||
model = VMSnapshotProduct
|
model = VMSnapshotProduct
|
||||||
fields = '__all__'
|
fields = '__all__'
|
||||||
|
|
||||||
|
|
||||||
|
# verify that vm.owner == user.request
|
||||||
|
def validate_vm(self, value):
|
||||||
|
print(value)
|
||||||
|
return True
|
||||||
|
|
|
@ -11,6 +11,7 @@ from uncloud_pay.models import Order
|
||||||
|
|
||||||
from .serializers import VMHostSerializer, VMProductSerializer, VMSnapshotProductSerializer
|
from .serializers import VMHostSerializer, VMProductSerializer, VMSnapshotProductSerializer
|
||||||
|
|
||||||
|
|
||||||
import datetime
|
import datetime
|
||||||
|
|
||||||
class VMHostViewSet(viewsets.ModelViewSet):
|
class VMHostViewSet(viewsets.ModelViewSet):
|
||||||
|
@ -29,7 +30,17 @@ class VMProductViewSet(viewsets.ModelViewSet):
|
||||||
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)
|
||||||
serializer.save(owner=request.user)
|
# Create 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()
|
||||||
|
|
||||||
|
serializer.save(owner=request.user, order=order)
|
||||||
|
|
||||||
return Response(serializer.data)
|
return Response(serializer.data)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue