Commit 9bc2639a by Dudás Ádám

vm: sort methods

parent 692f0819
...@@ -52,29 +52,8 @@ class InstanceActivity(ActivityModel): ...@@ -52,29 +52,8 @@ class InstanceActivity(ActivityModel):
return '{}({})'.format(self.activity_code, return '{}({})'.format(self.activity_code,
self.instance) self.instance)
def get_absolute_url(self): def abort(self):
return reverse('dashboard.views.vm-activity', args=[self.pk]) AbortableAsyncResult(self.task_uuid, backend=celery.backend).abort()
def get_readable_name(self):
activity_code_last_suffix = split_activity_code(self.activity_code)[-1]
return activity_code_last_suffix.replace('_', ' ').capitalize()
def get_status_id(self):
if self.succeeded is None:
return 'wait'
elif self.succeeded:
return 'success'
else:
return 'failed'
@property
def is_abortable(self):
"""Can the activity be aborted?
:returns: True if the activity can be aborted; otherwise, False.
"""
op = self.instance.get_operation_from_activity_code(self.activity_code)
return self.task_uuid and op and op.abortable and not self.finished
@classmethod @classmethod
def create(cls, code_suffix, instance, task_uuid=None, user=None, def create(cls, code_suffix, instance, task_uuid=None, user=None,
...@@ -104,21 +83,42 @@ class InstanceActivity(ActivityModel): ...@@ -104,21 +83,42 @@ class InstanceActivity(ActivityModel):
act.save() act.save()
return act return act
@contextmanager def get_absolute_url(self):
def sub_activity(self, code_suffix, on_abort=None, on_commit=None, return reverse('dashboard.views.vm-activity', args=[self.pk])
task_uuid=None, concurrency_check=True):
"""Create a transactional context for a nested instance activity. def get_readable_name(self):
activity_code_last_suffix = split_activity_code(self.activity_code)[-1]
return activity_code_last_suffix.replace('_', ' ').capitalize()
def get_status_id(self):
if self.succeeded is None:
return 'wait'
elif self.succeeded:
return 'success'
else:
return 'failed'
@property
def is_abortable(self):
"""Can the activity be aborted?
:returns: True if the activity can be aborted; otherwise, False.
""" """
act = self.create_sub(code_suffix, task_uuid, concurrency_check) op = self.instance.get_operation_from_activity_code(self.activity_code)
return activitycontextimpl(act, on_abort=on_abort, on_commit=on_commit) return self.task_uuid and op and op.abortable and not self.finished
def save(self, *args, **kwargs): def save(self, *args, **kwargs):
ret = super(InstanceActivity, self).save(*args, **kwargs) ret = super(InstanceActivity, self).save(*args, **kwargs)
self.instance._update_status() self.instance._update_status()
return ret return ret
def abort(self): @contextmanager
AbortableAsyncResult(self.task_uuid, backend=celery.backend).abort() def sub_activity(self, code_suffix, on_abort=None, on_commit=None,
task_uuid=None, concurrency_check=True):
"""Create a transactional context for a nested instance activity.
"""
act = self.create_sub(code_suffix, task_uuid, concurrency_check)
return activitycontextimpl(act, on_abort=on_abort, on_commit=on_commit)
@contextmanager @contextmanager
......
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