add uuid() to opennebula VM

This commit is contained in:
Nico Schottelius 2020-02-23 11:55:57 +01:00
parent fc4ec7b0f8
commit f8c29aa1d6
2 changed files with 25 additions and 1 deletions

View file

@ -0,0 +1,19 @@
# Generated by Django 3.0.3 on 2020-02-23 10:55
from django.db import migrations, models
import uuid
class Migration(migrations.Migration):
dependencies = [
('opennebula', '0001_initial'),
]
operations = [
migrations.AddField(
model_name='vm',
name='uuid',
field=models.UUIDField(default=uuid.uuid4, editable=False),
),
]

View file

@ -1,3 +1,4 @@
import uuid
from django.db import models
from django.contrib.auth import get_user_model
@ -5,16 +6,20 @@ from django.contrib.postgres.fields import JSONField
class VM(models.Model):
vmid = models.IntegerField(primary_key=True)
uuid = models.UUIDField(default=uuid.uuid4, editable=False)
owner = models.ForeignKey(get_user_model(), on_delete=models.CASCADE)
data = JSONField()
@property
def cores(self):
return self.data['TEMPLATE']['VCPU']
return int(self.data['TEMPLATE']['VCPU'])
@property
def ram_in_gb(self):
return (int(self.data['TEMPLATE']['MEMORY'])/1024.)
@property
def disks(self):
"""
If there is no disk then the key DISK does not exist.