Commit 283da340 by Dudás Ádám

storage: create model for disk activity

parent d8650c62
...@@ -3,7 +3,9 @@ ...@@ -3,7 +3,9 @@
import logging import logging
import uuid import uuid
from django.db import models from django.contrib.auth.models import User
from django.db.models import (Model, BooleanField, CharField, DateTimeField,
ForeignKey, TextField)
from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ugettext_lazy as _
from model_utils.models import TimeStampedModel from model_utils.models import TimeStampedModel
from sizefield.models import FileSizeField from sizefield.models import FileSizeField
...@@ -13,15 +15,13 @@ from .tasks import local_tasks, remote_tasks ...@@ -13,15 +15,13 @@ from .tasks import local_tasks, remote_tasks
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
class DataStore(models.Model): class DataStore(Model):
"""Collection of virtual disks. """Collection of virtual disks.
""" """
name = models.CharField(max_length=100, unique=True, name = CharField(max_length=100, unique=True, verbose_name=_('name'))
verbose_name=_('name')) path = CharField(max_length=200, unique=True, verbose_name=_('path'))
path = models.CharField(max_length=200, unique=True, hostname = CharField(max_length=40, unique=True,
verbose_name=_('path'))
hostname = models.CharField(max_length=40, unique=True,
verbose_name=_('hostname')) verbose_name=_('hostname'))
class Meta: class Meta:
...@@ -39,16 +39,16 @@ class Disk(TimeStampedModel): ...@@ -39,16 +39,16 @@ class Disk(TimeStampedModel):
""" """
TYPES = [('qcow2-norm', 'qcow2 normal'), ('qcow2-snap', 'qcow2 snapshot'), TYPES = [('qcow2-norm', 'qcow2 normal'), ('qcow2-snap', 'qcow2 snapshot'),
('iso', 'iso'), ('raw-ro', 'raw read-only'), ('raw-rw', 'raw')] ('iso', 'iso'), ('raw-ro', 'raw read-only'), ('raw-rw', 'raw')]
name = models.CharField(blank=True, max_length=100, name = CharField(blank=True, max_length=100, verbose_name=_("name"))
verbose_name=_('name')) filename = CharField(max_length=256, verbose_name=_("filename"))
filename = models.CharField(max_length=256, verbose_name=_('filename')) datastore = ForeignKey(DataStore, verbose_name=_("datastore"),
datastore = models.ForeignKey(DataStore) help_text=_("The datastore that holds the disk."))
type = models.CharField(max_length=10, choices=TYPES) type = CharField(max_length=10, choices=TYPES)
size = FileSizeField() size = FileSizeField()
base = models.ForeignKey('self', blank=True, null=True, base = ForeignKey('self', blank=True, null=True,
related_name='derivatives') related_name='derivatives')
ready = models.BooleanField(default=False) ready = BooleanField(default=False)
dev_num = models.CharField(default='a', max_length=1, dev_num = CharField(default='a', max_length=1,
verbose_name="device number") verbose_name="device number")
class Meta: class Meta:
...@@ -91,8 +91,9 @@ class Disk(TimeStampedModel): ...@@ -91,8 +91,9 @@ class Disk(TimeStampedModel):
'raw-ro': 'raw-rw', 'raw-ro': 'raw-rw',
}[self.type] }[self.type]
return Disk(base=self, datastore=self.datastore, filename=filename, return Disk.objects.create(base=self, datastore=self.datastore,
name=self.name, size=self.size, type=new_type) filename=filename, name=self.name,
size=self.size, type=new_type)
@property @property
def device_type(self): def device_type(self):
...@@ -149,3 +150,17 @@ class Disk(TimeStampedModel): ...@@ -149,3 +150,17 @@ class Disk(TimeStampedModel):
# TODO # TODO
# StorageDriver.delete_disk.delay(instance.to_json()).get() # StorageDriver.delete_disk.delay(instance.to_json()).get()
pass pass
class DiskActivity(TimeStampedModel):
activity_code = CharField(verbose_name=_('activity_code'), max_length=100)
task_uuid = CharField(verbose_name=_('task_uuid'), blank=True,
max_length=50, null=True, unique=True)
disk = ForeignKey(Disk, verbose_name=_('disk'),
related_name='activity_log')
user = ForeignKey(User, verbose_name=_('user'), blank=True, null=True)
started = DateTimeField(verbose_name=_('started'), blank=True, null=True)
finished = DateTimeField(verbose_name=_('finished'), blank=True, null=True)
result = TextField(verbose_name=_('result'), blank=True, null=True)
state = CharField(verbose_name=_('state'), default='PENDING',
max_length=50)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment