summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon Rettberg2021-07-05 18:44:48 +0200
committerSimon Rettberg2021-07-05 18:44:48 +0200
commit09d48d1daf3243907dd74fd5d8078d96c1ee5597 (patch)
tree68aa07d2d9722953505a92e49cc87bbde1fccfe2
parentAdd util methods to print App information from MANIFEST.MF (diff)
downloadmaster-sync-shared-09d48d1daf3243907dd74fd5d8078d96c1ee5597.tar.gz
master-sync-shared-09d48d1daf3243907dd74fd5d8078d96c1ee5597.tar.xz
master-sync-shared-09d48d1daf3243907dd74fd5d8078d96c1ee5597.zip
[virtualizer] Get rid of <?,?,?,?,?,?,?,?>de-generic-virtualizer
-rw-r--r--src/main/java/org/openslx/virtualization/Version.java11
-rw-r--r--src/main/java/org/openslx/virtualization/configuration/VirtualizationConfiguration.java210
-rw-r--r--src/main/java/org/openslx/virtualization/configuration/VirtualizationConfigurationDocker.java66
-rw-r--r--src/main/java/org/openslx/virtualization/configuration/VirtualizationConfigurationQemu.java557
-rw-r--r--src/main/java/org/openslx/virtualization/configuration/VirtualizationConfigurationQemuUtils.java78
-rw-r--r--src/main/java/org/openslx/virtualization/configuration/VirtualizationConfigurationVirtualBox.java378
-rw-r--r--src/main/java/org/openslx/virtualization/configuration/VirtualizationConfigurationVmware.java336
-rw-r--r--src/main/java/org/openslx/virtualization/configuration/logic/ConfigurationLogic.java2
-rw-r--r--src/main/java/org/openslx/virtualization/configuration/logic/ConfigurationLogicDozModClientToDozModServer.java4
-rw-r--r--src/main/java/org/openslx/virtualization/configuration/logic/ConfigurationLogicDozModServerToDozModClient.java9
-rw-r--r--src/main/java/org/openslx/virtualization/configuration/logic/ConfigurationLogicDozModServerToStatelessClient.java8
-rw-r--r--src/main/java/org/openslx/virtualization/hardware/AbstractConfigurableOption.java42
-rw-r--r--src/main/java/org/openslx/virtualization/hardware/ConfigurationGroups.java20
-rw-r--r--src/main/java/org/openslx/virtualization/hardware/Ethernet.java20
-rw-r--r--src/main/java/org/openslx/virtualization/hardware/SoundCard.java13
-rw-r--r--src/main/java/org/openslx/virtualization/hardware/Usb.java11
-rw-r--r--src/test/java/org/openslx/virtualization/configuration/VirtualizationConfigurationQemuTest.java129
-rw-r--r--src/test/java/org/openslx/virtualization/configuration/logic/ConfigurationLogicDozModClientToDozModServerTest.java6
-rw-r--r--src/test/java/org/openslx/virtualization/configuration/logic/ConfigurationLogicDozModServerToDozModClientTest.java6
-rw-r--r--src/test/java/org/openslx/virtualization/configuration/logic/ConfigurationLogicDozModServerToStatelessClientTest.java6
-rw-r--r--src/test/java/org/openslx/virtualization/configuration/logic/ConfigurationLogicTestUtils.java4
21 files changed, 808 insertions, 1108 deletions
diff --git a/src/main/java/org/openslx/virtualization/Version.java b/src/main/java/org/openslx/virtualization/Version.java
index 51dc98b..c823324 100644
--- a/src/main/java/org/openslx/virtualization/Version.java
+++ b/src/main/java/org/openslx/virtualization/Version.java
@@ -5,6 +5,8 @@ import java.util.function.Predicate;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
+import org.openslx.util.Util;
+
/**
* Represents a version information.
*
@@ -28,7 +30,7 @@ public class Version implements Comparable<Version>
* 5.10.13
* </pre>
*/
- private static final String VERSION_NUMBER_REGEX = "^(\\d+)(?:\\.(\\d+)(?:\\.(\\d+))?)?$";
+ private static final Pattern VERSION_NUMBER_REGEX = Pattern.compile( "^(\\d+)(?:\\.(\\d+)(?:\\.(\\d+))?)?$" );
/**
* Major number of the version.
@@ -236,11 +238,10 @@ public class Version implements Comparable<Version>
{
final Version parsedVersion;
- if ( version == null || version.isEmpty() ) {
+ if ( Util.isEmptyString( version ) ) {
parsedVersion = null;
} else {
- final Pattern versionPattern = Pattern.compile( Version.VERSION_NUMBER_REGEX );
- final Matcher versionMatcher = versionPattern.matcher( version );
+ final Matcher versionMatcher = VERSION_NUMBER_REGEX.matcher( version );
if ( versionMatcher.find() ) {
final String majorStr = versionMatcher.group( 1 );
@@ -262,7 +263,7 @@ public class Version implements Comparable<Version>
@Override
public String toString()
{
- if ( this.getName() == null || this.getName().isEmpty() ) {
+ if ( Util.isEmptyString( this.getName() ) ) {
return String.format( "%d.%d", this.getMajor(), this.getMinor() );
} else {
return String.format( "%d.%d %s", this.getMajor(), this.getMinor(), this.getName() );
diff --git a/src/main/java/org/openslx/virtualization/configuration/VirtualizationConfiguration.java b/src/main/java/org/openslx/virtualization/configuration/VirtualizationConfiguration.java
index cd8af1e..15a409f 100644
--- a/src/main/java/org/openslx/virtualization/configuration/VirtualizationConfiguration.java
+++ b/src/main/java/org/openslx/virtualization/configuration/VirtualizationConfiguration.java
@@ -5,95 +5,25 @@ import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Collections;
-import java.util.HashMap;
import java.util.List;
-import java.util.Map;
import org.apache.log4j.Logger;
import org.openslx.bwlp.thrift.iface.OperatingSystem;
import org.openslx.virtualization.Version;
+import org.openslx.virtualization.hardware.AbstractConfigurableOption;
+import org.openslx.virtualization.hardware.ConfigurationGroups;
import org.openslx.virtualization.virtualizer.Virtualizer;
/**
* Describes a configured virtual machine. This class is parsed from a machine
* description, like a *.vmx for VMware machines.
*/
-public abstract class VirtualizationConfiguration<T, U, W, X>
+public abstract class VirtualizationConfiguration
{
private static final Logger LOGGER = Logger.getLogger( VirtualizationConfiguration.class );
- /*
- * Helper types
- */
- protected Map<SoundCardType, T> soundCards = new HashMap<>();
- protected Map<DDAcceleration, U> ddacc = new HashMap<>();
- protected Map<EthernetDevType, W> networkCards = new HashMap<>();
- protected Map<UsbSpeed, X> usbSpeeds = new HashMap<>();
-
private final Virtualizer virtualizer;
- /**
- * Virtual sound cards types
- */
- public static enum SoundCardType
- {
- NONE( "None" ), DEFAULT( "(default)" ), SOUND_BLASTER( "Sound Blaster 16" ), ES( "ES 1371" ), HD_AUDIO(
- "Intel Integrated HD Audio" ), AC( "Intel ICH Audio Codec 97" );
-
- public final String displayName;
-
- private SoundCardType( String dName )
- {
- this.displayName = dName;
- }
- }
-
- /**
- * 3D acceleration types
- */
- public static enum DDAcceleration
- {
- OFF( "Off" ), ON( "On" );
-
- public final String displayName;
-
- private DDAcceleration( String dName )
- {
- this.displayName = dName;
- }
- }
-
- /**
- * Virtual network cards
- */
- public static enum EthernetDevType
- {
- AUTO( "(default)" ), PCNET32( "AMD PCnet32" ), E1000( "Intel E1000 (PCI)" ), E1000E(
- "Intel E1000e (PCI-Express)" ), VMXNET( "VMXnet" ), VMXNET3( "VMXnet 3" ), PCNETPCI2(
- "PCnet-PCI II" ), PCNETFAST3( "PCnet-FAST III" ), PRO1000MTD(
- "Intel PRO/1000 MT Desktop" ), PRO1000TS(
- "Intel PRO/1000 T Server" ), PRO1000MTS( "Intel PRO/1000 MT Server" ), PARAVIRT(
- "Paravirtualized Network" ), NONE( "No Network Card" );
-
- public final String displayName;
-
- private EthernetDevType( String dName )
- {
- this.displayName = dName;
- }
- }
-
- public static enum UsbSpeed
- {
- NONE( "None" ), USB1_1( "USB 1.1" ), USB2_0( "USB 2.0" ), USB3_0( "USB 3.0" );
-
- public final String displayName;
-
- private UsbSpeed( String dName )
- {
- this.displayName = dName;
- }
- }
public static enum DriveBusType
{
@@ -118,6 +48,30 @@ public abstract class VirtualizationConfiguration<T, U, W, X>
{
NAT, BRIDGED, HOST_ONLY;
}
+
+ public static class ConfigurableOptionGroup
+ {
+ public final ConfigurationGroups groupIdentifier; // Enum?
+
+ public final List<AbstractConfigurableOption> availableOptions;
+
+ public ConfigurableOptionGroup( ConfigurationGroups groupIdentifier, List<AbstractConfigurableOption> availableOptions )
+ {
+ this.groupIdentifier = groupIdentifier;
+ this.availableOptions = Collections.unmodifiableList( availableOptions );
+ }
+
+ public AbstractConfigurableOption getSelected()
+ {
+ for (AbstractConfigurableOption hw : availableOptions) {
+ if ( hw.isActive() )
+ return hw;
+ }
+ return null;
+ }
+
+ }
+
/*
* Members
*/
@@ -131,44 +85,8 @@ public abstract class VirtualizationConfiguration<T, U, W, X>
protected String displayName = null;
protected boolean isMachineSnapshot;
-
- /*
- * Getters for virtual hardware
- */
- public List<SoundCardType> getSupportedSoundCards()
- {
- ArrayList<SoundCardType> availables = new ArrayList<SoundCardType>( soundCards.keySet() );
- Collections.sort( availables );
- return availables;
- }
-
- public List<DDAcceleration> getSupportedDDAccs()
- {
- ArrayList<DDAcceleration> availables = new ArrayList<DDAcceleration>( ddacc.keySet() );
- Collections.sort( availables );
- return availables;
- }
-
- public List<Version> getSupportedHWVersions()
- {
- final List<Version> availables = this.getVirtualizer().getSupportedVersions();
- Collections.sort( availables );
- return Collections.unmodifiableList( availables );
- }
-
- public List<EthernetDevType> getSupportedEthernetDevices()
- {
- ArrayList<EthernetDevType> availables = new ArrayList<EthernetDevType>( networkCards.keySet() );
- Collections.sort( availables );
- return availables;
- }
-
- public List<UsbSpeed> getSupportedUsbSpeeds()
- {
- ArrayList<UsbSpeed> availables = new ArrayList<>( usbSpeeds.keySet() );
- Collections.sort( availables );
- return availables;
- }
+
+ protected final List<ConfigurableOptionGroup> configurableOptions = new ArrayList<>();
/**
* Get operating system of this VM.
@@ -217,6 +135,29 @@ public abstract class VirtualizationConfiguration<T, U, W, X>
{
return isMachineSnapshot;
}
+
+ private class VersionOption extends AbstractConfigurableOption {
+
+ private final Version version;
+
+ public VersionOption( Version version )
+ {
+ super( Integer.toString( version.getVersion() ), version.getName() );
+ this.version = version;
+ }
+
+ @Override
+ public boolean isActive()
+ {
+ return getVirtualizerVersion().equals( version );
+ }
+
+ @Override
+ public void apply()
+ {
+ setVirtualizerVersion( version );
+ }
+ }
/*
* Methods
@@ -234,6 +175,16 @@ public abstract class VirtualizationConfiguration<T, U, W, X>
}
// register virtual hardware models for graphical editing of virtual devices (GPU, sound, USB, ...)
+ final List<Version> availables = this.getVirtualizer().getSupportedVersions();
+ //Collections.sort( availables ); // XXX WTF? How did this not break before? It's an unmodifiable collection
+ if ( availables != null ) {
+ // XXX List is null for qemu?
+ List<AbstractConfigurableOption> list = new ArrayList<>();
+ for ( Version ver : availables ) {
+ list.add( new VersionOption( ver ) );
+ }
+ configurableOptions.add( new ConfigurableOptionGroup( ConfigurationGroups.HW_VERSION, list ) );
+ }
this.registerVirtualHW();
}
@@ -245,7 +196,7 @@ public abstract class VirtualizationConfiguration<T, U, W, X>
* @return VmMetaData object representing the relevant parts of the given machine description
* @throws IOException failed to read machine description from specified file.
*/
- public static VirtualizationConfiguration<?, ?, ?, ?> getInstance( List<OperatingSystem> osList, File file )
+ public static VirtualizationConfiguration getInstance( List<OperatingSystem> osList, File file )
throws IOException
{
try {
@@ -281,10 +232,11 @@ public abstract class VirtualizationConfiguration<T, U, W, X>
* @param length length of the byte array given as vmContent
* @return VmMetaData object representing the relevant parts of the given machine description
* @throws IOException failed to read machine description from specified byte stream.
+ * @throws VirtualizationConfigurationException
*/
- public static VirtualizationConfiguration<?, ?, ?, ?> getInstance( List<OperatingSystem> osList, byte[] vmContent,
+ public static VirtualizationConfiguration getInstance( List<OperatingSystem> osList, byte[] vmContent,
int length )
- throws IOException
+ throws IOException, VirtualizationConfigurationException
{
try {
return new VirtualizationConfigurationVmware( osList, vmContent, length );
@@ -306,9 +258,7 @@ public abstract class VirtualizationConfiguration<T, U, W, X>
} catch ( VirtualizationConfigurationException e ) {
LOGGER.debug( "Not a tar.gz file, for docker container", e );
}
-
- LOGGER.error( "Could not detect any known virtualizer format" );
- return null;
+ throw new VirtualizationConfigurationException( "Unknown virtualizer config format" );
}
/**
@@ -337,27 +287,11 @@ public abstract class VirtualizationConfiguration<T, U, W, X>
public abstract boolean addCdrom( String image );
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 setVirtualizerVersion( Version type );
public abstract Version getVirtualizerVersion();
- public abstract void setEthernetDevType( int cardIndex, EthernetDevType type );
-
- public abstract EthernetDevType getEthernetDevType( int cardIndex );
-
- public abstract void setMaxUsbSpeed( UsbSpeed speed );
-
- public abstract UsbSpeed getMaxUsbSpeed();
-
public abstract byte[] getConfigurationAsByteArray();
public String getConfigurationAsString()
@@ -418,4 +352,12 @@ public abstract class VirtualizationConfiguration<T, U, W, X>
* Function used to register virtual devices.
*/
public abstract void registerVirtualHW();
+
+ /**
+ * Get all config options this virtualizer supports, with all available options.
+ */
+ public List<ConfigurableOptionGroup> getConfigurableOptions()
+ {
+ return Collections.unmodifiableList( configurableOptions );
+ }
}
diff --git a/src/main/java/org/openslx/virtualization/configuration/VirtualizationConfigurationDocker.java b/src/main/java/org/openslx/virtualization/configuration/VirtualizationConfigurationDocker.java
index d5e9abb..ea888e4 100644
--- a/src/main/java/org/openslx/virtualization/configuration/VirtualizationConfigurationDocker.java
+++ b/src/main/java/org/openslx/virtualization/configuration/VirtualizationConfigurationDocker.java
@@ -1,33 +1,17 @@
package org.openslx.virtualization.configuration;
-import org.apache.log4j.Logger;
-import org.openslx.bwlp.thrift.iface.OperatingSystem;
-import org.openslx.virtualization.Version;
-import org.openslx.virtualization.virtualizer.VirtualizerDocker;
-
import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.List;
-class DockerSoundCardMeta
-{
-}
-
-class DockerDDAccelMeta
-{
-}
-
-class DockerEthernetDevTypeMeta
-{
-}
-
-class DockerUsbSpeedMeta
-{
-}
+import org.apache.log4j.Logger;
+import org.openslx.bwlp.thrift.iface.OperatingSystem;
+import org.openslx.virtualization.Version;
+import org.openslx.virtualization.virtualizer.VirtualizerDocker;
-public class VirtualizationConfigurationDocker extends VirtualizationConfiguration<DockerSoundCardMeta, DockerDDAccelMeta, DockerEthernetDevTypeMeta, DockerUsbSpeedMeta> {
+public class VirtualizationConfigurationDocker extends VirtualizationConfiguration {
/**
* File name extension for Docker virtualization configuration files.
@@ -145,46 +129,15 @@ public class VirtualizationConfigurationDocker extends VirtualizationConfigurati
return false;
}
- @Override public void setSoundCard(SoundCardType type) {
-
- }
-
- @Override public SoundCardType getSoundCard() {
- return SoundCardType.NONE;
- }
-
- @Override public void setDDAcceleration(DDAcceleration type) {
-
- }
-
- @Override public DDAcceleration getDDAcceleration() {
- return DDAcceleration.OFF;
- }
-
- @Override public void setVirtualizerVersion(Version type) {
-
+ @Override public void setVirtualizerVersion( Version type )
+ {
}
- @Override public Version getVirtualizerVersion() {
+ @Override public Version getVirtualizerVersion()
+ {
return null;
}
- @Override public void setEthernetDevType(int cardIndex, EthernetDevType type) {
-
- }
-
- @Override public EthernetDevType getEthernetDevType(int cardIndex) {
- return EthernetDevType.NONE;
- }
-
- @Override public void setMaxUsbSpeed(UsbSpeed speed) {
-
- }
-
- @Override public UsbSpeed getMaxUsbSpeed() {
- return UsbSpeed.NONE;
- }
-
@Override public byte[] getConfigurationAsByteArray() {
return this.containerDefinition;
}
@@ -210,4 +163,5 @@ public class VirtualizationConfigurationDocker extends VirtualizationConfigurati
public void validate() throws VirtualizationConfigurationException
{
}
+
}
diff --git a/src/main/java/org/openslx/virtualization/configuration/VirtualizationConfigurationQemu.java b/src/main/java/org/openslx/virtualization/configuration/VirtualizationConfigurationQemu.java
index b4bc0ba..19ad406 100644
--- a/src/main/java/org/openslx/virtualization/configuration/VirtualizationConfigurationQemu.java
+++ b/src/main/java/org/openslx/virtualization/configuration/VirtualizationConfigurationQemu.java
@@ -5,7 +5,6 @@ import java.math.BigInteger;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.List;
-import java.util.Map.Entry;
import org.openslx.bwlp.thrift.iface.OperatingSystem;
import org.openslx.libvirt.domain.Domain;
@@ -13,8 +12,6 @@ import org.openslx.libvirt.domain.DomainUtils;
import org.openslx.libvirt.domain.device.ControllerUsb;
import org.openslx.libvirt.domain.device.Disk.BusType;
import org.openslx.libvirt.domain.device.Disk.StorageType;
-import org.openslx.libvirt.libosinfo.LibOsInfo;
-import org.openslx.libvirt.libosinfo.os.Os;
import org.openslx.libvirt.domain.device.DiskCdrom;
import org.openslx.libvirt.domain.device.DiskFloppy;
import org.openslx.libvirt.domain.device.DiskStorage;
@@ -23,174 +20,28 @@ import org.openslx.libvirt.domain.device.GraphicsSpice;
import org.openslx.libvirt.domain.device.Interface;
import org.openslx.libvirt.domain.device.Sound;
import org.openslx.libvirt.domain.device.Video;
+import org.openslx.libvirt.libosinfo.LibOsInfo;
+import org.openslx.libvirt.libosinfo.os.Os;
import org.openslx.libvirt.xml.LibvirtXmlDocumentException;
import org.openslx.libvirt.xml.LibvirtXmlSerializationException;
import org.openslx.libvirt.xml.LibvirtXmlValidationException;
import org.openslx.util.LevenshteinDistance;
+import org.openslx.util.Util;
import org.openslx.virtualization.Version;
+import org.openslx.virtualization.hardware.AbstractConfigurableOption;
+import org.openslx.virtualization.hardware.ConfigurationGroups;
+import org.openslx.virtualization.hardware.Ethernet;
+import org.openslx.virtualization.hardware.SoundCard;
+import org.openslx.virtualization.hardware.Usb;
import org.openslx.virtualization.virtualizer.VirtualizerQemu;
/**
- * Metadata to describe the hardware type of a QEMU sound card.
- *
- * @author Manuel Bentele
- * @version 1.0
- */
-class QemuSoundCardMeta
-{
- /**
- * Stores the hardware model of the QEMU sound card.
- */
- private final Sound.Model model;
-
- /**
- * Creates metadata to describe the hardware model of a QEMU sound card.
- *
- * @param model hardware model of the QEMU sound card.
- */
- public QemuSoundCardMeta( Sound.Model model )
- {
- this.model = model;
- }
-
- /**
- * Returns hardware model of the QEMU sound card.
- *
- * @return hardware model of the QEMU sound card.
- */
- public Sound.Model getModel()
- {
- return this.model;
- }
-}
-
-/**
- * Metadata to describe the hardware acceleration state of QEMU virtual graphics.
- *
- * @author Manuel Bentele
- * @version 1.0
- */
-class QemuDDAccelMeta
-{
- /**
- * Stores state of the hardware acceleration for QEMU virtual graphics.
- */
- private final boolean enabled;
-
- /**
- * Creates metadata to describe the hardware acceleration state of QEMU virtual graphics.
- *
- * @param enabled state of the hardware acceleration for QEMU virtual graphics.
- */
- public QemuDDAccelMeta( boolean enabled )
- {
- this.enabled = enabled;
- }
-
- /**
- * Returns state of the hardware acceleration of QEMU virtual graphics.
- *
- * @return state of the hardware acceleration for QEMU virtual graphics.
- */
- public boolean isEnabled()
- {
- return this.enabled;
- }
-}
-
-/**
- * Metadata to describe the hardware type of a QEMU ethernet device.
- *
- * @author Manuel Bentele
- * @version 1.0
- */
-class QemuEthernetDevTypeMeta
-{
- /**
- * Stores the hardware model of the QEMU ethernet device.
- */
- private final Interface.Model model;
-
- /**
- * Creates metadata to describe the hardware type of a QEMU ethernet device.
- *
- * @param model hardware type of the QEMU ethernet device.
- */
- public QemuEthernetDevTypeMeta( Interface.Model model )
- {
- this.model = model;
- }
-
- /**
- * Returns the hardware type of a QEMU ethernet device.
- *
- * @return hardware type of the QEMU ethernet device.
- */
- public Interface.Model getModel()
- {
- return this.model;
- }
-}
-
-/**
- * Metadata to describe a QEMU USB controller.
- *
- * @author Manuel Bentele
- * @version 1.0
- */
-class QemuUsbSpeedMeta
-{
- /**
- * Stores the USB speed of the QEMU USB controller.
- */
- private final int speed;
-
- /**
- * Stores the QEMU hardware model of the USB controller.
- */
- private final ControllerUsb.Model model;
-
- /**
- * Creates metadata to describe a QEMU USB controller.
- *
- * @param speed USB speed of the QEMU USB controller.
- * @param model QEMU hardware model of the USB controller.
- */
- public QemuUsbSpeedMeta( int speed, ControllerUsb.Model model )
- {
- this.speed = speed;
- this.model = model;
- }
-
- /**
- * Returns the speed of the QEMU USB controller.
- *
- * @return speed of the QEMU USB controller.
- */
- public int getSpeed()
- {
- return this.speed;
- }
-
- /**
- * Returns QEMU hardware model of the USB controller.
- *
- * @return hardware model of the QEMU USB controller.
- */
- public ControllerUsb.Model getModel()
- {
- return this.model;
- }
-}
-
-/**
* Virtual machine configuration (managed by Libvirt) for the QEMU hypervisor.
*
* @author Manuel Bentele
* @version 1.0
*/
-public class VirtualizationConfigurationQemu extends
- VirtualizationConfiguration<QemuSoundCardMeta, QemuDDAccelMeta, QemuEthernetDevTypeMeta, QemuUsbSpeedMeta>
+public class VirtualizationConfigurationQemu extends VirtualizationConfiguration
{
/**
* Name of the network bridge for the LAN.
@@ -558,129 +409,98 @@ public class VirtualizationConfigurationQemu extends
return isVCpuSet;
}
-
- @Override
- public void setSoundCard( SoundCardType type )
+
+ class QemuGfxType extends AbstractConfigurableOption
{
- QemuSoundCardMeta soundDeviceConfig = this.soundCards.get( type );
- ArrayList<Sound> soundDevices = this.vmConfig.getSoundDevices();
- Sound.Model soundDeviceModel = soundDeviceConfig.getModel();
- if ( soundDevices.isEmpty() ) {
- // create new sound device with 'soundDeviceModel' hardware
- Sound soundDevice = this.vmConfig.addSoundDevice();
- soundDevice.setModel( soundDeviceModel );
- } else {
- // update sound device model type of existing sound devices
- for ( Sound soundDevice : soundDevices ) {
- soundDevice.setModel( soundDeviceModel );
- }
+ public QemuGfxType( String id, String displayName )
+ {
+ super( id, displayName );
}
- }
-
- @Override
- public SoundCardType getSoundCard()
- {
- ArrayList<Sound> soundDevices = this.vmConfig.getSoundDevices();
- SoundCardType soundDeviceType = SoundCardType.DEFAULT;
-
- if ( soundDevices.isEmpty() ) {
- // the VM configuration does not contain a sound card device
- soundDeviceType = SoundCardType.NONE;
- } else {
- // the VM configuration at least one sound card device, so return the type of the first one
- Sound.Model soundDeviceModel = soundDevices.get( 0 ).getModel();
- soundDeviceType = VirtualizationConfigurationQemuUtils.convertSoundDeviceModel( soundDeviceModel );
- }
-
- return soundDeviceType;
- }
- @Override
- public void setDDAcceleration( DDAcceleration type )
- {
- QemuDDAccelMeta accelerationConfig = this.ddacc.get( type );
- ArrayList<Graphics> graphicDevices = this.vmConfig.getGraphicDevices();
- ArrayList<Video> videoDevices = this.vmConfig.getVideoDevices();
- final boolean accelerationEnabled = accelerationConfig.isEnabled();
+ @Override
+ public void apply()
+ {
+ ArrayList<Graphics> graphicDevices = vmConfig.getGraphicDevices();
+ ArrayList<Video> videoDevices = vmConfig.getVideoDevices();
+ final boolean accelerationEnabled = this.id.equals( "true" );
- boolean acceleratedGraphicsAvailable = false;
+ boolean acceleratedGraphicsAvailable = false;
- if ( graphicDevices.isEmpty() ) {
- // add new graphics device with enabled acceleration to VM configuration
- GraphicsSpice graphicSpiceDevice = this.vmConfig.addGraphicsSpiceDevice();
- graphicSpiceDevice.setOpenGl( true );
- acceleratedGraphicsAvailable = true;
- } else {
- // enable graphic acceleration of existing graphics devices
- for ( Graphics graphicDevice : graphicDevices ) {
- // set hardware acceleration for SPICE based graphics output
- // other graphic devices do not support hardware acceleration
- if ( graphicDevice instanceof GraphicsSpice ) {
- GraphicsSpice.class.cast( graphicDevice ).setOpenGl( true );
- acceleratedGraphicsAvailable = true;
+ if ( graphicDevices.isEmpty() ) {
+ // add new graphics device with enabled acceleration to VM configuration
+ GraphicsSpice graphicSpiceDevice = vmConfig.addGraphicsSpiceDevice();
+ graphicSpiceDevice.setOpenGl( true );
+ acceleratedGraphicsAvailable = true;
+ } else {
+ // enable graphic acceleration of existing graphics devices
+ for ( Graphics graphicDevice : graphicDevices ) {
+ // set hardware acceleration for SPICE based graphics output
+ // other graphic devices do not support hardware acceleration
+ if ( graphicDevice instanceof GraphicsSpice ) {
+ GraphicsSpice.class.cast( graphicDevice ).setOpenGl( true );
+ acceleratedGraphicsAvailable = true;
+ }
}
}
- }
- // only configure hardware acceleration of video card(s) if graphics with hardware acceleration is available
- if ( acceleratedGraphicsAvailable ) {
- if ( videoDevices.isEmpty() ) {
- // add new video device with enabled acceleration to VM configuration
- Video videoDevice = this.vmConfig.addVideoDevice();
- videoDevice.setModel( Video.Model.VIRTIO );
- videoDevice.set2DAcceleration( true );
- videoDevice.set3DAcceleration( true );
- } else {
- // enable graphic acceleration of existing graphics and video devices
- for ( Video videoDevice : videoDevices ) {
- // set hardware acceleration for Virtio GPUs
- // other GPUs do not support hardware acceleration
- if ( videoDevice.getModel() == Video.Model.VIRTIO ) {
- videoDevice.set2DAcceleration( accelerationEnabled );
- videoDevice.set3DAcceleration( accelerationEnabled );
+ // only configure hardware acceleration of video card(s) if graphics with hardware acceleration is available
+ if ( acceleratedGraphicsAvailable ) {
+ if ( videoDevices.isEmpty() ) {
+ // add new video device with enabled acceleration to VM configuration
+ Video videoDevice = vmConfig.addVideoDevice();
+ videoDevice.setModel( Video.Model.VIRTIO );
+ videoDevice.set2DAcceleration( true );
+ videoDevice.set3DAcceleration( true );
+ } else {
+ // enable graphic acceleration of existing graphics and video devices
+ for ( Video videoDevice : videoDevices ) {
+ // set hardware acceleration for Virtio GPUs
+ // other GPUs do not support hardware acceleration
+ if ( videoDevice.getModel() == Video.Model.VIRTIO ) {
+ videoDevice.set2DAcceleration( accelerationEnabled );
+ videoDevice.set3DAcceleration( accelerationEnabled );
+ }
}
}
}
}
- }
- @Override
- public DDAcceleration getDDAcceleration()
- {
- ArrayList<Graphics> graphicsDevices = this.vmConfig.getGraphicDevices();
- ArrayList<Video> videoDevices = this.vmConfig.getVideoDevices();
- DDAcceleration accelerationState = DDAcceleration.OFF;
+ @Override
+ public boolean isActive()
+ {
+ ArrayList<Graphics> graphicsDevices = vmConfig.getGraphicDevices();
+ ArrayList<Video> videoDevices = vmConfig.getVideoDevices();
- boolean acceleratedGraphicsAvailable = false;
- boolean acceleratedVideoDevAvailable = false;
+ boolean acceleratedGraphicsAvailable = false;
+ boolean acceleratedVideoDevAvailable = false;
- // search for hardware accelerated graphics
- for ( Graphics graphicDevice : graphicsDevices ) {
- // only SPICE based graphic devices support hardware acceleration
- if ( graphicDevice instanceof GraphicsSpice ) {
- acceleratedGraphicsAvailable = true;
- break;
+ // search for hardware accelerated graphics
+ for ( Graphics graphicDevice : graphicsDevices ) {
+ // only SPICE based graphic devices support hardware acceleration
+ if ( graphicDevice instanceof GraphicsSpice ) {
+ acceleratedGraphicsAvailable = true;
+ break;
+ }
}
- }
- // search for hardware accelerated video devices
- for ( Video videoDevice : videoDevices ) {
- // only Virtio based video devices support hardware acceleration
- if ( videoDevice.getModel() == Video.Model.VIRTIO ) {
- acceleratedVideoDevAvailable = true;
- break;
+ // search for hardware accelerated video devices
+ for ( Video videoDevice : videoDevices ) {
+ // only Virtio based video devices support hardware acceleration
+ if ( videoDevice.getModel() == Video.Model.VIRTIO ) {
+ acceleratedVideoDevAvailable = true;
+ break;
+ }
}
- }
- // hardware acceleration is available if at least one accelerated graphics and video device is available
- if ( acceleratedGraphicsAvailable && acceleratedVideoDevAvailable ) {
- accelerationState = DDAcceleration.ON;
- } else {
- accelerationState = DDAcceleration.OFF;
+ // hardware acceleration is available if at least one accelerated graphics and video device is available
+ if ( acceleratedGraphicsAvailable && acceleratedVideoDevAvailable ) {
+ return this.id.equals( "true" );
+ } else {
+ return this.id.equals( "false" );
+ }
}
-
- return accelerationState;
+
}
@Override
@@ -716,77 +536,136 @@ public class VirtualizationConfigurationQemu extends
return checkedVersion;
}
- @Override
- public void setEthernetDevType( int cardIndex, EthernetDevType type )
+ class QemuNicModel extends AbstractConfigurableOption
{
- QemuEthernetDevTypeMeta networkDeviceConfig = this.networkCards.get( type );
- ArrayList<Interface> networkDevices = this.vmConfig.getInterfaceDevices();
- Interface networkDevice = VirtualizationConfigurationQemuUtils.getArrayIndex( networkDevices, cardIndex );
- Interface.Model networkDeviceModel = networkDeviceConfig.getModel();
+
+ private final int cardIndex;
- if ( networkDevice != null ) {
- networkDevice.setModel( networkDeviceModel );
+ public QemuNicModel( int cardIndex, Interface.Model model, String displayName )
+ {
+ super( model.toString(), displayName ); // XXX: toString/fromString would disappear if
+ this.cardIndex = cardIndex; // this were AbstractConfigurableOption<T extends Enum<T>>
}
- }
- @Override
- public EthernetDevType getEthernetDevType( int cardIndex )
- {
- ArrayList<Interface> networkDevices = this.vmConfig.getInterfaceDevices();
- Interface networkDevice = VirtualizationConfigurationQemuUtils.getArrayIndex( networkDevices, cardIndex );
- EthernetDevType networkDeviceType = EthernetDevType.NONE;
+ @Override
+ public void apply()
+ {
+ ArrayList<Interface> networkDevices = vmConfig.getInterfaceDevices();
+ Interface networkDevice = VirtualizationConfigurationQemuUtils.getArrayIndex( networkDevices, cardIndex );
- if ( networkDevice == null ) {
- // network interface device is not present
- networkDeviceType = EthernetDevType.NONE;
- } else {
+ if ( networkDevice != null ) {
+ networkDevice.setModel( Interface.Model.fromString( id ) );
+ }
+ }
+
+ @Override
+ public boolean isActive()
+ {
+ ArrayList<Interface> networkDevices = vmConfig.getInterfaceDevices();
+ Interface networkDevice = VirtualizationConfigurationQemuUtils.getArrayIndex( networkDevices, cardIndex );
+
+ if ( networkDevice == null ) {
+ // network interface device is not present
+ return Util.isEmptyString( this.id ); // XXX: would be more explicit with enum.NONE
+ }
// get model of existing network interface device
Interface.Model networkDeviceModel = networkDevice.getModel();
- networkDeviceType = VirtualizationConfigurationQemuUtils.convertNetworkDeviceModel( networkDeviceModel );
+ if ( networkDeviceModel == null ) {
+ return Util.isEmptyString( this.id ); // see above
+ }
+ // Success
+ return networkDeviceModel.toString().equals( this.id ); // XXX: enum would allow simple ==
}
-
- return networkDeviceType;
}
-
- @Override
- public void setMaxUsbSpeed( UsbSpeed speed )
+
+ class QemuSoundCardModel extends AbstractConfigurableOption
{
- QemuUsbSpeedMeta usbControllerConfig = this.usbSpeeds.get( speed );
- ArrayList<ControllerUsb> usbControllerDevices = this.vmConfig.getUsbControllerDevices();
- ControllerUsb.Model usbControllerModel = usbControllerConfig.getModel();
- if ( usbControllerDevices.isEmpty() ) {
- // add new USB controller with specified speed 'usbControllerModel'
- ControllerUsb usbControllerDevice = this.vmConfig.addControllerUsbDevice();
- usbControllerDevice.setModel( usbControllerModel );
- } else {
- // update model of all USB controller devices to support the maximum speed
- for ( ControllerUsb usbControllerDevice : usbControllerDevices ) {
- usbControllerDevice.setModel( usbControllerModel );
+ public QemuSoundCardModel( Sound.Model id, String displayName )
+ {
+ super( id.toString(), displayName );
+ }
+
+ @Override
+ public void apply()
+ {
+ ArrayList<Sound> soundDevices = vmConfig.getSoundDevices();
+ Sound.Model soundDeviceModel = Sound.Model.fromString( this.id );
+
+ if ( soundDevices.isEmpty() ) {
+ // create new sound device with 'soundDeviceModel' hardware
+ Sound soundDevice = vmConfig.addSoundDevice();
+ soundDevice.setModel( soundDeviceModel );
+ } else {
+ // update sound device model type of existing sound devices
+ for ( Sound soundDevice : soundDevices ) {
+ soundDevice.setModel( soundDeviceModel );
+ }
}
}
- }
- @Override
- public UsbSpeed getMaxUsbSpeed()
+ @Override
+ public boolean isActive()
+ {
+ ArrayList<Sound> soundDevices = vmConfig.getSoundDevices();
+
+ if ( soundDevices.isEmpty() ) {
+ // the VM configuration does not contain a sound card device
+ return Util.isEmptyString( this.id );
+ }
+ // the VM configuration at least one sound card device, so return the type of the first one
+ Sound.Model soundDeviceModel = soundDevices.get( 0 ).getModel();
+ return soundDeviceModel != null && soundDeviceModel.toString().equals( this.id );
+ }
+
+ }
+
+ class QemuUsbSpeed extends AbstractConfigurableOption
{
- ArrayList<ControllerUsb> usbControllerDevices = this.vmConfig.getUsbControllerDevices();
- UsbSpeed maxUsbSpeed = VirtualizationConfiguration.UsbSpeed.NONE;
- int maxUsbSpeedNumeric = 0;
- for ( ControllerUsb usbControllerDevice : usbControllerDevices ) {
- ControllerUsb.Model usbControllerModel = usbControllerDevice.getModel();
+ public QemuUsbSpeed( ControllerUsb.Model id, String displayName )
+ {
+ super( id.toString(), displayName );
+ }
+
+ @Override
+ public void apply()
+ {
+ ArrayList<ControllerUsb> usbControllerDevices = vmConfig.getUsbControllerDevices();
+ ControllerUsb.Model usbControllerModel = ControllerUsb.Model.fromString( this.id );
- for ( Entry<UsbSpeed, QemuUsbSpeedMeta> usbSpeedEntry : this.usbSpeeds.entrySet() ) {
- QemuUsbSpeedMeta usbSpeed = usbSpeedEntry.getValue();
- if ( usbSpeed.getSpeed() > maxUsbSpeedNumeric && usbSpeed.getModel() == usbControllerModel ) {
- maxUsbSpeed = usbSpeedEntry.getKey();
- maxUsbSpeedNumeric = usbSpeed.getSpeed();
+ if ( usbControllerDevices.isEmpty() ) {
+ // add new USB controller with specified speed 'usbControllerModel'
+ ControllerUsb usbControllerDevice = vmConfig.addControllerUsbDevice();
+ usbControllerDevice.setModel( usbControllerModel );
+ } else {
+ // update model of all USB controller devices to support the maximum speed
+ for ( ControllerUsb usbControllerDevice : usbControllerDevices ) {
+ usbControllerDevice.setModel( usbControllerModel );
}
}
}
- return maxUsbSpeed;
+ @Override
+ public boolean isActive()
+ {
+ ArrayList<ControllerUsb> usbControllerDevices = vmConfig.getUsbControllerDevices();
+ String maxUsbSpeed = null;
+ int maxUsbSpeedNumeric = 0;
+
+ for ( ControllerUsb usbControllerDevice : usbControllerDevices ) {
+ ControllerUsb.Model usbControllerModel = usbControllerDevice.getModel();
+
+ // TODO Need something to map from chip to usb speed. But this is conceptually broken anyways since
+ // it's modeled after vmware, where you only cannot configure different controllers at the same time
+ // anyways XXX
+ if ( usbControllerModel.toString().equals( this.id ) )
+ return true;
+ }
+
+ return false;
+ }
+
}
@Override
@@ -821,11 +700,10 @@ public class VirtualizationConfigurationQemu extends
*/
public boolean addEthernet( int index, EtherType type )
{
- QemuEthernetDevTypeMeta defaultNetworkDeviceConfig = this.networkCards.get( EthernetDevType.AUTO );
ArrayList<Interface> interfaceDevices = this.vmConfig.getInterfaceDevices();
Interface interfaceDevice = VirtualizationConfigurationQemuUtils.getArrayIndex( interfaceDevices, index );
- final Interface.Model defaultNetworkDeviceModel = defaultNetworkDeviceConfig.getModel();
+ final Interface.Model defaultNetworkDeviceModel = Interface.Model.VIRTIO_NET_PCI;
if ( interfaceDevice == null ) {
// network interface device does not exist, so create new network interface device
@@ -886,29 +764,40 @@ public class VirtualizationConfigurationQemu extends
@Override
public void registerVirtualHW()
{
+ // XXX Add missing qemu-only types/models
+ List<AbstractConfigurableOption> list;
// @formatter:off
- soundCards.put( VirtualizationConfiguration.SoundCardType.NONE, new QemuSoundCardMeta( null ) );
- soundCards.put( VirtualizationConfiguration.SoundCardType.DEFAULT, new QemuSoundCardMeta( Sound.Model.ICH9 ) );
- soundCards.put( VirtualizationConfiguration.SoundCardType.SOUND_BLASTER, new QemuSoundCardMeta( Sound.Model.SB16 ) );
- soundCards.put( VirtualizationConfiguration.SoundCardType.ES, new QemuSoundCardMeta( Sound.Model.ES1370 ) );
- soundCards.put( VirtualizationConfiguration.SoundCardType.AC, new QemuSoundCardMeta( Sound.Model.AC97 ) );
- soundCards.put( VirtualizationConfiguration.SoundCardType.HD_AUDIO, new QemuSoundCardMeta( Sound.Model.ICH9 ) );
-
- ddacc.put( VirtualizationConfiguration.DDAcceleration.OFF, new QemuDDAccelMeta( false ) );
- ddacc.put( VirtualizationConfiguration.DDAcceleration.ON, new QemuDDAccelMeta( true ) );
-
- networkCards.put( VirtualizationConfiguration.EthernetDevType.NONE, new QemuEthernetDevTypeMeta( null ) );
- networkCards.put( VirtualizationConfiguration.EthernetDevType.AUTO, new QemuEthernetDevTypeMeta( Interface.Model.VIRTIO_NET_PCI ) );
- networkCards.put( VirtualizationConfiguration.EthernetDevType.PCNETPCI2, new QemuEthernetDevTypeMeta( Interface.Model.PCNET ) );
- networkCards.put( VirtualizationConfiguration.EthernetDevType.E1000, new QemuEthernetDevTypeMeta( Interface.Model.E1000 ) );
- networkCards.put( VirtualizationConfiguration.EthernetDevType.E1000E, new QemuEthernetDevTypeMeta( Interface.Model.E1000E ) );
- networkCards.put( VirtualizationConfiguration.EthernetDevType.VMXNET3, new QemuEthernetDevTypeMeta( Interface.Model.VMXNET3 ) );
- networkCards.put( VirtualizationConfiguration.EthernetDevType.PARAVIRT, new QemuEthernetDevTypeMeta( Interface.Model.VIRTIO_NET_PCI ) );
-
- usbSpeeds.put( VirtualizationConfiguration.UsbSpeed.NONE, new QemuUsbSpeedMeta( 0, ControllerUsb.Model.NONE ) );
- usbSpeeds.put( VirtualizationConfiguration.UsbSpeed.USB1_1, new QemuUsbSpeedMeta( 1, ControllerUsb.Model.ICH9_UHCI1 ) );
- usbSpeeds.put( VirtualizationConfiguration.UsbSpeed.USB2_0, new QemuUsbSpeedMeta( 2, ControllerUsb.Model.ICH9_EHCI1 ) );
- usbSpeeds.put( VirtualizationConfiguration.UsbSpeed.USB3_0, new QemuUsbSpeedMeta( 3, ControllerUsb.Model.QEMU_XHCI ) );
+ list = new ArrayList<>();
+ //list.add( new QemuSoundCardModel( Sound.Model.NONE, SoundCard.NONE ) ); // XXX TODO
+ list.add( new QemuSoundCardModel( Sound.Model.ICH9, SoundCard.DEFAULT ) );
+ list.add( new QemuSoundCardModel( Sound.Model.SB16, SoundCard.SOUND_BLASTER ) );
+ list.add( new QemuSoundCardModel( Sound.Model.ES1370, SoundCard.ES ) );
+ list.add( new QemuSoundCardModel( Sound.Model.AC97, SoundCard.AC ) );
+ list.add( new QemuSoundCardModel( Sound.Model.ICH9, SoundCard.HD_AUDIO ) );
+ configurableOptions.add( new ConfigurableOptionGroup( ConfigurationGroups.SOUND_CARD_MODEL, list ) );
+
+ list = new ArrayList<>();
+ // XXX This would greatly benefit from having more meaningful options for qemu instead of on/off
+ list.add( new QemuGfxType( "false", "langsam" ) );
+ list.add( new QemuGfxType( "true", "3D OpenGL" ) );
+ configurableOptions.add( new ConfigurableOptionGroup( ConfigurationGroups.GFX_TYPE, list ) );
+
+ list = new ArrayList<>();
+ // XXX Represent NONE; can add missing models now with new approach (add human readable strings)
+ list.add( new QemuNicModel( 0, Interface.Model.VIRTIO, Ethernet.AUTO ) );
+ list.add( new QemuNicModel( 0, Interface.Model.PCNET, Ethernet.PCNETPCI2 ) );
+ list.add( new QemuNicModel( 0, Interface.Model.E1000, Ethernet.E1000 ) );
+ list.add( new QemuNicModel( 0, Interface.Model.E1000E, Ethernet.E1000E ) );
+ list.add( new QemuNicModel( 0, Interface.Model.VMXNET3, Ethernet.VMXNET3 ) );
+ list.add( new QemuNicModel( 0, Interface.Model.VIRTIO_NET_PCI, Ethernet.PARAVIRT ) );
+ configurableOptions.add( new ConfigurableOptionGroup( ConfigurationGroups.NIC_MODEL, list ) );
+
+ list = new ArrayList<>();
+ list.add( new QemuUsbSpeed( ControllerUsb.Model.NONE, Usb.NONE ) );
+ list.add( new QemuUsbSpeed( ControllerUsb.Model.ICH9_UHCI1, Usb.USB1_1 ) );
+ list.add( new QemuUsbSpeed( ControllerUsb.Model.ICH9_EHCI1, Usb.USB2_0 ) );
+ list.add( new QemuUsbSpeed( ControllerUsb.Model.QEMU_XHCI, Usb.USB3_0 ) );
+ configurableOptions.add( new ConfigurableOptionGroup( ConfigurationGroups.USB_SPEED, list ) );
// @formatter:on
}
diff --git a/src/main/java/org/openslx/virtualization/configuration/VirtualizationConfigurationQemuUtils.java b/src/main/java/org/openslx/virtualization/configuration/VirtualizationConfigurationQemuUtils.java
index 5d74d0d..06091c0 100644
--- a/src/main/java/org/openslx/virtualization/configuration/VirtualizationConfigurationQemuUtils.java
+++ b/src/main/java/org/openslx/virtualization/configuration/VirtualizationConfigurationQemuUtils.java
@@ -5,13 +5,9 @@ import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.openslx.libvirt.domain.device.Disk;
-import org.openslx.libvirt.domain.device.Interface;
import org.openslx.libvirt.domain.device.Disk.BusType;
import org.openslx.virtualization.Version;
import org.openslx.virtualization.configuration.VirtualizationConfiguration.DriveBusType;
-import org.openslx.virtualization.configuration.VirtualizationConfiguration.EthernetDevType;
-import org.openslx.virtualization.configuration.VirtualizationConfiguration.SoundCardType;
-import org.openslx.libvirt.domain.device.Sound;
/**
* Collection of utils to convert data types from bwLehrpool to Libvirt and vice versa.
@@ -83,80 +79,6 @@ public class VirtualizationConfigurationQemuUtils
}
/**
- * Converts a Libvirt sound device model to a VM metadata sound card type.
- *
- * @param soundDeviceModel Libvirt sound device model.
- * @return VM metadata sound card type.
- */
- public static SoundCardType convertSoundDeviceModel( Sound.Model soundDeviceModel )
- {
- SoundCardType type = SoundCardType.NONE;
-
- switch ( soundDeviceModel ) {
- case AC97:
- type = SoundCardType.AC;
- break;
- case ES1370:
- type = SoundCardType.ES;
- break;
- case ICH6:
- type = SoundCardType.HD_AUDIO;
- break;
- case ICH9:
- type = SoundCardType.HD_AUDIO;
- break;
- case SB16:
- type = SoundCardType.SOUND_BLASTER;
- break;
- }
-
- return type;
- }
-
- /**
- * Converts a Libvirt network device model to a VM metadata ethernet device type.
- *
- * @param networkDeviceModel Libvirt network device model.
- * @return VM metadata ethernet device type.
- */
- public static EthernetDevType convertNetworkDeviceModel( Interface.Model networkDeviceModel )
- {
- EthernetDevType type = EthernetDevType.NONE;
-
- switch ( networkDeviceModel ) {
- case E1000:
- type = EthernetDevType.E1000;
- break;
- case E1000E:
- type = EthernetDevType.E1000E;
- break;
- case PCNET:
- type = EthernetDevType.PCNETPCI2;
- break;
- case VIRTIO:
- type = EthernetDevType.PARAVIRT;
- break;
- case VIRTIO_NET_PCI:
- type = EthernetDevType.PARAVIRT;
- break;
- case VIRTIO_NET_PCI_NON_TRANSITIONAL:
- type = EthernetDevType.PARAVIRT;
- break;
- case VIRTIO_NET_PCI_TRANSITIONAL:
- type = EthernetDevType.PARAVIRT;
- break;
- case VMXNET3:
- type = EthernetDevType.VMXNET3;
- break;
- default:
- type = EthernetDevType.AUTO;
- break;
- }
-
- return type;
- }
-
- /**
* Returns an item from a given {@link ArrayList}.
*
* The item is selected by a given index. If the item is not available within the
diff --git a/src/main/java/org/openslx/virtualization/configuration/VirtualizationConfigurationVirtualBox.java b/src/main/java/org/openslx/virtualization/configuration/VirtualizationConfigurationVirtualBox.java
index 4715daf..219a3f1 100644
--- a/src/main/java/org/openslx/virtualization/configuration/VirtualizationConfigurationVirtualBox.java
+++ b/src/main/java/org/openslx/virtualization/configuration/VirtualizationConfigurationVirtualBox.java
@@ -5,70 +5,29 @@ import java.io.IOException;
import java.io.RandomAccessFile;
import java.nio.ByteBuffer;
import java.nio.charset.StandardCharsets;
+import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
-import java.util.Map.Entry;
import java.util.UUID;
import org.apache.log4j.Logger;
import org.openslx.bwlp.thrift.iface.OperatingSystem;
import org.openslx.thrifthelper.TConst;
+import org.openslx.util.Util;
import org.openslx.virtualization.Version;
import org.openslx.virtualization.configuration.VirtualizationConfigurationVirtualboxFileFormat.PlaceHolder;
+import org.openslx.virtualization.hardware.AbstractConfigurableOption;
+import org.openslx.virtualization.hardware.ConfigurationGroups;
+import org.openslx.virtualization.hardware.Ethernet;
+import org.openslx.virtualization.hardware.SoundCard;
+import org.openslx.virtualization.hardware.Usb;
import org.openslx.virtualization.virtualizer.VirtualizerVirtualBox;
import org.w3c.dom.Attr;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
-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 VBoxEthernetDevTypeMeta
-{
- public final String value;
- public final boolean isPresent;
-
- public VBoxEthernetDevTypeMeta( boolean present, String val )
- {
- value = val;
- isPresent = present;
- }
-}
-
-class VBoxUsbSpeedMeta
-{
- public final String value;
- public final int speed;
-
- public VBoxUsbSpeedMeta( String value, int speed )
- {
- this.value = value;
- this.speed = speed;
- }
-}
-
-public class VirtualizationConfigurationVirtualBox
- extends VirtualizationConfiguration<VBoxSoundCardMeta, VBoxDDAccelMeta, VBoxEthernetDevTypeMeta, VBoxUsbSpeedMeta>
+public class VirtualizationConfigurationVirtualBox extends VirtualizationConfiguration
{
/**
* File name extension for VirtualBox virtualization configuration files..
@@ -349,69 +308,69 @@ public class VirtualizationConfigurationVirtualBox
{
return config.changeAttribute( "/VirtualBox/Machine/Hardware/CPU", "count", Integer.toString( nrOfCores ) );
}
-
- @Override
- public void setSoundCard( org.openslx.virtualization.configuration.VirtualizationConfiguration.SoundCardType type )
+
+ class VBoxSoundCardModel extends AbstractConfigurableOption
{
- VBoxSoundCardMeta sound = soundCards.get( type );
- config.changeAttribute( "/VirtualBox/Machine/Hardware/AudioAdapter", "enabled",
- Boolean.toString( sound.isPresent ) );
- config.changeAttribute( "/VirtualBox/Machine/Hardware/AudioAdapter", "controller", sound.value );
- }
- @Override
- public VirtualizationConfiguration.SoundCardType getSoundCard()
- {
- // initialize here to type None to avoid all null pointer exceptions thrown for unknown user written sound cards
- VirtualizationConfiguration.SoundCardType returnsct = VirtualizationConfiguration.SoundCardType.NONE;
- Element x = (Element)config.findNodes( "/VirtualBox/Machine/Hardware/AudioAdapter" ).item( 0 );
- if ( !x.hasAttribute( "enabled" )
- || ( x.hasAttribute( "enabled" ) && x.getAttribute( "enabled" ).equals( "false" ) ) ) {
- return returnsct;
- } else {
- // extra separate case for the non-existing argument}
- if ( !x.hasAttribute( "controller" ) ) {
- returnsct = VirtualizationConfiguration.SoundCardType.AC;
- } else {
- String controller = x.getAttribute( "controller" );
- VBoxSoundCardMeta soundMeta = null;
- for ( VirtualizationConfiguration.SoundCardType type : VirtualizationConfiguration.SoundCardType
- .values() ) {
- soundMeta = soundCards.get( type );
- if ( soundMeta != null ) {
- if ( controller.equals( soundMeta.value ) ) {
- returnsct = type;
- }
- }
- }
+ public VBoxSoundCardModel( String id, String displayName )
+ {
+ super( id, displayName );
+ }
+
+ @Override
+ public void apply()
+ {
+ // XXX I guess this "present" hack will be nicer with enum too
+ if ( Util.isEmptyString( this.id ) ) {
+ config.changeAttribute( "/VirtualBox/Machine/Hardware/AudioAdapter", "enabled", "false" );
+ return;
}
+ config.changeAttribute( "/VirtualBox/Machine/Hardware/AudioAdapter", "enabled", "true" );
+ config.changeAttribute( "/VirtualBox/Machine/Hardware/AudioAdapter", "controller", this.id );
}
- return returnsct;
- }
- @Override
- public void setDDAcceleration( VirtualizationConfiguration.DDAcceleration type )
- {
- VBoxDDAccelMeta accel = ddacc.get( type );
- config.changeAttribute( "/VirtualBox/Machine/Hardware/Display", "accelerate3D",
- Boolean.toString( accel.isPresent ) );
+ @Override
+ public boolean isActive()
+ {
+ Element x = (Element)config.findNodes( "/VirtualBox/Machine/Hardware/AudioAdapter" ).item( 0 );
+ if ( !x.hasAttribute( "enabled" )
+ || ( x.hasAttribute( "enabled" ) && x.getAttribute( "enabled" ).equals( "false" ) ) ) {
+ return Util.isEmptyString( this.id ); // XXX enum
+ }
+ String val = "AC97";
+ if ( x.hasAttribute( "controller" ) ) {
+ val = x.getAttribute( "controller" );
+ }
+ return val.equals( this.id );
+ }
+
}
-
- @Override
- public VirtualizationConfiguration.DDAcceleration getDDAcceleration()
+
+ class VBoxAccel3D extends AbstractConfigurableOption
{
- VirtualizationConfiguration.DDAcceleration returndda = null;
- Element x = (Element)config.findNodes( "/VirtualBox/Machine/Hardware/Display" ).item( 0 );
- if ( x.hasAttribute( "accelerate3D" ) ) {
- if ( x.getAttribute( "accelerate3D" ).equals( "true" ) ) {
- returndda = VirtualizationConfiguration.DDAcceleration.ON;
- } else {
- returndda = VirtualizationConfiguration.DDAcceleration.OFF;
+
+ public VBoxAccel3D( String id, String displayName )
+ {
+ super( id, displayName );
+ }
+
+ @Override
+ public void apply()
+ {
+ config.changeAttribute( "/VirtualBox/Machine/Hardware/Display", "accelerate3D", this.id );
+ }
+
+ @Override
+ public boolean isActive()
+ {
+ Element x = (Element)config.findNodes( "/VirtualBox/Machine/Hardware/Display" ).item( 0 );
+ String val = "false";
+ if ( x.hasAttribute( "accelerate3D" ) ) {
+ val = x.getAttribute( "accelerate3D" );
}
- } else {
- returndda = VirtualizationConfiguration.DDAcceleration.OFF;
+ return val.equalsIgnoreCase( this.id );
}
- return returndda;
+
}
/**
@@ -434,80 +393,86 @@ public class VirtualizationConfigurationVirtualBox
// Virtual Box uses only one virtual hardware version and can't be changed
return null;
}
-
- @Override
- public void setEthernetDevType( int cardIndex, EthernetDevType type )
+
+ class VBoxNicModel extends AbstractConfigurableOption
{
- String index = "0";
- VBoxEthernetDevTypeMeta nic = networkCards.get( type );
- // cardIndex is not used yet...maybe later needed for different network cards
- config.changeAttribute( "/VirtualBox/Machine/Hardware/Network/Adapter[@slot='" + index + "']", "enabled",
- Boolean.toString( nic.isPresent ) );
- config.changeAttribute( "/VirtualBox/Machine/Hardware/Network/Adapter[@slot='" + index + "']", "type",
- nic.value );
- }
+
+ private final int cardIndex;
- @Override
- public VirtualizationConfiguration.EthernetDevType getEthernetDevType( int cardIndex )
- {
- VirtualizationConfiguration.EthernetDevType returnedt = VirtualizationConfiguration.EthernetDevType.NONE;
- Element x = (Element)config.findNodes( "/VirtualBox/Machine/Hardware/Network/Adapter" ).item( 0 );
- if ( !x.hasAttribute( "enabled" )
- || ( x.hasAttribute( "enabled" ) && x.getAttribute( "enabled" ).equals( "false" ) ) ) {
- return returnedt;
- } else {
- // extra separate case for the non-existing argument}
+ public VBoxNicModel( int cardIndex, String id, String displayName )
+ {
+ super( id, displayName );
+ this.cardIndex = cardIndex;
+ }
+
+ @Override
+ public void apply()
+ {
+ String index = Integer.toString( this.cardIndex );
+ String dev = this.id;
+ boolean present = true;
+ if ( "".equals( this.id ) ) {
+ // 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
+ dev = "Am79C970A";
+ present = false;
+ }
+ config.changeAttribute( "/VirtualBox/Machine/Hardware/Network/Adapter[@slot='" + index + "']", "enabled",
+ Boolean.toString( present ) );
+ config.changeAttribute( "/VirtualBox/Machine/Hardware/Network/Adapter[@slot='" + index + "']", "type",
+ dev );
+ }
+
+ @Override
+ public boolean isActive()
+ {
+ Element x = (Element)config.findNodes( "/VirtualBox/Machine/Hardware/Network/Adapter" ).item( 0 );
+ if ( !x.hasAttribute( "enabled" )
+ || ( x.hasAttribute( "enabled" ) && x.getAttribute( "enabled" ).equalsIgnoreCase( "false" ) ) ) {
+ return Util.isEmptyString( this.id );
+ }
+ // Has NIC
if ( !x.hasAttribute( "type" ) ) {
- returnedt = VirtualizationConfiguration.EthernetDevType.PCNETFAST3;
- } else {
- String temp = x.getAttribute( "type" );
- VBoxEthernetDevTypeMeta etherMeta = null;
- for ( VirtualizationConfiguration.EthernetDevType type : VirtualizationConfiguration.EthernetDevType
- .values() ) {
- etherMeta = networkCards.get( type );
- if ( etherMeta != null ) {
- if ( temp.equals( etherMeta.value ) ) {
- returnedt = type;
- }
- }
- }
+ return "Am79C973".equals( this.id );
}
+ return x.getAttribute( "type" ).equals( this.id );
}
- return returnedt;
+
}
public void registerVirtualHW()
{
+ List<AbstractConfigurableOption> list;
// none type needs to have a valid value; it takes the value of AC97; if value is left null or empty vm will not start because value is not valid
// TODO: Maybe just remove the entire section from the XML? Same for ethernet...
- soundCards.put( VirtualizationConfiguration.SoundCardType.NONE, new VBoxSoundCardMeta( false, "AC97" ) );
- soundCards.put( VirtualizationConfiguration.SoundCardType.SOUND_BLASTER, new VBoxSoundCardMeta( true, "SB16" ) );
- soundCards.put( VirtualizationConfiguration.SoundCardType.HD_AUDIO, new VBoxSoundCardMeta( true, "HDA" ) );
- soundCards.put( VirtualizationConfiguration.SoundCardType.AC, new VBoxSoundCardMeta( true, "AC97" ) );
-
- ddacc.put( VirtualizationConfiguration.DDAcceleration.OFF, new VBoxDDAccelMeta( false ) );
- ddacc.put( VirtualizationConfiguration.DDAcceleration.ON, new VBoxDDAccelMeta( true ) );
-
- // 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
- networkCards.put( VirtualizationConfiguration.EthernetDevType.NONE,
- new VBoxEthernetDevTypeMeta( false, "Am79C970A" ) );
- networkCards.put( VirtualizationConfiguration.EthernetDevType.PCNETPCI2,
- new VBoxEthernetDevTypeMeta( true, "Am79C970A" ) );
- networkCards.put( VirtualizationConfiguration.EthernetDevType.PCNETFAST3,
- new VBoxEthernetDevTypeMeta( true, "Am79C973" ) );
- networkCards.put( VirtualizationConfiguration.EthernetDevType.PRO1000MTD,
- new VBoxEthernetDevTypeMeta( true, "82540EM" ) );
- networkCards.put( VirtualizationConfiguration.EthernetDevType.PRO1000TS,
- new VBoxEthernetDevTypeMeta( true, "82543GC" ) );
- networkCards.put( VirtualizationConfiguration.EthernetDevType.PRO1000MTS,
- new VBoxEthernetDevTypeMeta( true, "82545EM" ) );
- networkCards.put( VirtualizationConfiguration.EthernetDevType.PARAVIRT,
- new VBoxEthernetDevTypeMeta( true, "virtio" ) );
-
- usbSpeeds.put( VirtualizationConfiguration.UsbSpeed.NONE, new VBoxUsbSpeedMeta( null, 0 ) );
- usbSpeeds.put( VirtualizationConfiguration.UsbSpeed.USB1_1, new VBoxUsbSpeedMeta( "OHCI", 1 ) );
- usbSpeeds.put( VirtualizationConfiguration.UsbSpeed.USB2_0, new VBoxUsbSpeedMeta( "EHCI", 2 ) );
- usbSpeeds.put( VirtualizationConfiguration.UsbSpeed.USB3_0, new VBoxUsbSpeedMeta( "XHCI", 3 ) );
+ list = new ArrayList<>();
+ list.add( new VBoxSoundCardModel( "AC97", SoundCard.NONE ) );
+ list.add( new VBoxSoundCardModel( "SB16", SoundCard.SOUND_BLASTER ) );
+ list.add( new VBoxSoundCardModel( "HDA", SoundCard.HD_AUDIO ) );
+ list.add( new VBoxSoundCardModel( "AC97", SoundCard.AC ) );
+ configurableOptions.add( new ConfigurableOptionGroup( ConfigurationGroups.SOUND_CARD_MODEL, list ) );
+
+ list = new ArrayList<>();
+ list.add( new VBoxAccel3D( "true", "3D" ) );
+ list.add( new VBoxAccel3D( "false", "2D" ) );
+ configurableOptions.add( new ConfigurableOptionGroup( ConfigurationGroups.GFX_TYPE, list ) );
+
+ list = new ArrayList<>();
+ list.add( new VBoxNicModel( 0, "", Ethernet.NONE ) );
+ list.add( new VBoxNicModel( 0, "Am79C970A", Ethernet.PCNETPCI2 ) );
+ list.add( new VBoxNicModel( 0, "Am79C973", Ethernet.PCNETFAST3 ) );
+ list.add( new VBoxNicModel( 0, "82540EM", Ethernet.PRO1000MTD ) );
+ list.add( new VBoxNicModel( 0, "82543GC", Ethernet.PRO1000TS ) );
+ list.add( new VBoxNicModel( 0, "82545EM", Ethernet.PRO1000MTS ) );
+ list.add( new VBoxNicModel( 0, "virtio", Ethernet.PARAVIRT ) );
+ configurableOptions.add( new ConfigurableOptionGroup( ConfigurationGroups.NIC_MODEL, list ) );
+
+ list = new ArrayList<>();
+ list.add( new VBoxUsbSpeed( null, Usb.NONE ) );
+ list.add( new VBoxUsbSpeed( "OHCI", Usb.USB1_1 ) );
+ list.add( new VBoxUsbSpeed( "EHCI", Usb.USB2_0 ) );
+ list.add( new VBoxUsbSpeed( "XHCI", Usb.USB3_0 ) );
+ configurableOptions.add( new ConfigurableOptionGroup( ConfigurationGroups.USB_SPEED, list ) );
}
@Override
@@ -540,51 +505,56 @@ public class VirtualizationConfigurationVirtualBox
this.removeEnhancedNetworkAdapters();
}
-
- @Override
- public void setMaxUsbSpeed( VirtualizationConfiguration.UsbSpeed speed )
+
+ class VBoxUsbSpeed extends AbstractConfigurableOption
{
- // Wipe existing ones
- config.removeNodes( "/VirtualBox/Machine/Hardware", "USB" );
- if ( speed == null || speed == VirtualizationConfiguration.UsbSpeed.NONE ) {
- // Add marker so we know it's not an old config and we really want no USB
- Element node = config.createNodeRecursive( "/VirtualBox/OpenSLX/USB" );
- if ( node != null ) {
- node.setAttribute( "disabled", "true" );
- }
- return; // NO USB
- }
- Element node = config.createNodeRecursive( "/VirtualBox/Machine/Hardware/USB/Controllers/Controller" );
- VBoxUsbSpeedMeta vboxSpeed = usbSpeeds.get( speed );
- node.setAttribute( "type", vboxSpeed.value );
- node.setAttribute( "name", vboxSpeed.value );
- if ( speed == UsbSpeed.USB2_0 ) {
- // If EHCI (2.0) is selected, VBox adds an OHCI controller too...
- node.setAttribute( "type", "OHCI" );
- node.setAttribute( "name", "OHCI" );
+
+ public VBoxUsbSpeed( String id, String displayName )
+ {
+ super( id, displayName );
}
- }
- @Override
- public VirtualizationConfiguration.UsbSpeed getMaxUsbSpeed()
- {
- NodeList nodes = config.findNodes( "/VirtualBox/Machine/Hardware/USB/Controllers/Controller/@type" );
- int maxSpeed = 0;
- VirtualizationConfiguration.UsbSpeed maxItem = VirtualizationConfiguration.UsbSpeed.NONE;
- for ( int i = 0; i < nodes.getLength(); ++i ) {
- if ( nodes.item( i ).getNodeType() != Node.ATTRIBUTE_NODE ) {
- LOGGER.info( "Not ATTRIBUTE type" );
- continue;
+ @Override
+ public void apply()
+ {
+ // Wipe existing ones
+ config.removeNodes( "/VirtualBox/Machine/Hardware", "USB" );
+ if ( Util.isEmptyString( this.id ) ) {
+ // Add marker so we know it's not an old config and we really want no USB
+ Element node = config.createNodeRecursive( "/VirtualBox/OpenSLX/USB" );
+ if ( node != null ) {
+ node.setAttribute( "disabled", "true" );
+ }
+ return; // NO USB
}
- String type = ( (Attr)nodes.item( i ) ).getValue();
- for ( Entry<VirtualizationConfiguration.UsbSpeed, VBoxUsbSpeedMeta> s : usbSpeeds.entrySet() ) {
- if ( s.getValue().speed > maxSpeed && type.equals( s.getValue().value ) ) {
- maxSpeed = s.getValue().speed;
- maxItem = s.getKey();
+ Element node = config.createNodeRecursive( "/VirtualBox/Machine/Hardware/USB/Controllers/Controller" );
+ node.setAttribute( "type", this.id );
+ node.setAttribute( "name", this.id );
+ if ( this.id.equals( "EHCI" ) ) { // XXX "mechanically" ported, could make a special class for this special case
+ // If EHCI (2.0) is selected, VBox adds an OHCI controller too...
+ // XXX Isn't this broken anyways, it's working on the same node as above *facepalm*
+ node.setAttribute( "type", "OHCI" );
+ node.setAttribute( "name", "OHCI" );
+ }
+ }
+
+ @Override
+ public boolean isActive()
+ {
+ // XXX not technically correct wrt max speed
+ NodeList nodes = config.findNodes( "/VirtualBox/Machine/Hardware/USB/Controllers/Controller/@type" );
+ for ( int i = 0; i < nodes.getLength(); ++i ) {
+ if ( nodes.item( i ).getNodeType() != Node.ATTRIBUTE_NODE ) {
+ LOGGER.info( "Not ATTRIBUTE type" );
+ continue;
}
+ String type = ( (Attr)nodes.item( i ) ).getValue();
+ if ( type.equals( this.id ) )
+ return true;
}
+ return Util.isEmptyString( this.id );
}
- return maxItem;
+
}
@Override
diff --git a/src/main/java/org/openslx/virtualization/configuration/VirtualizationConfigurationVmware.java b/src/main/java/org/openslx/virtualization/configuration/VirtualizationConfigurationVmware.java
index 2c2013a..5365416 100644
--- a/src/main/java/org/openslx/virtualization/configuration/VirtualizationConfigurationVmware.java
+++ b/src/main/java/org/openslx/virtualization/configuration/VirtualizationConfigurationVmware.java
@@ -3,6 +3,7 @@ package org.openslx.virtualization.configuration;
import java.io.File;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
+import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
@@ -17,54 +18,14 @@ import org.openslx.thrifthelper.TConst;
import org.openslx.util.Util;
import org.openslx.virtualization.Version;
import org.openslx.virtualization.configuration.VirtualizationConfigurationVmwareFileFormat.ConfigEntry;
+import org.openslx.virtualization.hardware.AbstractConfigurableOption;
+import org.openslx.virtualization.hardware.ConfigurationGroups;
+import org.openslx.virtualization.hardware.Ethernet;
+import org.openslx.virtualization.hardware.SoundCard;
+import org.openslx.virtualization.hardware.Usb;
import org.openslx.virtualization.virtualizer.VirtualizerVmware;
-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 VmWareEthernetDevTypeMeta
-{
- public final String value;
-
- public VmWareEthernetDevTypeMeta( String val )
- {
- value = val;
- }
-}
-
-class VmwareUsbSpeed
-{
- public final String keyName;
- public final int speedNumeric;
-
- public VmwareUsbSpeed( int speed, String key )
- {
- this.keyName = key == null ? null : ( key + ".present" );
- this.speedNumeric = speed;
- }
-}
-
-public class VirtualizationConfigurationVmware extends
- VirtualizationConfiguration<VmWareSoundCardMeta, VmWareDDAccelMeta, VmWareEthernetDevTypeMeta, VmwareUsbSpeed>
+public class VirtualizationConfigurationVmware extends VirtualizationConfiguration
{
/**
* File name extension for VMware virtualization configuration files.
@@ -511,51 +472,99 @@ public class VirtualizationConfigurationVmware extends
{
return config.get( key );
}
-
- public void setSoundCard( VirtualizationConfiguration.SoundCardType type )
+
+ class VmwareNoSoundCard extends AbstractConfigurableOption
{
- VmWareSoundCardMeta soundCardMeta = soundCards.get( type );
- addFiltered( "sound.present", vmBoolean( soundCardMeta.isPresent ) );
- if ( soundCardMeta.value != null ) {
- addFiltered( "sound.virtualDev", soundCardMeta.value );
- } else {
+
+ public VmwareNoSoundCard( String displayName )
+ {
+ super( "", displayName );
+ }
+
+ @Override
+ public void apply()
+ {
+ addFiltered( "sound.present", vmBoolean( false ) );
config.remove( "sound.virtualDev" );
}
+
+ @Override
+ public boolean isActive()
+ {
+ return !isSetAndTrue( "sound.present" );
+ }
+
}
- public VirtualizationConfiguration.SoundCardType getSoundCard()
+ class VmWareSoundCardModelNone extends AbstractConfigurableOption
{
- if ( !isSetAndTrue( "sound.present" ) || !isSetAndTrue( "sound.autodetect" ) ) {
- return VirtualizationConfiguration.SoundCardType.NONE;
+
+ public VmWareSoundCardModelNone( String displayName )
+ {
+ super( "none", displayName );
}
- String current = config.get( "sound.virtualDev" );
- if ( current != null ) {
- VmWareSoundCardMeta soundCardMeta = null;
- for ( VirtualizationConfiguration.SoundCardType type : VirtualizationConfiguration.SoundCardType.values() ) {
- soundCardMeta = soundCards.get( type );
- if ( soundCardMeta != null ) {
- if ( current.equals( soundCardMeta.value ) ) {
- return type;
- }
- }
- }
+
+ @Override
+ public void apply()
+ {
+ addFiltered( "sound.present", vmBoolean( false ) );
+ addFiltered( "sound.autodetect", vmBoolean( false ) );
+ config.remove( "sound.virtualDev" );
}
- return VirtualizationConfiguration.SoundCardType.DEFAULT;
+
+ @Override
+ public boolean isActive()
+ {
+ return !isSetAndTrue( "sound.present" );
+ }
+
}
- public void setDDAcceleration( VirtualizationConfiguration.DDAcceleration type )
+ class VmWareSoundCardModel extends AbstractConfigurableOption
{
- VmWareDDAccelMeta ddaMeta = ddacc.get( type );
- addFiltered( "mks.enable3d", vmBoolean( ddaMeta.isPresent ) );
+
+ public VmWareSoundCardModel( String id, String displayName )
+ {
+ super( id, displayName );
+ }
+
+ @Override
+ public void apply()
+ {
+ addFiltered( "sound.present", vmBoolean( true ) );
+ addFiltered( "sound.autodetect", vmBoolean( true ) );
+ addFiltered( "sound.virtualDev", this.id );
+ }
+
+ @Override
+ public boolean isActive()
+ {
+ return isSetAndTrue( "sound.present" ) && isSetAndTrue( "sound.autodetect" )
+ && this.id.equals( config.get( "sound.virtualDev" ) );
+ }
+
}
- public VirtualizationConfiguration.DDAcceleration getDDAcceleration()
+ class VmWareAccel3D extends AbstractConfigurableOption
{
- if ( isSetAndTrue( "mks.enable3d" ) ) {
- return VirtualizationConfiguration.DDAcceleration.ON;
- } else {
- return VirtualizationConfiguration.DDAcceleration.OFF;
+
+ public VmWareAccel3D( String id, String displayName )
+ {
+ super( id, displayName );
}
+
+ @Override
+ public void apply()
+ {
+ addFiltered( "mks.enable3d", this.id );
+ }
+
+ @Override
+ public boolean isActive()
+ {
+ return Boolean.parseBoolean( this.id ) == isSetAndTrue( "mks.enable3d" );
+ }
+
}
public void setVirtualizerVersion( Version type )
@@ -568,78 +577,81 @@ public class VirtualizationConfigurationVmware extends
final short major = Integer.valueOf( Util.parseInt( config.get( "virtualHW.version" ), -1 ) ).shortValue();
return Version.getInstanceByMajorFromVersions( major, this.getVirtualizer().getSupportedVersions() );
}
-
- public void setEthernetDevType( int cardIndex, VirtualizationConfiguration.EthernetDevType type )
+
+ class VmwareNicModel extends AbstractConfigurableOption
{
- VmWareEthernetDevTypeMeta ethernetDevTypeMeta = networkCards.get( type );
- if ( ethernetDevTypeMeta.value != null ) {
- addFiltered( "ethernet" + cardIndex + ".virtualDev", ethernetDevTypeMeta.value );
- } else {
- config.remove( "ethernet" + cardIndex + ".virtualDev" );
- }
- }
- public VirtualizationConfiguration.EthernetDevType getEthernetDevType( int cardIndex )
- {
- String temp = config.get( "ethernet" + cardIndex + ".virtualDev" );
- if ( temp != null ) {
- VmWareEthernetDevTypeMeta ethernetDevTypeMeta = null;
- for ( VirtualizationConfiguration.EthernetDevType type : VirtualizationConfiguration.EthernetDevType
- .values() ) {
- ethernetDevTypeMeta = networkCards.get( type );
- if ( ethernetDevTypeMeta == null ) {
- continue;
- }
- if ( temp.equals( ethernetDevTypeMeta.value ) ) {
- return type;
- }
- }
+ private final int cardIndex;
+
+ public VmwareNicModel( int cardIndex, String id, String displayName )
+ {
+ super( id, displayName );
+ this.cardIndex = cardIndex;
}
- return VirtualizationConfiguration.EthernetDevType.AUTO;
- }
- @Override
- public void setMaxUsbSpeed( VirtualizationConfiguration.UsbSpeed newSpeed )
- {
- if ( newSpeed == null ) {
- newSpeed = VirtualizationConfiguration.UsbSpeed.NONE;
- }
- VmwareUsbSpeed newSpeedMeta = usbSpeeds.get( newSpeed );
- if ( newSpeedMeta == null ) {
- throw new RuntimeException( "USB Speed " + newSpeed.name() + " not registered with VMware" );
- }
- for ( VmwareUsbSpeed meta : usbSpeeds.values() ) {
- if ( meta == null )
- continue; // Should not happen
- if ( meta.keyName == null )
- continue; // "No USB" has no config entry, obviously
- if ( meta.speedNumeric <= newSpeedMeta.speedNumeric ) {
- // Enable desired speed class, plus all lower ones
- addFiltered( meta.keyName, "TRUE" );
+ @Override
+ public void apply()
+ {
+ if ( Util.isEmptyString( id ) ) {
+ config.remove( "ethernet" + cardIndex + ".virtualDev" );
} else {
- // This one is higher – remove
- config.remove( meta.keyName );
+ addFiltered( "ethernet" + cardIndex + ".virtualDev", id );
}
}
- // VMware 14+ needs this to use USB 3.0 devices at USB 3.0 ports in VMs configured for < 3.0
- if ( newSpeedMeta.speedNumeric > 0 && newSpeedMeta.speedNumeric < 3 ) {
- addFiltered( "usb.mangleUsb3Speed", "TRUE" );
+
+ @Override
+ public boolean isActive()
+ {
+ String temp = config.get( "ethernet" + cardIndex + ".virtualDev" );
+ if ( temp == null )
+ return Util.isEmptyString( this.id );
+ return temp.equals( this.id );
}
+
}
+
+ class VmWareUsbSpeed extends AbstractConfigurableOption
+ {
+ private final String[] SPEED = { null, "usb", "ehci", "usb_xhci" };
+ private final int speed;
- @Override
- public VirtualizationConfiguration.UsbSpeed getMaxUsbSpeed()
- {
- int max = 0;
- VirtualizationConfiguration.UsbSpeed maxEnum = VirtualizationConfiguration.UsbSpeed.NONE;
- for ( Entry<VirtualizationConfiguration.UsbSpeed, VmwareUsbSpeed> entry : usbSpeeds.entrySet() ) {
- VmwareUsbSpeed v = entry.getValue();
- if ( v.speedNumeric > max && isSetAndTrue( v.keyName ) ) {
- max = v.speedNumeric;
- maxEnum = entry.getKey();
+ public VmWareUsbSpeed( String id, int speed, String displayName )
+ {
+ super( id, displayName );
+ this.speed = speed;
+ }
+
+ @Override
+ public void apply()
+ {
+ // XXX TODO This sucks, qnd
+ for ( int i = 1; i < SPEED.length; ++i ) {
+ String key = SPEED[i] + ".present";
+ if ( i <= speed ) {
+ // Enable desired speed class, plus all lower ones
+ addFiltered( key, "TRUE" );
+ } else {
+ config.remove( key );
+ }
+ }
+ // VMware 14+ needs this to use USB 3.0 devices at USB 3.0 ports in VMs configured for < 3.0
+ if ( speed > 0 && speed < 3 ) {
+ addFiltered( "usb.mangleUsb3Speed", "TRUE" );
+ }
+ }
+
+ @Override
+ public boolean isActive()
+ {
+ int max = 0;
+ for ( int i = 1; i < SPEED.length; ++i ) {
+ if ( isSetAndTrue( SPEED[i] + ".present" ) ) {
+ max = i;
+ }
}
+ return speed == max;
}
- return maxEnum;
+
}
@Override
@@ -651,29 +663,35 @@ public class VirtualizationConfigurationVmware extends
public void registerVirtualHW()
{
- soundCards.put( VirtualizationConfiguration.SoundCardType.NONE, new VmWareSoundCardMeta( false, null ) );
- soundCards.put( VirtualizationConfiguration.SoundCardType.DEFAULT, new VmWareSoundCardMeta( true, null ) );
- soundCards.put( VirtualizationConfiguration.SoundCardType.SOUND_BLASTER,
- new VmWareSoundCardMeta( true, "sb16" ) );
- soundCards.put( VirtualizationConfiguration.SoundCardType.ES, new VmWareSoundCardMeta( true, "es1371" ) );
- soundCards.put( VirtualizationConfiguration.SoundCardType.HD_AUDIO, new VmWareSoundCardMeta( true, "hdaudio" ) );
-
- ddacc.put( VirtualizationConfiguration.DDAcceleration.OFF, new VmWareDDAccelMeta( false ) );
- ddacc.put( VirtualizationConfiguration.DDAcceleration.ON, new VmWareDDAccelMeta( true ) );
-
- networkCards.put( VirtualizationConfiguration.EthernetDevType.AUTO, new VmWareEthernetDevTypeMeta( null ) );
- networkCards.put( VirtualizationConfiguration.EthernetDevType.PCNET32,
- new VmWareEthernetDevTypeMeta( "vlance" ) );
- networkCards.put( VirtualizationConfiguration.EthernetDevType.E1000, new VmWareEthernetDevTypeMeta( "e1000" ) );
- networkCards.put( VirtualizationConfiguration.EthernetDevType.E1000E, new VmWareEthernetDevTypeMeta( "e1000e" ) );
- networkCards.put( VirtualizationConfiguration.EthernetDevType.VMXNET, new VmWareEthernetDevTypeMeta( "vmxnet" ) );
- networkCards.put( VirtualizationConfiguration.EthernetDevType.VMXNET3,
- new VmWareEthernetDevTypeMeta( "vmxnet3" ) );
-
- usbSpeeds.put( VirtualizationConfiguration.UsbSpeed.NONE, new VmwareUsbSpeed( 0, null ) );
- usbSpeeds.put( VirtualizationConfiguration.UsbSpeed.USB1_1, new VmwareUsbSpeed( 1, "usb" ) );
- usbSpeeds.put( VirtualizationConfiguration.UsbSpeed.USB2_0, new VmwareUsbSpeed( 2, "ehci" ) );
- usbSpeeds.put( VirtualizationConfiguration.UsbSpeed.USB3_0, new VmwareUsbSpeed( 3, "usb_xhci" ) );
+ List<AbstractConfigurableOption> list;
+ list = new ArrayList<>();
+ list.add( new VmWareSoundCardModelNone( SoundCard.NONE ) );
+ list.add( new VmWareSoundCardModel( "", SoundCard.DEFAULT ) );
+ list.add( new VmWareSoundCardModel( "sb16", SoundCard.SOUND_BLASTER ) );
+ list.add( new VmWareSoundCardModel( "es1371", SoundCard.ES ) );
+ list.add( new VmWareSoundCardModel( "hdaudio", SoundCard.HD_AUDIO ) );
+ configurableOptions.add( new ConfigurableOptionGroup( ConfigurationGroups.SOUND_CARD_MODEL, list ) );
+
+ list = new ArrayList<>();
+ list.add( new VmWareAccel3D( "FALSE", "2D" ) );
+ list.add( new VmWareAccel3D( "TRUE", "3D" ) );
+ configurableOptions.add( new ConfigurableOptionGroup( ConfigurationGroups.GFX_TYPE, list ) );
+
+ list = new ArrayList<>();
+ list.add( new VmwareNicModel( 0, "", Ethernet.AUTO ) );
+ list.add( new VmwareNicModel( 0, "vlance", Ethernet.PCNET32 ) );
+ list.add( new VmwareNicModel( 0, "e1000", Ethernet.E1000 ) );
+ list.add( new VmwareNicModel( 0, "e1000e", Ethernet.E1000E ) );
+ list.add( new VmwareNicModel( 0, "vmxnet", Ethernet.VMXNET ) );
+ list.add( new VmwareNicModel( 0, "vmxnet3", Ethernet.VMXNET3 ) );
+ configurableOptions.add( new ConfigurableOptionGroup( ConfigurationGroups.NIC_MODEL, list ) );
+
+ list = new ArrayList<>();
+ list.add( new VmWareUsbSpeed( null, 0, Usb.NONE ) );
+ list.add( new VmWareUsbSpeed( "usb", 1, Usb.USB1_1 ) );
+ list.add( new VmWareUsbSpeed( "ehci", 2, Usb.USB2_0 ) );
+ list.add( new VmWareUsbSpeed( "usb_xhci", 3, Usb.USB3_0 ) );
+ configurableOptions.add( new ConfigurableOptionGroup( ConfigurationGroups.USB_SPEED, list ) );
}
@Override
diff --git a/src/main/java/org/openslx/virtualization/configuration/logic/ConfigurationLogic.java b/src/main/java/org/openslx/virtualization/configuration/logic/ConfigurationLogic.java
index 018d046..90319e2 100644
--- a/src/main/java/org/openslx/virtualization/configuration/logic/ConfigurationLogic.java
+++ b/src/main/java/org/openslx/virtualization/configuration/logic/ConfigurationLogic.java
@@ -14,7 +14,7 @@ import org.openslx.virtualization.configuration.transformation.TransformationGen
*
* @param <T> type of configuration data used as input arguments for a transformation.
*/
-public abstract class ConfigurationLogic<T> extends TransformationGeneric<VirtualizationConfiguration<?, ?, ?, ?>, T>
+public abstract class ConfigurationLogic<T> extends TransformationGeneric<VirtualizationConfiguration, T>
{
/**
* Creates a new generic transformation logic for virtualization configurations.
diff --git a/src/main/java/org/openslx/virtualization/configuration/logic/ConfigurationLogicDozModClientToDozModServer.java b/src/main/java/org/openslx/virtualization/configuration/logic/ConfigurationLogicDozModClientToDozModServer.java
index f375693..f5d9a76 100644
--- a/src/main/java/org/openslx/virtualization/configuration/logic/ConfigurationLogicDozModClientToDozModServer.java
+++ b/src/main/java/org/openslx/virtualization/configuration/logic/ConfigurationLogicDozModClientToDozModServer.java
@@ -47,7 +47,7 @@ public class ConfigurationLogicDozModClientToDozModServer
* @param args input arguments for the validation.
* @throws TransformationException validation has failed.
*/
- private void validateInputs( VirtualizationConfiguration<?, ?, ?, ?> config,
+ private void validateInputs( VirtualizationConfiguration config,
ConfigurationDataDozModClientToDozModServer args )
throws TransformationException
{
@@ -59,7 +59,7 @@ public class ConfigurationLogicDozModClientToDozModServer
}
@Override
- public void transform( VirtualizationConfiguration<?, ?, ?, ?> config,
+ public void transform( VirtualizationConfiguration config,
ConfigurationDataDozModClientToDozModServer args )
throws TransformationException
{
diff --git a/src/main/java/org/openslx/virtualization/configuration/logic/ConfigurationLogicDozModServerToDozModClient.java b/src/main/java/org/openslx/virtualization/configuration/logic/ConfigurationLogicDozModServerToDozModClient.java
index 06c8ad1..e38857a 100644
--- a/src/main/java/org/openslx/virtualization/configuration/logic/ConfigurationLogicDozModServerToDozModClient.java
+++ b/src/main/java/org/openslx/virtualization/configuration/logic/ConfigurationLogicDozModServerToDozModClient.java
@@ -4,7 +4,6 @@ import java.util.Map;
import org.openslx.bwlp.thrift.iface.OperatingSystem;
import org.openslx.virtualization.configuration.VirtualizationConfiguration;
-import org.openslx.virtualization.configuration.VirtualizationConfiguration.UsbSpeed;
import org.openslx.virtualization.configuration.VirtualizationConfigurationException;
import org.openslx.virtualization.configuration.data.ConfigurationDataDozModServerToDozModClient;
import org.openslx.virtualization.configuration.transformation.TransformationException;
@@ -63,7 +62,7 @@ public class ConfigurationLogicDozModServerToDozModClient
* @param args input arguments for the validation.
* @throws TransformationException validation has failed.
*/
- private void validateInputs( VirtualizationConfiguration<?, ?, ?, ?> config,
+ private void validateInputs( VirtualizationConfiguration config,
ConfigurationDataDozModServerToDozModClient args )
throws TransformationException
{
@@ -122,7 +121,7 @@ public class ConfigurationLogicDozModServerToDozModClient
}
@Override
- public void transform( VirtualizationConfiguration<?, ?, ?, ?> config,
+ public void transform( VirtualizationConfiguration config,
ConfigurationDataDozModServerToDozModClient args )
throws TransformationException
{
@@ -188,10 +187,12 @@ public class ConfigurationLogicDozModServerToDozModClient
// append second CDROM drive connected to the host's physical drive
config.addCdrom( null );
- // set maximum USB speed
+ // XXX TODO set maximum USB speed
+ /*
if ( config.getMaxUsbSpeed() != UsbSpeed.USB3_0 ) {
config.setMaxUsbSpeed( UsbSpeed.USB2_0 );
}
+ */
// apply settings to edit virtualized system locally
try {
diff --git a/src/main/java/org/openslx/virtualization/configuration/logic/ConfigurationLogicDozModServerToStatelessClient.java b/src/main/java/org/openslx/virtualization/configuration/logic/ConfigurationLogicDozModServerToStatelessClient.java
index 96d0b91..5dec3d9 100644
--- a/src/main/java/org/openslx/virtualization/configuration/logic/ConfigurationLogicDozModServerToStatelessClient.java
+++ b/src/main/java/org/openslx/virtualization/configuration/logic/ConfigurationLogicDozModServerToStatelessClient.java
@@ -2,7 +2,6 @@ package org.openslx.virtualization.configuration.logic;
import org.openslx.virtualization.configuration.VirtualizationConfiguration;
import org.openslx.virtualization.configuration.VirtualizationConfiguration.EtherType;
-import org.openslx.virtualization.configuration.VirtualizationConfiguration.UsbSpeed;
import org.openslx.virtualization.configuration.VirtualizationConfigurationException;
import org.openslx.virtualization.configuration.data.ConfigurationDataDozModServerToStatelessClient;
import org.openslx.virtualization.configuration.transformation.TransformationException;
@@ -54,7 +53,7 @@ public class ConfigurationLogicDozModServerToStatelessClient
* @param args input arguments for the validation.
* @throws TransformationException validation has failed.
*/
- private void validateInputs( VirtualizationConfiguration<?, ?, ?, ?> config,
+ private void validateInputs( VirtualizationConfiguration config,
ConfigurationDataDozModServerToStatelessClient args )
throws TransformationException
{
@@ -66,7 +65,7 @@ public class ConfigurationLogicDozModServerToStatelessClient
}
@Override
- public void transform( VirtualizationConfiguration<?, ?, ?, ?> config,
+ public void transform( VirtualizationConfiguration config,
ConfigurationDataDozModServerToStatelessClient args )
throws TransformationException
{
@@ -103,7 +102,8 @@ public class ConfigurationLogicDozModServerToStatelessClient
// disable USB if necessary
if ( !args.hasUsbAccess() ) {
- config.setMaxUsbSpeed( UsbSpeed.NONE );
+ // XXX TODO find best way to do this without explicit method
+ // config.setMaxUsbSpeed( UsbSpeed.NONE );
}
}
}
diff --git a/src/main/java/org/openslx/virtualization/hardware/AbstractConfigurableOption.java b/src/main/java/org/openslx/virtualization/hardware/AbstractConfigurableOption.java
new file mode 100644
index 0000000..9384c8a
--- /dev/null
+++ b/src/main/java/org/openslx/virtualization/hardware/AbstractConfigurableOption.java
@@ -0,0 +1,42 @@
+package org.openslx.virtualization.hardware;
+
+public abstract class AbstractConfigurableOption
+{
+
+ protected final String id;
+
+ protected final String displayName;
+
+ public AbstractConfigurableOption( String id, String displayName )
+ {
+ this.id = id;
+ this.displayName = displayName;
+ }
+
+ public String getId()
+ {
+ return this.id;
+ }
+
+ public String getDisplayName()
+ {
+ return this.displayName;
+ }
+
+ public abstract void apply();
+
+ public abstract boolean isActive();
+
+ @Override
+ public boolean equals( Object obj )
+ {
+ if ( this == obj )
+ return true;
+ if ( obj instanceof AbstractConfigurableOption ) {
+ AbstractConfigurableOption other = ( (AbstractConfigurableOption)obj );
+ return other.id == this.id || ( other.id != null && other.id.equals( this.id ) );
+ }
+ return false;
+ }
+
+}
diff --git a/src/main/java/org/openslx/virtualization/hardware/ConfigurationGroups.java b/src/main/java/org/openslx/virtualization/hardware/ConfigurationGroups.java
new file mode 100644
index 0000000..ad5b771
--- /dev/null
+++ b/src/main/java/org/openslx/virtualization/hardware/ConfigurationGroups.java
@@ -0,0 +1,20 @@
+package org.openslx.virtualization.hardware;
+
+public enum ConfigurationGroups
+{
+
+ NIC_MODEL( "E0VirtDev" ),
+ USB_SPEED( "maxUSBSpeed" ),
+ SOUND_CARD_MODEL( "sound" ),
+ GFX_TYPE( "3DAcceleration" ),
+ HW_VERSION( "HWVersion" );
+
+ /** Identifier to use when looking up translation for this group. Should never change */
+ public final String i18n;
+
+ private ConfigurationGroups( String i18n )
+ {
+ this.i18n = i18n;
+ }
+
+}
diff --git a/src/main/java/org/openslx/virtualization/hardware/Ethernet.java b/src/main/java/org/openslx/virtualization/hardware/Ethernet.java
new file mode 100644
index 0000000..744a71d
--- /dev/null
+++ b/src/main/java/org/openslx/virtualization/hardware/Ethernet.java
@@ -0,0 +1,20 @@
+package org.openslx.virtualization.hardware;
+
+public class Ethernet
+{
+
+ public static final String AUTO = "(default)";
+ public static final String PCNET32 = "AMD PCnet32";
+ public static final String E1000 = "Intel E1000 (PCI)";
+ public static final String E1000E = "Intel E1000e (PCI-Express)";
+ public static final String VMXNET = "VMXnet";
+ public static final String VMXNET3 = "VMXnet 3";
+ public static final String PCNETPCI2 = "PCnet-PCI II";
+ public static final String PCNETFAST3 = "PCnet-FAST III";
+ public static final String PRO1000MTD = "Intel PRO/1000 MT Desktop";
+ public static final String PRO1000TS = "Intel PRO/1000 T Server";
+ public static final String PRO1000MTS = "Intel PRO/1000 MT Server";
+ public static final String PARAVIRT = "Paravirtualized Network";
+ public static final String NONE = "No Network Card";
+
+}
diff --git a/src/main/java/org/openslx/virtualization/hardware/SoundCard.java b/src/main/java/org/openslx/virtualization/hardware/SoundCard.java
new file mode 100644
index 0000000..e4065e4
--- /dev/null
+++ b/src/main/java/org/openslx/virtualization/hardware/SoundCard.java
@@ -0,0 +1,13 @@
+package org.openslx.virtualization.hardware;
+
+public class SoundCard
+{
+
+ public static final String NONE = "None";
+ public static final String DEFAULT = "(default)";
+ public static final String SOUND_BLASTER = "Sound Blaster 16";
+ public static final String ES = "ES 1371";
+ public static final String HD_AUDIO = "Intel Integrated HD Audio";
+ public static final String AC = "Intel ICH Audio Codec 97";
+
+}
diff --git a/src/main/java/org/openslx/virtualization/hardware/Usb.java b/src/main/java/org/openslx/virtualization/hardware/Usb.java
new file mode 100644
index 0000000..200bf8e
--- /dev/null
+++ b/src/main/java/org/openslx/virtualization/hardware/Usb.java
@@ -0,0 +1,11 @@
+package org.openslx.virtualization.hardware;
+
+public class Usb
+{
+
+ public static final String NONE = "None";
+ public static final String USB1_1 = "USB 1.1";
+ public static final String USB2_0 = "USB 2.0";
+ public static final String USB3_0 = "USB 3.0";
+
+}
diff --git a/src/test/java/org/openslx/virtualization/configuration/VirtualizationConfigurationQemuTest.java b/src/test/java/org/openslx/virtualization/configuration/VirtualizationConfigurationQemuTest.java
index fa2ed13..9d7b179 100644
--- a/src/test/java/org/openslx/virtualization/configuration/VirtualizationConfigurationQemuTest.java
+++ b/src/test/java/org/openslx/virtualization/configuration/VirtualizationConfigurationQemuTest.java
@@ -27,22 +27,19 @@ import org.junit.jupiter.params.provider.MethodSource;
import org.junit.jupiter.params.provider.ValueSource;
import org.openslx.bwlp.thrift.iface.OperatingSystem;
import org.openslx.libvirt.domain.Domain;
-import org.openslx.libvirt.domain.device.ControllerUsb;
import org.openslx.libvirt.domain.device.DiskCdrom;
import org.openslx.libvirt.domain.device.DiskFloppy;
import org.openslx.libvirt.domain.device.DiskStorage;
import org.openslx.libvirt.domain.device.Interface;
-import org.openslx.libvirt.domain.device.Sound;
import org.openslx.libvirt.xml.LibvirtXmlTestResources;
import org.openslx.virtualization.Version;
+import org.openslx.virtualization.configuration.VirtualizationConfiguration.ConfigurableOptionGroup;
import org.openslx.virtualization.configuration.VirtualizationConfiguration.EtherType;
-import org.openslx.virtualization.configuration.VirtualizationConfiguration.EthernetDevType;
-import org.openslx.virtualization.configuration.VirtualizationConfiguration.SoundCardType;
-import org.openslx.virtualization.configuration.VirtualizationConfiguration.UsbSpeed;
import org.openslx.virtualization.configuration.logic.ConfigurationLogicTestUtils;
import org.openslx.virtualization.disk.DiskImage;
-import org.openslx.virtualization.disk.DiskImageTestResources;
import org.openslx.virtualization.disk.DiskImage.ImageFormat;
+import org.openslx.virtualization.disk.DiskImageTestResources;
+import org.openslx.virtualization.hardware.ConfigurationGroups;
public class VirtualizationConfigurationQemuTest
{
@@ -340,58 +337,6 @@ public class VirtualizationConfigurationQemuTest
}
@ParameterizedTest
- @DisplayName( "Test get sound card from VM configuration" )
- @ValueSource( strings = { "qemu-kvm_default-archlinux-vm.xml", "qemu-kvm_default-archlinux-vm-no-sound.xml" } )
- public void testQemuMetaDataGetSoundCardType( String xmlFileName )
- throws VirtualizationConfigurationException, NoSuchFieldException, SecurityException,
- IllegalArgumentException, IllegalAccessException
- {
- File file = LibvirtXmlTestResources.getLibvirtXmlFile( xmlFileName );
- VirtualizationConfigurationQemu vmConfig = new VirtualizationConfigurationQemu( null, file );
-
- final Domain vmLibvirtDomainConfig = VirtualizationConfigurationQemuTest
- .getPrivateDomainFromQemuMetaData( vmConfig );
-
- SoundCardType soundCardType = vmConfig.getSoundCard();
-
- if ( vmLibvirtDomainConfig.getSoundDevices().isEmpty() ) {
- assertEquals( SoundCardType.NONE, soundCardType );
- } else {
- assertEquals( SoundCardType.HD_AUDIO, soundCardType );
- }
-
- assertDoesNotThrow( () -> vmConfig.validate() );
- }
-
- @ParameterizedTest
- @DisplayName( "Test set sound card in VM configuration" )
- @ValueSource( strings = { "qemu-kvm_default-archlinux-vm.xml", "qemu-kvm_default-archlinux-vm-no-sound.xml" } )
- public void testQemuMetaDataSetSoundCardType( String xmlFileName )
- throws VirtualizationConfigurationException, NoSuchFieldException, SecurityException,
- IllegalArgumentException, IllegalAccessException
- {
- File file = LibvirtXmlTestResources.getLibvirtXmlFile( xmlFileName );
- VirtualizationConfigurationQemu vmConfig = new VirtualizationConfigurationQemu( null, file );
-
- final Domain vmLibvirtDomainConfig = VirtualizationConfigurationQemuTest
- .getPrivateDomainFromQemuMetaData( vmConfig );
-
- final int numSoundDevsLibvirtDomainXmlBeforeAdd = vmLibvirtDomainConfig.getSoundDevices().size();
-
- vmConfig.setSoundCard( SoundCardType.SOUND_BLASTER );
-
- final int numSoundDevsLibvirtDomainXmlAfterAdd = vmLibvirtDomainConfig.getSoundDevices().size();
-
- assertTrue( numSoundDevsLibvirtDomainXmlBeforeAdd >= 0 );
- assertTrue( numSoundDevsLibvirtDomainXmlAfterAdd > 0 );
-
- Sound addedSoundDevice = vmLibvirtDomainConfig.getSoundDevices().get( 0 );
- assertEquals( Sound.Model.SB16, addedSoundDevice.getModel() );
-
- assertDoesNotThrow( () -> vmConfig.validate() );
- }
-
- @ParameterizedTest
@DisplayName( "Test get ethernet device type from VM configuration" )
@ValueSource( strings = { "qemu-kvm_default-archlinux-vm.xml", "qemu-kvm_default-archlinux-vm-no-nic.xml" } )
public void testQemuMetaDataGetEthernetDevType( String xmlFileName )
@@ -404,12 +349,16 @@ public class VirtualizationConfigurationQemuTest
final Domain vmLibvirtDomainConfig = VirtualizationConfigurationQemuTest
.getPrivateDomainFromQemuMetaData( vmConfig );
- EthernetDevType ethernetDeviceType = vmConfig.getEthernetDevType( 0 );
+ List<ConfigurableOptionGroup> groups = vmConfig.getConfigurableOptions();
- if ( vmLibvirtDomainConfig.getInterfaceDevices().isEmpty() ) {
- assertEquals( EthernetDevType.NONE, ethernetDeviceType );
- } else {
- assertEquals( EthernetDevType.PARAVIRT, ethernetDeviceType );
+ for ( ConfigurableOptionGroup group : groups ) {
+ if ( group.groupIdentifier != ConfigurationGroups.NIC_MODEL )
+ continue;
+ if ( vmLibvirtDomainConfig.getInterfaceDevices().isEmpty() ) {
+ assertEquals( null, group.getSelected() );
+ } else {
+ assertEquals( Interface.Model.VIRTIO.toString(), group.getSelected().getId() );
+ }
}
assertDoesNotThrow( () -> vmConfig.validate() );
@@ -428,7 +377,7 @@ public class VirtualizationConfigurationQemuTest
final Domain vmLibvirtDomainConfig = VirtualizationConfigurationQemuTest
.getPrivateDomainFromQemuMetaData( vmConfig );
- vmConfig.setEthernetDevType( 0, EthernetDevType.E1000E );
+ // TODO < set to e100e >
if ( !vmLibvirtDomainConfig.getInterfaceDevices().isEmpty() ) {
Interface addedEthernetDevice = vmLibvirtDomainConfig.getInterfaceDevices().get( 0 );
@@ -438,58 +387,6 @@ public class VirtualizationConfigurationQemuTest
assertDoesNotThrow( () -> vmConfig.validate() );
}
- @ParameterizedTest
- @DisplayName( "Test get maximal USB speed from VM configuration" )
- @ValueSource( strings = { "qemu-kvm_default-archlinux-vm.xml", "qemu-kvm_default-archlinux-vm-no-usb.xml" } )
- public void testQemuMetaDataGetMaxUsbSpeed( String xmlFileName )
- throws VirtualizationConfigurationException, NoSuchFieldException, SecurityException,
- IllegalArgumentException, IllegalAccessException
- {
- File file = LibvirtXmlTestResources.getLibvirtXmlFile( xmlFileName );
- VirtualizationConfigurationQemu vmConfig = new VirtualizationConfigurationQemu( null, file );
-
- final Domain vmLibvirtDomainConfig = VirtualizationConfigurationQemuTest
- .getPrivateDomainFromQemuMetaData( vmConfig );
-
- UsbSpeed maxUsbSpeed = vmConfig.getMaxUsbSpeed();
-
- if ( vmLibvirtDomainConfig.getUsbControllerDevices().isEmpty() ) {
- assertEquals( UsbSpeed.NONE, maxUsbSpeed );
- } else {
- assertEquals( UsbSpeed.USB3_0, maxUsbSpeed );
- }
-
- assertDoesNotThrow( () -> vmConfig.validate() );
- }
-
- @ParameterizedTest
- @DisplayName( "Test set maximal USB speed in VM configuration" )
- @ValueSource( strings = { "qemu-kvm_default-archlinux-vm.xml", "qemu-kvm_default-archlinux-vm-no-usb.xml" } )
- public void testQemuMetaDataSetMaxUsbSpeed( String xmlFileName )
- throws VirtualizationConfigurationException, NoSuchFieldException, SecurityException,
- IllegalArgumentException, IllegalAccessException
- {
- File file = LibvirtXmlTestResources.getLibvirtXmlFile( xmlFileName );
- VirtualizationConfigurationQemu vmConfig = new VirtualizationConfigurationQemu( null, file );
-
- final Domain vmLibvirtDomainConfig = VirtualizationConfigurationQemuTest
- .getPrivateDomainFromQemuMetaData( vmConfig );
-
- final int numUsbControllersLibvirtDomainXmlBeforeAdd = vmLibvirtDomainConfig.getUsbControllerDevices().size();
-
- vmConfig.setMaxUsbSpeed( UsbSpeed.USB2_0 );
-
- final int numUsbControllersLibvirtDomainXmlAfterAdd = vmLibvirtDomainConfig.getUsbControllerDevices().size();
-
- assertTrue( numUsbControllersLibvirtDomainXmlBeforeAdd >= 0 );
- assertTrue( numUsbControllersLibvirtDomainXmlAfterAdd > 0 );
-
- ControllerUsb addedUsbControllerDevice = vmLibvirtDomainConfig.getUsbControllerDevices().get( 0 );
- assertEquals( ControllerUsb.Model.ICH9_EHCI1, addedUsbControllerDevice.getModel() );
-
- assertDoesNotThrow( () -> vmConfig.validate() );
- }
-
static Stream<Arguments> configAndEthernetTypeProvider()
{
return Stream.of(
diff --git a/src/test/java/org/openslx/virtualization/configuration/logic/ConfigurationLogicDozModClientToDozModServerTest.java b/src/test/java/org/openslx/virtualization/configuration/logic/ConfigurationLogicDozModClientToDozModServerTest.java
index 01408f0..7493fec 100644
--- a/src/test/java/org/openslx/virtualization/configuration/logic/ConfigurationLogicDozModClientToDozModServerTest.java
+++ b/src/test/java/org/openslx/virtualization/configuration/logic/ConfigurationLogicDozModClientToDozModServerTest.java
@@ -32,7 +32,7 @@ public class ConfigurationLogicDozModClientToDozModServerTest
final String expectedConfigFileName = "qemu-kvm_default-ubuntu-20-04-vm_transform-privacy.xml";
final File inputConfig = LibvirtXmlTestResources.getLibvirtXmlFile( inputConfigFileName );
final File expectedConfig = LibvirtXmlTestResources.getLibvirtXmlFile( expectedConfigFileName );
- final VirtualizationConfiguration<?, ?, ?, ?> config;
+ final VirtualizationConfiguration config;
config = ConfigurationLogicTestUtils.newVirtualizationConfigurationInstance( inputConfig );
final ConfigurationLogicDozModClientToDozModServer logic = new ConfigurationLogicDozModClientToDozModServer();
@@ -53,7 +53,7 @@ public class ConfigurationLogicDozModClientToDozModServerTest
final String expectedConfigFileName = "virtualbox_default-ubuntu_transform-privacy.vbox";
final File inputConfig = ConfigurationLogicTestResources.getVirtualBoxXmlFile( inputConfigFileName );
final File expectedConfig = ConfigurationLogicTestResources.getVirtualBoxXmlFile( expectedConfigFileName );
- final VirtualizationConfiguration<?, ?, ?, ?> config;
+ final VirtualizationConfiguration config;
config = ConfigurationLogicTestUtils.newVirtualizationConfigurationInstance( inputConfig );
final ConfigurationLogicDozModClientToDozModServer logic = new ConfigurationLogicDozModClientToDozModServer();
@@ -77,7 +77,7 @@ public class ConfigurationLogicDozModClientToDozModServerTest
final String expectedConfigFileName = "vmware-player_default-ubuntu_transform-privacy.vmx";
final File inputConfig = ConfigurationLogicTestResources.getVmwareVmxFile( inputConfigFileName );
final File expectedConfig = ConfigurationLogicTestResources.getVmwareVmxFile( expectedConfigFileName );
- final VirtualizationConfiguration<?, ?, ?, ?> config;
+ final VirtualizationConfiguration config;
config = ConfigurationLogicTestUtils.newVirtualizationConfigurationInstance( inputConfig );
assertTrue( config.getHdds().size() == 1 );
final ConfigurationLogicDozModClientToDozModServer logic = new ConfigurationLogicDozModClientToDozModServer();
diff --git a/src/test/java/org/openslx/virtualization/configuration/logic/ConfigurationLogicDozModServerToDozModClientTest.java b/src/test/java/org/openslx/virtualization/configuration/logic/ConfigurationLogicDozModServerToDozModClientTest.java
index 844e5ec..5a1098a 100644
--- a/src/test/java/org/openslx/virtualization/configuration/logic/ConfigurationLogicDozModServerToDozModClientTest.java
+++ b/src/test/java/org/openslx/virtualization/configuration/logic/ConfigurationLogicDozModServerToDozModClientTest.java
@@ -47,7 +47,7 @@ public class ConfigurationLogicDozModServerToDozModClientTest
final String expectedConfigFileName = "qemu-kvm_default-ubuntu-20-04-vm_transform-editable.xml";
final File inputConfig = LibvirtXmlTestResources.getLibvirtXmlFile( inputConfigFileName );
final File expectedConfig = LibvirtXmlTestResources.getLibvirtXmlFile( expectedConfigFileName );
- final VirtualizationConfiguration<?, ?, ?, ?> config;
+ final VirtualizationConfiguration config;
config = ConfigurationLogicTestUtils.newVirtualizationConfigurationInstance( inputConfig );
final ConfigurationLogicDozModServerToDozModClient logic = new ConfigurationLogicDozModServerToDozModClient();
@@ -68,7 +68,7 @@ public class ConfigurationLogicDozModServerToDozModClientTest
final String expectedConfigFileName = "virtualbox_default-ubuntu_transform-editable.vbox";
final File inputConfig = ConfigurationLogicTestResources.getVirtualBoxXmlFile( inputConfigFileName );
final File expectedConfig = ConfigurationLogicTestResources.getVirtualBoxXmlFile( expectedConfigFileName );
- final VirtualizationConfiguration<?, ?, ?, ?> config;
+ final VirtualizationConfiguration config;
config = ConfigurationLogicTestUtils.newVirtualizationConfigurationInstance( inputConfig );
final ConfigurationLogicDozModServerToDozModClient logic = new ConfigurationLogicDozModServerToDozModClient();
@@ -93,7 +93,7 @@ public class ConfigurationLogicDozModServerToDozModClientTest
final String expectedConfigFileName = "vmware-player_default-ubuntu_transform-editable.vmx";
final File inputConfig = ConfigurationLogicTestResources.getVmwareVmxFile( inputConfigFileName );
final File expectedConfig = ConfigurationLogicTestResources.getVmwareVmxFile( expectedConfigFileName );
- final VirtualizationConfiguration<?, ?, ?, ?> config;
+ final VirtualizationConfiguration config;
config = ConfigurationLogicTestUtils.newVirtualizationConfigurationInstance( inputConfig );
assertTrue( config.getHdds().size() == 1 );
final ConfigurationLogicDozModServerToDozModClient logic = new ConfigurationLogicDozModServerToDozModClient();
diff --git a/src/test/java/org/openslx/virtualization/configuration/logic/ConfigurationLogicDozModServerToStatelessClientTest.java b/src/test/java/org/openslx/virtualization/configuration/logic/ConfigurationLogicDozModServerToStatelessClientTest.java
index 47d8a45..f6d56c3 100644
--- a/src/test/java/org/openslx/virtualization/configuration/logic/ConfigurationLogicDozModServerToStatelessClientTest.java
+++ b/src/test/java/org/openslx/virtualization/configuration/logic/ConfigurationLogicDozModServerToStatelessClientTest.java
@@ -41,7 +41,7 @@ public class ConfigurationLogicDozModServerToStatelessClientTest
final String expectedConfigFileName = "qemu-kvm_default-ubuntu-20-04-vm_transform-non-persistent.xml";
final File inputConfig = LibvirtXmlTestResources.getLibvirtXmlFile( inputConfigFileName );
final File expectedConfig = LibvirtXmlTestResources.getLibvirtXmlFile( expectedConfigFileName );
- final VirtualizationConfiguration<?, ?, ?, ?> config;
+ final VirtualizationConfiguration config;
config = ConfigurationLogicTestUtils.newVirtualizationConfigurationInstance( inputConfig );
final ConfigurationLogicDozModServerToStatelessClient logic = new ConfigurationLogicDozModServerToStatelessClient();
@@ -62,7 +62,7 @@ public class ConfigurationLogicDozModServerToStatelessClientTest
final String expectedConfigFileName = "virtualbox_default-ubuntu_transform-non-persistent.vbox";
final File inputConfig = ConfigurationLogicTestResources.getVirtualBoxXmlFile( inputConfigFileName );
final File expectedConfig = ConfigurationLogicTestResources.getVirtualBoxXmlFile( expectedConfigFileName );
- final VirtualizationConfiguration<?, ?, ?, ?> config;
+ final VirtualizationConfiguration config;
config = ConfigurationLogicTestUtils.newVirtualizationConfigurationInstance( inputConfig );
final ConfigurationLogicDozModServerToStatelessClient logic = new ConfigurationLogicDozModServerToStatelessClient();
@@ -87,7 +87,7 @@ public class ConfigurationLogicDozModServerToStatelessClientTest
final String expectedConfigFileName = "vmware-player_default-ubuntu_transform-non-persistent.vmx";
final File inputConfig = ConfigurationLogicTestResources.getVmwareVmxFile( inputConfigFileName );
final File expectedConfig = ConfigurationLogicTestResources.getVmwareVmxFile( expectedConfigFileName );
- final VirtualizationConfiguration<?, ?, ?, ?> config;
+ final VirtualizationConfiguration config;
config = ConfigurationLogicTestUtils.newVirtualizationConfigurationInstance( inputConfig );
assertTrue( config.getHdds().size() == 1 );
final ConfigurationLogicDozModServerToStatelessClient logic = new ConfigurationLogicDozModServerToStatelessClient();
diff --git a/src/test/java/org/openslx/virtualization/configuration/logic/ConfigurationLogicTestUtils.java b/src/test/java/org/openslx/virtualization/configuration/logic/ConfigurationLogicTestUtils.java
index 11f8ee6..1159d74 100644
--- a/src/test/java/org/openslx/virtualization/configuration/logic/ConfigurationLogicTestUtils.java
+++ b/src/test/java/org/openslx/virtualization/configuration/logic/ConfigurationLogicTestUtils.java
@@ -38,9 +38,9 @@ public class ConfigurationLogicTestUtils
private static final String REGEX_UUID = "[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}";
private static final String REGEX_SOURCE_FILE_PATHS = "(<source.*file=\")(.*)(\".*>)";
- public static VirtualizationConfiguration<?, ?, ?, ?> newVirtualizationConfigurationInstance( File configFile )
+ public static VirtualizationConfiguration newVirtualizationConfigurationInstance( File configFile )
{
- VirtualizationConfiguration<?, ?, ?, ?> config = null;
+ VirtualizationConfiguration config = null;
try {
config = VirtualizationConfiguration.getInstance( ConfigurationLogicTestUtils.STUB_OS_LIST, configFile );