diff options
-rw-r--r-- | src/main/java/org/openslx/util/vm/VboxConfig.java | 2 | ||||
-rw-r--r-- | src/main/java/org/openslx/util/vm/VboxMetaData.java | 101 | ||||
-rw-r--r-- | src/main/java/org/openslx/util/vm/VmMetaData.java | 22 | ||||
-rw-r--r-- | src/main/java/org/openslx/util/vm/VmwareMetaData.java | 16 |
4 files changed, 53 insertions, 88 deletions
diff --git a/src/main/java/org/openslx/util/vm/VboxConfig.java b/src/main/java/org/openslx/util/vm/VboxConfig.java index 94211d0..7905698 100644 --- a/src/main/java/org/openslx/util/vm/VboxConfig.java +++ b/src/main/java/org/openslx/util/vm/VboxConfig.java @@ -405,8 +405,6 @@ public class VboxConfig */ public void enableUsb() { - Node newUsbNode = addNewNode( "Hardware", "USB", false ); - Node newUsbControllers = addNewNode( "USB", "Controllers", false ); Node controller1 = addNewNode( "Controllers", "Controller", true ); addAttributeToNode( controller1, "name", "OHCI" ); addAttributeToNode( controller1, "type", "OHCI" ); diff --git a/src/main/java/org/openslx/util/vm/VboxMetaData.java b/src/main/java/org/openslx/util/vm/VboxMetaData.java index 1f83572..147b4d2 100644 --- a/src/main/java/org/openslx/util/vm/VboxMetaData.java +++ b/src/main/java/org/openslx/util/vm/VboxMetaData.java @@ -7,14 +7,6 @@ import java.nio.charset.StandardCharsets; import java.util.List; import java.util.UUID; -import javax.xml.transform.Source; -import javax.xml.transform.Transformer; -import javax.xml.transform.TransformerException; -import javax.xml.transform.TransformerFactory; -import javax.xml.transform.TransformerFactoryConfigurationError; -import javax.xml.transform.dom.DOMSource; -import javax.xml.transform.stream.StreamResult; - import org.apache.log4j.Logger; import org.openslx.bwlp.thrift.iface.OperatingSystem; import org.openslx.bwlp.thrift.iface.Virtualizer; @@ -99,16 +91,6 @@ public class VboxMetaData extends VmMetaData<VBoxSoundCardMeta, VBoxDDAccelMeta, } } - // TODO DELETE LATER WHEN NOT NEEDED ANYMORE - private void WriteToFile() throws TransformerFactoryConfigurationError, TransformerException - { - Transformer transformer = TransformerFactory.newInstance().newTransformer(); - StreamResult output = new StreamResult( new File( "output.xml" ) ); - Source input = new DOMSource( config.getConfigDoc() ); - transformer.transform( input, output ); - } - // TODO END DELETE LATER WHEN NOT NEEDED ANYMORE - @Override public Virtualizer getVirtualizer() { @@ -204,15 +186,6 @@ public class VboxMetaData extends VmMetaData<VBoxSoundCardMeta, VBoxDDAccelMeta, return true; } - public void reWrite() - { - try { - WriteToFile(); - } catch ( TransformerFactoryConfigurationError | TransformerException e ) { - e.printStackTrace(); - } - } - @Override public void setOs( String vendorOsId ) { @@ -238,7 +211,7 @@ public class VboxMetaData extends VmMetaData<VBoxSoundCardMeta, VBoxDDAccelMeta, @Override public void addFloppy( int index, String image, boolean readOnly ) { - + // TODO will need to add this soon if ( image == null ) { } else { } @@ -278,19 +251,20 @@ public class VboxMetaData extends VmMetaData<VBoxSoundCardMeta, VBoxDDAccelMeta, if ( !x.hasAttribute( "enabled" ) || ( x.hasAttribute( "enabled" ) && x.getAttribute( "enabled" ).equals( "false" ) ) ) { returnsct = VmMetaData.SoundCardType.NONE; } else { - String controller = x.getAttribute( "controller" ); - switch ( controller ) { - case "HDA": - returnsct = VmMetaData.SoundCardType.HD_AUDIO; - break; - case "SB16": - returnsct = VmMetaData.SoundCardType.SOUND_BLASTER; - break; - case "AC97": + // extra separate case for the non-existing argument} + if ( !x.hasAttribute( "type" ) ) { returnsct = VmMetaData.SoundCardType.AC; - break; - default: - throw new IllegalArgumentException( "Invalid entry: controller=" + controller ); + } else { + String controller = x.getAttribute( "controller" ); + VBoxSoundCardMeta soundMeta = null; + for ( VmMetaData.SoundCardType type : VmMetaData.SoundCardType.values() ) { + soundMeta = soundCards.get( type ); + if ( soundMeta != null ) { + if ( controller.equals( soundMeta.value ) ) { + returnsct = type; + } + } + } } } return returnsct; @@ -330,12 +304,11 @@ public class VboxMetaData extends VmMetaData<VBoxSoundCardMeta, VBoxDDAccelMeta, } @Override - public HWVersion getHWVersion() + public VmMetaData.HWVersion getHWVersion() { VmMetaData.HWVersion returnhwv = null; - // TODO what do here? there is only one supported hwversion as far as I know + // Virtual Box uses only one virtual hardware version and can't be changed returnhwv = VmMetaData.HWVersion.DEFAULT; - // TODO End return returnhwv; } @@ -344,41 +317,33 @@ public class VboxMetaData extends VmMetaData<VBoxSoundCardMeta, VBoxDDAccelMeta, { String index = "0"; VBoxEthernetDevTypeMeta networkc = networkCards.get( type ); - // TODO cardIndex is not used yet...maybe later needed for different network cards + // cardIndex is not used yet...maybe later needed for different network cards config.changeAttribute( "Adapter", "enabled", vmBoolean( networkc.isPresent ), "slot", index ); config.changeAttribute( "Adapter", "type", networkc.value, "slot", index ); } @Override - public EthernetDevType getEthernetDevType( int cardIndex ) + public VmMetaData.EthernetDevType getEthernetDevType( int cardIndex ) { VmMetaData.EthernetDevType returnedt = null; Element x = (Element)config.findANode( "Adapter" ).item( 0 ); if ( !x.hasAttribute( "enabled" ) || ( x.hasAttribute( "enabled" ) && x.getAttribute( "enabled" ).equals( "false" ) ) ) { returnedt = VmMetaData.EthernetDevType.NONE; } else { - String type = x.getAttribute( "type" ); - switch ( type ) { - case "Am79C970A": - returnedt = VmMetaData.EthernetDevType.PCNETPCI2; - break; - case "Am79C973": + // extra separate case for the non-existing argument} + if ( !x.hasAttribute( "type" ) ) { returnedt = VmMetaData.EthernetDevType.PCNETFAST3; - break; - case "82540EM": - returnedt = VmMetaData.EthernetDevType.PRO1000MTD; - break; - case "82543GC": - returnedt = VmMetaData.EthernetDevType.PRO1000TS; - break; - case "82545EM": - returnedt = VmMetaData.EthernetDevType.PRO1000MTS; - break; - case "virtio": - returnedt = VmMetaData.EthernetDevType.PARAVIRT; - break; - default: - throw new IllegalArgumentException( "Invalid entry: type=" + type); + } else { + String temp = x.getAttribute( "type" ); + VBoxEthernetDevTypeMeta etherMeta = null; + for ( VmMetaData.EthernetDevType type : VmMetaData.EthernetDevType.values() ) { + etherMeta = networkCards.get( type ); + if ( etherMeta != null ) { + if ( temp.equals( etherMeta.value ) ) { + returnedt = type; + } + } + } } } return returnedt; @@ -405,7 +370,6 @@ public class VboxMetaData extends VmMetaData<VBoxSoundCardMeta, VBoxDDAccelMeta, // end of all from vmware supported settings for the 3D acceleration // add all from vmware supported Hardware versions here hwversion.put( VmMetaData.HWVersion.DEFAULT, new VBoxHWVersionMeta( 0 ) ); - // end of all from vmware supported Hardware versions here // add all from vmware supported Ethernet devices versions here // none type needs to have a valid value; it takes the value of pcnetcpi2; if value is left null or empty vm will not start because value is not valid @@ -419,8 +383,6 @@ public class VboxMetaData extends VmMetaData<VBoxSoundCardMeta, VBoxDDAccelMeta, // end of all from vmware supported Ethernet devices versions here } - - /** * given a boolean value returns a string in lowercase of given boolean * @@ -451,6 +413,7 @@ public class VboxMetaData extends VmMetaData<VBoxSoundCardMeta, VBoxDDAccelMeta, public boolean disableSuspend() { // TODO how?? + // https://forums.virtualbox.org/viewtopic.php?f=6&t=77169 // https://forums.virtualbox.org/viewtopic.php?f=8&t=80338 return true; } diff --git a/src/main/java/org/openslx/util/vm/VmMetaData.java b/src/main/java/org/openslx/util/vm/VmMetaData.java index 3c1d485..46097df 100644 --- a/src/main/java/org/openslx/util/vm/VmMetaData.java +++ b/src/main/java/org/openslx/util/vm/VmMetaData.java @@ -10,6 +10,8 @@ import java.util.List; import java.util.Map; import java.util.Map.Entry; +import javax.swing.tree.ExpandVetoException; + import org.apache.log4j.Logger; import org.openslx.bwlp.thrift.iface.OperatingSystem; import org.openslx.bwlp.thrift.iface.Virtualizer; @@ -156,7 +158,6 @@ public abstract class VmMetaData<T, U, V, W> } } - public static enum EtherType { NAT, @@ -313,18 +314,23 @@ public abstract class VmMetaData<T, U, V, W> // meta object needed when reading from configarray public static VmMetaData<?, ?, ?, ?> getInstance( List<OperatingSystem> osList, byte[] vmContent, int length ) throws IOException { + Exception errEx = null; try { return new VmwareMetaData( osList, vmContent, length ); } catch ( UnsupportedVirtualizerFormatException e ) { - LOGGER.debug( "Machine description not in .vmx format.", e ); + LOGGER.debug( "Machine description not in .vmx format." ); + errEx = e; } try { LOGGER.debug( "versuche vbox" ); return new VboxMetaData( osList, vmContent, length ); } catch ( UnsupportedVirtualizerFormatException e ) { - LOGGER.debug( "Machine description not in .vbox format.", e ); + LOGGER.debug( "Machine description not in .vbox format." ); + errEx = e; + } + if ( errEx != null ) { + LOGGER.error( "Machine description has an unknown format!", errEx ); } - LOGGER.error( "Machine description has an unknown format!" ); return null; } @@ -363,17 +369,15 @@ public abstract class VmMetaData<T, U, V, W> public abstract EthernetDevType getEthernetDevType( int cardIndex ); public abstract byte[] getDefinitionArray(); - - public abstract boolean addEthernet( EtherType type ); - public abstract void reWrite(); + public abstract boolean addEthernet( EtherType type ); public abstract Virtualizer getVirtualizer(); public abstract void enableUsb( boolean enabled ); - + public abstract boolean disableSuspend(); - + /** * * Function used by subclasses to put the virtual devices, which the subclass supports in the diff --git a/src/main/java/org/openslx/util/vm/VmwareMetaData.java b/src/main/java/org/openslx/util/vm/VmwareMetaData.java index 47deb27..dda5578 100644 --- a/src/main/java/org/openslx/util/vm/VmwareMetaData.java +++ b/src/main/java/org/openslx/util/vm/VmwareMetaData.java @@ -417,12 +417,14 @@ public class VmwareMetaData extends VmMetaData<VmWareSoundCardMeta, VmWareDDAcce addFiltered( "suspend.disabled", "TRUE" ); return true; } + @Override public boolean addDisplayName( String name ) { addFiltered( "displayName", name ); return true; } + @Override public boolean addRam( int mem ) { @@ -555,6 +557,9 @@ public class VmwareMetaData extends VmMetaData<VmWareSoundCardMeta, VmWareDDAcce VmWareHWVersionMeta hwVersionMeta = null; for ( VmMetaData.HWVersion ver : VmMetaData.HWVersion.values() ) { hwVersionMeta = hwversion.get( ver ); + if ( hwVersionMeta == null ) { + continue; + } if ( currentValue == hwVersionMeta.version ) { return ver; } @@ -579,6 +584,9 @@ public class VmwareMetaData extends VmMetaData<VmWareSoundCardMeta, VmWareDDAcce VmWareEthernetDevTypeMeta ethernetDevTypeMeta = null; for ( EthernetDevType type : VmMetaData.EthernetDevType.values() ) { ethernetDevTypeMeta = networkCards.get( type ); + if ( ethernetDevTypeMeta == null ) { + continue; + } if ( temp.equals( ethernetDevTypeMeta.value ) ) { return type; } @@ -588,16 +596,8 @@ public class VmwareMetaData extends VmMetaData<VmWareSoundCardMeta, VmWareDDAcce } @Override - public void reWrite() - { - // TODO Auto-generated method stub - - } - - @Override public boolean addCpuCoreCount( int nrOfCores ) { - // TODO Auto-generated method stub return false; } |