[elbe-devel] [PATCH v2 1/7] initvmaction: Allow "submit" without libvirt

Bastian Germann bage at linutronix.de
Tue Dec 20 11:31:24 CET 2022


The initvm submit command does not allow to be run even if the initvm is
on a remote machine. Import the libvirt module locally where it is used.

Signed-off-by: Bastian Germann <bage at linutronix.de>
---
 elbepack/initvmaction.py | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/elbepack/initvmaction.py b/elbepack/initvmaction.py
index e64502c876..f0eb2a19d2 100644
--- a/elbepack/initvmaction.py
+++ b/elbepack/initvmaction.py
@@ -13,8 +13,6 @@ import time
 import os
 import datetime
 
-import libvirt
-
 from tempfile import NamedTemporaryFile
 
 import elbepack
@@ -84,6 +82,8 @@ class InitVMAction:
         if not is_soap_local():
             return
 
+        import libvirt
+
         # The tag initvmNeeded is required in order to be able to run `elbe
         # initvm create`
         try:
@@ -161,6 +161,8 @@ class StartAction(InitVMAction):
         InitVMAction.__init__(self, node)
 
     def execute(self, _initvmdir, _opt, _args):
+        import libvirt
+
         if self.initvm_state() == libvirt.VIR_DOMAIN_RUNNING:
             print('Initvm already running.')
             sys.exit(20)
@@ -190,6 +192,8 @@ class EnsureAction(InitVMAction):
         if not is_soap_local():
             return
 
+        import libvirt
+
         if self.initvm_state() == libvirt.VIR_DOMAIN_SHUTOFF:
             system(f'{elbe_exe} initvm start')
         elif self.initvm_state() == libvirt.VIR_DOMAIN_RUNNING:
@@ -215,6 +219,7 @@ class StopAction(InitVMAction):
         InitVMAction.__init__(self, node)
 
     def execute(self, _initvmdir, _opt, _args):
+        import libvirt
 
         if self.initvm_state() != libvirt.VIR_DOMAIN_RUNNING:
             print('Initvm is not running.')
@@ -249,6 +254,8 @@ class AttachAction(InitVMAction):
         InitVMAction.__init__(self, node)
 
     def execute(self, _initvmdir, _opt, _args):
+        import libvirt
+
         if self.initvm_state() != libvirt.VIR_DOMAIN_RUNNING:
             print('Error: Initvm not running properly.')
             sys.exit(20)
-- 
2.30.2



More information about the elbe-devel mailing list