summaryrefslogtreecommitdiffstats
path: root/src/main/java/org/openslx/util/vm/VboxConfig.java
diff options
context:
space:
mode:
authorJonathan Bauer2018-04-20 14:32:46 +0200
committerJonathan Bauer2018-04-20 14:32:46 +0200
commitd0bc412b23162e22a489adae75d22860672b4683 (patch)
tree18295f0b3800d09eb764280b8992a359baaac093 /src/main/java/org/openslx/util/vm/VboxConfig.java
parent[vbox] blacklist VideoCapture and RemoteDisplay (diff)
downloadmaster-sync-shared-d0bc412b23162e22a489adae75d22860672b4683.tar.gz
master-sync-shared-d0bc412b23162e22a489adae75d22860672b4683.tar.xz
master-sync-shared-d0bc412b23162e22a489adae75d22860672b4683.zip
[*] add support for machine snapshot detection
Diffstat (limited to 'src/main/java/org/openslx/util/vm/VboxConfig.java')
-rw-r--r--src/main/java/org/openslx/util/vm/VboxConfig.java43
1 files changed, 29 insertions, 14 deletions
diff --git a/src/main/java/org/openslx/util/vm/VboxConfig.java b/src/main/java/org/openslx/util/vm/VboxConfig.java
index bca9183..db82cc4 100644
--- a/src/main/java/org/openslx/util/vm/VboxConfig.java
+++ b/src/main/java/org/openslx/util/vm/VboxConfig.java
@@ -48,7 +48,7 @@ public class VboxConfig
private String hddsExpression = "/VirtualBox/Machine/MediaRegistry/HardDisks/*";
private ArrayList<HardDisk> hddsArray = new ArrayList<HardDisk>();
-
+ private boolean isMachineSnapshot = false;
// list of nodes to automatically remove when reading the vbox file
private static String[] blackList = { "SharedFolders", "HID", "USB", "ExtraData", "Adapter", "GuestProperties", "LPT", "StorageController", "FloppyImages", "DVDImages",
"AttachedDevice", "RemoteDisplay", "VideoCapture" };
@@ -147,6 +147,7 @@ public class VboxConfig
}
try {
setMachineName();
+ checkForMachineSnapshots();
ensureHardwareUuid();
setOsType();
if ( checkForPlaceholders() ) {
@@ -161,17 +162,24 @@ public class VboxConfig
}
}
+ private void checkForMachineSnapshots() throws XPathExpressionException {
+ // check if the vbox configuration file contains some machine snapshots.
+ // by looking at the existance of /VirtualBox/Machine/Snapshot
+ NodeList machineSnapshots = findNodes("/VirtualBox/Machine/Snapshot");
+ isMachineSnapshot = (machineSnapshots != null && machineSnapshots.getLength() > 0 );
+ }
+
private void ensureHardwareUuid() throws XPathExpressionException
{
- NodeList hwNodes = findNodes( "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
+
+ NodeList hwNodes = findNodes( "/VirtualBox/Machine/Hardware" );
+ int count = hwNodes.getLength();
if ( count == 1 ) {
Element hw = (Element)hwNodes.item( 0 );
String hwUuid = hw.getAttribute( "uuid" );
@@ -186,9 +194,8 @@ public class VboxConfig
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!" );
+ // HACK: hijack XPathExpressionException ...
+ throw new XPathExpressionException( "Zero or more '/VirtualBox/Machine/Hardware' node were found, should never happen!" );
}
}
@@ -330,17 +337,21 @@ public class VboxConfig
}
/**
- * Function used to find nodes in the document
- * Function returnes a NodeList of Nodes...not just a Node...even when the wanted Node is a
- * single
- * Node, you get a NodeList with just one element
+ * Search through the doc for nodes with the given name.
+ * If the given name starts with '/', assume a full XPath was
+ * given and do not do a full search
*
- * @param targetTag as String
+ * @param identifier
* @return nodes as NodeList
*/
- public NodeList findNodes( String targetTag )
+ public NodeList findNodes( String identifier )
{
- String path = ".//" + targetTag;
+ String path;
+ if ( identifier.startsWith( "/", 0 ) )
+ path = identifier;
+ else
+ path = ".//" + identifier;
+
XPathExpression expr;
NodeList nodes = null;
try {
@@ -617,4 +628,8 @@ public class VboxConfig
throw new RuntimeException( "Error converting to String", ex );
}
}
+
+ public boolean isMachineSnapshot() {
+ return isMachineSnapshot;
+ }
}