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

Torben Hohn torben.hohn at linutronix.de
Tue Sep 17 14:14:40 CEST 2019


On Fri, Sep 13, 2019 at 01:11:51PM +0200, bage at linutronix.de wrote:
> 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>

Acked-by: Torben Hohn <torben.hohn at linutronix.de>

i would have preferred, if this was using treeutils
but since the surrounding code is already using the Element
this is acceptable.

but we really want to only use one API for messing with dom trees.

> ---
>  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
> 
> 
> _______________________________________________
> elbe-devel mailing list
> elbe-devel at linutronix.de
> https://lists.linutronix.de/mailman/listinfo/elbe-devel

-- 
Torben Hohn
Linutronix GmbH | Bahnhofstrasse 3 | D-88690 Uhldingen-Mühlhofen
Phone: +49 7556 25 999 18; Fax.: +49 7556 25 999 99

Hinweise zum Datenschutz finden Sie hier (Informations on data privacy 
can be found here): https://linutronix.de/kontakt/Datenschutz.php

Linutronix GmbH | Firmensitz (Registered Office): Uhldingen-Mühlhofen | 
Registergericht (Registration Court): Amtsgericht Freiburg i.Br., HRB700 
806 | Geschäftsführer (Managing Directors): Heinz Egger, Thomas Gleixner



More information about the elbe-devel mailing list