From a9b730ee13d921616d4f9d6e3420bc7453c654f3 Mon Sep 17 00:00:00 2001 From: Victor Mocanu Date: Thu, 26 Oct 2017 12:58:30 +0200 Subject: [VBox] work in progress for the DropDownSelectWindow... everything was vmx specific, made it more generic --- .../java/org/openslx/util/vm/VboxMetaData.java | 113 +++++++++- src/main/java/org/openslx/util/vm/VmMetaData.java | 123 ++++++++++- .../java/org/openslx/util/vm/VmwareMetaData.java | 234 +++++++++++---------- 3 files changed, 352 insertions(+), 118 deletions(-) diff --git a/src/main/java/org/openslx/util/vm/VboxMetaData.java b/src/main/java/org/openslx/util/vm/VboxMetaData.java index f504c70..fe3f31c 100644 --- a/src/main/java/org/openslx/util/vm/VboxMetaData.java +++ b/src/main/java/org/openslx/util/vm/VboxMetaData.java @@ -19,7 +19,49 @@ import org.apache.log4j.Logger; import org.openslx.bwlp.thrift.iface.OperatingSystem; import org.openslx.bwlp.thrift.iface.Virtualizer; -public class VboxMetaData extends VmMetaData +class VBoxSoundCardMeta +{ + public final boolean isPresent; + public final String value; + + public VBoxSoundCardMeta( boolean present, String val ) + { + isPresent = present; + value = val; + } +} + +class VBoxDDAccelMeta +{ + public final boolean isPresent; + + public VBoxDDAccelMeta( boolean present ) + { + isPresent = present; + } +} + +class VBoxHWVersionMeta +{ + public final int version; + + public VBoxHWVersionMeta( int vers ) + { + version = vers; + } +} + +class VBoxEthernetDevTypeMeta +{ + public final String value; + + public VBoxEthernetDevTypeMeta( String val ) + { + value = val; + } +} + +public class VboxMetaData extends VmMetaData { private static final Logger LOGGER = Logger.getLogger( VboxMetaData.class ); @@ -28,8 +70,7 @@ public class VboxMetaData extends VmMetaData private final VboxConfig config; - public VboxMetaData( List osList, File file ) - throws IOException, UnsupportedVirtualizerFormatException + public VboxMetaData( List osList, File file ) throws IOException, UnsupportedVirtualizerFormatException { super( osList ); @@ -37,8 +78,7 @@ public class VboxMetaData extends VmMetaData init(); } - public VboxMetaData( List osList, byte[] vmContent, int length ) - throws IOException, UnsupportedVirtualizerFormatException + public VboxMetaData( List osList, byte[] vmContent, int length ) throws IOException, UnsupportedVirtualizerFormatException { super( osList ); @@ -221,4 +261,67 @@ public class VboxMetaData extends VmMetaData config.changeAttribute( "CPU", "count", "1" ); return true; } + + @Override + public void setSoundCard( org.openslx.util.vm.VmMetaData.SoundCardType type ) + { + // TODO Auto-generated method stub + + } + + @Override + public org.openslx.util.vm.VmMetaData.SoundCardType getSoundCard() + { + // TODO Auto-generated method stub + return null; + } + + @Override + public void setDDAcceleration( org.openslx.util.vm.VmMetaData.DDAcceleration type ) + { + // TODO Auto-generated method stub + + } + + @Override + public org.openslx.util.vm.VmMetaData.DDAcceleration getDDAcceleration() + { + // TODO Auto-generated method stub + return null; + } + + @Override + public void setHWVersion( HWVersion type ) + { + // TODO Auto-generated method stub + + } + + @Override + public HWVersion getHWVersion() + { + // TODO Auto-generated method stub + return null; + } + + @Override + public void setEthernetDevType( int cardIndex, EthernetDevType type ) + { + // TODO Auto-generated method stub + + } + + @Override + public EthernetDevType getEthernetDevType( int cardIndex ) + { + // TODO Auto-generated method stub + return null; + } + + @Override + public byte[] getDefinitionArray() + { + // 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 a32da4e..1130f9b 100644 --- a/src/main/java/org/openslx/util/vm/VmMetaData.java +++ b/src/main/java/org/openslx/util/vm/VmMetaData.java @@ -5,7 +5,9 @@ import java.io.IOException; import java.nio.ByteBuffer; import java.util.ArrayList; import java.util.Collections; +import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.Map.Entry; import org.apache.log4j.Logger; @@ -16,16 +18,92 @@ import org.openslx.bwlp.thrift.iface.Virtualizer; * Describes a configured virtual machine. This class is parsed from a machine * description, like a *.vmx for VMware machines. */ -public abstract class VmMetaData +public abstract class VmMetaData { private static final Logger LOGGER = Logger.getLogger( VmMetaData.class ); + /* * Helper types */ + protected Map soundCards = new HashMap<>(); + protected Map ddacc = new HashMap<>(); + protected Map hwversion = new HashMap<>(); + protected Map networkCards = new HashMap<>(); + + public static enum SoundCardType + { + NONE( "None" ), + DEFAULT( "(default)" ), + SOUND_BLASTER( "Sound Blaster 16" ), + ES( "ES 1371" ), + HD_AUDIO( "Intel Integrated HD Audio" ); + + public final String displayName; + + private SoundCardType( String dName ) + { + this.displayName = dName; + } + } + + public static enum DDAcceleration + { + OFF( "Off" ), + ON( "On" ); + + public final String displayName; + + private DDAcceleration( String dName ) + { + this.displayName = dName; + } + } + + // Virtual hardware version + public static enum HWVersion + { + NONE( "(invalid)" ), + THREE( " 3 (Workstation 4/5, Player 1)" ), + FOUR( " 4 (Workstation 4/5, Player 1/2, Fusion 1)" ), + SIX( " 6 (Workstation 6)" ), + SEVEN( " 7 (Workstation 6.5/7, Player 3, Fusion 2/3)" ), + EIGHT( " 8 (Workstation 8, Player/Fusion 4)" ), + NINE( " 9 (Workstation 9, Player/Fusion 5)" ), + TEN( "10 (Workstation 10, Player/Fusion 6)" ), + ELEVEN( "11 (Workstation 11, Player/Fusion 7)" ), + TWELVE( "12 (Workstation/Player 12, Fusion 8)" ); + + public final String displayName; + + private HWVersion( String dName ) + { + this.displayName = dName; + } + } + + // Virtual network adapter + public static enum EthernetDevType + { + AUTO( "(default)" ), + PCNET32( "AMD PCnet32" ), + E1000( "Intel E1000 (PCI)" ), + E1000E( "Intel E1000e (PCI-Express)" ), + VMXNET( "VMXnet" ), + VMXNET3( "VMXnet 3" ); + + public final String displayName; + + private EthernetDevType( String dName ) + { + this.displayName = dName; + } + } public static enum DriveBusType { - SCSI, IDE, SATA; + SCSI, + IDE, + SATA; } public static class HardDisk @@ -53,9 +131,28 @@ public abstract class VmMetaData private OperatingSystem os = null; protected String displayName = null; + /* * Guettas */ + public List getSupportedSoundCards() + { + return new ArrayList( soundCards.keySet() ); + } + + public List getSupportedDDAccs() + { + return new ArrayList( ddacc.keySet() ); + } + + public List getSupportedHWVersions() + { + return new ArrayList( hwversion.keySet() ); + } + + public List getSupportedEthernetDevices() { + return new ArrayList( networkCards.keySet() ); + } /** * Get operating system of this VM. @@ -164,8 +261,7 @@ public abstract class VmMetaData } // meta object needed when reading from configarray - public static VmMetaData getInstance( List osList, byte[] vmContent, int length ) - throws IOException + public static VmMetaData getInstance( List osList, byte[] vmContent, int length ) throws IOException { try { return new VmwareMetaData( osList, vmContent, length ); @@ -199,4 +295,23 @@ public abstract class VmMetaData public abstract boolean addCpuCoreCount( int nrOfCores ); + public abstract void setSoundCard( SoundCardType type ); + + public abstract SoundCardType getSoundCard(); + + + public abstract void setDDAcceleration( DDAcceleration type ); + + public abstract DDAcceleration getDDAcceleration(); + + public abstract void setHWVersion( HWVersion type ); + + public abstract HWVersion getHWVersion(); + // TODO export to VmMetaData like SoundCardType + public abstract void setEthernetDevType( int cardIndex, EthernetDevType type ); + + public abstract EthernetDevType getEthernetDevType( int cardIndex ); + + public abstract byte[] getDefinitionArray(); + } diff --git a/src/main/java/org/openslx/util/vm/VmwareMetaData.java b/src/main/java/org/openslx/util/vm/VmwareMetaData.java index 379bbd7..f2c6a80 100644 --- a/src/main/java/org/openslx/util/vm/VmwareMetaData.java +++ b/src/main/java/org/openslx/util/vm/VmwareMetaData.java @@ -16,15 +16,56 @@ import org.openslx.bwlp.thrift.iface.Virtualizer; import org.openslx.util.Util; import org.openslx.util.vm.VmwareConfig.ConfigEntry; -public class VmwareMetaData extends VmMetaData +class VmWareSoundCardMeta +{ + public final boolean isPresent; + public final String value; + + public VmWareSoundCardMeta( boolean present, String val ) + { + isPresent = present; + value = val; + } +} + +class VmWareDDAccelMeta +{ + public final boolean isPresent; + + public VmWareDDAccelMeta( boolean present ) + { + isPresent = present; + } +} + +class VmWareHWVersionMeta +{ + public final int version; + + public VmWareHWVersionMeta( int vers ) + { + version = vers; + } +} + +class VmWareEthernetDevTypeMeta +{ + public final String value; + + public VmWareEthernetDevTypeMeta( String val ) + { + value = val; + } +} + +public class VmwareMetaData extends VmMetaData { private static final Logger LOGGER = Logger.getLogger( VmwareMetaData.class ); private static final Virtualizer virtualizer = new Virtualizer( "vmware", "VMware" ); - private static final Pattern hddKey = Pattern.compile( "^(ide\\d|scsi\\d|sata\\d):?(\\d)?\\.(.*)", - Pattern.CASE_INSENSITIVE ); + private static final Pattern hddKey = Pattern.compile( "^(ide\\d|scsi\\d|sata\\d):?(\\d)?\\.(.*)", Pattern.CASE_INSENSITIVE ); // Lowercase list of allowed settings for upload (as regex) private static final Pattern[] whitelist; @@ -33,9 +74,8 @@ public class VmwareMetaData extends VmMetaData // Init static members static { - String[] list = { "^guestos", "^uuid\\.bios", "^config\\.version", "^ehci\\.", "^mks\\.enable3d", - "^virtualhw\\.", "^sound\\.", "\\.pcislotnumber$", "^pcibridge", "\\.virtualdev$", "^tools\\.syncTime$", - "^time\\.synchronize", "^bios\\.bootDelay", "^rtc\\.", "^xhci\\." }; + String[] list = { "^guestos", "^uuid\\.bios", "^config\\.version", "^ehci\\.", "^mks\\.enable3d", "^virtualhw\\.", "^sound\\.", "\\.pcislotnumber$", "^pcibridge", + "\\.virtualdev$", "^tools\\.syncTime$", "^time\\.synchronize", "^bios\\.bootDelay", "^rtc\\.", "^xhci\\." }; whitelist = new Pattern[ list.length ]; for ( int i = 0; i < list.length; ++i ) { whitelist[i] = Pattern.compile( list[i].toLowerCase() ); @@ -44,16 +84,14 @@ public class VmwareMetaData extends VmMetaData private final Map disks = new HashMap<>(); - public VmwareMetaData( List osList, File file ) - throws IOException, UnsupportedVirtualizerFormatException + public VmwareMetaData( List osList, File file ) throws IOException, UnsupportedVirtualizerFormatException { super( osList ); this.config = new VmwareConfig( file ); init(); } - public VmwareMetaData( List osList, byte[] vmxContent, int length ) - throws UnsupportedVirtualizerFormatException + public VmwareMetaData( List osList, byte[] vmxContent, int length ) throws UnsupportedVirtualizerFormatException { super( osList ); this.config = new VmwareConfig( vmxContent, length ); // still unfiltered @@ -62,6 +100,8 @@ public class VmwareMetaData extends VmMetaData private void init() { + populateTheMaps(); + for ( Entry entry : config.entrySet() ) { handleLoadEntry( entry ); } @@ -411,7 +451,9 @@ public class VmwareMetaData extends VmMetaData public static enum EthernetType { - NAT( "vmnet1" ), BRIDGED( "vmnet0" ), HOST_ONLY( "vmnet2" ); + NAT( "vmnet1" ), + BRIDGED( "vmnet0" ), + HOST_ONLY( "vmnet2" ); public final String vmnet; @@ -439,138 +481,76 @@ public class VmwareMetaData extends VmMetaData return config.get( key ); } - // SOUND - public static enum SoundCardType + public void setSoundCard( VmMetaData.SoundCardType type ) { - NONE( false, null, "None" ), DEFAULT( true, null, "(default)" ), SOUND_BLASTER( true, "sb16", - "Sound Blaster 16" ), ES( true, "es1371", - "ES 1371" ), HD_AUDIO( true, "hdaudio", "Intel Integrated HD Audio" ); - - public final boolean isPresent; - public final String value; - public final String displayName; - - private SoundCardType( boolean present, String value, String dName ) - { - this.isPresent = present; - this.value = value; - this.displayName = dName; - } - } - - public void setSoundCard( SoundCardType type ) - { - addFiltered( "sound.present", vmBoolean( type.isPresent ) ); - if ( type.value != null ) { - addFiltered( "sound.virtualDev", type.value ); + VmWareSoundCardMeta soundCardMeta = soundCards.get( type ); + addFiltered( "sound.present", vmBoolean( soundCardMeta.isPresent ) ); + if ( soundCardMeta.value != null ) { + addFiltered( "sound.virtualDev", soundCardMeta.value ); } else { config.remove( "sound.virtualDev" ); } } - public SoundCardType getSoundCard() + public VmMetaData.SoundCardType getSoundCard() { if ( !isSetAndTrue( "sound.present" ) || !isSetAndTrue( "sound.autodetect" ) ) { - return SoundCardType.NONE; + return VmMetaData.SoundCardType.NONE; } String current = config.get( "sound.virtualDev" ); if ( current != null ) { - for ( SoundCardType type : SoundCardType.values() ) { - if ( current.equals( type.value ) ) { - return type; + VmWareSoundCardMeta soundCardMeta = null; + for ( VmMetaData.SoundCardType type : VmMetaData.SoundCardType.values() ) { + soundCardMeta = soundCards.get( type ); + if ( soundCardMeta != null ) { + if ( current.equals( soundCardMeta.value ) ) { + return type; + } } } } - return SoundCardType.DEFAULT; - } - - // 3DAcceleration - public static enum DDAcceleration - { - OFF( false, "Off" ), ON( true, "On" ); - - public final boolean isPresent; - public final String displayName; - - private DDAcceleration( boolean present, String dName ) - { - this.isPresent = present; - this.displayName = dName; - } + return VmMetaData.SoundCardType.DEFAULT; } - public void setDDAcceleration( DDAcceleration type ) + public void setDDAcceleration( VmMetaData.DDAcceleration type ) { - addFiltered( "mks.enable3d", vmBoolean( type.isPresent ) ); + VmWareDDAccelMeta ddaMeta = ddacc.get( type ); + addFiltered( "mks.enable3d", vmBoolean( ddaMeta.isPresent ) ); } - public DDAcceleration getDDAcceleration() + public VmMetaData.DDAcceleration getDDAcceleration() { if ( isSetAndTrue( "mks.enable3d" ) ) { - return DDAcceleration.ON; + return VmMetaData.DDAcceleration.ON; } else { - return DDAcceleration.OFF; - } - } - - // Virtual hardware version - public static enum HWVersion - { - NONE( 0, "(invalid)" ), THREE( 3, " 3 (Workstation 4/5, Player 1)" ), FOUR( 4, - " 4 (Workstation 4/5, Player 1/2, Fusion 1)" ), SIX( 6, " 6 (Workstation 6)" ), SEVEN( 7, - " 7 (Workstation 6.5/7, Player 3, Fusion 2/3)" ), EIGHT( 8, - " 8 (Workstation 8, Player/Fusion 4)" ), NINE( 9, - " 9 (Workstation 9, Player/Fusion 5)" ), TEN( 10, - "10 (Workstation 10, Player/Fusion 6)" ), ELEVEN( 11, - "11 (Workstation 11, Player/Fusion 7)" ), TWELVE( 12, - "12 (Workstation/Player 12, Fusion 8)" ); - - public final int version; - public final String displayName; - - private HWVersion( int vers, String dName ) - { - this.version = vers; - this.displayName = dName; + return VmMetaData.DDAcceleration.OFF; } } - public void setHWVersion( HWVersion type ) + public void setHWVersion( VmMetaData.HWVersion type ) { - addFiltered( "virtualHW.version", vmInteger( type.version ) ); + VmWareHWVersionMeta hwVersionMeta = hwversion.get( type ); + addFiltered( "virtualHW.version", vmInteger( hwVersionMeta.version ) ); } - public HWVersion getHWVersion() + public VmMetaData.HWVersion getHWVersion() { int currentValue = Util.parseInt( config.get( "virtualHW.version" ), -1 ); - for ( HWVersion ver : HWVersion.values() ) { - if ( currentValue == ver.version ) { + VmWareHWVersionMeta hwVersionMeta = null; + for ( VmMetaData.HWVersion ver : VmMetaData.HWVersion.values() ) { + hwVersionMeta = hwversion.get( ver ); + if ( currentValue == hwVersionMeta.version ) { return ver; } } return HWVersion.NONE; } - // Virtual network adapter - public static enum EthernetDevType - { - AUTO( null, "(default)" ), PCNET32( "vlance", "AMD PCnet32" ), E1000( "e1000", "Intel E1000 (PCI)" ), E1000E( "e1000e", - "Intel E1000e (PCI-Express)" ), VMXNET( "vmxnet", "VMXnet" ), VMXNET3( "vmxnet3", "VMXnet 3" ); - - public final String value; - public final String displayName; - - private EthernetDevType( String value, String dName ) - { - this.value = value; - this.displayName = dName; - } - } - - public void setEthernetDevType( int cardIndex, EthernetDevType type ) + public void setEthernetDevType( int cardIndex, VmMetaData.EthernetDevType type ) { - if ( type.value != null ) { - addFiltered( "ethernet" + cardIndex + ".virtualDev", type.value ); + VmWareEthernetDevTypeMeta ethernetDevTypeMeta = networkCards.get( type ); + if ( ethernetDevTypeMeta.value != null ) { + addFiltered( "ethernet" + cardIndex + ".virtualDev", ethernetDevTypeMeta.value ); } else { config.remove( "ethernet" + cardIndex + ".virtualDev" ); } @@ -580,9 +560,10 @@ public class VmwareMetaData extends VmMetaData { String temp = config.get( "ethernet" + cardIndex + ".virtualDev" ); if ( temp != null ) { - - for ( EthernetDevType type : EthernetDevType.values() ) { - if ( temp.equals( type.value ) ) { + VmWareEthernetDevTypeMeta ethernetDevTypeMeta = null; + for ( EthernetDevType type : VmMetaData.EthernetDevType.values() ) { + ethernetDevTypeMeta = networkCards.get( type ); + if ( temp.equals( ethernetDevTypeMeta.value ) ) { return type; } } @@ -603,4 +584,39 @@ public class VmwareMetaData extends VmMetaData // TODO Auto-generated method stub return false; } + + public void populateTheMaps() + { + // add all from vmware supported sound cards here + soundCards.put( VmMetaData.SoundCardType.NONE, new VmWareSoundCardMeta( false, null ) ); + soundCards.put( VmMetaData.SoundCardType.DEFAULT, new VmWareSoundCardMeta( true, null ) ); + soundCards.put( VmMetaData.SoundCardType.SOUND_BLASTER, new VmWareSoundCardMeta( true, "sb16" ) ); + soundCards.put( VmMetaData.SoundCardType.ES, new VmWareSoundCardMeta( true, "es1371" ) ); + soundCards.put( VmMetaData.SoundCardType.HD_AUDIO, new VmWareSoundCardMeta( true, "hdaudio" ) ); + // end of supported sound cards + // add all from vmware supported settings for the 3D acceleration + ddacc.put( VmMetaData.DDAcceleration.OFF, new VmWareDDAccelMeta( false ) ); + ddacc.put( VmMetaData.DDAcceleration.ON, new VmWareDDAccelMeta( true ) ); + // end of all from vmware supported settings for the 3D acceleration + // add all from vmware supported Hardware versions here + hwversion.put( VmMetaData.HWVersion.NONE, new VmWareHWVersionMeta( 0 ) ); + hwversion.put( VmMetaData.HWVersion.THREE, new VmWareHWVersionMeta( 3 ) ); + hwversion.put( VmMetaData.HWVersion.FOUR, new VmWareHWVersionMeta( 4 ) ); + hwversion.put( VmMetaData.HWVersion.SIX, new VmWareHWVersionMeta( 6 ) ); + hwversion.put( VmMetaData.HWVersion.SEVEN, new VmWareHWVersionMeta( 7 ) ); + hwversion.put( VmMetaData.HWVersion.EIGHT, new VmWareHWVersionMeta( 8 ) ); + hwversion.put( VmMetaData.HWVersion.NINE, new VmWareHWVersionMeta( 9 ) ); + hwversion.put( VmMetaData.HWVersion.TEN, new VmWareHWVersionMeta( 10 ) ); + hwversion.put( VmMetaData.HWVersion.ELEVEN, new VmWareHWVersionMeta( 11 ) ); + hwversion.put( VmMetaData.HWVersion.TWELVE, new VmWareHWVersionMeta( 12 ) ); + // end of all from vmware supported Hardware versions here + // add all from vmware supported Ethernet devices versions here + networkCards.put( VmMetaData.EthernetDevType.AUTO, new VmWareEthernetDevTypeMeta( null ) ); + networkCards.put( VmMetaData.EthernetDevType.PCNET32, new VmWareEthernetDevTypeMeta( "vlance" ) ); + networkCards.put( VmMetaData.EthernetDevType.E1000, new VmWareEthernetDevTypeMeta( "e1000" ) ); + networkCards.put( VmMetaData.EthernetDevType.E1000E, new VmWareEthernetDevTypeMeta( "e1000e" ) ); + networkCards.put( VmMetaData.EthernetDevType.VMXNET, new VmWareEthernetDevTypeMeta( "vmxnet" ) ); + networkCards.put( VmMetaData.EthernetDevType.VMXNET3, new VmWareEthernetDevTypeMeta( "vmxnet3" ) ); + // end of all from vmware supported Ethernet devices versions here + } } -- cgit v1.2.3-55-g7522