From bc32fca470e84a95e1571bb00fd6f583d8df4c24 Mon Sep 17 00:00:00 2001 From: Jonathan Bauer Date: Mon, 5 Feb 2018 17:30:29 +0100 Subject: [vbox] use vboxnet1 for NAT on bwlp clients do not use vbox's embedded NAT mode for network adapter when delivering the machine config to clients. (Still do use it when downloading locally though) + minor cleanup --- src/main/java/org/openslx/util/vm/VboxConfig.java | 65 +++++++++++++--------- .../java/org/openslx/util/vm/VboxMetaData.java | 26 ++++++--- 2 files changed, 56 insertions(+), 35 deletions(-) diff --git a/src/main/java/org/openslx/util/vm/VboxConfig.java b/src/main/java/org/openslx/util/vm/VboxConfig.java index 70af022..a244497 100644 --- a/src/main/java/org/openslx/util/vm/VboxConfig.java +++ b/src/main/java/org/openslx/util/vm/VboxConfig.java @@ -23,6 +23,7 @@ import javax.xml.xpath.XPathFactory; import org.apache.log4j.Logger; import org.openslx.util.vm.VmMetaData.DriveBusType; import org.openslx.util.vm.VmMetaData.HardDisk; +import org.w3c.dom.DOMException; import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.Node; @@ -293,8 +294,6 @@ public class VboxConfig * @param targetTag * @param targetAttr0 * @param value0 - * @param targetAttr1 - * @param value1 * @return */ public Node findANode( String targetTag, String targetAttr0, String value0 ) @@ -357,13 +356,19 @@ public class VboxConfig } } - public void addAttributeToNode( Node targetNode, String attrName, String value ) + public boolean addAttributeToNode( Node targetNode, String attrName, String value ) { if ( targetNode == null ) { LOGGER.warn( "Node is null; stopped!" ); - return; + return false; + } + try { + ( (Element)targetNode ).setAttribute( attrName, value ); + } catch (DOMException e) { + LOGGER.error("Failed set '" + attrName + "' to '" + value + "' of xml node '" + targetNode.getNodeName() + "': ", e); + return false; } - ( (Element)targetNode ).setAttribute( attrName, value ); + return true; } public Node addNewNode( String nameOfParent, String nameOfnewNode, boolean oneLiner ) @@ -375,33 +380,39 @@ public class VboxConfig { Node parent = null; NodeList posibleParents = findANode( nameOfParent ); - if ( posibleParents.getLength() > 1 ) { - // if we have more then 1 parent we need to have an sanityArg s.t. we insert our new attribute in the right tag - if ( refAttr == null ) { - LOGGER.warn( "Action would change values of more than one node; stopped!" ); - return null; - } - for ( int i = 1; i < posibleParents.getLength(); i++ ) { - if ( ( (Element)posibleParents.item( i ) ).getAttribute( refAttr ).equals( refVal ) ) { - parent = posibleParents.item( i ); - break; + Element newNode; + try { + if ( posibleParents.getLength() > 1 ) { + // if we have more then 1 parent we need to have an sanityArg s.t. we insert our new attribute in the right tag + if ( refAttr == null ) { + LOGGER.warn( "Action would change values of more than one node; stopped!" ); + return null; + } + for ( int i = 1; i < posibleParents.getLength(); i++ ) { + if ( ( (Element)posibleParents.item( i ) ).getAttribute( refAttr ).equals( refVal ) ) { + parent = posibleParents.item( i ); + break; + } } + } else { + parent = posibleParents.item( 0 ); } - } else { - parent = posibleParents.item( 0 ); - } - if ( parent == null ) { - LOGGER.warn( "Node: '" + nameOfParent + "' could not be found" ); - return null; - } - Element newNode = doc.createElement( nameOfnewNode ); + if ( parent == null ) { + LOGGER.warn( "Node: '" + nameOfParent + "' could not be found" ); + return null; + } + newNode = doc.createElement( nameOfnewNode ); - if ( !oneLiner ) { - org.w3c.dom.Text a = doc.createTextNode( "\n" ); - newNode.appendChild( a ); + if ( !oneLiner ) { + org.w3c.dom.Text a = doc.createTextNode( "\n" ); + newNode.appendChild( a ); + } + parent.appendChild( newNode ); + } catch (DOMException e) { + LOGGER.error("Something went wrong: ", e); + return null; } - parent.appendChild( newNode ); return newNode; } diff --git a/src/main/java/org/openslx/util/vm/VboxMetaData.java b/src/main/java/org/openslx/util/vm/VboxMetaData.java index 1110e2f..d5e26a6 100644 --- a/src/main/java/org/openslx/util/vm/VboxMetaData.java +++ b/src/main/java/org/openslx/util/vm/VboxMetaData.java @@ -65,6 +65,20 @@ public class VboxMetaData extends VmMetaData osList, File file ) throws IOException, UnsupportedVirtualizerFormatException { super( osList ); @@ -421,16 +435,12 @@ public class VboxMetaData extends VmMetaData