summaryrefslogtreecommitdiffstats
path: root/src/main/java
diff options
context:
space:
mode:
authorJonathan Bauer2018-03-19 17:52:38 +0100
committerJonathan Bauer2018-03-19 17:52:38 +0100
commit33c43e31729533d086e4c83c7ee932e9ccfb4d25 (patch)
tree42ccc0192096d79d3f7626bb641430175f011e1d /src/main/java
parent[VBox] fixed bug where the audio adapter was not selected properly, found and... (diff)
downloadmaster-sync-shared-33c43e31729533d086e4c83c7ee932e9ccfb4d25.tar.gz
master-sync-shared-33c43e31729533d086e4c83c7ee932e9ccfb4d25.tar.xz
master-sync-shared-33c43e31729533d086e4c83c7ee932e9ccfb4d25.zip
[vbox] ensure <hardware/> has a uuid
to prevent windows from believing the vm is running on new hardware
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/org/openslx/util/vm/VboxConfig.java30
1 files changed, 30 insertions, 0 deletions
diff --git a/src/main/java/org/openslx/util/vm/VboxConfig.java b/src/main/java/org/openslx/util/vm/VboxConfig.java
index a244497..eab20cb 100644
--- a/src/main/java/org/openslx/util/vm/VboxConfig.java
+++ b/src/main/java/org/openslx/util/vm/VboxConfig.java
@@ -129,6 +129,7 @@ public class VboxConfig
}
try {
setMachineName();
+ ensureHardwareUuid();
setOsType();
if ( checkForPlaceholders() ) {
return;
@@ -142,6 +143,35 @@ public class VboxConfig
}
}
+ private void ensureHardwareUuid() throws XPathExpressionException {
+ NodeList hwNodes = findANode( "Hardware" );
+ int count = hwNodes.getLength();
+ // we will need the machine uuid, so get it
+ String machineUuid = xPath.compile( "/VirtualBox/Machine/@uuid" ).evaluate( this.doc );
+ if (machineUuid.isEmpty()) {
+ LOGGER.error("Machine UUID empty, should never happen!");
+ return;
+ }
+ // now check if we had a <Hardware/> node, which we always should
+ if (count == 1) {
+ Element hw = (Element) hwNodes.item(0);
+ String hwUuid = hw.getAttribute("uuid");
+ if (!hwUuid.isEmpty()) {
+ LOGGER.info("Found hardware uuid: " + hwUuid);
+ return;
+ } else {
+ if (!addAttributeToNode(hw, "uuid", machineUuid)) {
+ LOGGER.error("Failed to set machine UUID '" + machineUuid + "' as hardware UUID.");
+ return;
+ }
+ LOGGER.info("Saved machine UUID as hardware UUID.");
+ }
+ } else {
+ // zero or more than 1 <Hardware/> were found, fatal either way
+ // HACK: hijack XPathExpressionException ...
+ throw new XPathExpressionException("Zero or more than one <Hardware> node found, should never happen!");
+ }
+ }
/**
* Function checks if the placeholders are present
*