[elbe-devel] [PATCH 4/4] elbepack: replace calls to run_elbe('initvm') with method calls

Thomas Weißschuh thomas.weissschuh at linutronix.de
Fri Jul 26 13:45:57 CEST 2024


These calls are shorter and provide better error context.

Signed-off-by: Thomas Weißschuh <thomas.weissschuh at linutronix.de>
---
 elbepack/initvm.py       |  2 +-
 elbepack/initvmaction.py | 25 ++-----------------------
 2 files changed, 3 insertions(+), 24 deletions(-)

diff --git a/elbepack/initvm.py b/elbepack/initvm.py
index 64fc6cce32bc..adcded58c5bb 100644
--- a/elbepack/initvm.py
+++ b/elbepack/initvm.py
@@ -254,7 +254,7 @@ class LibvirtInitVM(_InitVM):
     def ensure(self):
         state = self._state(self._get_domain())
         if state == self._libvirt.VIR_DOMAIN_SHUTOFF:
-            run_elbe(['initvm', 'start'], check=True)
+            self.start()
         elif state == self._libvirt.VIR_DOMAIN_RUNNING:
             _test_soap_communication()
         else:
diff --git a/elbepack/initvmaction.py b/elbepack/initvmaction.py
index 01dfdf598632..30acf8628c9a 100644
--- a/elbepack/initvmaction.py
+++ b/elbepack/initvmaction.py
@@ -390,18 +390,7 @@ class CreateAction(InitVMAction):
             sys.exit(145)
 
         self.initvm._build()
-
-        # In case of QEMU mode, we need to forward the additional parameters.
-        additional_params = []
-        if opt.qemu_mode:
-            additional_params = ['--qemu', '--directory', self.directory]
-
-        ps = run_elbe(['initvm', 'start', *additional_params], capture_output=False,
-                      encoding='utf-8')
-        if ps.returncode != 0:
-            print('Starting the initvm Failed', file=sys.stderr)
-            print('Giving up', file=sys.stderr)
-            sys.exit(148)
+        self.initvm.start()
 
         if len(args) == 1:
             # If provided xml file has no initvm section xmlfile is set to a
@@ -429,17 +418,7 @@ class CreateAction(InitVMAction):
 class SubmitAction(InitVMAction):
 
     def execute(self, opt, args):
-        # In case of QEMU mode, we need to forward the additional parameters.
-        additional_params = []
-        if opt.qemu_mode:
-            additional_params = ['--qemu', '--directory', self.directory]
-
-        ps = run_elbe(['initvm', 'ensure', *additional_params], capture_output=True,
-                      encoding='utf-8')
-        if ps.returncode != 0:
-            print('Starting the initvm Failed', file=sys.stderr)
-            print('Giving up', file=sys.stderr)
-            sys.exit(150)
+        self.initvm.ensure()
 
         # Init cdrom to None, if we detect it, we set it
         cdrom = None

-- 
2.45.2



More information about the elbe-devel mailing list