[elbe-devel] [PATCH v2 1/1] preprocess: prevent host forwarding conflicts

bage at linutronix.de bage at linutronix.de
Fri Sep 13 13:11:51 CEST 2019


From: Bastian Germann <bage at linutronix.de>

Remove a port forwarding in preprocess if it matches the default forwarding.
This will prevent an unnecessary qemu error.  If the guest forward port is
in conflict with the default the user has to deal with the qemu error.

Signed-off-by: Bastian Germann <bage at linutronix.de>
---
 elbepack/xmlpreprocess.py | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

diff --git a/elbepack/xmlpreprocess.py b/elbepack/xmlpreprocess.py
index 0e986a75..598ced45 100644
--- a/elbepack/xmlpreprocess.py
+++ b/elbepack/xmlpreprocess.py
@@ -17,6 +17,7 @@ from lxml import etree
 from lxml.etree import XMLParser, parse
 
 from elbepack.archivedir import ArchivedirError, combinearchivedir
+from elbepack.config import cfg
 from elbepack.directories import elbe_exe
 from elbepack.shellhelper import command_out_stderr, CommandError
 from elbepack.isooptions import iso_option_valid
@@ -68,6 +69,20 @@ def preprocess_iso_option(xml):
             raise XMLPreprocessError(violation)
         print("[WARN] %s" % violation)
 
+def preprocess_initvm_ports(xml):
+    "Filters out the default port forwardings to prevent qemu conflict"
+
+    for forward in xml.iterfind('initvm/portforwarding/forward'):
+        prot = forward.find('proto')
+        benv = forward.find('buildenv')
+        host = forward.find('host')
+        if prot is None or benv is None or host is None:
+            continue
+        if prot.text == 'tcp' and (
+                host.text == cfg['sshport'] and benv.text == '22' or
+                host.text == cfg['soapport'] and benv.text == '7588'):
+            forward.getparent().remove(forward)
+
 
 def xmlpreprocess(fname, output, variants=None):
 
@@ -141,6 +156,8 @@ def xmlpreprocess(fname, output, variants=None):
 
         preprocess_iso_option(xml)
 
+        preprocess_initvm_ports(xml)
+
         if schema.validate(xml):
             # if validation succedes write xml file
             xml.write(
-- 
2.20.1




More information about the elbe-devel mailing list