Commit 61c03f78 by Őry Máté

vm: move NodeActivity to vm.models.activity

parent 65aeedfe
# flake8: noqa
from .activity import NodeActivity
from .activity import InstanceActivity
from .instance import InstanceActiveManager
from .instance import BaseResourceConfigModel
......@@ -12,7 +13,6 @@ from .network import InterfaceTemplate
from .network import Interface
from .node import Trait
from .node import Node
from .node import NodeActivity
from .node import Lease
__all__ = [
......
......@@ -58,3 +58,40 @@ class InstanceActivity(ActivityModel):
def instance_activity(code_suffix, instance, task_uuid=None, user=None):
act = InstanceActivity.create(code_suffix, instance, task_uuid, user)
return activitycontextimpl(act)
class NodeActivity(ActivityModel):
node = ForeignKey('Node', related_name='activity_log',
help_text=_('Node this activity works on.'),
verbose_name=_('node'))
class Meta:
app_label = 'vm'
db_table = 'vm_nodeactivity'
@classmethod
def create(cls, code_suffix, node, task_uuid=None, user=None):
act = cls(activity_code='vm.Node.' + code_suffix,
node=node, parent=None, started=timezone.now(),
task_uuid=task_uuid, user=user)
act.save()
return act
def create_sub(self, code_suffix, task_uuid=None):
act = NodeActivity(
activity_code=self.activity_code + '.' + code_suffix,
node=self.node, parent=self, started=timezone.now(),
task_uuid=task_uuid, user=self.user)
act.save()
return act
@contextmanager
def sub_activity(self, code_suffix, task_uuid=None):
act = self.create_sub(code_suffix, task_uuid)
return activitycontextimpl(act)
@contextmanager
def node_activity(code_suffix, node, task_uuid=None, user=None):
act = InstanceActivity.create(code_suffix, node, task_uuid, user)
return activitycontextimpl(act)
from __future__ import unicode_literals
from contextlib import contextmanager
from datetime import timedelta
from logging import getLogger
......@@ -7,17 +6,15 @@ from django.db.models import (
Model, CharField, IntegerField, ForeignKey, BooleanField, ManyToManyField,
FloatField,
)
from django.utils import timezone
from django.utils.translation import ugettext_lazy as _
from celery.exceptions import TimeoutError
from model_utils.models import TimeStampedModel
from taggit.managers import TaggableManager
from common.models import ActivityModel, activitycontextimpl, method_cache
from common.models import method_cache
from firewall.models import Host
from ..tasks import vm_tasks
from .activity import InstanceActivity
logger = getLogger(__name__)
......@@ -139,43 +136,6 @@ class Node(TimeStampedModel):
return self.name
class NodeActivity(ActivityModel):
node = ForeignKey(Node, related_name='activity_log',
help_text=_('Node this activity works on.'),
verbose_name=_('node'))
class Meta:
app_label = 'vm'
db_table = 'vm_nodeactivity'
@classmethod
def create(cls, code_suffix, node, task_uuid=None, user=None):
act = cls(activity_code='vm.Node.' + code_suffix,
node=node, parent=None, started=timezone.now(),
task_uuid=task_uuid, user=user)
act.save()
return act
def create_sub(self, code_suffix, task_uuid=None):
act = NodeActivity(
activity_code=self.activity_code + '.' + code_suffix,
node=self.node, parent=self, started=timezone.now(),
task_uuid=task_uuid, user=self.user)
act.save()
return act
@contextmanager
def sub_activity(self, code_suffix, task_uuid=None):
act = self.create_sub(code_suffix, task_uuid)
return activitycontextimpl(act)
@contextmanager
def node_activity(code_suffix, node, task_uuid=None, user=None):
act = InstanceActivity.create(code_suffix, node, task_uuid, user)
return activitycontextimpl(act)
class Lease(Model):
"""Lease times for VM instances.
......
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