summaryrefslogtreecommitdiffstats
path: root/src
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
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')
-rw-r--r--src/main/java/org/openslx/util/vm/VboxConfig.java43
-rw-r--r--src/main/java/org/openslx/util/vm/VboxMetaData.java2
-rw-r--r--src/main/java/org/openslx/util/vm/VmMetaData.java7
-rw-r--r--src/main/java/org/openslx/util/vm/VmwareMetaData.java2
4 files changed, 39 insertions, 15 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;
+ }
}
diff --git a/src/main/java/org/openslx/util/vm/VboxMetaData.java b/src/main/java/org/openslx/util/vm/VboxMetaData.java
index 81ffc5b..f95a2c9 100644
--- a/src/main/java/org/openslx/util/vm/VboxMetaData.java
+++ b/src/main/java/org/openslx/util/vm/VboxMetaData.java
@@ -100,7 +100,7 @@ public class VboxMetaData extends VmMetaData<VBoxSoundCardMeta, VBoxDDAccelMeta,
this.config.init();
displayName = config.getDisplayName();
setOs( "virtualbox", config.getOsName() );
-
+ this.isMachineSnapshot = config.isMachineSnapshot();
for ( HardDisk hardDisk : config.getHdds() ) {
hdds.add( hardDisk );
}
diff --git a/src/main/java/org/openslx/util/vm/VmMetaData.java b/src/main/java/org/openslx/util/vm/VmMetaData.java
index c3bbb38..fe74897 100644
--- a/src/main/java/org/openslx/util/vm/VmMetaData.java
+++ b/src/main/java/org/openslx/util/vm/VmMetaData.java
@@ -130,6 +130,7 @@ public abstract class VmMetaData<T, U, V, W>
protected String displayName = null;
+ protected boolean isMachineSnapshot;
/*
* Getters for virtual hardware
*/
@@ -185,6 +186,12 @@ public abstract class VmMetaData<T, U, V, W>
return displayName;
}
+ /*
+ * Getter for isMachineSnapshot
+ */
+ public boolean isMachineSnapshot() {
+ return isMachineSnapshot;
+ }
/**
* This method should return a minimal representation of the input meta data.
* The representation is platform dependent, and should be stripped of all
diff --git a/src/main/java/org/openslx/util/vm/VmwareMetaData.java b/src/main/java/org/openslx/util/vm/VmwareMetaData.java
index c8e4716..f1efb8c 100644
--- a/src/main/java/org/openslx/util/vm/VmwareMetaData.java
+++ b/src/main/java/org/openslx/util/vm/VmwareMetaData.java
@@ -144,6 +144,8 @@ public class VmwareMetaData extends VmMetaData<VmWareSoundCardMeta, VmWareDDAcce
hdds.add( new HardDisk( controller.virtualDev, bus, device.filename ) );
}
}
+ // TODO check if this machine is in a paused/suspended state
+ this.isMachineSnapshot = false;
// Add HDD to cleaned vmx
if ( !hdds.isEmpty() ) {