2020-02-25 19:53:12 +00:00
|
|
|
from django.contrib.auth import get_user_model
|
|
|
|
|
|
|
|
from rest_framework import serializers
|
2020-02-27 10:59:28 +00:00
|
|
|
from .models import VMHost, VMProduct, VMSnapshotProduct
|
2020-02-25 19:53:12 +00:00
|
|
|
|
|
|
|
class VMHostSerializer(serializers.HyperlinkedModelSerializer):
|
|
|
|
class Meta:
|
|
|
|
model = VMHost
|
|
|
|
fields = '__all__'
|
2020-02-25 21:01:55 +00:00
|
|
|
|
|
|
|
|
|
|
|
class VMProductSerializer(serializers.HyperlinkedModelSerializer):
|
|
|
|
class Meta:
|
|
|
|
model = VMProduct
|
2020-02-28 15:26:45 +00:00
|
|
|
fields = ['uuid', 'order', 'owner', 'status', 'name', \
|
2020-02-28 14:07:20 +00:00
|
|
|
'cores', 'ram_in_gb']
|
2020-02-28 15:26:45 +00:00
|
|
|
read_only_fields = ['uuid', 'order', 'owner', 'status']
|
2020-02-27 14:29:15 +00:00
|
|
|
|
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__'
|
2020-02-27 14:29:15 +00:00
|
|
|
|
|
|
|
|
|
|
|
# verify that vm.owner == user.request
|
|
|
|
def validate_vm(self, value):
|
|
|
|
print(value)
|
|
|
|
return True
|