[elbe-devel] [PATCH v2 1/2] initvmaction: Cleanup actions registration
Torben Hohn
torben.hohn at linutronix.de
Mon May 25 14:57:08 CEST 2020
On Mon, May 18, 2020 at 11:22:06AM -0400, Olivier Dion wrote:
> This follows the style in finetuning using decorator.
>
> Signed-off-by: Olivier Dion <dion at linutronix.de>
Reviewed-by: Torben Hohn <torben.hohn 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
>
>
> _______________________________________________
> elbe-devel mailing list
> elbe-devel at linutronix.de
> https://lists.linutronix.de/mailman/listinfo/elbe-devel
--
Torben Hohn
Linutronix GmbH | Bahnhofstrasse 3 | D-88690 Uhldingen-Mühlhofen
Phone: +49 7556 25 999 18; Fax.: +49 7556 25 999 99
Hinweise zum Datenschutz finden Sie hier (Informations on data privacy
can be found here): https://linutronix.de/kontakt/Datenschutz.php
Linutronix GmbH | Firmensitz (Registered Office): Uhldingen-Mühlhofen |
Registergericht (Registration Court): Amtsgericht Freiburg i.Br., HRB700
806 | Geschäftsführer (Managing Directors): Heinz Egger, Thomas Gleixner
More information about the elbe-devel
mailing list