Merge branch 'opennebula-5.8.1/misc' into 'master'
Revert back to old serializer code See merge request ungleich-public/dynamicweb!692
This commit is contained in:
commit
19e03f218a
2 changed files with 8 additions and 16 deletions
|
@ -46,7 +46,7 @@ class VirtualMachineSerializer(serializers.Serializer):
|
||||||
"""Serializer to map the virtual machine instance into JSON format."""
|
"""Serializer to map the virtual machine instance into JSON format."""
|
||||||
|
|
||||||
name = serializers.SerializerMethodField()
|
name = serializers.SerializerMethodField()
|
||||||
cores = serializers.SerializerMethodField()
|
cores = serializers.IntegerField(source='template.vcpu')
|
||||||
disk = serializers.IntegerField(write_only=True)
|
disk = serializers.IntegerField(write_only=True)
|
||||||
set_memory = serializers.IntegerField(write_only=True, label='Memory')
|
set_memory = serializers.IntegerField(write_only=True, label='Memory')
|
||||||
memory = serializers.SerializerMethodField()
|
memory = serializers.SerializerMethodField()
|
||||||
|
@ -99,9 +99,6 @@ class VirtualMachineSerializer(serializers.Serializer):
|
||||||
|
|
||||||
return manager.get_vm(opennebula_id)
|
return manager.get_vm(opennebula_id)
|
||||||
|
|
||||||
def get_cores(self, obj):
|
|
||||||
return int(float(obj.template.cpu) * 10)
|
|
||||||
|
|
||||||
def get_memory(self, obj):
|
def get_memory(self, obj):
|
||||||
return int(obj.template.memory) / 1024
|
return int(obj.template.memory) / 1024
|
||||||
|
|
||||||
|
@ -130,23 +127,19 @@ class VirtualMachineSerializer(serializers.Serializer):
|
||||||
|
|
||||||
def get_price(self, obj):
|
def get_price(self, obj):
|
||||||
template = obj.template
|
template = obj.template
|
||||||
price = float(template.cpu) * 10 * 5.0
|
price = float(template.vcpu) * 5.0
|
||||||
price += (int(template.memory) / 1024 * 2.0)
|
price += (int(template.memory) / 1024 * 2.0)
|
||||||
for disk in template.disks:
|
for disk in template.disks:
|
||||||
price += int(disk.size) / 1024 * 0.6
|
price += int(disk.size) / 1024 * 0.6
|
||||||
return price
|
return price
|
||||||
|
|
||||||
def get_configuration(self, obj):
|
def get_configuration(self, obj):
|
||||||
if hasattr(obj, 'template'):
|
template_id = obj.template.template_id
|
||||||
if hasattr(obj, 'template.template_id'):
|
template = OpenNebulaManager().get_template(template_id)
|
||||||
template_id = obj.template.template_id
|
if template.name.startswith('public-'):
|
||||||
template = OpenNebulaManager().get_template(template_id)
|
return template.name.lstrip('public-')
|
||||||
if template.name.startswith('public-'):
|
|
||||||
return template.name.lstrip('public-')
|
|
||||||
else:
|
|
||||||
return template.name
|
|
||||||
else:
|
else:
|
||||||
return ""
|
return template.name
|
||||||
|
|
||||||
def get_ipv4(self, obj):
|
def get_ipv4(self, obj):
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -47,8 +47,7 @@ def get_or_create_vm_detail(user, manager, vm_id):
|
||||||
vm_detail_obj = VMDetail.objects.create(
|
vm_detail_obj = VMDetail.objects.create(
|
||||||
user=user, vm_id=vm_id, disk_size=vm['disk_size'],
|
user=user, vm_id=vm_id, disk_size=vm['disk_size'],
|
||||||
cores=vm['cores'], memory=vm['memory'],
|
cores=vm['cores'], memory=vm['memory'],
|
||||||
configuration="" if vm['configuration'] is None else vm['configuration'],
|
configuration=vm['configuration'], ipv4=vm['ipv4'],
|
||||||
ipv4=vm['ipv4'],
|
|
||||||
ipv6=vm['ipv6']
|
ipv6=vm['ipv6']
|
||||||
)
|
)
|
||||||
return vm_detail_obj
|
return vm_detail_obj
|
||||||
|
|
Loading…
Reference in a new issue