diff --git a/nicohack202002/uncloud/opennebula/migrations/0002_vm_uuid.py b/nicohack202002/uncloud/opennebula/migrations/0002_vm_uuid.py new file mode 100644 index 0000000..595fd05 --- /dev/null +++ b/nicohack202002/uncloud/opennebula/migrations/0002_vm_uuid.py @@ -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), + ), + ] diff --git a/nicohack202002/uncloud/opennebula/models.py b/nicohack202002/uncloud/opennebula/models.py index babba26..0f93b78 100644 --- a/nicohack202002/uncloud/opennebula/models.py +++ b/nicohack202002/uncloud/opennebula/models.py @@ -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.