[elbe-devel] [PATCH v2 05/10] initvm: allow configuration of initvm domain

Torben Hohn torben.hohn at linutronix.de
Tue Apr 17 12:39:36 CEST 2018


libvirt identifies virtual machine via their domain
identifier. This domain identifier needs to be unique
when we move to the qemu:///system provider.

In order to still permit more than one initvm per host,
we need to make the identifier configurable.

Add cfg['initvm_domain'] and obey it where 'initvm' was
used previously.

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

diff --git a/elbepack/config.py b/elbepack/config.py
index 37e1ee18..07a726ac 100644
--- a/elbepack/config.py
+++ b/elbepack/config.py
@@ -27,6 +27,7 @@ class Config(dict):
         self['elbeuser'] = "root"
         self['elbepass'] = "foo"
         self['pbuilder_jobs'] = "auto"
+        self['initvm_domain'] = "initvm"
 
         if 'ELBE_SOAPPORT' in os.environ:
             self['soapport'] = os.environ['ELBE_SOAPPORT']
@@ -43,5 +44,8 @@ class Config(dict):
         if 'ELBE_PBUILDER_JOBS' in os.environ:
             self['pbuilder_jobs'] = os.environ['ELBE_PBUILDER_JOBS']
 
+        if 'ELBE_INITVM_DOMAIN' in os.environ:
+            self['initvm_domain'] = os.environ['ELBE_INITVM_DOMAIN']
+
 
 cfg = Config()
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