[elbe-devel] [PATCH 2/3] initvmaction: remove hardcoded values

Torben Hohn torben.hohn at linutronix.de
Wed Mar 13 18:01:15 CET 2019


On Wed, Mar 13, 2019 at 05:56:49PM +0100, Manuel Traut wrote:
> Libvirt state was compared with hardcoded values.
> Replace hardcoded values by human readable definitions.
> 
> Signed-off-by: Manuel Traut <manut at linutronix.de>

Reviewed-by: Torben Hohn <torben.hohn at linutronix.de>

> ---
>  elbepack/initvmaction.py | 16 ++++++++--------
>  1 file changed, 8 insertions(+), 8 deletions(-)
> 
> diff --git a/elbepack/initvmaction.py b/elbepack/initvmaction.py
> index 038dc3bc..98ccdd00 100644
> --- a/elbepack/initvmaction.py
> +++ b/elbepack/initvmaction.py
> @@ -127,10 +127,10 @@ class StartAction(InitVMAction):
>          InitVMAction.__init__(self, node)
>  
>      def execute(self, _initvmdir, _opt, _args):
> -        if self.initvm_state() == 1:
> +        if self.initvm_state() == libvirt.VIR_DOMAIN_RUNNING:
>              print('Initvm already running.')
>              sys.exit(20)
> -        elif self.initvm_state() == 5:
> +        elif self.initvm_state() == libvirt.VIR_DOMAIN_SHUTOFF:
>              # Domain is shut off. Let's start it!
>              self.initvm.create()
>              # Wait five seconds for the initvm to boot
> @@ -154,9 +154,9 @@ class EnsureAction(InitVMAction):
>          InitVMAction.__init__(self, node)
>  
>      def execute(self, _initvmdir, _opt, _args):
> -        if self.initvm_state() == 5:
> +        if self.initvm_state() == libvirt.VIR_DOMAIN_SHUTOFF:
>              system('%s initvm start' % elbe_exe)
> -        elif self.initvm_state() == 1:
> +        elif self.initvm_state() == libvirt.VIR_DOMAIN_RUNNING:
>              pass
>          else:
>              print("Elbe initvm in bad state.")
> @@ -174,7 +174,7 @@ class StopAction(InitVMAction):
>          InitVMAction.__init__(self, node)
>  
>      def execute(self, _initvmdir, _opt, _args):
> -        if self.initvm_state() != 1:
> +        if self.initvm_state() != libvirt.VIR_DOMAIN_RUNNING:
>              print('Initvm is not running.')
>              sys.exit(20)
>          else:
> @@ -184,11 +184,11 @@ class StopAction(InitVMAction):
>                  except libvirt.libvirtError as e:
>                      # ignore that initvm is already shutdown but raise all
>                      # other errors
> -                    if self.initvm_state() != 5:
> +                    if self.initvm_state() != libvirt.VIR_DOMAIN_SHUTOFF:
>                          raise e
>                  sys.stdout.write("*")
>                  sys.stdout.flush()
> -                if self.initvm_state() == 5:
> +                if self.initvm_state() == libvirt.VIR_DOMAIN_SHUTOFF:
>                      print("\nInitvm shut off.")
>                      break
>                  time.sleep(1)
> @@ -205,7 +205,7 @@ class AttachAction(InitVMAction):
>          InitVMAction.__init__(self, node)
>  
>      def execute(self, _initvmdir, _opt, _args):
> -        if self.initvm_state() != 1:
> +        if self.initvm_state() != libvirt.VIR_DOMAIN_RUNNING:
>              print('Error: Initvm not running properly.')
>              sys.exit(20)
>  
> -- 
> 2.20.1
> 

-- 
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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 488 bytes
Desc: not available
URL: <http://lists.linutronix.de/pipermail/elbe-devel/attachments/20190313/314cd10d/attachment.sig>


More information about the elbe-devel mailing list