uncloud-mravi/uncloud/uncloud_vm/serializers.py

43 lines
1.2 KiB
Python
Raw Normal View History

from django.contrib.auth import get_user_model
from rest_framework import serializers
from .models import VMHost, VMProduct, VMSnapshotProduct
from uncloud_pay.models import RecurringPeriod
class VMHostSerializer(serializers.HyperlinkedModelSerializer):
class Meta:
model = VMHost
fields = '__all__'
2020-02-25 21:01:55 +00:00
class VMProductSerializer(serializers.HyperlinkedModelSerializer):
# Custom field used at creation (= ordering) only.
recurring_period = serializers.ChoiceField(
2020-03-03 09:51:16 +00:00
choices=VMProduct.allowed_recurring_periods())
2020-02-25 21:01:55 +00:00
class Meta:
model = VMProduct
fields = ['uuid', 'order', 'owner', 'status', 'name', \
'cores', 'ram_in_gb', 'recurring_period']
read_only_fields = ['uuid', 'order', 'owner', 'status']
2020-03-03 09:51:16 +00:00
class ManagedVMProductSerializer(serializers.ModelSerializer):
"""
Managed VM serializer used in ungleich_service app.
"""
class Meta:
model = VMProduct
fields = [ 'cores', 'ram_in_gb']
2020-02-27 11:31:20 +00:00
class VMSnapshotProductSerializer(serializers.ModelSerializer):
2020-02-27 10:36:50 +00:00
class Meta:
model = VMSnapshotProduct
fields = '__all__'
# verify that vm.owner == user.request
def validate_vm(self, value):
print(value)
return True