[elbe-devel] [PATCH v2] initvmaction: Fix initvm command stop

Bastian Germann bage at linutronix.de
Tue Aug 4 17:21:38 CEST 2020


Am 04.08.20 um 17:22 schrieb Olivier Dion:
> This should fix problems that some users had with elbe-initvm-stop.
> 
> Signed-off-by: Olivier Dion <dion at linutronix.de>

Reviewed-by: Bastian Germann <bage at linutronix.de>

> ---
>  elbepack/initvmaction.py | 38 ++++++++++++++++++++++----------------
>  1 file changed, 22 insertions(+), 16 deletions(-)
> 
> diff --git a/elbepack/initvmaction.py b/elbepack/initvmaction.py
> index a0b76e15..348c82b3 100644
> --- a/elbepack/initvmaction.py
> +++ b/elbepack/initvmaction.py
> @@ -195,25 +195,31 @@ class StopAction(InitVMAction):
>          InitVMAction.__init__(self, node)
>  
>      def execute(self, _initvmdir, _opt, _args):
> +
>          if self.initvm_state() != libvirt.VIR_DOMAIN_RUNNING:
>              print('Initvm is not running.')
>              sys.exit(20)
> -        else:
> -            while True:
> -                try:
> -                    self.initvm.shutdown()
> -                except libvirt.libvirtError as e:
> -                    # ignore that initvm is already shutoff or is currently
> -                    # shutting down but raise all other errors
> -                    if (self.initvm_state() != libvirt.VIR_DOMAIN_SHUTOFF and
> -                        self.initvm_state() != libvirt.VIR_DOMAIN_SHUTDOWN):
> -                        raise e
> -                sys.stdout.write("*")
> -                sys.stdout.flush()
> -                if self.initvm_state() == libvirt.VIR_DOMAIN_SHUTOFF:
> -                    print("\nInitvm shut off.")
> -                    break
> -                time.sleep(1)
> +
> +        while True:
> +
> +            sys.stdout.write("*")
> +            sys.stdout.flush()
> +            time.sleep(1)
> +
> +            state = self.initvm_state()
> +
> +            if state == libvirt.VIR_DOMAIN_SHUTDOWN:
> +                continue
> +
> +            if state == libvirt.VIR_DOMAIN_SHUTOFF:
> +                break
> +
> +            try:
> +                self.initvm.shutdown()
> +            except libvirt.libvirtError as e:
> +                raise e
> +
> +        print("\nInitvm shutoff")
>  
>  
>  @InitVMAction.register('attach')
> 


More information about the elbe-devel mailing list