summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/main/java/org/openslx/util/vm/VboxConfig.java65
-rw-r--r--src/main/java/org/openslx/util/vm/VboxMetaData.java26
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<VBoxSoundCardMeta, VBoxDDAccelMeta,
private final VboxConfig config;
+ public static enum EthernetType
+ {
+ NAT( "vboxnet1" ),
+ BRIDGED( "vboxnet0" ),
+ HOST_ONLY( "vboxnet2" );
+
+ public final String vnet;
+
+ private EthernetType( String vnet )
+ {
+ this.vnet = vnet;
+ }
+ }
+
public VboxMetaData( List<OperatingSystem> osList, File file ) throws IOException, UnsupportedVirtualizerFormatException
{
super( osList );
@@ -421,16 +435,12 @@ public class VboxMetaData extends VmMetaData<VBoxSoundCardMeta, VBoxDDAccelMeta,
@Override
public boolean addEthernet( VmMetaData.EtherType type )
{
- switch ( type ) {
- case NAT:
- return addDefaultNat();
- case BRIDGED: // implement later
- return false;
- case HOST_ONLY: // implement later
- return false;
- default: // implement later
+ Node hostOnlyInterfaceNode = config.addNewNode( "Adapter", "HostOnlyInterface", true, "slot", "0" );
+ if (hostOnlyInterfaceNode == null) {
+ LOGGER.error("Failed to create node for HostOnlyInterface.");
return false;
}
+ return config.addAttributeToNode(hostOnlyInterfaceNode, "name", EthernetType.valueOf(type.name()).vnet);
}
@Override