Add sdd_size, hdd_size to VirtualMachineSerializer
This commit is contained in:
parent
a4ff33f0fd
commit
43999d803a
1 changed files with 18 additions and 0 deletions
|
@ -49,6 +49,8 @@ class VirtualMachineSerializer(serializers.Serializer):
|
|||
memory = serializers.SerializerMethodField()
|
||||
|
||||
disk_size = serializers.SerializerMethodField()
|
||||
hdd_size = serializers.SerializerMethodField()
|
||||
sdd_size = serializers.SerializerMethodField()
|
||||
ipv4 = serializers.SerializerMethodField()
|
||||
ipv6 = serializers.SerializerMethodField()
|
||||
vm_id = serializers.IntegerField(read_only=True, source='id')
|
||||
|
@ -102,6 +104,22 @@ class VirtualMachineSerializer(serializers.Serializer):
|
|||
disk_size += int(disk.size)
|
||||
return disk_size / 1024
|
||||
|
||||
def get_sdd_size(self, obj):
|
||||
template = obj.template
|
||||
disk_size = 0
|
||||
for disk in template.disks:
|
||||
if disk.datastore == 'cephds':
|
||||
disk_size += int(disk.size)
|
||||
return disk_size / 1024
|
||||
|
||||
def get_hdd_size(self, obj):
|
||||
template = obj.template
|
||||
disk_size = 0
|
||||
for disk in template.disks:
|
||||
if disk.datastore == 'ceph_hdd_ds':
|
||||
disk_size += int(disk.size)
|
||||
return disk_size / 1024
|
||||
|
||||
def get_price(self, obj):
|
||||
template = obj.template
|
||||
price = float(template.vcpu) * 5.0
|
||||
|
|
Loading…
Reference in a new issue