Commit d4a34912 by Dudás Ádám

storage, vm: add missing *Activity model helper methods

parent 0a32ce30
...@@ -6,6 +6,7 @@ import uuid ...@@ -6,6 +6,7 @@ import uuid
from django.contrib.auth.models import User from django.contrib.auth.models import User
from django.db.models import (Model, BooleanField, CharField, DateTimeField, from django.db.models import (Model, BooleanField, CharField, DateTimeField,
ForeignKey, TextField) ForeignKey, TextField)
from django.utils import timezone
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
...@@ -172,3 +173,14 @@ class DiskActivity(TimeStampedModel): ...@@ -172,3 +173,14 @@ class DiskActivity(TimeStampedModel):
result = TextField(verbose_name=_('result'), blank=True, null=True) result = TextField(verbose_name=_('result'), blank=True, null=True)
state = CharField(verbose_name=_('state'), default='PENDING', state = CharField(verbose_name=_('state'), default='PENDING',
max_length=50) max_length=50)
def update_state(self, new_state):
self.state = new_state
self.save()
def finish(self, result=None):
if not self.finished:
self.finished = timezone.now()
self.result = result
self.state = 'COMPLETED'
self.save()
...@@ -121,6 +121,17 @@ class NodeActivity(TimeStampedModel): ...@@ -121,6 +121,17 @@ class NodeActivity(TimeStampedModel):
status = CharField(verbose_name=_('status'), default='PENDING', status = CharField(verbose_name=_('status'), default='PENDING',
max_length=50, help_text=_('Actual state of activity')) max_length=50, help_text=_('Actual state of activity'))
def update_state(self, new_state):
self.state = new_state
self.save()
def finish(self, result=None):
if not self.finished:
self.finished = timezone.now()
self.result = result
self.state = 'COMPLETED'
self.save()
class Lease(Model): class Lease(Model):
......
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