[elbe-devel] [PATCH v2 1/2] initvmaction: Cleanup actions registration
Olivier Dion
dion at linutronix.de
Mon May 18 17:22:06 CEST 2020
This follows the style in finetuning using decorator.
Signed-off-by: Olivier Dion <dion at linutronix.de>
---
elbepack/initvmaction.py | 41 +++++++++++++---------------------------
1 file changed, 13 insertions(+), 28 deletions(-)
diff --git a/elbepack/initvmaction.py b/elbepack/initvmaction.py
index f8572402..c6c1943f 100644
--- a/elbepack/initvmaction.py
+++ b/elbepack/initvmaction.py
@@ -52,8 +52,12 @@ class InitVMAction(object):
actiondict = {}
@classmethod
- def register(cls, action):
- cls.actiondict[action.tag] = action
+ def register(cls, tag):
+ def _register(action):
+ action.tag = tag
+ cls.actiondict[action.tag] = action
+ return action
+ return _register
@classmethod
def print_actions(cls):
@@ -119,10 +123,9 @@ class InitVMAction(object):
return self.initvm.info()[0]
+ at InitVMAction.register('start')
class StartAction(InitVMAction):
- tag = 'start'
-
def __init__(self, node):
InitVMAction.__init__(self, node)
@@ -143,13 +146,9 @@ class StartAction(InitVMAction):
print("*")
-InitVMAction.register(StartAction)
-
-
+ at InitVMAction.register('ensure')
class EnsureAction(InitVMAction):
- tag = 'ensure'
-
def __init__(self, node):
InitVMAction.__init__(self, node)
@@ -163,13 +162,10 @@ class EnsureAction(InitVMAction):
sys.exit(20)
-InitVMAction.register(EnsureAction)
-
+ at InitVMAction.register('stop')
class StopAction(InitVMAction):
- tag = 'stop'
-
def __init__(self, node):
InitVMAction.__init__(self, node)
@@ -195,13 +191,9 @@ class StopAction(InitVMAction):
time.sleep(1)
-InitVMAction.register(StopAction)
-
-
+ at InitVMAction.register('attach')
class AttachAction(InitVMAction):
- tag = 'attach'
-
def __init__(self, node):
InitVMAction.__init__(self, node)
@@ -214,8 +206,6 @@ class AttachAction(InitVMAction):
system('virsh --connect qemu:///system console %s' % cfg['initvm_domain'])
-InitVMAction.register(AttachAction)
-
def submit_and_dl_result(xmlfile, cdrom, opt):
@@ -452,9 +442,9 @@ def extract_cdrom(cdrom):
return tmp
-class CreateAction(InitVMAction):
- tag = 'create'
+ at InitVMAction.register('create')
+class CreateAction(InitVMAction):
def __init__(self, node):
InitVMAction.__init__(self, node, initvmNeeded=False)
@@ -601,13 +591,9 @@ class CreateAction(InitVMAction):
submit_and_dl_result(xmlfile, cdrom, opt)
-InitVMAction.register(CreateAction)
-
-
+ at InitVMAction.register('submit')
class SubmitAction(InitVMAction):
- tag = 'submit'
-
def __init__(self, node):
InitVMAction.__init__(self, node)
@@ -642,4 +628,3 @@ class SubmitAction(InitVMAction):
submit_and_dl_result(xmlfile, cdrom, opt)
-InitVMAction.register(SubmitAction)
--
2.26.2
More information about the elbe-devel
mailing list