diff options
author | Victor Mocanu | 2017-05-22 12:15:47 +0200 |
---|---|---|
committer | Victor Mocanu | 2017-05-22 12:15:47 +0200 |
commit | 908be91fa0ecca4ef0904bce729b3aaf184d2c4b (patch) | |
tree | 2ac20675e4d1c01ba4f7c7c5f789a3cf13e111c7 /src/main | |
parent | Add Feature support for dozmod; add allowLoginByDefault option (diff) | |
download | master-sync-shared-908be91fa0ecca4ef0904bce729b3aaf184d2c4b.tar.gz master-sync-shared-908be91fa0ecca4ef0904bce729b3aaf184d2c4b.tar.xz master-sync-shared-908be91fa0ecca4ef0904bce729b3aaf184d2c4b.zip |
[VBOX] restructured generic VmMetaData for comming VBox support
Diffstat (limited to 'src/main')
6 files changed, 113 insertions, 10 deletions
diff --git a/src/main/java/org/openslx/util/vm/DiskImage.java b/src/main/java/org/openslx/util/vm/DiskImage.java index 80eec2a..5f9756f 100644 --- a/src/main/java/org/openslx/util/vm/DiskImage.java +++ b/src/main/java/org/openslx/util/vm/DiskImage.java @@ -54,7 +54,7 @@ public class DiskImage public final int hwVersion; public DiskImage( File disk ) throws FileNotFoundException, IOException, - UnknownImageFormatException + UnknownImageFormatException, UnsupportedVirtualizerFormatException { // For now we only support VMDK... try ( RandomAccessFile file = new RandomAccessFile( disk, "r" ) ) { diff --git a/src/main/java/org/openslx/util/vm/UnsupportedVirtualizerFormatException.java b/src/main/java/org/openslx/util/vm/UnsupportedVirtualizerFormatException.java new file mode 100644 index 0000000..8327e9e --- /dev/null +++ b/src/main/java/org/openslx/util/vm/UnsupportedVirtualizerFormatException.java @@ -0,0 +1,9 @@ +package org.openslx.util.vm; + +@SuppressWarnings( "serial" ) +public class UnsupportedVirtualizerFormatException extends Exception +{ + public UnsupportedVirtualizerFormatException(String message) { + super(message); + } +} diff --git a/src/main/java/org/openslx/util/vm/VboxMetaData.java b/src/main/java/org/openslx/util/vm/VboxMetaData.java new file mode 100644 index 0000000..5fa5cba --- /dev/null +++ b/src/main/java/org/openslx/util/vm/VboxMetaData.java @@ -0,0 +1,45 @@ +package org.openslx.util.vm; + +import java.io.File; +import java.util.List; + +import org.openslx.bwlp.thrift.iface.OperatingSystem; +import org.openslx.bwlp.thrift.iface.Virtualizer; + +public class VboxMetaData extends VmMetaData +{ + + public VboxMetaData( List<OperatingSystem> osList, File file ) throws UnsupportedVirtualizerFormatException + { + super( osList ); + // TODO Auto-generated constructor stub + } + + @Override + public Virtualizer getVirtualizer() + { + // TODO Auto-generated method stub + return null; + } + + @Override + public void enableUsb( boolean enabled ) + { + // TODO Auto-generated method stub + + } + + @Override + public void applySettingsForLocalEdit() + { + // TODO Auto-generated method stub + + } + @Override + public byte[] getFilteredDefinitionArray() + { + // TODO Auto-generated method stub + return null; + } + +} diff --git a/src/main/java/org/openslx/util/vm/VmMetaData.java b/src/main/java/org/openslx/util/vm/VmMetaData.java index 75e559a..7530039 100644 --- a/src/main/java/org/openslx/util/vm/VmMetaData.java +++ b/src/main/java/org/openslx/util/vm/VmMetaData.java @@ -1,11 +1,15 @@ package org.openslx.util.vm; +import java.io.File; +import java.io.IOException; import java.nio.ByteBuffer; import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.Map.Entry; +import javax.swing.JOptionPane; + import org.openslx.bwlp.thrift.iface.OperatingSystem; import org.openslx.bwlp.thrift.iface.Virtualizer; @@ -15,7 +19,6 @@ import org.openslx.bwlp.thrift.iface.Virtualizer; */ public abstract class VmMetaData { - /* * Helper types */ @@ -140,5 +143,38 @@ public abstract class VmMetaData * for vmware, this disables automatic DPI scaling of the guest. */ public abstract void applySettingsForLocalEdit(); - + + + public static VmMetaData getInstance(List<OperatingSystem> osList, File file) throws IOException { + + // throw new IOException(); + + // TODO file object check nach "Pattern" + // TODO make it genericsher + + // unknown file > try to init vmware, vbox, ... until one works + + + + + + String fileName = file.getName(); + + VmMetaData meta = null; + try { + meta = new VmwareMetaData(osList, file); + } catch ( UnsupportedVirtualizerFormatException e ) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + if (meta != null) { + return meta; + } + /*try { + meta = new VboxMetaData(osList, file); + } catch ( UnsupportedVirtualizerFormatException e ) { + + }*/ + return null; + } } diff --git a/src/main/java/org/openslx/util/vm/VmwareConfig.java b/src/main/java/org/openslx/util/vm/VmwareConfig.java index c0e30f6..f425b23 100644 --- a/src/main/java/org/openslx/util/vm/VmwareConfig.java +++ b/src/main/java/org/openslx/util/vm/VmwareConfig.java @@ -1,7 +1,9 @@ package org.openslx.util.vm; +import java.awt.RenderingHints.Key; import java.io.BufferedReader; import java.io.ByteArrayInputStream; +import java.io.Console; import java.io.File; import java.io.FileInputStream; import java.io.IOException; @@ -31,7 +33,7 @@ public class VmwareConfig // (void) } - public VmwareConfig( File file ) throws IOException + public VmwareConfig( File file ) throws IOException, UnsupportedVirtualizerFormatException { int todo = (int)Math.min( 100000, file.length() ); int offset = 0; @@ -53,7 +55,7 @@ public class VmwareConfig } - public VmwareConfig( InputStream is ) throws IOException + public VmwareConfig( InputStream is ) throws IOException, UnsupportedVirtualizerFormatException { int todo = Math.max( 4000, Math.min( 100000, is.available() ) ); int offset = 0; @@ -68,22 +70,33 @@ public class VmwareConfig init( data, offset ); } - public VmwareConfig( byte[] vmxContent, int length ) + public VmwareConfig( byte[] vmxContent, int length ) throws UnsupportedVirtualizerFormatException { init( vmxContent, length ); } - private void init( byte[] vmxContent, int length ) + // function is used for both .vmx and .vmdk files + private void init( byte[] vmxContent, int length) throws UnsupportedVirtualizerFormatException { try { + boolean isValid = false; BufferedReader reader = getVmxReader( vmxContent, length ); String line; while ( ( line = reader.readLine() ) != null ) { KeyValuePair entry = parse( line ); + + if ( entry != null ) { - set( entry.key, unescape( entry.value ) ); + // TODO ask Simon which key is best for the check + if ( entry.key.equals("virtualHW.version") || entry.key.equals("ddb.virtualHWVersion")) { + isValid = true; + } + set( entry.key, unescape( entry.value ) ); } } + if (!isValid) { + throw new UnsupportedVirtualizerFormatException("not Vmware image format"); + } } catch ( IOException e ) { LOGGER.warn( "Exception when loading vmx from byte array (how!?)", e ); } diff --git a/src/main/java/org/openslx/util/vm/VmwareMetaData.java b/src/main/java/org/openslx/util/vm/VmwareMetaData.java index 8b4fa0f..2697fc1 100644 --- a/src/main/java/org/openslx/util/vm/VmwareMetaData.java +++ b/src/main/java/org/openslx/util/vm/VmwareMetaData.java @@ -42,14 +42,14 @@ public class VmwareMetaData extends VmMetaData private final Map<String, Controller> disks = new HashMap<>(); - public VmwareMetaData( List<OperatingSystem> osList, File file ) throws IOException + public VmwareMetaData( List<OperatingSystem> osList, File file ) throws IOException, UnsupportedVirtualizerFormatException { super( osList ); this.config = new VmwareConfig( file ); init(); } - public VmwareMetaData( List<OperatingSystem> osList, byte[] vmxContent, int length ) + public VmwareMetaData( List<OperatingSystem> osList, byte[] vmxContent, int length ) throws UnsupportedVirtualizerFormatException { super( osList ); this.config = new VmwareConfig( vmxContent, length ); // still unfiltered |