summaryrefslogtreecommitdiffstats
path: root/src/main/java/org/openslx/util/vm/VboxConfig.java
diff options
context:
space:
mode:
authorVictor Mocanu2017-11-02 17:12:56 +0100
committerVictor Mocanu2017-11-02 17:12:56 +0100
commit1f58a5c478c82978418cb152ad43a7cc18a002a8 (patch)
treeed26ba585b5e9e6cbd1dfe3c6009be259d74cb8e /src/main/java/org/openslx/util/vm/VboxConfig.java
parent[VBox] added sorting to the keysarrays (diff)
downloadmaster-sync-shared-1f58a5c478c82978418cb152ad43a7cc18a002a8.tar.gz
master-sync-shared-1f58a5c478c82978418cb152ad43a7cc18a002a8.tar.xz
master-sync-shared-1f58a5c478c82978418cb152ad43a7cc18a002a8.zip
[VBox] new working coppy
added new Javadocs, updated getters of VBoxMetaData still got TODOs
Diffstat (limited to 'src/main/java/org/openslx/util/vm/VboxConfig.java')
-rw-r--r--src/main/java/org/openslx/util/vm/VboxConfig.java48
1 files changed, 28 insertions, 20 deletions
diff --git a/src/main/java/org/openslx/util/vm/VboxConfig.java b/src/main/java/org/openslx/util/vm/VboxConfig.java
index ee9cd25..6a44402 100644
--- a/src/main/java/org/openslx/util/vm/VboxConfig.java
+++ b/src/main/java/org/openslx/util/vm/VboxConfig.java
@@ -41,13 +41,13 @@ public class VboxConfig
private Document doc = null;
private String displayNameExpression = "/VirtualBox/Machine/@name";
- private String displayName;
+ private String displayName = new String();
private String osTypeExpression = "/VirtualBox/Machine/@OSType";
- private String osName = new String();;
+ private String osName = new String();
private String hddsExpression = "/VirtualBox/Machine/MediaRegistry/HardDisks/*";
- private ArrayList<HardDisk> hddsArray = new ArrayList<HardDisk>();;
+ private ArrayList<HardDisk> hddsArray = new ArrayList<HardDisk>();
// a black list of sorts of tags that need to be removed from the .vbox file
private static String[] blackList = { "ExtraData", "Adapter", "GuestProperties", "LPT", "StorageController", "FloppyImages", "DVDImages", "AttachedDevice" };
@@ -77,7 +77,6 @@ public class VboxConfig
LOGGER.warn( "Could not parse .Vbox", e );
throw new UnsupportedVirtualizerFormatException( "Could not create VBoxConfig!" );
}
- displayName = new String();
}
/**
@@ -119,6 +118,8 @@ public class VboxConfig
/**
* initialization function
+ * reads the doc, sets Machine name, os type, sets the hdds, adds placeholders, removes unwanted/
+ * unneeded nodes
*/
public void init()
{
@@ -150,13 +151,18 @@ public class VboxConfig
NodeList hdds = findANode( "HardDisk" );
for ( int i = 0; i < hdds.getLength(); i++ ) {
Element hdd = (Element)hdds.item( i );
- if ( hdd.getAttribute( "location" ).equals( "#some_fancy_HDD_place_holder" ) ) {
+ if ( hdd.getAttribute( "location" ).equals( "#OpenSLX_HDD_place_holder" ) ) {
return true;
}
}
return false;
}
+ /**
+ * Function finds and saves the name of the machine
+ *
+ * @throws XPathExpressionException
+ */
public void setMachineName() throws XPathExpressionException
{
String name = xPath.compile( displayNameExpression ).evaluate( this.doc );
@@ -165,6 +171,11 @@ public class VboxConfig
}
}
+ /**
+ * Function finds and saves the name of the os
+ *
+ * @throws XPathExpressionException
+ */
public void setOsType() throws XPathExpressionException
{
String os = xPath.compile( osTypeExpression ).evaluate( this.doc );
@@ -179,8 +190,6 @@ public class VboxConfig
Object result = hddsExpr.evaluate( this.doc, XPathConstants.NODESET );
// take all the hdd nodes
NodeList nodes = (NodeList)result;
-
- // TODO find all HardDisk under HardDisks, give them to the hdds
// foreach hdd in the hddnodes do:
for ( int i = 0; i < nodes.getLength(); i++ ) {
// have the node
@@ -191,24 +200,19 @@ public class VboxConfig
String fileName = hddElement.getAttribute( "location" );
// take the uuid
String uuid = hddElement.getAttribute( "uuid" );
-
- // do the loop the loop
// search in the xml object and give back the parent of the parent of the node that is called Image and has the given uuid
String pathToParent = givePathToStorageController( uuid );
XPathExpression attachedDevicesExpr = xPath.compile( pathToParent );
Object devicesResult = attachedDevicesExpr.evaluate( this.doc, XPathConstants.NODESET );
NodeList devicesNodes = (NodeList)devicesResult;
-
// TODO -- ehm...should only have 1 element...what do when there are more?
if ( devicesNodes.getLength() > 1 ) {
LOGGER.error( "There can not be more HDDs with the same UUID!" );
return;
}
-
Element deviceElement = (Element)devicesNodes.item( 0 );
String controllerDevice = deviceElement.getAttribute( "type" );
String bus = deviceElement.getAttribute( "name" );
-
DriveBusType busType = null;
if ( bus.equals( "IDE" ) ) {
busType = DriveBusType.IDE;
@@ -225,13 +229,13 @@ public class VboxConfig
public void addPlaceHolders()
{
// placeholder for the location of the virtual hdd
- changeAttribute( "HardDisk", "location", "#some_fancy_HDD_place_holder" );
+ changeAttribute( "HardDisk", "location", "#OpenSLX_HDD_place_holder" );
// placeholder for the memory
- changeAttribute( "Memory", "RAMSize", "#some_fancy_MEMORY_place_holder" );
+ changeAttribute( "Memory", "RAMSize", "#OpenSLX_MEMORY_place_holder" );
// placeholder for the CPU
- changeAttribute( "CPU", "count", "#some_fancy_CPU_place_holder" );
+ changeAttribute( "CPU", "count", "#OpenSLX_CPU_place_holder" );
// add placeholder for the uuid of the virtual harddrive.
// must be added on 2 positions...in the HardDisk tag and the attachedDevice tag
@@ -240,13 +244,13 @@ public class VboxConfig
for ( int i = 0; i < hdds.getLength(); i++ ) {
Element hdd = (Element)findANode( "HardDisk" ).item( i );
String uuid = hdd.getAttribute( "uuid" );
- hdd.setAttribute( "uuid", "#some_fancy_HDDUUID_" + i + "_placeholder" );
+ hdd.setAttribute( "uuid", "#OpenSLX_HDDUUID_" + i + "_placeholder" );
NodeList images = findANode( "Image" );
Element image;
for ( int j = 0; j < images.getLength(); j++ ) {
if ( ( (Element)images.item( j ) ).getAttribute( "uuid" ).equals( uuid ) ) {
image = (Element)images.item( j );
- image.setAttribute( "uuid", "#some_fancy_HDDUUID_" + i + "_placeholder" );
+ image.setAttribute( "uuid", "#OpenSLX_HDDUUID_" + i + "_placeholder" );
break;
}
}
@@ -405,7 +409,6 @@ public class VboxConfig
XPathExpression blackedExpr = xPath.compile( blackedExpression );
NodeList blackedNodes = (NodeList)blackedExpr.evaluate( this.doc, XPathConstants.NODESET );
- //LOGGER.debug( blackedNodes.getLength() );
for ( int i = 0; i < blackedNodes.getLength(); i++ ) {
// get the child node
Element child = (Element)blackedNodes.item( i );
@@ -413,9 +416,14 @@ public class VboxConfig
if ( child.getTagName().equals( "Adapter" ) && child.getAttribute( "enabled" ).equals( "true" ) ) {
// we need to remove the children of the active network adapter
// these are the mode of network connection and disabled modes...they go together -> see wiki
- if ( child.getChildNodes().item( 0 ).getNodeName().equals( "#text" ) && !child.getChildNodes().item( 1 ).getNodeName().equals( "#text" ) ) {
- removeNode( child.getChildNodes().item( 1 ) );
+ Node firstChild = child.getChildNodes().item( 0 );
+ Node secondChild = child.getChildNodes().item( 1 );
+ if ( firstChild != null && secondChild != null ) {
+ if ( firstChild.getNodeName().equals( "#text" ) && !secondChild.getNodeName().equals( "#text" ) ) {
+ removeNode( child.getChildNodes().item( 1 ) );
+ }
}
+ LOGGER.warn( "possible problem while removing formating node" );
continue;
}