[elbe-devel] [PATCH 6/7] initvm init: obey cfg['initvm_domain'] where libvirt domain name is used

Torben Hohn torben.hohn at linutronix.de
Fri Apr 13 14:43:15 CEST 2018


Signed-off-by: Torben Hohn <torben.hohn at linutronix.de>
---
 elbepack/init/libvirt.xml.mako |  2 +-
 elbepack/initvmaction.py       | 21 ++++++++-------------
 2 files changed, 9 insertions(+), 14 deletions(-)

diff --git a/elbepack/init/libvirt.xml.mako b/elbepack/init/libvirt.xml.mako
index 13c9b82c..ca579242 100644
--- a/elbepack/init/libvirt.xml.mako
+++ b/elbepack/init/libvirt.xml.mako
@@ -10,7 +10,7 @@ import os
 # Generate UUID
 uid = uuid.uuid4()
 
-name = 'initvm'
+name = cfg['initvm_domain']
 cpus = multiprocessing.cpu_count()
 memory = 1048576
 
diff --git a/elbepack/initvmaction.py b/elbepack/initvmaction.py
index 02059358..b9fcdeb6 100644
--- a/elbepack/initvmaction.py
+++ b/elbepack/initvmaction.py
@@ -24,6 +24,7 @@ from elbepack.directories import elbe_exe
 from elbepack.shellhelper import CommandError, system, command_out_stderr
 from elbepack.filesystem import wdfs, TmpdirFilesystem
 from elbepack.elbexml import ElbeXML, ValidationError, ValidationMode
+from elbepack.config import cfg
 
 from tempfile import NamedTemporaryFile
 
@@ -82,7 +83,7 @@ class InitVMAction(object):
         # initvm create`
         self.conn = libvirt.open("qemu:///session")
         try:
-            self.initvm = self.conn.lookupByName('initvm')
+            self.initvm = self.conn.lookupByName(cfg['initvm_domain'])
         except libvirt.libvirtError:
             self.initvm = None
             if initvmNeeded:
@@ -179,7 +180,7 @@ class AttachAction(InitVMAction):
             sys.exit(20)
 
         print('Attaching to initvm console.')
-        system('virsh console initvm')
+        system('virsh console %s' % cfg['initvm_domain'])
 
 
 InitVMAction.register(AttachAction)
@@ -226,10 +227,10 @@ class CreateAction(InitVMAction):
             print("If you want to build in your old initvm, "
                   "use `elbe initvm submit <xml>`.")
             print("If you want to remove your old initvm from libvirt "
-                  "run `virsh undefine initvm`.\n")
+                    "run `virsh undefine %s`.\n" % cfg['initvm_domain'])
             print("Note:")
             print("\t1) You can reimport your old initvm via "
-                  "`virsh define <file>`")
+                    "`virsh define <file>`")
             print("\t   where <file> is the corresponding libvirt.xml")
             print("\t2) virsh undefine does not delete the image "
                   "of your old initvm.")
@@ -331,22 +332,16 @@ class CreateAction(InitVMAction):
             print("Giving up", file=sys.stderr)
             sys.exit(20)
 
-        # Register initvm in libvirt
-        # TODO: Extended vm name support? Currently, only one initvm with the
-        # name `initvm` is allowed. But perhaps it is a good idea to leave it
-        # that way because otherwise the user may be tempted to start more than
-        # one elbe-initvm which is not possible in the current network
-        # configuration (user networking with portforwarding).
-
-        # Read xml file
+        # Read xml file for libvirt
         with open(os.path.join(initvmdir, 'libvirt.xml')) as f:
             xml = f.read()
 
+        # Register initvm in libvirt
         try:
             self.conn.defineXML(xml)
         except CommandError:
             print('Registering initvm in libvirt failed', file=sys.stderr)
-            print('Try `virsh undefine initvm` to delete existing initvm',
+            print('Try `virsh undefine %s` to delete existing initvm' % cfg['initvm_domain'],
                   file=sys.stderr)
             sys.exit(20)
 
-- 
2.11.0




More information about the elbe-devel mailing list