Commit 25356007 by Dudás Ádám

vm: helper function for registering operations

parent 9ef83cbc
......@@ -218,6 +218,7 @@ class Instance(AclBase, VirtualMachineDescModel, StatusModel,
"destruction."))
objects = Manager()
active = InstanceActiveManager()
_ops = {} # operation factory registry
class Meta:
app_label = 'vm'
......
......@@ -3,6 +3,7 @@ from __future__ import absolute_import, unicode_literals
from common.models import activity_context
from ..tasks.local_tasks import async_operation
from .activity import InstanceActivity
from .instance import Instance
class Operation:
......@@ -77,3 +78,12 @@ class Operation:
"""This method is called when the operation executes successfully.
"""
pass
def register_operation(op_cls, op_id=None):
"""Register the specified operation with Instance.
"""
if op_id is None:
op_id = op_cls.id
Instance._ops[op_id] = lambda inst: op_cls(inst)
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