forked from uncloud/uncloud
add url for importing disk image
Signed-off-by: Nico Schottelius <nico@nico-notebook.schottelius.org>
This commit is contained in:
parent
bcbd6f6f83
commit
6a38e4e0a4
4 changed files with 45 additions and 6 deletions
23
uncloud/uncloud_vm/migrations/0007_auto_20200229_1559.py
Normal file
23
uncloud/uncloud_vm/migrations/0007_auto_20200229_1559.py
Normal file
|
@ -0,0 +1,23 @@
|
|||
# Generated by Django 3.0.3 on 2020-02-29 15:59
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('uncloud_vm', '0006_auto_20200229_1545'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='vmdiskimageproduct',
|
||||
name='import_url',
|
||||
field=models.URLField(blank=True, null=True),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='vmdiskimageproduct',
|
||||
name='size_in_gb',
|
||||
field=models.FloatField(blank=True, null=True),
|
||||
),
|
||||
]
|
|
@ -55,7 +55,9 @@ class VMDiskImageProduct(models.Model):
|
|||
|
||||
"""
|
||||
|
||||
uuid = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
|
||||
uuid = models.UUIDField(primary_key=True,
|
||||
default=uuid.uuid4,
|
||||
editable=False)
|
||||
owner = models.ForeignKey(get_user_model(),
|
||||
on_delete=models.CASCADE,
|
||||
editable=False)
|
||||
|
@ -64,7 +66,10 @@ class VMDiskImageProduct(models.Model):
|
|||
is_os_image = models.BooleanField(default=False)
|
||||
is_public = models.BooleanField(default=False)
|
||||
|
||||
size_in_gb = models.FloatField()
|
||||
size_in_gb = models.FloatField(null=True,
|
||||
blank=True)
|
||||
import_url = models.URLField(null=True,
|
||||
blank=True)
|
||||
|
||||
|
||||
storage_class = models.CharField(max_length=32,
|
||||
|
|
|
@ -3,6 +3,13 @@ from django.contrib.auth import get_user_model
|
|||
from rest_framework import serializers
|
||||
from .models import VMHost, VMProduct, VMSnapshotProduct, VMDiskProduct, VMDiskImageProduct
|
||||
|
||||
GB_SSD_PER_DAY=0.012
|
||||
GB_HDD_PER_DAY=0.0006
|
||||
|
||||
GB_SSD_PER_DAY=0.012
|
||||
GB_HDD_PER_DAY=0.0006
|
||||
|
||||
|
||||
class VMHostSerializer(serializers.ModelSerializer):
|
||||
class Meta:
|
||||
model = VMHost
|
||||
|
@ -32,11 +39,9 @@ class VMSnapshotProductSerializer(serializers.ModelSerializer):
|
|||
|
||||
# verify that vm.owner == user.request
|
||||
def validate_vm(self, value):
|
||||
|
||||
if not value.owner == self.context['request'].user:
|
||||
raise serializers.ValidationError("VM {} not found for owner {}.".format(value,
|
||||
self.context['request'].user))
|
||||
|
||||
disks = VMDiskProduct.objects.filter(vm=value)
|
||||
|
||||
if len(disks) == 0:
|
||||
|
|
|
@ -26,7 +26,14 @@ class VMDiskImageProductMineViewSet(viewsets.ModelViewSet):
|
|||
def get_queryset(self):
|
||||
return VMDiskImageProduct.objects.filter(owner=self.request.user)
|
||||
|
||||
class VMDiskImageProductPublicViewSet(viewsets.ModelViewSet):
|
||||
def create(self, request):
|
||||
serializer = VMProductSerializer(data=request.data, context={'request': request})
|
||||
serializer.is_valid(raise_exception=True)
|
||||
serializer.save(owner=request.user)
|
||||
return Response(serializer.data)
|
||||
|
||||
|
||||
class VMDiskImageProductPublicViewSet(viewsets.ReadOnlyModelViewSet):
|
||||
permission_classes = [permissions.IsAuthenticated]
|
||||
serializer_class = VMDiskImageProductSerializer
|
||||
|
||||
|
@ -55,7 +62,6 @@ class VMProductViewSet(viewsets.ModelViewSet):
|
|||
order.save()
|
||||
|
||||
serializer.save(owner=request.user, order=order)
|
||||
|
||||
return Response(serializer.data)
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue