summaryrefslogtreecommitdiffstats
path: root/src/main/java/org/openslx/util/vm/DiskImage.java
diff options
context:
space:
mode:
authorManuel Bentele2021-01-29 12:25:44 +0100
committerManuel Bentele2021-01-29 12:25:44 +0100
commit706910e440527c22f176bcab0032c37c60357c25 (patch)
tree1173cdb610cb81bc17dccff3d2df4ba0ecd1c078 /src/main/java/org/openslx/util/vm/DiskImage.java
parentAdd implementation of Libvirt domain XML documents (diff)
downloadmaster-sync-shared-706910e440527c22f176bcab0032c37c60357c25.tar.gz
master-sync-shared-706910e440527c22f176bcab0032c37c60357c25.tar.xz
master-sync-shared-706910e440527c22f176bcab0032c37c60357c25.zip
Add support for QEMU VMs (based on Libvirt domain XML documents)
Diffstat (limited to 'src/main/java/org/openslx/util/vm/DiskImage.java')
-rw-r--r--src/main/java/org/openslx/util/vm/DiskImage.java35
1 files changed, 35 insertions, 0 deletions
diff --git a/src/main/java/org/openslx/util/vm/DiskImage.java b/src/main/java/org/openslx/util/vm/DiskImage.java
index 1602926..617fadd 100644
--- a/src/main/java/org/openslx/util/vm/DiskImage.java
+++ b/src/main/java/org/openslx/util/vm/DiskImage.java
@@ -5,6 +5,8 @@ import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.util.Arrays;
+import java.util.List;
+import java.util.function.Predicate;
import org.apache.log4j.Logger;
import org.openslx.bwlp.thrift.iface.Virtualizer;
@@ -318,7 +320,40 @@ public class DiskImage
}
throw new UnknownImageFormatException();
}
+
+ /**
+ * Creates new disk image and checks if image is supported by hypervisor's image formats.
+ *
+ * @param disk file to a disk storing the virtual machine content.
+ * @param supportedImageTypes list of supported image types of a hypervisor's image format.
+ * @throws FileNotFoundException cannot find virtual machine image file.
+ * @throws IOException cannot access the virtual machine image file.
+ * @throws UnknownImageFormatException virtual machine image file has an unknown image format.
+ */
+ public DiskImage( File disk, List<ImageFormat> supportedImageTypes )
+ throws FileNotFoundException, IOException, UnknownImageFormatException
+ {
+ this( disk );
+ if ( !this.isSupportedByHypervisor( supportedImageTypes ) ) {
+ throw new UnknownImageFormatException();
+ }
+ }
+
+ /**
+ * Checks if image format is supported by a list of supported hypervisor image formats.
+ *
+ * @param supportedImageTypes list of supported image types of a hypervisor.
+ * @return <code>true</code> if image type is supported by the hypervisor; otherwise
+ * <code>false</code>.
+ */
+ public boolean isSupportedByHypervisor( List<ImageFormat> supportedImageTypes )
+ {
+ Predicate<ImageFormat> matchDiskFormat = supportedImageType -> supportedImageType.toString()
+ .equalsIgnoreCase( this.getImageFormat().toString() );
+ return supportedImageTypes.stream().anyMatch( matchDiskFormat );
+ }
+
private int findNull( byte[] buffer )
{
for ( int i = 0; i < buffer.length; ++i ) {