diff options
Diffstat (limited to 'src/main/java/org/openslx/util/vm/VmwareMetaData.java')
-rw-r--r-- | src/main/java/org/openslx/util/vm/VmwareMetaData.java | 234 |
1 files changed, 125 insertions, 109 deletions
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<VmWareSoundCardMeta, VmWareDDAccelMeta, VmWareHWVersionMeta, VmWareEthernetDevTypeMeta> { 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<String, Controller> disks = new HashMap<>(); - public VmwareMetaData( List<OperatingSystem> osList, File file ) - throws IOException, UnsupportedVirtualizerFormatException + 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 ) - throws UnsupportedVirtualizerFormatException + public VmwareMetaData( List<OperatingSystem> 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<String, ConfigEntry> 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 + } } |