Wire disk images to VM creation/ordering

This commit is contained in:
fnux 2020-03-09 14:18:07 +01:00
commit d3b7470294
5 changed files with 85 additions and 22 deletions

View file

@ -31,13 +31,16 @@ class VMDiskProductSerializer(serializers.ModelSerializer):
model = VMDiskProduct
fields = '__all__'
class CreateVMDiskProductSerializer(serializers.ModelSerializer):
class Meta:
model = VMDiskProduct
fields = ['size_in_gb', 'image']
class VMDiskImageProductSerializer(serializers.ModelSerializer):
class Meta:
model = VMDiskImageProduct
fields = '__all__'
class DCLVMProductSerializer(serializers.HyperlinkedModelSerializer):
"""
Create an interface similar to standard DCL
@ -84,18 +87,19 @@ class VMSnapshotProductSerializer(serializers.ModelSerializer):
pricing['per_gb_hdd'] = 0.0006
pricing['recurring_period'] = 'per_day'
class VMProductSerializer(serializers.ModelSerializer):
class Meta:
model = VMProduct
fields = ['uuid', 'order', 'owner', 'status', 'name',
'cores', 'ram_in_gb', 'recurring_period',
'snapshots', 'disks',
'extra_data' ]
read_only_fields = ['uuid', 'order', 'owner', 'status' ]
class VMProductSerializer(serializers.HyperlinkedModelSerializer):
# Custom field used at creation (= ordering) only.
recurring_period = serializers.ChoiceField(
choices=VMProduct.allowed_recurring_periods())
choices=VMProduct.allowed_recurring_periods())
primary_disk = CreateVMDiskProductSerializer()
class Meta:
model = VMProduct
fields = ['uuid', 'order', 'owner', 'status', 'name', \
'cores', 'ram_in_gb', 'recurring_period', 'primary_disk',
'snapshots', 'disks', 'extra_data' ]
read_only_fields = ['uuid', 'order', 'owner', 'status']
snapshots = VMSnapshotProductSerializer(many=True,
read_only=True)