summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon Rettberg2023-05-12 16:56:37 +0200
committerSimon Rettberg2023-05-12 16:56:37 +0200
commit7ab25606e539ad7455699c6a4ca43e57dbe3f2d6 (patch)
treeba96cbffff317eda901e153d80cca65b13e322e4
parentvbox: Update testing, UUID replacement hack is not needed anymore (diff)
downloadmaster-sync-shared-7ab25606e539ad7455699c6a4ca43e57dbe3f2d6.tar.gz
master-sync-shared-7ab25606e539ad7455699c6a4ca43e57dbe3f2d6.tar.xz
master-sync-shared-7ab25606e539ad7455699c6a4ca43e57dbe3f2d6.zip
[vbox] Handle the version-dependent StorageControllers path everywhere
-rw-r--r--src/main/java/org/openslx/virtualization/configuration/VirtualizationConfigurationVirtualBox.java7
-rw-r--r--src/main/java/org/openslx/virtualization/configuration/VirtualizationConfigurationVirtualboxFileFormat.java25
2 files changed, 13 insertions, 19 deletions
diff --git a/src/main/java/org/openslx/virtualization/configuration/VirtualizationConfigurationVirtualBox.java b/src/main/java/org/openslx/virtualization/configuration/VirtualizationConfigurationVirtualBox.java
index 4566e92..ebfd918 100644
--- a/src/main/java/org/openslx/virtualization/configuration/VirtualizationConfigurationVirtualBox.java
+++ b/src/main/java/org/openslx/virtualization/configuration/VirtualizationConfigurationVirtualBox.java
@@ -146,7 +146,7 @@ public class VirtualizationConfigurationVirtualBox extends VirtualizationConfigu
// patching the new uuid in the vbox config file here
String vboxUUid = "{" + newhdduuid.toString() + "}";
config.changeAttribute( "/VirtualBox/Machine/MediaRegistry/HardDisks/HardDisk", "uuid", vboxUUid, MatchMode.FIRST_ONLY );
- config.changeAttribute( "/VirtualBox/Machine/StorageControllers/StorageController/AttachedDevice/Image", "uuid",
+ config.changeAttribute( config.storageControllersPath() + "/StorageController/AttachedDevice/Image", "uuid",
vboxUUid, MatchMode.FIRST_ONLY );
// the order of the UUID is BIG_ENDIAN but we need to change the order of the first 8 Bytes
@@ -238,10 +238,9 @@ public class VirtualizationConfigurationVirtualBox extends VirtualizationConfigu
public void addFloppy( int index, String image, boolean readOnly )
{
Element floppyController = null;
- NodeList matches = (NodeList)config
- .findNodes( "/VirtualBox/Machine/StorageControllers/StorageController[@name='Floppy']" );
+ NodeList matches = config.findNodes( config.storageControllersPath() + "/StorageController[@name='Floppy']" );
if ( matches == null || matches.getLength() == 0 ) {
- floppyController = (Element)config.addNewNode( "/VirtualBox/Machine/StorageControllers", "StorageController" );
+ floppyController = (Element)config.addNewNode( config.storageControllersPath(), "StorageController" );
if ( floppyController == null ) {
LOGGER.error( "Failed to add <Image> to floppy device." );
return;
diff --git a/src/main/java/org/openslx/virtualization/configuration/VirtualizationConfigurationVirtualboxFileFormat.java b/src/main/java/org/openslx/virtualization/configuration/VirtualizationConfigurationVirtualboxFileFormat.java
index 5446ddb..b5b3180 100644
--- a/src/main/java/org/openslx/virtualization/configuration/VirtualizationConfigurationVirtualboxFileFormat.java
+++ b/src/main/java/org/openslx/virtualization/configuration/VirtualizationConfigurationVirtualboxFileFormat.java
@@ -287,13 +287,7 @@ public class VirtualizationConfigurationVirtualboxFileFormat
private void removeUnusedHdds()
{
Set<String> existing = new HashSet<>();
- String path;
- if ( this.getVersion().isSmallerThan( Version.valueOf( "1.17" ) ) ) {
- path = "/VirtualBox/Machine/StorageControllers/StorageController/AttachedDevice/Image";
- } else {
- path = "/VirtualBox/Machine/Hardware/StorageControllers/StorageController/AttachedDevice/Image";
- }
- NodeList list = findNodes( path );
+ NodeList list = findNodes( storageControllersPath() + "/StorageController/AttachedDevice/Image" );
if ( list != null && list.getLength() != 0 ) {
for ( int i = 0; i < list.getLength(); ++i ) {
Node item = list.item( i );
@@ -323,6 +317,13 @@ public class VirtualizationConfigurationVirtualboxFileFormat
}
}
+ public String storageControllersPath()
+ {
+ if ( this.getVersion().isSmallerThan( Version.valueOf( "1.17" ) ) )
+ return "/VirtualBox/Machine/StorageControllers";
+ return "/VirtualBox/Machine/Hardware/StorageControllers";
+ }
+
/**
* Saves the machine's uuid as hardware uuid to prevent VMs from
* believing in a hardware change.
@@ -459,14 +460,8 @@ public class VirtualizationConfigurationVirtualboxFileFormat
*/
public void setHdds() throws XPathExpressionException
{
- final XPathExpression hddsExpr;
- if ( this.getVersion().isSmallerThan( Version.valueOf( "1.17" ) ) ) {
- hddsExpr = XmlHelper.compileXPath(
- "/VirtualBox/Machine/StorageControllers/StorageController/AttachedDevice[@type='HardDisk']/Image" );
- } else {
- hddsExpr = XmlHelper.compileXPath(
- "/VirtualBox/Machine/Hardware/StorageControllers/StorageController/AttachedDevice[@type='HardDisk']/Image" );
- }
+ final XPathExpression hddsExpr = XmlHelper.compileXPath( storageControllersPath()
+ + "/StorageController/AttachedDevice[@type='HardDisk']/Image" );
NodeList nodes = (NodeList)hddsExpr.evaluate( this.doc, XPathConstants.NODESET );
if ( nodes == null ) {