summaryrefslogtreecommitdiffstats
path: root/src/main/java/org/openslx/util/vm/VboxConfig.java
diff options
context:
space:
mode:
authorJonathan Bauer2018-02-05 17:30:29 +0100
committerJonathan Bauer2018-02-05 17:30:29 +0100
commitbc32fca470e84a95e1571bb00fd6f583d8df4c24 (patch)
treeedd10dc7c089559aa0b477a8e40cbb4736d65f9d /src/main/java/org/openslx/util/vm/VboxConfig.java
parent[VBox - Qemu] refined and improved the qemu metadata class (diff)
downloadmaster-sync-shared-bc32fca470e84a95e1571bb00fd6f583d8df4c24.tar.gz
master-sync-shared-bc32fca470e84a95e1571bb00fd6f583d8df4c24.tar.xz
master-sync-shared-bc32fca470e84a95e1571bb00fd6f583d8df4c24.zip
[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
Diffstat (limited to 'src/main/java/org/openslx/util/vm/VboxConfig.java')
-rw-r--r--src/main/java/org/openslx/util/vm/VboxConfig.java65
1 files changed, 38 insertions, 27 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;
}