summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJonathan Bauer2019-02-28 11:09:00 +0100
committerJonathan Bauer2019-02-28 11:09:00 +0100
commit50325c96681b1b23d457aed49bac594dcd51f37f (patch)
tree35fbaa0dc6f09f884aa4d6b597a694a75f30b400
parentAdd predefined firewall rulesets (diff)
downloadmaster-sync-shared-50325c96681b1b23d457aed49bac594dcd51f37f.tar.gz
master-sync-shared-50325c96681b1b23d457aed49bac594dcd51f37f.tar.xz
master-sync-shared-50325c96681b1b23d457aed49bac594dcd51f37f.zip
[vbox] fix bad detection of multiple hard drives
-rw-r--r--src/main/java/org/openslx/util/vm/VboxConfig.java43
1 files changed, 31 insertions, 12 deletions
diff --git a/src/main/java/org/openslx/util/vm/VboxConfig.java b/src/main/java/org/openslx/util/vm/VboxConfig.java
index fe85638..1eee0ed 100644
--- a/src/main/java/org/openslx/util/vm/VboxConfig.java
+++ b/src/main/java/org/openslx/util/vm/VboxConfig.java
@@ -306,24 +306,42 @@ public class VboxConfig
}
/**
- * Search disk drives within the DOM using this class
+ * Search for attached hard drives and determine their controller and their path.
*
* @throws XPathExpressionException
*/
public void setHdds() throws XPathExpressionException
{
- XPathExpression hddsExpr = XmlHelper.XPath.compile( "/VirtualBox/Machine/MediaRegistry/HardDisks/*" );
+ XPathExpression hddsExpr = XmlHelper.XPath.compile( "/VirtualBox/Machine/StorageControllers/StorageController/AttachedDevice[@type='HardDisk']/Image" );
NodeList nodes = (NodeList)hddsExpr.evaluate( this.doc, XPathConstants.NODESET );
+ if ( nodes == null ) {
+ LOGGER.error( "Failed to find attached hard drives." );
+ return;
+ }
for ( int i = 0; i < nodes.getLength(); i++ ) {
Element hddElement = (Element)nodes.item( i );
if ( hddElement == null )
continue;
- String fileName = hddElement.getAttribute( "location" );
- String type = hddElement.getAttribute( "type" );
+ String uuid = hddElement.getAttribute( "uuid" );
+ if ( uuid.isEmpty() )
+ continue;
+ // got uuid, check if it was registered
+ XPathExpression hddsRegistered = XmlHelper.XPath.compile( "/VirtualBox/Machine/MediaRegistry/HardDisks/HardDisk[@uuid='" + uuid + "']" );
+ NodeList hddsRegisteredNodes = (NodeList)hddsRegistered.evaluate( this.doc, XPathConstants.NODESET );
+ if ( hddsRegisteredNodes == null || hddsRegisteredNodes.getLength() != 1 ) {
+ LOGGER.error( "Found hard disk with uuid '" + uuid + "' which does not appear (unique) in the Media Registry. Skipping." );
+ continue;
+ }
+ Element hddElementReg = (Element)hddsRegisteredNodes.item( 0 );
+ if ( hddElementReg == null )
+ continue;
+ String fileName = hddElementReg.getAttribute( "location" );
+ String type = hddElementReg.getAttribute( "type" );
if ( !type.equals( "Normal" ) && !type.equals( "Writethrough" ) ) {
LOGGER.warn( "Type of the disk file is neither 'Normal' nor 'Writethrough' but: " + type );
LOGGER.warn( "This makes the image not directly modificable, which might lead to problems when editing it locally." );
}
+ // search if it is also attached to a controller
Node hddDevice = hddElement.getParentNode();
if ( hddDevice == null ) {
LOGGER.error( "HDD node had a null parent, shouldn't happen" );
@@ -334,18 +352,19 @@ public class VboxConfig
LOGGER.error( "HDD node had a null parent, shouldn't happen" );
continue;
}
- String controllerDevice = hddController.getAttribute( "type" );
- String bus = hddController.getAttribute( "name" );
+ String controllerMode = hddController.getAttribute( "type" );
+ String controllerType = hddController.getAttribute( "name" );
DriveBusType busType = null;
- if ( bus.equals( "IDE" ) ) {
+ if ( controllerType.equals( "IDE" ) ) {
busType = DriveBusType.IDE;
- } else if ( bus.equals( "SCSI" ) ) {
+ } else if ( controllerType.equals( "SCSI" ) ) {
busType = DriveBusType.SCSI;
- } else if ( bus.equals( "SATA" ) ) {
+ } else if ( controllerType.equals( "SATA" ) ) {
busType = DriveBusType.SATA;
- }
- // add them together
- hddsArray.add( new HardDisk( controllerDevice, busType, fileName ) );
+ } else
+ continue;
+ LOGGER.info( "Adding hard disk with controller: " + busType + " (" + controllerMode + ") from file '" + fileName + "'." );
+ hddsArray.add( new HardDisk( controllerMode, busType, fileName ) );
}
}