From bf15b73d90a18e52f8764058d6fe80037d8a2307 Mon Sep 17 00:00:00 2001 From: Manuel Bentele Date: Fri, 19 Mar 2021 13:42:29 +0100 Subject: Add implementation of Libvirt XML capabilities documents --- .../openslx/libvirt/capabilities/Capabilities.java | 155 ++++ .../org/openslx/libvirt/capabilities/cpu/Cpu.java | 165 ++++ .../openslx/libvirt/capabilities/cpu/Feature.java | 51 ++ .../openslx/libvirt/capabilities/cpu/Pages.java | 60 ++ .../openslx/libvirt/capabilities/guest/Domain.java | 53 ++ .../openslx/libvirt/capabilities/guest/Guest.java | 127 +++ .../libvirt/capabilities/guest/Machine.java | 72 ++ .../java/org/openslx/libvirt/domain/Domain.java | 116 +++ .../libvirt/capabilities/CapabilitiesTest.java | 305 +++++++ .../org/openslx/libvirt/domain/DomainTest.java | 52 ++ .../libvirt/xml/qemu-kvm_capabilities_default.xml | 986 +++++++++++++++++++++ .../xml/qemu-kvm_capabilities_no-cpu-features.xml | 961 ++++++++++++++++++++ .../xml/qemu-kvm_capabilities_no-cpu-pages.xml | 983 ++++++++++++++++++++ .../libvirt/xml/qemu-kvm_capabilities_no-cpu.xml | 950 ++++++++++++++++++++ .../qemu-kvm_capabilities_no-guest-machines.xml | 896 +++++++++++++++++++ .../xml/qemu-kvm_capabilities_no-guests.xml | 82 ++ .../libvirt/xml/qemu-kvm_capabilities_no-iommu.xml | 985 ++++++++++++++++++++ 17 files changed, 6999 insertions(+) create mode 100644 src/main/java/org/openslx/libvirt/capabilities/Capabilities.java create mode 100644 src/main/java/org/openslx/libvirt/capabilities/cpu/Cpu.java create mode 100644 src/main/java/org/openslx/libvirt/capabilities/cpu/Feature.java create mode 100644 src/main/java/org/openslx/libvirt/capabilities/cpu/Pages.java create mode 100644 src/main/java/org/openslx/libvirt/capabilities/guest/Domain.java create mode 100644 src/main/java/org/openslx/libvirt/capabilities/guest/Guest.java create mode 100644 src/main/java/org/openslx/libvirt/capabilities/guest/Machine.java create mode 100644 src/test/java/org/openslx/libvirt/capabilities/CapabilitiesTest.java create mode 100644 src/test/resources/libvirt/xml/qemu-kvm_capabilities_default.xml create mode 100644 src/test/resources/libvirt/xml/qemu-kvm_capabilities_no-cpu-features.xml create mode 100644 src/test/resources/libvirt/xml/qemu-kvm_capabilities_no-cpu-pages.xml create mode 100644 src/test/resources/libvirt/xml/qemu-kvm_capabilities_no-cpu.xml create mode 100644 src/test/resources/libvirt/xml/qemu-kvm_capabilities_no-guest-machines.xml create mode 100644 src/test/resources/libvirt/xml/qemu-kvm_capabilities_no-guests.xml create mode 100644 src/test/resources/libvirt/xml/qemu-kvm_capabilities_no-iommu.xml diff --git a/src/main/java/org/openslx/libvirt/capabilities/Capabilities.java b/src/main/java/org/openslx/libvirt/capabilities/Capabilities.java new file mode 100644 index 0000000..7987371 --- /dev/null +++ b/src/main/java/org/openslx/libvirt/capabilities/Capabilities.java @@ -0,0 +1,155 @@ +package org.openslx.libvirt.capabilities; + +import java.io.File; +import java.io.InputStream; +import java.util.ArrayList; +import java.util.List; + +import org.openslx.libvirt.capabilities.cpu.Cpu; +import org.openslx.libvirt.capabilities.guest.Guest; +import org.openslx.libvirt.xml.LibvirtXmlDocument; +import org.openslx.libvirt.xml.LibvirtXmlDocumentException; +import org.openslx.libvirt.xml.LibvirtXmlNode; +import org.openslx.libvirt.xml.LibvirtXmlResources; +import org.openslx.libvirt.xml.LibvirtXmlSerializationException; +import org.openslx.libvirt.xml.LibvirtXmlValidationException; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; +import org.xml.sax.InputSource; + +/** + * Implementation of the Libvirt capabilities XML document. + * + * The Libvirt capabilities XML document is used to describe the configuration and capabilities of + * the hypervisor's host. + * + * @author Manuel Bentele + * @version 1.0 + */ +public class Capabilities extends LibvirtXmlDocument +{ + /** + * Creates Libvirt capabilities XML document from {@link String} providing Libvirt capabilities + * XML content. + * + * @param xml {@link String} with Libvirt capabilities XML content. + * + * @throws LibvirtXmlDocumentException creation of XML context failed. + * @throws LibvirtXmlSerializationException serialization of the capabilities XML content failed. + * @throws LibvirtXmlValidationException XML content is not a valid capabilities XML document. + */ + public Capabilities( String xml ) + throws LibvirtXmlDocumentException, LibvirtXmlSerializationException, LibvirtXmlValidationException + { + super( xml, LibvirtXmlResources.getLibvirtRng( "capabilities.rng" ) ); + } + + /** + * Creates Libvirt capabilities XML document from {@link File} containing Libvirt capabilities + * XML content. + * + * @param xml existing {@link File} containing Libvirt capabilities XML content. + * + * @throws LibvirtXmlDocumentException creation of XML context failed. + * @throws LibvirtXmlSerializationException serialization of the capabilities XML content failed. + * @throws LibvirtXmlValidationException XML content is not a valid capabilities XML document. + */ + public Capabilities( File xml ) + throws LibvirtXmlDocumentException, LibvirtXmlSerializationException, LibvirtXmlValidationException + { + super( xml, LibvirtXmlResources.getLibvirtRng( "capabilities.rng" ) ); + } + + /** + * Creates Libvirt capabilities XML document from {@link InputStream} providing Libvirt + * capabilities XML content. + * + * @param xml {@link InputStream} providing Libvirt capabilities XML content. + * + * @throws LibvirtXmlDocumentException creation of XML context failed. + * @throws LibvirtXmlSerializationException serialization of the capabilities XML content failed. + * @throws LibvirtXmlValidationException XML content is not a valid capabilities XML document. + */ + public Capabilities( InputStream xml ) + throws LibvirtXmlDocumentException, LibvirtXmlSerializationException, LibvirtXmlValidationException + { + super( xml, LibvirtXmlResources.getLibvirtRng( "capabilities.rng" ) ); + } + + /** + * Creates Libvirt capabilities XML document from {@link InputSource} providing Libvirt + * capabilities XML content. + * + * @param xml {@link InputSource} providing Libvirt capabilities XML content. + * + * @throws LibvirtXmlDocumentException creation of XML context failed. + * @throws LibvirtXmlSerializationException serialization of the capabilities XML content failed. + * @throws LibvirtXmlValidationException XML content is not a valid capabilities XML document. + */ + public Capabilities( InputSource xml ) + throws LibvirtXmlDocumentException, LibvirtXmlSerializationException, LibvirtXmlValidationException + { + super( xml, LibvirtXmlResources.getLibvirtRng( "capabilities.rng" ) ); + } + + /** + * Returns UUID of the Libvirt host machine. + * + * @return UUID of the host machine. + */ + public String getHostUuid() + { + return this.getRootXmlNode().getXmlElementValue( "host/uuid" ); + } + + /** + * Returns CPU capabilities of the host machine. + * + * @return CPU capabilities of the host machine. + */ + public Cpu getHostCpu() + { + final Node hostCpuNode = this.getRootXmlNode().getXmlElement( "host/cpu" ); + + if ( hostCpuNode == null ) { + return null; + } else { + final LibvirtXmlNode hostCpuXmlNode = new LibvirtXmlNode( this.getRootXmlNode().getXmlDocument(), + hostCpuNode ); + return Cpu.newInstance( hostCpuXmlNode ); + } + } + + /** + * Checks whether the Libvirt host machine has IOMMU support. + * + * @return State of the IOMMU support. + */ + public boolean hasHostIommuSupport() + { + return this.getRootXmlNode().getXmlElementAttributeValueAsBool( "host/iommu", "support" ); + } + + /** + * Returns capabilities of all possible guest machines. + * + * @return capabilities of all possible guest machines. + */ + public List getGuests() + { + final List guestList = new ArrayList(); + final NodeList guestNodes = this.getRootXmlNode().getXmlNodes( "guest" ); + + for ( int i = 0; i < guestNodes.getLength(); i++ ) { + final LibvirtXmlNode guestNode = new LibvirtXmlNode( this.getRootXmlNode().getXmlDocument(), + guestNodes.item( i ) ); + final Guest guest = Guest.newInstance( guestNode ); + + if ( guest != null ) { + guestList.add( guest ); + } + } + + return guestList; + } +} diff --git a/src/main/java/org/openslx/libvirt/capabilities/cpu/Cpu.java b/src/main/java/org/openslx/libvirt/capabilities/cpu/Cpu.java new file mode 100644 index 0000000..dc5fbd0 --- /dev/null +++ b/src/main/java/org/openslx/libvirt/capabilities/cpu/Cpu.java @@ -0,0 +1,165 @@ +package org.openslx.libvirt.capabilities.cpu; + +import java.util.ArrayList; +import java.util.List; + +import org.openslx.libvirt.xml.LibvirtXmlNode; +import org.w3c.dom.NodeList; + +/** + * Implementation of the host CPU capabilities as part of the Libvirt capabilities XML document. + * + * @author Manuel Bentele + * @version 1.0 + */ +public class Cpu extends LibvirtXmlNode +{ + /** + * Creates an empty host CPU capabilities instance. + */ + public Cpu() + { + super(); + } + + /** + * Creates a host CPU capabilities instance representing an existing Libvirt XML host CPU + * capabilities element. + * + * @param xmlNode existing Libvirt XML host CPU capabilities element. + */ + public Cpu( LibvirtXmlNode xmlNode ) + { + super( xmlNode ); + } + + /** + * Returns the architecture name of the host CPU. + * + * @return architecture name of the host CPU. + */ + public String getArch() + { + return this.getXmlElementValue( "arch" ); + } + + /** + * Returns the model name of the host CPU. + * + * @return model name of the host CPU. + */ + public String getModel() + { + return this.getXmlElementValue( "model" ); + } + + /** + * Returns the vendor name of the host CPU. + * + * @return vendor name of the host CPU. + */ + public String getVendor() + { + return this.getXmlElementValue( "vendor" ); + } + + /** + * Returns the number of sockets of the host CPU. + * + * @return number of sockets of the host CPU. + */ + public int getTopologySockets() + { + final String numSockets = this.getXmlElementAttributeValue( "topology", "sockets" ); + return Integer.parseInt( numSockets ); + } + + /** + * Returns the number of dies of the host CPU. + * + * @return number of dies of the host CPU. + */ + public int getTopologyDies() + { + final String numDies = this.getXmlElementAttributeValue( "topology", "dies" ); + return Integer.parseInt( numDies ); + } + + /** + * Returns the number of cores of the host CPU. + * + * @return number of cores of the host CPU. + */ + public int getTopologyCores() + { + final String numCores = this.getXmlElementAttributeValue( "topology", "cores" ); + return Integer.parseInt( numCores ); + } + + /** + * Returns the number of threads of the host CPU. + * + * @return number of threads of the host CPU. + */ + public int getTopologyThreads() + { + final String numThreads = this.getXmlElementAttributeValue( "topology", "threads" ); + return Integer.parseInt( numThreads ); + } + + /** + * Returns the supported features of the host CPU. + * + * @return supported features of the host CPU. + */ + public List getFeatures() + { + final List featureList = new ArrayList(); + final NodeList featureNodes = this.getXmlNodes( "feature" ); + + for ( int i = 0; i < featureNodes.getLength(); i++ ) { + final LibvirtXmlNode featureNode = new LibvirtXmlNode( this.getXmlDocument(), featureNodes.item( i ) ); + final Feature feature = Feature.newInstance( featureNode ); + + if ( feature != null ) { + featureList.add( feature ); + } + } + + return featureList; + } + + /** + * Returns the supported memory pages of the host CPU. + * + * @return supported memory pages of the host CPU. + */ + public List getPages() + { + final List pagesList = new ArrayList(); + final NodeList pagesNodes = this.getXmlNodes( "pages" ); + + for ( int i = 0; i < pagesNodes.getLength(); i++ ) { + final LibvirtXmlNode pagesNode = new LibvirtXmlNode( this.getXmlDocument(), pagesNodes.item( i ) ); + final Pages pages = Pages.newInstance( pagesNode ); + + if ( pages != null ) { + pagesList.add( pages ); + } + } + + return pagesList; + } + + /** + * Creates a host CPU capabilities instance representing an existing Libvirt XML host CPU + * capabilities element. + * + * @param xmlNode existing Libvirt XML host CPU capabilities element. + * @return host CPU capabilities instance. + */ + public static Cpu newInstance( LibvirtXmlNode xmlNode ) + { + return new Cpu( xmlNode ); + } +} diff --git a/src/main/java/org/openslx/libvirt/capabilities/cpu/Feature.java b/src/main/java/org/openslx/libvirt/capabilities/cpu/Feature.java new file mode 100644 index 0000000..96c77d5 --- /dev/null +++ b/src/main/java/org/openslx/libvirt/capabilities/cpu/Feature.java @@ -0,0 +1,51 @@ +package org.openslx.libvirt.capabilities.cpu; + +import org.openslx.libvirt.xml.LibvirtXmlNode; + +/** + * Implementation of a host CPU feature as part of the Libvirt capabilities XML document. + * + * @author Manuel Bentele + * @version 1.0 + */ +public class Feature extends LibvirtXmlNode +{ + /** + * Creates an empty host CPU feature instance. + */ + public Feature() + { + super(); + } + + /** + * Creates an host CPU feature representing an existing Libvirt XML host CPU feature element. + * + * @param xmlNode existing Libvirt XML host CPU feature element. + */ + public Feature( LibvirtXmlNode xmlNode ) + { + super( xmlNode ); + } + + /** + * Returns the name of the host CPU feature. + * + * @return name of the host CPU feature. + */ + public String getName() + { + return this.getXmlElementAttributeValue( "name" ); + } + + /** + * Creates an host CPU feature representing an existing Libvirt XML host CPU feature element. + * + * @param xmlNode existing Libvirt XML host CPU feature element. + * @return host CPU feature instance. + */ + public static Feature newInstance( LibvirtXmlNode xmlNode ) + { + return new Feature( xmlNode ); + } +} diff --git a/src/main/java/org/openslx/libvirt/capabilities/cpu/Pages.java b/src/main/java/org/openslx/libvirt/capabilities/cpu/Pages.java new file mode 100644 index 0000000..eea5a36 --- /dev/null +++ b/src/main/java/org/openslx/libvirt/capabilities/cpu/Pages.java @@ -0,0 +1,60 @@ +package org.openslx.libvirt.capabilities.cpu; + +import java.math.BigInteger; + +import org.openslx.libvirt.domain.DomainUtils; +import org.openslx.libvirt.xml.LibvirtXmlNode; + +/** + * Implementation of a host CPU memory pages instance as part of the Libvirt capabilities XML + * document. + * + * @author Manuel Bentele + * @version 1.0 + */ +public class Pages extends LibvirtXmlNode +{ + /** + * Creates an empty host CPU memory pages instance. + */ + public Pages() + { + super(); + } + + /** + * Creates a host CPU memory pages instance representing an existing Libvirt XML host CPU pages + * element. + * + * @param xmlNode existing Libvirt XML host CPU pages element. + */ + public Pages( LibvirtXmlNode xmlNode ) + { + super( xmlNode ); + } + + /** + * Returns size of the memory pages instance. + * + * @return size of the memory pages instance. + */ + public BigInteger getSize() + { + final String pagesValue = this.getXmlElementAttributeValue( "size" ); + final String pagesUnit = this.getXmlElementAttributeValue( "unit" ); + + return DomainUtils.decodeMemory( pagesValue, pagesUnit ); + } + + /** + * Creates a host CPU memory pages instance representing an existing Libvirt XML host CPU pages + * element. + * + * @param xmlNode existing Libvirt XML host CPU pages element. + * @return host CPU memory pages instance. + */ + public static Pages newInstance( LibvirtXmlNode xmlNode ) + { + return new Pages( xmlNode ); + } +} diff --git a/src/main/java/org/openslx/libvirt/capabilities/guest/Domain.java b/src/main/java/org/openslx/libvirt/capabilities/guest/Domain.java new file mode 100644 index 0000000..8716064 --- /dev/null +++ b/src/main/java/org/openslx/libvirt/capabilities/guest/Domain.java @@ -0,0 +1,53 @@ +package org.openslx.libvirt.capabilities.guest; + +import org.openslx.libvirt.domain.Domain.Type; +import org.openslx.libvirt.xml.LibvirtXmlNode; + +/** + * Implementation of a guest domain as part of the Libvirt capabilities XML capabilities document. + * + * @author Manuel Bentele + * @version 1.0 + */ +public class Domain extends LibvirtXmlNode +{ + /** + * Creates an empty guest domain instance. + */ + public Domain() + { + super(); + } + + /** + * Creates a guest domain representing an existing Libvirt XML guest domain element. + * + * @param xmlNode existing Libvirt XML guest domain element. + */ + public Domain( LibvirtXmlNode xmlNode ) + { + super( xmlNode ); + } + + /** + * Returns the domain type of the guest domain. + * + * @return type of the guest domain. + */ + public Type getType() + { + final String type = this.getXmlElementAttributeValue( "type" ); + return Type.fromString( type ); + } + + /** + * Creates a guest domain representing an existing Libvirt XML guest domain element. + * + * @param xmlNode existing Libvirt XML guest domain element. + * @return guest domain instance. + */ + public static Domain newInstance( LibvirtXmlNode xmlNode ) + { + return new Domain( xmlNode ); + } +} diff --git a/src/main/java/org/openslx/libvirt/capabilities/guest/Guest.java b/src/main/java/org/openslx/libvirt/capabilities/guest/Guest.java new file mode 100644 index 0000000..2471180 --- /dev/null +++ b/src/main/java/org/openslx/libvirt/capabilities/guest/Guest.java @@ -0,0 +1,127 @@ +package org.openslx.libvirt.capabilities.guest; + +import java.util.ArrayList; +import java.util.List; + +import org.openslx.libvirt.domain.Domain.OsType; +import org.openslx.libvirt.xml.LibvirtXmlNode; +import org.w3c.dom.NodeList; + +/** + * Implementation of the guest capabilities as part of the Libvirt capabilities XML document. + * + * @author Manuel Bentele + * @version 1.0 + */ +public class Guest extends LibvirtXmlNode +{ + /** + * Creates an empty guest instance. + */ + public Guest() + { + super(); + } + + /** + * Creates a guest representing an existing Libvirt XML guest capabilities element. + * + * @param xmlNode existing Libvirt XML guest capabilities element. + */ + public Guest( LibvirtXmlNode xmlNode ) + { + super( xmlNode ); + } + + /** + * Return OS type of the guest. + * + * @return OS type of the guest. + */ + public OsType getOsType() + { + final String osType = this.getXmlElementValue( "os_type" ); + return OsType.fromString( osType ); + } + + /** + * Returns the architecture name of the guest. + * + * @return architecture name of the guest. + */ + public String getArchName() + { + return this.getXmlElementAttributeValue( "arch", "name" ); + } + + /** + * Return word size of the guest's architecture. + * + * @return word size of the guest's architecture. + */ + public int getArchWordSize() + { + final String archWordSize = this.getXmlElementValue( "arch/wordsize" ); + return Integer.parseInt( archWordSize ); + } + + public String getArchEmulator() + { + return this.getXmlElementValue( "arch/emulator" ); + } + + /** + * Returns the available machines of the guest's architecture. + * + * @return available machines of the guest's architecture. + */ + public List getArchMachines() + { + final List machinesList = new ArrayList(); + final NodeList machineNodes = this.getXmlNodes( "arch/machine" ); + + for ( int i = 0; i < machineNodes.getLength(); i++ ) { + final LibvirtXmlNode machineNode = new LibvirtXmlNode( this.getXmlDocument(), machineNodes.item( i ) ); + final Machine machine = Machine.newInstance( machineNode ); + + if ( machine != null ) { + machinesList.add( machine ); + } + } + + return machinesList; + } + + /** + * Returns the supported domains of the guest. + * + * @return supported domains of the guest. + */ + public List getArchDomains() + { + final List domainList = new ArrayList(); + final NodeList domainNodes = this.getXmlNodes( "arch/domain" ); + + for ( int i = 0; i < domainNodes.getLength(); i++ ) { + final LibvirtXmlNode domainNode = new LibvirtXmlNode( this.getXmlDocument(), domainNodes.item( i ) ); + final Domain domain = Domain.newInstance( domainNode ); + + if ( domain != null ) { + domainList.add( domain ); + } + } + + return domainList; + } + + /** + * Creates a guest representing an existing Libvirt XML guest capabilities element. + * + * @param xmlNode existing Libvirt XML guest capabilities element. + * @return guest capabilities instance. + */ + public static Guest newInstance( LibvirtXmlNode xmlNode ) + { + return new Guest( xmlNode ); + } +} diff --git a/src/main/java/org/openslx/libvirt/capabilities/guest/Machine.java b/src/main/java/org/openslx/libvirt/capabilities/guest/Machine.java new file mode 100644 index 0000000..dfe6362 --- /dev/null +++ b/src/main/java/org/openslx/libvirt/capabilities/guest/Machine.java @@ -0,0 +1,72 @@ +package org.openslx.libvirt.capabilities.guest; + +import org.openslx.libvirt.xml.LibvirtXmlNode; + +/** + * Implementation of a guest machine as part of the Libvirt XML capabilities document. + * + * @author Manuel Bentele + * @version 1.0 + */ +public class Machine extends LibvirtXmlNode +{ + /** + * Creates an empty guest machine instance. + */ + public Machine() + { + super(); + } + + /** + * Creates an guest machine representing an existing Libvirt XML guest machine element. + * + * @param xmlNode existing Libvirt XML guest machine element. + */ + public Machine( LibvirtXmlNode xmlNode ) + { + super( xmlNode ); + } + + /** + * Returns the canonical machine name. + * + * @return canonical machine name. + */ + public String getCanonicalMachine() + { + return this.getXmlElementAttributeValue( "canonical" ); + } + + /** + * Returns the maximum number of CPUs supported by the guest machine. + * + * @return maximum number of CPUs supported by the guest machine. + */ + public int getMaxCpus() + { + final String numMaxCpus = this.getXmlElementAttributeValue( "maxCpus" ); + return Integer.parseUnsignedInt( numMaxCpus ); + } + + /** + * Returns the name of the guest machine. + * + * @return name of the guest machine. + */ + public String getName() + { + return this.getXmlElementValue( null ); + } + + /** + * Creates an guest machine representing an existing Libvirt XML guest machine element. + * + * @param xmlNode existing Libvirt XML guest machine element. + * @return guest machine instance. + */ + public static Machine newInstance( LibvirtXmlNode xmlNode ) + { + return new Machine( xmlNode ); + } +} diff --git a/src/main/java/org/openslx/libvirt/domain/Domain.java b/src/main/java/org/openslx/libvirt/domain/Domain.java index 4e15ec1..9611c59 100644 --- a/src/main/java/org/openslx/libvirt/domain/Domain.java +++ b/src/main/java/org/openslx/libvirt/domain/Domain.java @@ -352,6 +352,122 @@ public class Domain extends LibvirtXmlDocument this.getRootXmlNode().setXmlElementValue( "vcpu", Integer.toString( number ) ); } + /** + * Returns OS type defined in the Libvirt domain XML document. + * + * @return OS type of the virtual machine. + */ + public OsType getOsType() + { + final String osType = this.getRootXmlNode().getXmlElementValue( "os/type" ); + return OsType.fromString( osType ); + } + + /** + * Set OS type in the Libvirt domain XML document. + * + * @param type OS type for the virtual machine. + */ + public void setOsType( OsType type ) + { + this.getRootXmlNode().setXmlElementValue( "os/type", type.toString() ); + } + + /** + * Returns OS architecture defined in the Libvirt domain XML document. + * + * @return OS architecture of the virtual machine. + */ + public String getOsArch() + { + return this.getRootXmlNode().getXmlElementAttributeValue( "os/type", "arch" ); + } + + /** + * Set OS architecture in the Libvirt domain XML document. + * + * @param arch OS architecture for the virtual machine. + */ + public void setOsArch( String arch ) + { + this.getRootXmlNode().setXmlElementAttributeValue( "os/type", "arch", arch ); + } + + /** + * Returns OS machine defined in the Libvirt domain XML document. + * + * @return OS machine of the virtual machine. + */ + public String getOsMachine() + { + return this.getRootXmlNode().getXmlElementAttributeValue( "os/type", "machine" ); + } + + /** + * Set OS machine in the Libvirt domain XML document. + * + * @param machine OS machine for the virtual machine. + */ + public void setOsMachine( String machine ) + { + this.getRootXmlNode().setXmlElementAttributeValue( "os/type", "machine", machine ); + } + + /** + * Operating system types specifiable for a virtual machine in the Libvirt domain XML document. + * + * @author Manuel Bentele + * @version 1.0 + */ + public enum OsType + { + // @formatter:off + XEN ( "xen" ), + LINUX( "linux" ), + HVM ( "hvm" ), + EXE ( "exe" ), + UML ( "uml" ); + // @formatter:on + + /** + * Name of the OS type in a Libvirt domain XML document. + */ + private final String osType; + + /** + * Creates an OS type. + * + * @param osType valid name of the OS type in the Libvirt domain XML document. + */ + OsType( String osType ) + { + this.osType = osType; + } + + @Override + public String toString() + { + return this.osType; + } + + /** + * Creates an OS type from its name with error check. + * + * @param osType name of the OS type in the Libvirt domain XML document. + * @return valid OS type. + */ + public static OsType fromString( String osType ) + { + for ( OsType t : OsType.values() ) { + if ( t.osType.equalsIgnoreCase( osType ) ) { + return t; + } + } + + return null; + } + } + /** * Returns virtual machine CPU model defined in the Libvirt domain XML document. * diff --git a/src/test/java/org/openslx/libvirt/capabilities/CapabilitiesTest.java b/src/test/java/org/openslx/libvirt/capabilities/CapabilitiesTest.java new file mode 100644 index 0000000..e7d7651 --- /dev/null +++ b/src/test/java/org/openslx/libvirt/capabilities/CapabilitiesTest.java @@ -0,0 +1,305 @@ +package org.openslx.libvirt.capabilities; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.fail; + +import java.math.BigInteger; +import java.util.List; + +import org.apache.log4j.Level; +import org.apache.log4j.LogManager; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.openslx.libvirt.capabilities.cpu.Cpu; +import org.openslx.libvirt.capabilities.cpu.Feature; +import org.openslx.libvirt.capabilities.cpu.Pages; +import org.openslx.libvirt.capabilities.guest.Domain; +import org.openslx.libvirt.capabilities.guest.Guest; +import org.openslx.libvirt.capabilities.guest.Machine; +import org.openslx.libvirt.domain.Domain.OsType; +import org.openslx.libvirt.domain.Domain.Type; +import org.openslx.libvirt.xml.LibvirtXmlDocumentException; +import org.openslx.libvirt.xml.LibvirtXmlSerializationException; +import org.openslx.libvirt.xml.LibvirtXmlTestResources; +import org.openslx.libvirt.xml.LibvirtXmlValidationException; + +public class CapabilitiesTest +{ + @BeforeAll + public static void setUp() + { + // disable logging with log4j + LogManager.getRootLogger().setLevel( Level.OFF ); + } + + private Capabilities newCapabilitiesInstance( String xmlFileName ) + { + Capabilities caps = null; + + try { + caps = new Capabilities( LibvirtXmlTestResources.getLibvirtXmlFile( xmlFileName ) ); + } catch ( LibvirtXmlDocumentException | LibvirtXmlSerializationException | LibvirtXmlValidationException e ) { + final String errorMsg = new String( + "Cannot prepare requested Libvirt capabilities XML file from the resources folder" ); + fail( errorMsg ); + } + + return caps; + } + + @Test + @DisplayName( "Get host UUID from libvirt XML capabilities file" ) + public void testGetHostUuid() + { + final Capabilities caps = this.newCapabilitiesInstance( "qemu-kvm_capabilities_default.xml" ); + + assertEquals( "9b2f12af-1fba-444c-b72b-9cbc43fb3ca5", caps.getHostUuid() ); + } + + @Test + @DisplayName( "Get host CPU from libvirt XML capabilities file" ) + public void testGetHostCpu() + { + final Capabilities caps = this.newCapabilitiesInstance( "qemu-kvm_capabilities_default.xml" ); + final Cpu hostCpu = caps.getHostCpu(); + + assertNotNull( hostCpu ); + assertEquals( "x86_64", hostCpu.getArch() ); + assertEquals( "Skylake-Client-IBRS", hostCpu.getModel() ); + assertEquals( "Intel", hostCpu.getVendor() ); + assertEquals( 1, hostCpu.getTopologySockets() ); + assertEquals( 1, hostCpu.getTopologyDies() ); + assertEquals( 4, hostCpu.getTopologyCores() ); + assertEquals( 1, hostCpu.getTopologyThreads() ); + } + + @Test + @DisplayName( "Get non-existent host CPU from libvirt XML capabilities file" ) + public void testGetHostCpuNonExistent() + { + final Capabilities caps = this.newCapabilitiesInstance( "qemu-kvm_capabilities_no-cpu.xml" ); + final Cpu hostCpu = caps.getHostCpu(); + + assertNull( hostCpu ); + } + + @Test + @DisplayName( "Get host CPU features from libvirt XML capabilities file" ) + public void testGetHostCpuFeatures() + { + final Capabilities caps = this.newCapabilitiesInstance( "qemu-kvm_capabilities_default.xml" ); + final Cpu hostCpu = caps.getHostCpu(); + + assertNotNull( hostCpu ); + + final List hostCpuFeatures = hostCpu.getFeatures(); + assertNotNull( hostCpuFeatures ); + assertEquals( 25, hostCpuFeatures.size() ); + + final Feature hostCpuFeature = hostCpuFeatures.get( 9 ); + assertNotNull( hostCpuFeature ); + assertEquals( "vmx", hostCpuFeature.getName() ); + } + + @Test + @DisplayName( "Get empty host CPU features from libvirt XML capabilities file" ) + public void testGetHostCpuFeaturesEmpty() + { + final Capabilities caps = this.newCapabilitiesInstance( "qemu-kvm_capabilities_no-cpu-features.xml" ); + final Cpu hostCpu = caps.getHostCpu(); + + assertNotNull( hostCpu ); + + final List hostCpuFeatures = hostCpu.getFeatures(); + assertNotNull( hostCpuFeatures ); + assertEquals( 0, hostCpuFeatures.size() ); + } + + @Test + @DisplayName( "Get host CPU pages from libvirt XML capabilities file" ) + public void testGetHostCpuPages() + { + final Capabilities caps = this.newCapabilitiesInstance( "qemu-kvm_capabilities_default.xml" ); + final Cpu hostCpu = caps.getHostCpu(); + + assertNotNull( hostCpu ); + + final List hostCpuPages = hostCpu.getPages(); + assertNotNull( hostCpuPages ); + assertEquals( 3, hostCpuPages.size() ); + + final Pages hostCpuPage = hostCpuPages.get( 2 ); + assertNotNull( hostCpuPage ); + assertEquals( new BigInteger( "1073741824" ).toString(), hostCpuPage.getSize().toString() ); + } + + @Test + @DisplayName( "Get empty host CPU pages from libvirt XML capabilities file" ) + public void testGetHostCpuPagesEmpty() + { + final Capabilities caps = this.newCapabilitiesInstance( "qemu-kvm_capabilities_no-cpu-pages.xml" ); + final Cpu hostCpu = caps.getHostCpu(); + + assertNotNull( hostCpu ); + + final List hostCpuPages = hostCpu.getPages(); + assertNotNull( hostCpuPages ); + assertEquals( 0, hostCpuPages.size() ); + } + + @Test + @DisplayName( "Get host IOMMU support from libvirt XML capabilities file" ) + public void testGetHostIommuSupport() + { + final Capabilities caps = this.newCapabilitiesInstance( "qemu-kvm_capabilities_default.xml" ); + + assertEquals( true, caps.hasHostIommuSupport() ); + } + + @Test + @DisplayName( "Get non-existent host IOMMU support from libvirt XML capabilities file" ) + public void testGetHostIommuSupportNonExistent() + { + final Capabilities caps = this.newCapabilitiesInstance( "qemu-kvm_capabilities_no-iommu.xml" ); + + assertEquals( false, caps.hasHostIommuSupport() ); + } + + @Test + @DisplayName( "Get guests from libvirt XML capabilities file" ) + public void testGetGuests() + { + final Capabilities caps = this.newCapabilitiesInstance( "qemu-kvm_capabilities_default.xml" ); + + final List guests = caps.getGuests(); + assertNotNull( guests ); + assertEquals( 26, guests.size() ); + + final Guest guest = guests.get( 3 ); + assertNotNull( guest ); + assertEquals( OsType.HVM.toString(), guest.getOsType().toString() ); + assertEquals( "aarch64", guest.getArchName() ); + assertEquals( 64, guest.getArchWordSize() ); + assertEquals( "/usr/bin/qemu-system-aarch64", guest.getArchEmulator() ); + } + + @Test + @DisplayName( "Get empty guests from libvirt XML capabilities file" ) + public void testGetGuestsEmpty() + { + final Capabilities caps = this.newCapabilitiesInstance( "qemu-kvm_capabilities_no-guests.xml" ); + + final List guests = caps.getGuests(); + assertNotNull( guests ); + assertEquals( 0, guests.size() ); + } + + @Test + @DisplayName( "Get guest machines from libvirt XML capabilities file" ) + public void testGetGuestMachines() + { + final Capabilities caps = this.newCapabilitiesInstance( "qemu-kvm_capabilities_default.xml" ); + + final List guests = caps.getGuests(); + assertNotNull( guests ); + assertEquals( 26, guests.size() ); + + final Guest guest = guests.get( 3 ); + assertNotNull( guest ); + + final List guestMachines = guest.getArchMachines(); + assertNotNull( guestMachines ); + assertEquals( 89, guestMachines.size() ); + + final Machine guestMachine = guestMachines.get( 5 ); + assertNotNull( guestMachine ); + assertNull( guestMachine.getCanonicalMachine() ); + assertEquals( 2, guestMachine.getMaxCpus() ); + assertEquals( "nuri", guestMachine.getName() ); + } + + @Test + @DisplayName( "Get empty guest machines from libvirt XML capabilities file" ) + public void testGetGuestMachinesEmpty() + { + final Capabilities caps = this.newCapabilitiesInstance( "qemu-kvm_capabilities_no-guest-machines.xml" ); + + final List guests = caps.getGuests(); + assertNotNull( guests ); + assertEquals( 26, guests.size() ); + + final Guest guest = guests.get( 3 ); + assertNotNull( guest ); + + final List guestMachines = guest.getArchMachines(); + assertNotNull( guestMachines ); + assertEquals( 0, guestMachines.size() ); + } + + @Test + @DisplayName( "Get canonical guest machine from libvirt XML capabilities file" ) + public void testGetGuestMachineCanonical() + { + final Capabilities caps = this.newCapabilitiesInstance( "qemu-kvm_capabilities_default.xml" ); + + final List guests = caps.getGuests(); + assertNotNull( guests ); + assertEquals( 26, guests.size() ); + + final Guest guest = guests.get( 3 ); + assertNotNull( guest ); + + final List guestMachines = guest.getArchMachines(); + assertNotNull( guestMachines ); + assertEquals( 89, guestMachines.size() ); + + final Machine guestMachine = guestMachines.get( 29 ); + assertNotNull( guestMachine ); + assertEquals( "virt-5.2", guestMachine.getCanonicalMachine() ); + assertEquals( 512, guestMachine.getMaxCpus() ); + assertEquals( "virt", guestMachine.getName() ); + } + + @Test + @DisplayName( "Get guest machine domains from libvirt XML capabilities file" ) + public void testGetGuestMachineDomains() + { + final Capabilities caps = this.newCapabilitiesInstance( "qemu-kvm_capabilities_default.xml" ); + + final List guests = caps.getGuests(); + assertNotNull( guests ); + assertEquals( 26, guests.size() ); + + final Guest guest = guests.get( 5 ); + assertNotNull( guest ); + + final List guestDomains = guest.getArchDomains(); + assertNotNull( guestDomains ); + assertEquals( 2, guestDomains.size() ); + + final Domain guestDomain = guestDomains.get( 1 ); + assertNotNull( guestDomain ); + assertEquals( Type.KVM, guestDomain.getType() ); + } + + @Test + @DisplayName( "Get empty guest machine domains from libvirt XML capabilities file" ) + public void testGetGuestMachineDomainsEmpty() + { + final Capabilities caps = this.newCapabilitiesInstance( "qemu-kvm_capabilities_no-guest-machines.xml" ); + + final List guests = caps.getGuests(); + assertNotNull( guests ); + assertEquals( 26, guests.size() ); + + final Guest guest = guests.get( 3 ); + assertNotNull( guest ); + + final List guestDomains = guest.getArchDomains(); + assertNotNull( guestDomains ); + assertEquals( 0, guestDomains.size() ); + } +} diff --git a/src/test/java/org/openslx/libvirt/domain/DomainTest.java b/src/test/java/org/openslx/libvirt/domain/DomainTest.java index a604b21..84f6a32 100644 --- a/src/test/java/org/openslx/libvirt/domain/DomainTest.java +++ b/src/test/java/org/openslx/libvirt/domain/DomainTest.java @@ -13,6 +13,7 @@ import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.openslx.libvirt.domain.Domain.CpuCheck; import org.openslx.libvirt.domain.Domain.CpuMode; +import org.openslx.libvirt.domain.Domain.OsType; import org.openslx.libvirt.xml.LibvirtXmlDocumentException; import org.openslx.libvirt.xml.LibvirtXmlSerializationException; import org.openslx.libvirt.xml.LibvirtXmlTestResources; @@ -177,6 +178,57 @@ public class DomainTest assertEquals( 4, vm.getVCpu() ); } + @Test + @DisplayName( "Get VM's OS type from libvirt XML file" ) + public void testGetOsType() + { + Domain vm = this.newDomainInstance( "qemu-kvm_default-ubuntu-20-04-vm.xml" ); + assertEquals( OsType.HVM.toString(), vm.getOsType().toString() ); + } + + @Test + @DisplayName( "Set VM's OS type in libvirt XML file" ) + public void testSetOsType() + { + Domain vm = this.newDomainInstance( "qemu-kvm_default-ubuntu-20-04-vm.xml" ); + vm.setOsType( OsType.XEN ); + assertEquals( OsType.XEN.toString(), vm.getOsType().toString() ); + } + + @Test + @DisplayName( "Get VM's OS architecture from libvirt XML file" ) + public void testGetOsArch() + { + Domain vm = this.newDomainInstance( "qemu-kvm_default-ubuntu-20-04-vm.xml" ); + assertEquals( "x86_64", vm.getOsArch() ); + } + + @Test + @DisplayName( "Set VM's OS architecture in libvirt XML file" ) + public void testSetOsArch() + { + Domain vm = this.newDomainInstance( "qemu-kvm_default-ubuntu-20-04-vm.xml" ); + vm.setOsArch( "aarch" ); + assertEquals( "aarch", vm.getOsArch() ); + } + + @Test + @DisplayName( "Get VM's OS machine from libvirt XML file" ) + public void testGetOsMachine() + { + Domain vm = this.newDomainInstance( "qemu-kvm_default-ubuntu-20-04-vm.xml" ); + assertEquals( "pc-q35-5.1", vm.getOsMachine() ); + } + + @Test + @DisplayName( "Set VM's OS machine in libvirt XML file" ) + public void testSetOsMachine() + { + Domain vm = this.newDomainInstance( "qemu-kvm_default-ubuntu-20-04-vm.xml" ); + vm.setOsMachine( "pc" ); + assertEquals( "pc", vm.getOsMachine() ); + } + @Test @DisplayName( "Get VM CPU model from libvirt XML file" ) public void testGetCpuModel() diff --git a/src/test/resources/libvirt/xml/qemu-kvm_capabilities_default.xml b/src/test/resources/libvirt/xml/qemu-kvm_capabilities_default.xml new file mode 100644 index 0000000..4f2a94f --- /dev/null +++ b/src/test/resources/libvirt/xml/qemu-kvm_capabilities_default.xml @@ -0,0 +1,986 @@ + + + + 9b2f12af-1fba-444c-b72b-9cbc43fb3ca5 + + x86_64 + Skylake-Client-IBRS + Intel + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + tcp + rdma + + + + + + 16161320 + 4040330 + 0 + 0 + + + + + + + + + + + + + + + + + none + 0 + + + + + hvm + + 64 + /usr/bin/qemu-system-alpha + clipper + + + + + + + + + + + hvm + + 32 + /usr/bin/qemu-system-arm + integratorcp + ast2600-evb + borzoi + spitz + virt-2.7 + nuri + mcimx7d-sabre + romulus-bmc + virt-3.0 + virt-5.0 + npcm750-evb + virt-2.10 + musca-b1 + virt-2.8 + realview-pbx-a9 + versatileab + kzm + musca-a + virt-3.1 + mcimx6ul-evk + virt-5.1 + smdkc210 + sx1 + virt-2.11 + imx25-pdk + virt-2.9 + orangepi-pc + z2 + virt-5.2 + virt + xilinx-zynq-a9 + tosa + mps2-an500 + virt-2.12 + mps2-an521 + sabrelite + mps2-an511 + canon-a1100 + realview-eb + emcraft-sf2 + realview-pb-a8 + virt-4.0 + raspi1ap + palmetto-bmc + sx1-v1 + n810 + tacoma-bmc + n800 + virt-4.1 + quanta-gsj + versatilepb + terrier + mainstone + realview-eb-mpcore + supermicrox11-bmc + virt-4.2 + witherspoon-bmc + swift-bmc + vexpress-a9 + midway + musicpal + lm3s811evb + lm3s6965evb + microbit + mps2-an505 + mps2-an385 + cubieboard + verdex + netduino2 + mps2-an386 + raspi2b + raspi2 + vexpress-a15 + sonorapass-bmc + cheetah + virt-2.6 + ast2500-evb + highbank + akita + connex + netduinoplus2 + collie + raspi0 + + + + + + + + + + + hvm + + 32 + /usr/bin/qemu-system-arm + integratorcp + ast2600-evb + borzoi + spitz + virt-2.7 + nuri + mcimx7d-sabre + romulus-bmc + virt-3.0 + virt-5.0 + npcm750-evb + virt-2.10 + musca-b1 + virt-2.8 + realview-pbx-a9 + versatileab + kzm + musca-a + virt-3.1 + mcimx6ul-evk + virt-5.1 + smdkc210 + sx1 + virt-2.11 + imx25-pdk + virt-2.9 + orangepi-pc + z2 + virt-5.2 + virt + xilinx-zynq-a9 + tosa + mps2-an500 + virt-2.12 + mps2-an521 + sabrelite + mps2-an511 + canon-a1100 + realview-eb + emcraft-sf2 + realview-pb-a8 + virt-4.0 + raspi1ap + palmetto-bmc + sx1-v1 + n810 + tacoma-bmc + n800 + virt-4.1 + quanta-gsj + versatilepb + terrier + mainstone + realview-eb-mpcore + supermicrox11-bmc + virt-4.2 + witherspoon-bmc + swift-bmc + vexpress-a9 + midway + musicpal + lm3s811evb + lm3s6965evb + microbit + mps2-an505 + mps2-an385 + cubieboard + verdex + netduino2 + mps2-an386 + raspi2b + raspi2 + vexpress-a15 + sonorapass-bmc + cheetah + virt-2.6 + ast2500-evb + highbank + akita + connex + netduinoplus2 + collie + raspi0 + + + + + + + + + + + hvm + + 64 + /usr/bin/qemu-system-aarch64 + integratorcp + ast2600-evb + borzoi + spitz + virt-2.7 + nuri + mcimx7d-sabre + romulus-bmc + virt-3.0 + virt-5.0 + npcm750-evb + virt-2.10 + musca-b1 + virt-2.8 + realview-pbx-a9 + versatileab + kzm + musca-a + virt-3.1 + mcimx6ul-evk + virt-5.1 + smdkc210 + sx1 + virt-2.11 + imx25-pdk + virt-2.9 + orangepi-pc + z2 + virt-5.2 + virt + xilinx-zynq-a9 + xlnx-zcu102 + tosa + mps2-an500 + virt-2.12 + mps2-an521 + sabrelite + mps2-an511 + canon-a1100 + realview-eb + emcraft-sf2 + realview-pb-a8 + sbsa-ref + virt-4.0 + raspi1ap + palmetto-bmc + sx1-v1 + n810 + tacoma-bmc + n800 + virt-4.1 + quanta-gsj + versatilepb + terrier + mainstone + realview-eb-mpcore + supermicrox11-bmc + virt-4.2 + witherspoon-bmc + swift-bmc + vexpress-a9 + midway + musicpal + lm3s811evb + lm3s6965evb + microbit + mps2-an505 + mps2-an385 + raspi3ap + cubieboard + verdex + netduino2 + xlnx-versal-virt + mps2-an386 + raspi3b + raspi3 + raspi2b + raspi2 + vexpress-a15 + sonorapass-bmc + cheetah + virt-2.6 + ast2500-evb + highbank + akita + connex + netduinoplus2 + collie + raspi0 + + + + + + + + + + + + hvm + + 32 + /usr/bin/qemu-system-cris + axis-dev88 + + + + + + + + + + + hvm + + 32 + /usr/bin/qemu-system-i386 + pc-i440fx-5.2 + pc + pc-q35-5.2 + q35 + pc-i440fx-2.12 + pc-i440fx-2.0 + pc-q35-4.2 + pc-i440fx-2.5 + pc-i440fx-4.2 + pc-i440fx-1.5 + pc-q35-2.7 + pc-i440fx-2.2 + pc-1.1 + pc-i440fx-2.7 + pc-q35-2.4 + pc-q35-2.10 + pc-i440fx-1.7 + pc-q35-5.1 + pc-q35-2.9 + pc-i440fx-2.11 + pc-q35-3.1 + pc-q35-4.1 + pc-i440fx-2.4 + pc-1.3 + pc-i440fx-4.1 + pc-i440fx-5.1 + pc-i440fx-2.9 + isapc + pc-i440fx-1.4 + pc-q35-2.6 + pc-i440fx-3.1 + pc-q35-2.12 + pc-i440fx-2.1 + pc-1.0 + pc-i440fx-2.6 + pc-q35-4.0.1 + pc-i440fx-1.6 + pc-q35-5.0 + pc-q35-2.8 + pc-i440fx-2.10 + pc-q35-3.0 + pc-q35-4.0 + microvm + pc-i440fx-2.3 + pc-1.2 + pc-i440fx-4.0 + pc-i440fx-5.0 + pc-i440fx-2.8 + pc-q35-2.5 + pc-i440fx-3.0 + pc-q35-2.11 + + + + + + + + + + + + + + + + hvm + + 32 + /usr/bin/qemu-system-m68k + mcf5208evb + an5206 + q800 + next-cube + + + + + + + + + + + hvm + + 32 + /usr/bin/qemu-system-microblaze + petalogix-s3adsp1800 + petalogix-ml605 + xlnx-zynqmp-pmu + + + + + + + + + + + hvm + + 32 + /usr/bin/qemu-system-microblazeel + petalogix-s3adsp1800 + petalogix-ml605 + xlnx-zynqmp-pmu + + + + + + + + + + + hvm + + 32 + /usr/bin/qemu-system-mips + malta + mipssim + + + + + + + + + + + hvm + + 32 + /usr/bin/qemu-system-mipsel + malta + mipssim + + + + + + + + + + + hvm + + 64 + /usr/bin/qemu-system-mips64 + malta + pica61 + mipssim + magnum + + + + + + + + + + + hvm + + 64 + /usr/bin/qemu-system-mips64el + malta + mipssim + pica61 + magnum + boston + fuloong2e + fulong2e + + + + + + + + + + + hvm + + 32 + /usr/bin/qemu-system-ppc + g3beige + virtex-ml507 + mac99 + ppce500 + sam460ex + bamboo + 40p + ref405ep + mpc8544ds + taihu + + + + + + + + + + + hvm + + 64 + /usr/bin/qemu-system-ppc64 + pseries-5.2 + pseries + powernv9 + powernv + taihu + pseries-4.1 + mpc8544ds + pseries-2.5 + powernv10 + pseries-4.2 + pseries-2.6 + ppce500 + pseries-2.7 + pseries-3.0 + pseries-5.0 + 40p + pseries-2.8 + pseries-3.1 + pseries-5.1 + pseries-2.9 + bamboo + g3beige + pseries-2.12-sxxm + pseries-2.10 + virtex-ml507 + pseries-2.11 + pseries-2.1 + pseries-2.12 + pseries-2.2 + mac99 + sam460ex + ref405ep + pseries-2.3 + powernv8 + pseries-4.0 + pseries-2.4 + + + + + + + + + + + hvm + + 64 + /usr/bin/qemu-system-ppc64 + pseries-5.2 + pseries + powernv9 + powernv + taihu + pseries-4.1 + mpc8544ds + pseries-2.5 + powernv10 + pseries-4.2 + pseries-2.6 + ppce500 + pseries-2.7 + pseries-3.0 + pseries-5.0 + 40p + pseries-2.8 + pseries-3.1 + pseries-5.1 + pseries-2.9 + bamboo + g3beige + pseries-2.12-sxxm + pseries-2.10 + virtex-ml507 + pseries-2.11 + pseries-2.1 + pseries-2.12 + pseries-2.2 + mac99 + sam460ex + ref405ep + pseries-2.3 + powernv8 + pseries-4.0 + pseries-2.4 + + + + + + + + + + + hvm + + 32 + /usr/bin/qemu-system-riscv32 + spike + virt + opentitan + sifive_e + sifive_u + + + + + + + + + + + hvm + + 64 + /usr/bin/qemu-system-riscv64 + spike + virt + sifive_e + sifive_u + microchip-icicle-kit + + + + + + + + + + + hvm + + 64 + /usr/bin/qemu-system-s390x + s390-ccw-virtio-5.2 + s390-ccw-virtio + s390-ccw-virtio-4.0 + s390-ccw-virtio-3.1 + s390-ccw-virtio-2.6 + s390-ccw-virtio-2.12 + s390-ccw-virtio-2.9 + s390-ccw-virtio-5.1 + s390-ccw-virtio-3.0 + s390-ccw-virtio-4.2 + s390-ccw-virtio-2.5 + s390-ccw-virtio-2.11 + s390-ccw-virtio-2.8 + s390-ccw-virtio-5.0 + s390-ccw-virtio-4.1 + s390-ccw-virtio-2.4 + s390-ccw-virtio-2.10 + s390-ccw-virtio-2.7 + + + + + + + + + + + hvm + + 32 + /usr/bin/qemu-system-sh4 + shix + r2d + + + + + + + + + + + hvm + + 64 + /usr/bin/qemu-system-sh4eb + shix + r2d + + + + + + + + + + + hvm + + 32 + /usr/bin/qemu-system-sparc + SS-5 + SS-20 + LX + SPARCClassic + leon3_generic + SPARCbook + SS-4 + SS-600MP + SS-10 + Voyager + + + + + + + + + + + hvm + + 64 + /usr/bin/qemu-system-sparc64 + sun4u + niagara + sun4v + + + + + + + + + + + hvm + + 64 + /usr/bin/qemu-system-x86_64 + pc-i440fx-5.2 + pc + pc-q35-5.2 + q35 + pc-i440fx-2.12 + pc-i440fx-2.0 + pc-q35-4.2 + pc-i440fx-2.5 + pc-i440fx-4.2 + pc-i440fx-1.5 + pc-q35-2.7 + pc-i440fx-2.2 + pc-1.1 + pc-i440fx-2.7 + pc-q35-2.4 + pc-q35-2.10 + pc-i440fx-1.7 + pc-q35-5.1 + pc-q35-2.9 + pc-i440fx-2.11 + pc-q35-3.1 + pc-q35-4.1 + pc-i440fx-2.4 + pc-1.3 + pc-i440fx-4.1 + pc-i440fx-5.1 + pc-i440fx-2.9 + isapc + pc-i440fx-1.4 + pc-q35-2.6 + pc-i440fx-3.1 + pc-q35-2.12 + pc-i440fx-2.1 + pc-1.0 + pc-i440fx-2.6 + pc-q35-4.0.1 + pc-i440fx-1.6 + pc-q35-5.0 + pc-q35-2.8 + pc-i440fx-2.10 + pc-q35-3.0 + pc-q35-4.0 + microvm + pc-i440fx-2.3 + pc-1.2 + pc-i440fx-4.0 + pc-i440fx-5.0 + pc-i440fx-2.8 + pc-q35-2.5 + pc-i440fx-3.0 + pc-q35-2.11 + + + + + + + + + + + + + + hvm + + 32 + /usr/bin/qemu-system-xtensa + sim + kc705 + ml605 + ml605-nommu + virt + lx60-nommu + lx200 + lx200-nommu + lx60 + kc705-nommu + + + + + + + + + + + hvm + + 32 + /usr/bin/qemu-system-xtensaeb + sim + kc705 + ml605 + ml605-nommu + virt + lx60-nommu + lx200 + lx200-nommu + lx60 + kc705-nommu + + + + + + + + + + + + diff --git a/src/test/resources/libvirt/xml/qemu-kvm_capabilities_no-cpu-features.xml b/src/test/resources/libvirt/xml/qemu-kvm_capabilities_no-cpu-features.xml new file mode 100644 index 0000000..07111f0 --- /dev/null +++ b/src/test/resources/libvirt/xml/qemu-kvm_capabilities_no-cpu-features.xml @@ -0,0 +1,961 @@ + + + + 9b2f12af-1fba-444c-b72b-9cbc43fb3ca5 + + x86_64 + Skylake-Client-IBRS + Intel + + + + + + + + + + + + + + + tcp + rdma + + + + + + 16161320 + 4040330 + 0 + 0 + + + + + + + + + + + + + + + + + none + 0 + + + + + hvm + + 64 + /usr/bin/qemu-system-alpha + clipper + + + + + + + + + + + hvm + + 32 + /usr/bin/qemu-system-arm + integratorcp + ast2600-evb + borzoi + spitz + virt-2.7 + nuri + mcimx7d-sabre + romulus-bmc + virt-3.0 + virt-5.0 + npcm750-evb + virt-2.10 + musca-b1 + virt-2.8 + realview-pbx-a9 + versatileab + kzm + musca-a + virt-3.1 + mcimx6ul-evk + virt-5.1 + smdkc210 + sx1 + virt-2.11 + imx25-pdk + virt-2.9 + orangepi-pc + z2 + virt-5.2 + virt + xilinx-zynq-a9 + tosa + mps2-an500 + virt-2.12 + mps2-an521 + sabrelite + mps2-an511 + canon-a1100 + realview-eb + emcraft-sf2 + realview-pb-a8 + virt-4.0 + raspi1ap + palmetto-bmc + sx1-v1 + n810 + tacoma-bmc + n800 + virt-4.1 + quanta-gsj + versatilepb + terrier + mainstone + realview-eb-mpcore + supermicrox11-bmc + virt-4.2 + witherspoon-bmc + swift-bmc + vexpress-a9 + midway + musicpal + lm3s811evb + lm3s6965evb + microbit + mps2-an505 + mps2-an385 + cubieboard + verdex + netduino2 + mps2-an386 + raspi2b + raspi2 + vexpress-a15 + sonorapass-bmc + cheetah + virt-2.6 + ast2500-evb + highbank + akita + connex + netduinoplus2 + collie + raspi0 + + + + + + + + + + + hvm + + 32 + /usr/bin/qemu-system-arm + integratorcp + ast2600-evb + borzoi + spitz + virt-2.7 + nuri + mcimx7d-sabre + romulus-bmc + virt-3.0 + virt-5.0 + npcm750-evb + virt-2.10 + musca-b1 + virt-2.8 + realview-pbx-a9 + versatileab + kzm + musca-a + virt-3.1 + mcimx6ul-evk + virt-5.1 + smdkc210 + sx1 + virt-2.11 + imx25-pdk + virt-2.9 + orangepi-pc + z2 + virt-5.2 + virt + xilinx-zynq-a9 + tosa + mps2-an500 + virt-2.12 + mps2-an521 + sabrelite + mps2-an511 + canon-a1100 + realview-eb + emcraft-sf2 + realview-pb-a8 + virt-4.0 + raspi1ap + palmetto-bmc + sx1-v1 + n810 + tacoma-bmc + n800 + virt-4.1 + quanta-gsj + versatilepb + terrier + mainstone + realview-eb-mpcore + supermicrox11-bmc + virt-4.2 + witherspoon-bmc + swift-bmc + vexpress-a9 + midway + musicpal + lm3s811evb + lm3s6965evb + microbit + mps2-an505 + mps2-an385 + cubieboard + verdex + netduino2 + mps2-an386 + raspi2b + raspi2 + vexpress-a15 + sonorapass-bmc + cheetah + virt-2.6 + ast2500-evb + highbank + akita + connex + netduinoplus2 + collie + raspi0 + + + + + + + + + + + hvm + + 64 + /usr/bin/qemu-system-aarch64 + integratorcp + ast2600-evb + borzoi + spitz + virt-2.7 + nuri + mcimx7d-sabre + romulus-bmc + virt-3.0 + virt-5.0 + npcm750-evb + virt-2.10 + musca-b1 + virt-2.8 + realview-pbx-a9 + versatileab + kzm + musca-a + virt-3.1 + mcimx6ul-evk + virt-5.1 + smdkc210 + sx1 + virt-2.11 + imx25-pdk + virt-2.9 + orangepi-pc + z2 + virt-5.2 + virt + xilinx-zynq-a9 + xlnx-zcu102 + tosa + mps2-an500 + virt-2.12 + mps2-an521 + sabrelite + mps2-an511 + canon-a1100 + realview-eb + emcraft-sf2 + realview-pb-a8 + sbsa-ref + virt-4.0 + raspi1ap + palmetto-bmc + sx1-v1 + n810 + tacoma-bmc + n800 + virt-4.1 + quanta-gsj + versatilepb + terrier + mainstone + realview-eb-mpcore + supermicrox11-bmc + virt-4.2 + witherspoon-bmc + swift-bmc + vexpress-a9 + midway + musicpal + lm3s811evb + lm3s6965evb + microbit + mps2-an505 + mps2-an385 + raspi3ap + cubieboard + verdex + netduino2 + xlnx-versal-virt + mps2-an386 + raspi3b + raspi3 + raspi2b + raspi2 + vexpress-a15 + sonorapass-bmc + cheetah + virt-2.6 + ast2500-evb + highbank + akita + connex + netduinoplus2 + collie + raspi0 + + + + + + + + + + + + hvm + + 32 + /usr/bin/qemu-system-cris + axis-dev88 + + + + + + + + + + + hvm + + 32 + /usr/bin/qemu-system-i386 + pc-i440fx-5.2 + pc + pc-q35-5.2 + q35 + pc-i440fx-2.12 + pc-i440fx-2.0 + pc-q35-4.2 + pc-i440fx-2.5 + pc-i440fx-4.2 + pc-i440fx-1.5 + pc-q35-2.7 + pc-i440fx-2.2 + pc-1.1 + pc-i440fx-2.7 + pc-q35-2.4 + pc-q35-2.10 + pc-i440fx-1.7 + pc-q35-5.1 + pc-q35-2.9 + pc-i440fx-2.11 + pc-q35-3.1 + pc-q35-4.1 + pc-i440fx-2.4 + pc-1.3 + pc-i440fx-4.1 + pc-i440fx-5.1 + pc-i440fx-2.9 + isapc + pc-i440fx-1.4 + pc-q35-2.6 + pc-i440fx-3.1 + pc-q35-2.12 + pc-i440fx-2.1 + pc-1.0 + pc-i440fx-2.6 + pc-q35-4.0.1 + pc-i440fx-1.6 + pc-q35-5.0 + pc-q35-2.8 + pc-i440fx-2.10 + pc-q35-3.0 + pc-q35-4.0 + microvm + pc-i440fx-2.3 + pc-1.2 + pc-i440fx-4.0 + pc-i440fx-5.0 + pc-i440fx-2.8 + pc-q35-2.5 + pc-i440fx-3.0 + pc-q35-2.11 + + + + + + + + + + + + + + + + hvm + + 32 + /usr/bin/qemu-system-m68k + mcf5208evb + an5206 + q800 + next-cube + + + + + + + + + + + hvm + + 32 + /usr/bin/qemu-system-microblaze + petalogix-s3adsp1800 + petalogix-ml605 + xlnx-zynqmp-pmu + + + + + + + + + + + hvm + + 32 + /usr/bin/qemu-system-microblazeel + petalogix-s3adsp1800 + petalogix-ml605 + xlnx-zynqmp-pmu + + + + + + + + + + + hvm + + 32 + /usr/bin/qemu-system-mips + malta + mipssim + + + + + + + + + + + hvm + + 32 + /usr/bin/qemu-system-mipsel + malta + mipssim + + + + + + + + + + + hvm + + 64 + /usr/bin/qemu-system-mips64 + malta + pica61 + mipssim + magnum + + + + + + + + + + + hvm + + 64 + /usr/bin/qemu-system-mips64el + malta + mipssim + pica61 + magnum + boston + fuloong2e + fulong2e + + + + + + + + + + + hvm + + 32 + /usr/bin/qemu-system-ppc + g3beige + virtex-ml507 + mac99 + ppce500 + sam460ex + bamboo + 40p + ref405ep + mpc8544ds + taihu + + + + + + + + + + + hvm + + 64 + /usr/bin/qemu-system-ppc64 + pseries-5.2 + pseries + powernv9 + powernv + taihu + pseries-4.1 + mpc8544ds + pseries-2.5 + powernv10 + pseries-4.2 + pseries-2.6 + ppce500 + pseries-2.7 + pseries-3.0 + pseries-5.0 + 40p + pseries-2.8 + pseries-3.1 + pseries-5.1 + pseries-2.9 + bamboo + g3beige + pseries-2.12-sxxm + pseries-2.10 + virtex-ml507 + pseries-2.11 + pseries-2.1 + pseries-2.12 + pseries-2.2 + mac99 + sam460ex + ref405ep + pseries-2.3 + powernv8 + pseries-4.0 + pseries-2.4 + + + + + + + + + + + hvm + + 64 + /usr/bin/qemu-system-ppc64 + pseries-5.2 + pseries + powernv9 + powernv + taihu + pseries-4.1 + mpc8544ds + pseries-2.5 + powernv10 + pseries-4.2 + pseries-2.6 + ppce500 + pseries-2.7 + pseries-3.0 + pseries-5.0 + 40p + pseries-2.8 + pseries-3.1 + pseries-5.1 + pseries-2.9 + bamboo + g3beige + pseries-2.12-sxxm + pseries-2.10 + virtex-ml507 + pseries-2.11 + pseries-2.1 + pseries-2.12 + pseries-2.2 + mac99 + sam460ex + ref405ep + pseries-2.3 + powernv8 + pseries-4.0 + pseries-2.4 + + + + + + + + + + + hvm + + 32 + /usr/bin/qemu-system-riscv32 + spike + virt + opentitan + sifive_e + sifive_u + + + + + + + + + + + hvm + + 64 + /usr/bin/qemu-system-riscv64 + spike + virt + sifive_e + sifive_u + microchip-icicle-kit + + + + + + + + + + + hvm + + 64 + /usr/bin/qemu-system-s390x + s390-ccw-virtio-5.2 + s390-ccw-virtio + s390-ccw-virtio-4.0 + s390-ccw-virtio-3.1 + s390-ccw-virtio-2.6 + s390-ccw-virtio-2.12 + s390-ccw-virtio-2.9 + s390-ccw-virtio-5.1 + s390-ccw-virtio-3.0 + s390-ccw-virtio-4.2 + s390-ccw-virtio-2.5 + s390-ccw-virtio-2.11 + s390-ccw-virtio-2.8 + s390-ccw-virtio-5.0 + s390-ccw-virtio-4.1 + s390-ccw-virtio-2.4 + s390-ccw-virtio-2.10 + s390-ccw-virtio-2.7 + + + + + + + + + + + hvm + + 32 + /usr/bin/qemu-system-sh4 + shix + r2d + + + + + + + + + + + hvm + + 64 + /usr/bin/qemu-system-sh4eb + shix + r2d + + + + + + + + + + + hvm + + 32 + /usr/bin/qemu-system-sparc + SS-5 + SS-20 + LX + SPARCClassic + leon3_generic + SPARCbook + SS-4 + SS-600MP + SS-10 + Voyager + + + + + + + + + + + hvm + + 64 + /usr/bin/qemu-system-sparc64 + sun4u + niagara + sun4v + + + + + + + + + + + hvm + + 64 + /usr/bin/qemu-system-x86_64 + pc-i440fx-5.2 + pc + pc-q35-5.2 + q35 + pc-i440fx-2.12 + pc-i440fx-2.0 + pc-q35-4.2 + pc-i440fx-2.5 + pc-i440fx-4.2 + pc-i440fx-1.5 + pc-q35-2.7 + pc-i440fx-2.2 + pc-1.1 + pc-i440fx-2.7 + pc-q35-2.4 + pc-q35-2.10 + pc-i440fx-1.7 + pc-q35-5.1 + pc-q35-2.9 + pc-i440fx-2.11 + pc-q35-3.1 + pc-q35-4.1 + pc-i440fx-2.4 + pc-1.3 + pc-i440fx-4.1 + pc-i440fx-5.1 + pc-i440fx-2.9 + isapc + pc-i440fx-1.4 + pc-q35-2.6 + pc-i440fx-3.1 + pc-q35-2.12 + pc-i440fx-2.1 + pc-1.0 + pc-i440fx-2.6 + pc-q35-4.0.1 + pc-i440fx-1.6 + pc-q35-5.0 + pc-q35-2.8 + pc-i440fx-2.10 + pc-q35-3.0 + pc-q35-4.0 + microvm + pc-i440fx-2.3 + pc-1.2 + pc-i440fx-4.0 + pc-i440fx-5.0 + pc-i440fx-2.8 + pc-q35-2.5 + pc-i440fx-3.0 + pc-q35-2.11 + + + + + + + + + + + + + + hvm + + 32 + /usr/bin/qemu-system-xtensa + sim + kc705 + ml605 + ml605-nommu + virt + lx60-nommu + lx200 + lx200-nommu + lx60 + kc705-nommu + + + + + + + + + + + hvm + + 32 + /usr/bin/qemu-system-xtensaeb + sim + kc705 + ml605 + ml605-nommu + virt + lx60-nommu + lx200 + lx200-nommu + lx60 + kc705-nommu + + + + + + + + + + + + diff --git a/src/test/resources/libvirt/xml/qemu-kvm_capabilities_no-cpu-pages.xml b/src/test/resources/libvirt/xml/qemu-kvm_capabilities_no-cpu-pages.xml new file mode 100644 index 0000000..cadd96f --- /dev/null +++ b/src/test/resources/libvirt/xml/qemu-kvm_capabilities_no-cpu-pages.xml @@ -0,0 +1,983 @@ + + + + 9b2f12af-1fba-444c-b72b-9cbc43fb3ca5 + + x86_64 + Skylake-Client-IBRS + Intel + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + tcp + rdma + + + + + + 16161320 + 4040330 + 0 + 0 + + + + + + + + + + + + + + + + + none + 0 + + + + + hvm + + 64 + /usr/bin/qemu-system-alpha + clipper + + + + + + + + + + + hvm + + 32 + /usr/bin/qemu-system-arm + integratorcp + ast2600-evb + borzoi + spitz + virt-2.7 + nuri + mcimx7d-sabre + romulus-bmc + virt-3.0 + virt-5.0 + npcm750-evb + virt-2.10 + musca-b1 + virt-2.8 + realview-pbx-a9 + versatileab + kzm + musca-a + virt-3.1 + mcimx6ul-evk + virt-5.1 + smdkc210 + sx1 + virt-2.11 + imx25-pdk + virt-2.9 + orangepi-pc + z2 + virt-5.2 + virt + xilinx-zynq-a9 + tosa + mps2-an500 + virt-2.12 + mps2-an521 + sabrelite + mps2-an511 + canon-a1100 + realview-eb + emcraft-sf2 + realview-pb-a8 + virt-4.0 + raspi1ap + palmetto-bmc + sx1-v1 + n810 + tacoma-bmc + n800 + virt-4.1 + quanta-gsj + versatilepb + terrier + mainstone + realview-eb-mpcore + supermicrox11-bmc + virt-4.2 + witherspoon-bmc + swift-bmc + vexpress-a9 + midway + musicpal + lm3s811evb + lm3s6965evb + microbit + mps2-an505 + mps2-an385 + cubieboard + verdex + netduino2 + mps2-an386 + raspi2b + raspi2 + vexpress-a15 + sonorapass-bmc + cheetah + virt-2.6 + ast2500-evb + highbank + akita + connex + netduinoplus2 + collie + raspi0 + + + + + + + + + + + hvm + + 32 + /usr/bin/qemu-system-arm + integratorcp + ast2600-evb + borzoi + spitz + virt-2.7 + nuri + mcimx7d-sabre + romulus-bmc + virt-3.0 + virt-5.0 + npcm750-evb + virt-2.10 + musca-b1 + virt-2.8 + realview-pbx-a9 + versatileab + kzm + musca-a + virt-3.1 + mcimx6ul-evk + virt-5.1 + smdkc210 + sx1 + virt-2.11 + imx25-pdk + virt-2.9 + orangepi-pc + z2 + virt-5.2 + virt + xilinx-zynq-a9 + tosa + mps2-an500 + virt-2.12 + mps2-an521 + sabrelite + mps2-an511 + canon-a1100 + realview-eb + emcraft-sf2 + realview-pb-a8 + virt-4.0 + raspi1ap + palmetto-bmc + sx1-v1 + n810 + tacoma-bmc + n800 + virt-4.1 + quanta-gsj + versatilepb + terrier + mainstone + realview-eb-mpcore + supermicrox11-bmc + virt-4.2 + witherspoon-bmc + swift-bmc + vexpress-a9 + midway + musicpal + lm3s811evb + lm3s6965evb + microbit + mps2-an505 + mps2-an385 + cubieboard + verdex + netduino2 + mps2-an386 + raspi2b + raspi2 + vexpress-a15 + sonorapass-bmc + cheetah + virt-2.6 + ast2500-evb + highbank + akita + connex + netduinoplus2 + collie + raspi0 + + + + + + + + + + + hvm + + 64 + /usr/bin/qemu-system-aarch64 + integratorcp + ast2600-evb + borzoi + spitz + virt-2.7 + nuri + mcimx7d-sabre + romulus-bmc + virt-3.0 + virt-5.0 + npcm750-evb + virt-2.10 + musca-b1 + virt-2.8 + realview-pbx-a9 + versatileab + kzm + musca-a + virt-3.1 + mcimx6ul-evk + virt-5.1 + smdkc210 + sx1 + virt-2.11 + imx25-pdk + virt-2.9 + orangepi-pc + z2 + virt-5.2 + virt + xilinx-zynq-a9 + xlnx-zcu102 + tosa + mps2-an500 + virt-2.12 + mps2-an521 + sabrelite + mps2-an511 + canon-a1100 + realview-eb + emcraft-sf2 + realview-pb-a8 + sbsa-ref + virt-4.0 + raspi1ap + palmetto-bmc + sx1-v1 + n810 + tacoma-bmc + n800 + virt-4.1 + quanta-gsj + versatilepb + terrier + mainstone + realview-eb-mpcore + supermicrox11-bmc + virt-4.2 + witherspoon-bmc + swift-bmc + vexpress-a9 + midway + musicpal + lm3s811evb + lm3s6965evb + microbit + mps2-an505 + mps2-an385 + raspi3ap + cubieboard + verdex + netduino2 + xlnx-versal-virt + mps2-an386 + raspi3b + raspi3 + raspi2b + raspi2 + vexpress-a15 + sonorapass-bmc + cheetah + virt-2.6 + ast2500-evb + highbank + akita + connex + netduinoplus2 + collie + raspi0 + + + + + + + + + + + + hvm + + 32 + /usr/bin/qemu-system-cris + axis-dev88 + + + + + + + + + + + hvm + + 32 + /usr/bin/qemu-system-i386 + pc-i440fx-5.2 + pc + pc-q35-5.2 + q35 + pc-i440fx-2.12 + pc-i440fx-2.0 + pc-q35-4.2 + pc-i440fx-2.5 + pc-i440fx-4.2 + pc-i440fx-1.5 + pc-q35-2.7 + pc-i440fx-2.2 + pc-1.1 + pc-i440fx-2.7 + pc-q35-2.4 + pc-q35-2.10 + pc-i440fx-1.7 + pc-q35-5.1 + pc-q35-2.9 + pc-i440fx-2.11 + pc-q35-3.1 + pc-q35-4.1 + pc-i440fx-2.4 + pc-1.3 + pc-i440fx-4.1 + pc-i440fx-5.1 + pc-i440fx-2.9 + isapc + pc-i440fx-1.4 + pc-q35-2.6 + pc-i440fx-3.1 + pc-q35-2.12 + pc-i440fx-2.1 + pc-1.0 + pc-i440fx-2.6 + pc-q35-4.0.1 + pc-i440fx-1.6 + pc-q35-5.0 + pc-q35-2.8 + pc-i440fx-2.10 + pc-q35-3.0 + pc-q35-4.0 + microvm + pc-i440fx-2.3 + pc-1.2 + pc-i440fx-4.0 + pc-i440fx-5.0 + pc-i440fx-2.8 + pc-q35-2.5 + pc-i440fx-3.0 + pc-q35-2.11 + + + + + + + + + + + + + + + + hvm + + 32 + /usr/bin/qemu-system-m68k + mcf5208evb + an5206 + q800 + next-cube + + + + + + + + + + + hvm + + 32 + /usr/bin/qemu-system-microblaze + petalogix-s3adsp1800 + petalogix-ml605 + xlnx-zynqmp-pmu + + + + + + + + + + + hvm + + 32 + /usr/bin/qemu-system-microblazeel + petalogix-s3adsp1800 + petalogix-ml605 + xlnx-zynqmp-pmu + + + + + + + + + + + hvm + + 32 + /usr/bin/qemu-system-mips + malta + mipssim + + + + + + + + + + + hvm + + 32 + /usr/bin/qemu-system-mipsel + malta + mipssim + + + + + + + + + + + hvm + + 64 + /usr/bin/qemu-system-mips64 + malta + pica61 + mipssim + magnum + + + + + + + + + + + hvm + + 64 + /usr/bin/qemu-system-mips64el + malta + mipssim + pica61 + magnum + boston + fuloong2e + fulong2e + + + + + + + + + + + hvm + + 32 + /usr/bin/qemu-system-ppc + g3beige + virtex-ml507 + mac99 + ppce500 + sam460ex + bamboo + 40p + ref405ep + mpc8544ds + taihu + + + + + + + + + + + hvm + + 64 + /usr/bin/qemu-system-ppc64 + pseries-5.2 + pseries + powernv9 + powernv + taihu + pseries-4.1 + mpc8544ds + pseries-2.5 + powernv10 + pseries-4.2 + pseries-2.6 + ppce500 + pseries-2.7 + pseries-3.0 + pseries-5.0 + 40p + pseries-2.8 + pseries-3.1 + pseries-5.1 + pseries-2.9 + bamboo + g3beige + pseries-2.12-sxxm + pseries-2.10 + virtex-ml507 + pseries-2.11 + pseries-2.1 + pseries-2.12 + pseries-2.2 + mac99 + sam460ex + ref405ep + pseries-2.3 + powernv8 + pseries-4.0 + pseries-2.4 + + + + + + + + + + + hvm + + 64 + /usr/bin/qemu-system-ppc64 + pseries-5.2 + pseries + powernv9 + powernv + taihu + pseries-4.1 + mpc8544ds + pseries-2.5 + powernv10 + pseries-4.2 + pseries-2.6 + ppce500 + pseries-2.7 + pseries-3.0 + pseries-5.0 + 40p + pseries-2.8 + pseries-3.1 + pseries-5.1 + pseries-2.9 + bamboo + g3beige + pseries-2.12-sxxm + pseries-2.10 + virtex-ml507 + pseries-2.11 + pseries-2.1 + pseries-2.12 + pseries-2.2 + mac99 + sam460ex + ref405ep + pseries-2.3 + powernv8 + pseries-4.0 + pseries-2.4 + + + + + + + + + + + hvm + + 32 + /usr/bin/qemu-system-riscv32 + spike + virt + opentitan + sifive_e + sifive_u + + + + + + + + + + + hvm + + 64 + /usr/bin/qemu-system-riscv64 + spike + virt + sifive_e + sifive_u + microchip-icicle-kit + + + + + + + + + + + hvm + + 64 + /usr/bin/qemu-system-s390x + s390-ccw-virtio-5.2 + s390-ccw-virtio + s390-ccw-virtio-4.0 + s390-ccw-virtio-3.1 + s390-ccw-virtio-2.6 + s390-ccw-virtio-2.12 + s390-ccw-virtio-2.9 + s390-ccw-virtio-5.1 + s390-ccw-virtio-3.0 + s390-ccw-virtio-4.2 + s390-ccw-virtio-2.5 + s390-ccw-virtio-2.11 + s390-ccw-virtio-2.8 + s390-ccw-virtio-5.0 + s390-ccw-virtio-4.1 + s390-ccw-virtio-2.4 + s390-ccw-virtio-2.10 + s390-ccw-virtio-2.7 + + + + + + + + + + + hvm + + 32 + /usr/bin/qemu-system-sh4 + shix + r2d + + + + + + + + + + + hvm + + 64 + /usr/bin/qemu-system-sh4eb + shix + r2d + + + + + + + + + + + hvm + + 32 + /usr/bin/qemu-system-sparc + SS-5 + SS-20 + LX + SPARCClassic + leon3_generic + SPARCbook + SS-4 + SS-600MP + SS-10 + Voyager + + + + + + + + + + + hvm + + 64 + /usr/bin/qemu-system-sparc64 + sun4u + niagara + sun4v + + + + + + + + + + + hvm + + 64 + /usr/bin/qemu-system-x86_64 + pc-i440fx-5.2 + pc + pc-q35-5.2 + q35 + pc-i440fx-2.12 + pc-i440fx-2.0 + pc-q35-4.2 + pc-i440fx-2.5 + pc-i440fx-4.2 + pc-i440fx-1.5 + pc-q35-2.7 + pc-i440fx-2.2 + pc-1.1 + pc-i440fx-2.7 + pc-q35-2.4 + pc-q35-2.10 + pc-i440fx-1.7 + pc-q35-5.1 + pc-q35-2.9 + pc-i440fx-2.11 + pc-q35-3.1 + pc-q35-4.1 + pc-i440fx-2.4 + pc-1.3 + pc-i440fx-4.1 + pc-i440fx-5.1 + pc-i440fx-2.9 + isapc + pc-i440fx-1.4 + pc-q35-2.6 + pc-i440fx-3.1 + pc-q35-2.12 + pc-i440fx-2.1 + pc-1.0 + pc-i440fx-2.6 + pc-q35-4.0.1 + pc-i440fx-1.6 + pc-q35-5.0 + pc-q35-2.8 + pc-i440fx-2.10 + pc-q35-3.0 + pc-q35-4.0 + microvm + pc-i440fx-2.3 + pc-1.2 + pc-i440fx-4.0 + pc-i440fx-5.0 + pc-i440fx-2.8 + pc-q35-2.5 + pc-i440fx-3.0 + pc-q35-2.11 + + + + + + + + + + + + + + hvm + + 32 + /usr/bin/qemu-system-xtensa + sim + kc705 + ml605 + ml605-nommu + virt + lx60-nommu + lx200 + lx200-nommu + lx60 + kc705-nommu + + + + + + + + + + + hvm + + 32 + /usr/bin/qemu-system-xtensaeb + sim + kc705 + ml605 + ml605-nommu + virt + lx60-nommu + lx200 + lx200-nommu + lx60 + kc705-nommu + + + + + + + + + + + + diff --git a/src/test/resources/libvirt/xml/qemu-kvm_capabilities_no-cpu.xml b/src/test/resources/libvirt/xml/qemu-kvm_capabilities_no-cpu.xml new file mode 100644 index 0000000..b579b57 --- /dev/null +++ b/src/test/resources/libvirt/xml/qemu-kvm_capabilities_no-cpu.xml @@ -0,0 +1,950 @@ + + + + 9b2f12af-1fba-444c-b72b-9cbc43fb3ca5 + + + + + + + + tcp + rdma + + + + + + 16161320 + 4040330 + 0 + 0 + + + + + + + + + + + + + + + + + none + 0 + + + + + hvm + + 64 + /usr/bin/qemu-system-alpha + clipper + + + + + + + + + + + hvm + + 32 + /usr/bin/qemu-system-arm + integratorcp + ast2600-evb + borzoi + spitz + virt-2.7 + nuri + mcimx7d-sabre + romulus-bmc + virt-3.0 + virt-5.0 + npcm750-evb + virt-2.10 + musca-b1 + virt-2.8 + realview-pbx-a9 + versatileab + kzm + musca-a + virt-3.1 + mcimx6ul-evk + virt-5.1 + smdkc210 + sx1 + virt-2.11 + imx25-pdk + virt-2.9 + orangepi-pc + z2 + virt-5.2 + virt + xilinx-zynq-a9 + tosa + mps2-an500 + virt-2.12 + mps2-an521 + sabrelite + mps2-an511 + canon-a1100 + realview-eb + emcraft-sf2 + realview-pb-a8 + virt-4.0 + raspi1ap + palmetto-bmc + sx1-v1 + n810 + tacoma-bmc + n800 + virt-4.1 + quanta-gsj + versatilepb + terrier + mainstone + realview-eb-mpcore + supermicrox11-bmc + virt-4.2 + witherspoon-bmc + swift-bmc + vexpress-a9 + midway + musicpal + lm3s811evb + lm3s6965evb + microbit + mps2-an505 + mps2-an385 + cubieboard + verdex + netduino2 + mps2-an386 + raspi2b + raspi2 + vexpress-a15 + sonorapass-bmc + cheetah + virt-2.6 + ast2500-evb + highbank + akita + connex + netduinoplus2 + collie + raspi0 + + + + + + + + + + + hvm + + 32 + /usr/bin/qemu-system-arm + integratorcp + ast2600-evb + borzoi + spitz + virt-2.7 + nuri + mcimx7d-sabre + romulus-bmc + virt-3.0 + virt-5.0 + npcm750-evb + virt-2.10 + musca-b1 + virt-2.8 + realview-pbx-a9 + versatileab + kzm + musca-a + virt-3.1 + mcimx6ul-evk + virt-5.1 + smdkc210 + sx1 + virt-2.11 + imx25-pdk + virt-2.9 + orangepi-pc + z2 + virt-5.2 + virt + xilinx-zynq-a9 + tosa + mps2-an500 + virt-2.12 + mps2-an521 + sabrelite + mps2-an511 + canon-a1100 + realview-eb + emcraft-sf2 + realview-pb-a8 + virt-4.0 + raspi1ap + palmetto-bmc + sx1-v1 + n810 + tacoma-bmc + n800 + virt-4.1 + quanta-gsj + versatilepb + terrier + mainstone + realview-eb-mpcore + supermicrox11-bmc + virt-4.2 + witherspoon-bmc + swift-bmc + vexpress-a9 + midway + musicpal + lm3s811evb + lm3s6965evb + microbit + mps2-an505 + mps2-an385 + cubieboard + verdex + netduino2 + mps2-an386 + raspi2b + raspi2 + vexpress-a15 + sonorapass-bmc + cheetah + virt-2.6 + ast2500-evb + highbank + akita + connex + netduinoplus2 + collie + raspi0 + + + + + + + + + + + hvm + + 64 + /usr/bin/qemu-system-aarch64 + integratorcp + ast2600-evb + borzoi + spitz + virt-2.7 + nuri + mcimx7d-sabre + romulus-bmc + virt-3.0 + virt-5.0 + npcm750-evb + virt-2.10 + musca-b1 + virt-2.8 + realview-pbx-a9 + versatileab + kzm + musca-a + virt-3.1 + mcimx6ul-evk + virt-5.1 + smdkc210 + sx1 + virt-2.11 + imx25-pdk + virt-2.9 + orangepi-pc + z2 + virt-5.2 + virt + xilinx-zynq-a9 + xlnx-zcu102 + tosa + mps2-an500 + virt-2.12 + mps2-an521 + sabrelite + mps2-an511 + canon-a1100 + realview-eb + emcraft-sf2 + realview-pb-a8 + sbsa-ref + virt-4.0 + raspi1ap + palmetto-bmc + sx1-v1 + n810 + tacoma-bmc + n800 + virt-4.1 + quanta-gsj + versatilepb + terrier + mainstone + realview-eb-mpcore + supermicrox11-bmc + virt-4.2 + witherspoon-bmc + swift-bmc + vexpress-a9 + midway + musicpal + lm3s811evb + lm3s6965evb + microbit + mps2-an505 + mps2-an385 + raspi3ap + cubieboard + verdex + netduino2 + xlnx-versal-virt + mps2-an386 + raspi3b + raspi3 + raspi2b + raspi2 + vexpress-a15 + sonorapass-bmc + cheetah + virt-2.6 + ast2500-evb + highbank + akita + connex + netduinoplus2 + collie + raspi0 + + + + + + + + + + + + hvm + + 32 + /usr/bin/qemu-system-cris + axis-dev88 + + + + + + + + + + + hvm + + 32 + /usr/bin/qemu-system-i386 + pc-i440fx-5.2 + pc + pc-q35-5.2 + q35 + pc-i440fx-2.12 + pc-i440fx-2.0 + pc-q35-4.2 + pc-i440fx-2.5 + pc-i440fx-4.2 + pc-i440fx-1.5 + pc-q35-2.7 + pc-i440fx-2.2 + pc-1.1 + pc-i440fx-2.7 + pc-q35-2.4 + pc-q35-2.10 + pc-i440fx-1.7 + pc-q35-5.1 + pc-q35-2.9 + pc-i440fx-2.11 + pc-q35-3.1 + pc-q35-4.1 + pc-i440fx-2.4 + pc-1.3 + pc-i440fx-4.1 + pc-i440fx-5.1 + pc-i440fx-2.9 + isapc + pc-i440fx-1.4 + pc-q35-2.6 + pc-i440fx-3.1 + pc-q35-2.12 + pc-i440fx-2.1 + pc-1.0 + pc-i440fx-2.6 + pc-q35-4.0.1 + pc-i440fx-1.6 + pc-q35-5.0 + pc-q35-2.8 + pc-i440fx-2.10 + pc-q35-3.0 + pc-q35-4.0 + microvm + pc-i440fx-2.3 + pc-1.2 + pc-i440fx-4.0 + pc-i440fx-5.0 + pc-i440fx-2.8 + pc-q35-2.5 + pc-i440fx-3.0 + pc-q35-2.11 + + + + + + + + + + + + + + + + hvm + + 32 + /usr/bin/qemu-system-m68k + mcf5208evb + an5206 + q800 + next-cube + + + + + + + + + + + hvm + + 32 + /usr/bin/qemu-system-microblaze + petalogix-s3adsp1800 + petalogix-ml605 + xlnx-zynqmp-pmu + + + + + + + + + + + hvm + + 32 + /usr/bin/qemu-system-microblazeel + petalogix-s3adsp1800 + petalogix-ml605 + xlnx-zynqmp-pmu + + + + + + + + + + + hvm + + 32 + /usr/bin/qemu-system-mips + malta + mipssim + + + + + + + + + + + hvm + + 32 + /usr/bin/qemu-system-mipsel + malta + mipssim + + + + + + + + + + + hvm + + 64 + /usr/bin/qemu-system-mips64 + malta + pica61 + mipssim + magnum + + + + + + + + + + + hvm + + 64 + /usr/bin/qemu-system-mips64el + malta + mipssim + pica61 + magnum + boston + fuloong2e + fulong2e + + + + + + + + + + + hvm + + 32 + /usr/bin/qemu-system-ppc + g3beige + virtex-ml507 + mac99 + ppce500 + sam460ex + bamboo + 40p + ref405ep + mpc8544ds + taihu + + + + + + + + + + + hvm + + 64 + /usr/bin/qemu-system-ppc64 + pseries-5.2 + pseries + powernv9 + powernv + taihu + pseries-4.1 + mpc8544ds + pseries-2.5 + powernv10 + pseries-4.2 + pseries-2.6 + ppce500 + pseries-2.7 + pseries-3.0 + pseries-5.0 + 40p + pseries-2.8 + pseries-3.1 + pseries-5.1 + pseries-2.9 + bamboo + g3beige + pseries-2.12-sxxm + pseries-2.10 + virtex-ml507 + pseries-2.11 + pseries-2.1 + pseries-2.12 + pseries-2.2 + mac99 + sam460ex + ref405ep + pseries-2.3 + powernv8 + pseries-4.0 + pseries-2.4 + + + + + + + + + + + hvm + + 64 + /usr/bin/qemu-system-ppc64 + pseries-5.2 + pseries + powernv9 + powernv + taihu + pseries-4.1 + mpc8544ds + pseries-2.5 + powernv10 + pseries-4.2 + pseries-2.6 + ppce500 + pseries-2.7 + pseries-3.0 + pseries-5.0 + 40p + pseries-2.8 + pseries-3.1 + pseries-5.1 + pseries-2.9 + bamboo + g3beige + pseries-2.12-sxxm + pseries-2.10 + virtex-ml507 + pseries-2.11 + pseries-2.1 + pseries-2.12 + pseries-2.2 + mac99 + sam460ex + ref405ep + pseries-2.3 + powernv8 + pseries-4.0 + pseries-2.4 + + + + + + + + + + + hvm + + 32 + /usr/bin/qemu-system-riscv32 + spike + virt + opentitan + sifive_e + sifive_u + + + + + + + + + + + hvm + + 64 + /usr/bin/qemu-system-riscv64 + spike + virt + sifive_e + sifive_u + microchip-icicle-kit + + + + + + + + + + + hvm + + 64 + /usr/bin/qemu-system-s390x + s390-ccw-virtio-5.2 + s390-ccw-virtio + s390-ccw-virtio-4.0 + s390-ccw-virtio-3.1 + s390-ccw-virtio-2.6 + s390-ccw-virtio-2.12 + s390-ccw-virtio-2.9 + s390-ccw-virtio-5.1 + s390-ccw-virtio-3.0 + s390-ccw-virtio-4.2 + s390-ccw-virtio-2.5 + s390-ccw-virtio-2.11 + s390-ccw-virtio-2.8 + s390-ccw-virtio-5.0 + s390-ccw-virtio-4.1 + s390-ccw-virtio-2.4 + s390-ccw-virtio-2.10 + s390-ccw-virtio-2.7 + + + + + + + + + + + hvm + + 32 + /usr/bin/qemu-system-sh4 + shix + r2d + + + + + + + + + + + hvm + + 64 + /usr/bin/qemu-system-sh4eb + shix + r2d + + + + + + + + + + + hvm + + 32 + /usr/bin/qemu-system-sparc + SS-5 + SS-20 + LX + SPARCClassic + leon3_generic + SPARCbook + SS-4 + SS-600MP + SS-10 + Voyager + + + + + + + + + + + hvm + + 64 + /usr/bin/qemu-system-sparc64 + sun4u + niagara + sun4v + + + + + + + + + + + hvm + + 64 + /usr/bin/qemu-system-x86_64 + pc-i440fx-5.2 + pc + pc-q35-5.2 + q35 + pc-i440fx-2.12 + pc-i440fx-2.0 + pc-q35-4.2 + pc-i440fx-2.5 + pc-i440fx-4.2 + pc-i440fx-1.5 + pc-q35-2.7 + pc-i440fx-2.2 + pc-1.1 + pc-i440fx-2.7 + pc-q35-2.4 + pc-q35-2.10 + pc-i440fx-1.7 + pc-q35-5.1 + pc-q35-2.9 + pc-i440fx-2.11 + pc-q35-3.1 + pc-q35-4.1 + pc-i440fx-2.4 + pc-1.3 + pc-i440fx-4.1 + pc-i440fx-5.1 + pc-i440fx-2.9 + isapc + pc-i440fx-1.4 + pc-q35-2.6 + pc-i440fx-3.1 + pc-q35-2.12 + pc-i440fx-2.1 + pc-1.0 + pc-i440fx-2.6 + pc-q35-4.0.1 + pc-i440fx-1.6 + pc-q35-5.0 + pc-q35-2.8 + pc-i440fx-2.10 + pc-q35-3.0 + pc-q35-4.0 + microvm + pc-i440fx-2.3 + pc-1.2 + pc-i440fx-4.0 + pc-i440fx-5.0 + pc-i440fx-2.8 + pc-q35-2.5 + pc-i440fx-3.0 + pc-q35-2.11 + + + + + + + + + + + + + + hvm + + 32 + /usr/bin/qemu-system-xtensa + sim + kc705 + ml605 + ml605-nommu + virt + lx60-nommu + lx200 + lx200-nommu + lx60 + kc705-nommu + + + + + + + + + + + hvm + + 32 + /usr/bin/qemu-system-xtensaeb + sim + kc705 + ml605 + ml605-nommu + virt + lx60-nommu + lx200 + lx200-nommu + lx60 + kc705-nommu + + + + + + + + + + + + diff --git a/src/test/resources/libvirt/xml/qemu-kvm_capabilities_no-guest-machines.xml b/src/test/resources/libvirt/xml/qemu-kvm_capabilities_no-guest-machines.xml new file mode 100644 index 0000000..0cd14ec --- /dev/null +++ b/src/test/resources/libvirt/xml/qemu-kvm_capabilities_no-guest-machines.xml @@ -0,0 +1,896 @@ + + + + 9b2f12af-1fba-444c-b72b-9cbc43fb3ca5 + + x86_64 + Skylake-Client-IBRS + Intel + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + tcp + rdma + + + + + + 16161320 + 4040330 + 0 + 0 + + + + + + + + + + + + + + + + + none + 0 + + + + + hvm + + 64 + /usr/bin/qemu-system-alpha + clipper + + + + + + + + + + + hvm + + 32 + /usr/bin/qemu-system-arm + integratorcp + ast2600-evb + borzoi + spitz + virt-2.7 + nuri + mcimx7d-sabre + romulus-bmc + virt-3.0 + virt-5.0 + npcm750-evb + virt-2.10 + musca-b1 + virt-2.8 + realview-pbx-a9 + versatileab + kzm + musca-a + virt-3.1 + mcimx6ul-evk + virt-5.1 + smdkc210 + sx1 + virt-2.11 + imx25-pdk + virt-2.9 + orangepi-pc + z2 + virt-5.2 + virt + xilinx-zynq-a9 + tosa + mps2-an500 + virt-2.12 + mps2-an521 + sabrelite + mps2-an511 + canon-a1100 + realview-eb + emcraft-sf2 + realview-pb-a8 + virt-4.0 + raspi1ap + palmetto-bmc + sx1-v1 + n810 + tacoma-bmc + n800 + virt-4.1 + quanta-gsj + versatilepb + terrier + mainstone + realview-eb-mpcore + supermicrox11-bmc + virt-4.2 + witherspoon-bmc + swift-bmc + vexpress-a9 + midway + musicpal + lm3s811evb + lm3s6965evb + microbit + mps2-an505 + mps2-an385 + cubieboard + verdex + netduino2 + mps2-an386 + raspi2b + raspi2 + vexpress-a15 + sonorapass-bmc + cheetah + virt-2.6 + ast2500-evb + highbank + akita + connex + netduinoplus2 + collie + raspi0 + + + + + + + + + + + hvm + + 32 + /usr/bin/qemu-system-arm + integratorcp + ast2600-evb + borzoi + spitz + virt-2.7 + nuri + mcimx7d-sabre + romulus-bmc + virt-3.0 + virt-5.0 + npcm750-evb + virt-2.10 + musca-b1 + virt-2.8 + realview-pbx-a9 + versatileab + kzm + musca-a + virt-3.1 + mcimx6ul-evk + virt-5.1 + smdkc210 + sx1 + virt-2.11 + imx25-pdk + virt-2.9 + orangepi-pc + z2 + virt-5.2 + virt + xilinx-zynq-a9 + tosa + mps2-an500 + virt-2.12 + mps2-an521 + sabrelite + mps2-an511 + canon-a1100 + realview-eb + emcraft-sf2 + realview-pb-a8 + virt-4.0 + raspi1ap + palmetto-bmc + sx1-v1 + n810 + tacoma-bmc + n800 + virt-4.1 + quanta-gsj + versatilepb + terrier + mainstone + realview-eb-mpcore + supermicrox11-bmc + virt-4.2 + witherspoon-bmc + swift-bmc + vexpress-a9 + midway + musicpal + lm3s811evb + lm3s6965evb + microbit + mps2-an505 + mps2-an385 + cubieboard + verdex + netduino2 + mps2-an386 + raspi2b + raspi2 + vexpress-a15 + sonorapass-bmc + cheetah + virt-2.6 + ast2500-evb + highbank + akita + connex + netduinoplus2 + collie + raspi0 + + + + + + + + + + + hvm + + 64 + /usr/bin/qemu-system-aarch64 + + + + + + + + + + + hvm + + 32 + /usr/bin/qemu-system-cris + axis-dev88 + + + + + + + + + + + hvm + + 32 + /usr/bin/qemu-system-i386 + pc-i440fx-5.2 + pc + pc-q35-5.2 + q35 + pc-i440fx-2.12 + pc-i440fx-2.0 + pc-q35-4.2 + pc-i440fx-2.5 + pc-i440fx-4.2 + pc-i440fx-1.5 + pc-q35-2.7 + pc-i440fx-2.2 + pc-1.1 + pc-i440fx-2.7 + pc-q35-2.4 + pc-q35-2.10 + pc-i440fx-1.7 + pc-q35-5.1 + pc-q35-2.9 + pc-i440fx-2.11 + pc-q35-3.1 + pc-q35-4.1 + pc-i440fx-2.4 + pc-1.3 + pc-i440fx-4.1 + pc-i440fx-5.1 + pc-i440fx-2.9 + isapc + pc-i440fx-1.4 + pc-q35-2.6 + pc-i440fx-3.1 + pc-q35-2.12 + pc-i440fx-2.1 + pc-1.0 + pc-i440fx-2.6 + pc-q35-4.0.1 + pc-i440fx-1.6 + pc-q35-5.0 + pc-q35-2.8 + pc-i440fx-2.10 + pc-q35-3.0 + pc-q35-4.0 + microvm + pc-i440fx-2.3 + pc-1.2 + pc-i440fx-4.0 + pc-i440fx-5.0 + pc-i440fx-2.8 + pc-q35-2.5 + pc-i440fx-3.0 + pc-q35-2.11 + + + + + + + + + + + + + + + + hvm + + 32 + /usr/bin/qemu-system-m68k + mcf5208evb + an5206 + q800 + next-cube + + + + + + + + + + + hvm + + 32 + /usr/bin/qemu-system-microblaze + petalogix-s3adsp1800 + petalogix-ml605 + xlnx-zynqmp-pmu + + + + + + + + + + + hvm + + 32 + /usr/bin/qemu-system-microblazeel + petalogix-s3adsp1800 + petalogix-ml605 + xlnx-zynqmp-pmu + + + + + + + + + + + hvm + + 32 + /usr/bin/qemu-system-mips + malta + mipssim + + + + + + + + + + + hvm + + 32 + /usr/bin/qemu-system-mipsel + malta + mipssim + + + + + + + + + + + hvm + + 64 + /usr/bin/qemu-system-mips64 + malta + pica61 + mipssim + magnum + + + + + + + + + + + hvm + + 64 + /usr/bin/qemu-system-mips64el + malta + mipssim + pica61 + magnum + boston + fuloong2e + fulong2e + + + + + + + + + + + hvm + + 32 + /usr/bin/qemu-system-ppc + g3beige + virtex-ml507 + mac99 + ppce500 + sam460ex + bamboo + 40p + ref405ep + mpc8544ds + taihu + + + + + + + + + + + hvm + + 64 + /usr/bin/qemu-system-ppc64 + pseries-5.2 + pseries + powernv9 + powernv + taihu + pseries-4.1 + mpc8544ds + pseries-2.5 + powernv10 + pseries-4.2 + pseries-2.6 + ppce500 + pseries-2.7 + pseries-3.0 + pseries-5.0 + 40p + pseries-2.8 + pseries-3.1 + pseries-5.1 + pseries-2.9 + bamboo + g3beige + pseries-2.12-sxxm + pseries-2.10 + virtex-ml507 + pseries-2.11 + pseries-2.1 + pseries-2.12 + pseries-2.2 + mac99 + sam460ex + ref405ep + pseries-2.3 + powernv8 + pseries-4.0 + pseries-2.4 + + + + + + + + + + + hvm + + 64 + /usr/bin/qemu-system-ppc64 + pseries-5.2 + pseries + powernv9 + powernv + taihu + pseries-4.1 + mpc8544ds + pseries-2.5 + powernv10 + pseries-4.2 + pseries-2.6 + ppce500 + pseries-2.7 + pseries-3.0 + pseries-5.0 + 40p + pseries-2.8 + pseries-3.1 + pseries-5.1 + pseries-2.9 + bamboo + g3beige + pseries-2.12-sxxm + pseries-2.10 + virtex-ml507 + pseries-2.11 + pseries-2.1 + pseries-2.12 + pseries-2.2 + mac99 + sam460ex + ref405ep + pseries-2.3 + powernv8 + pseries-4.0 + pseries-2.4 + + + + + + + + + + + hvm + + 32 + /usr/bin/qemu-system-riscv32 + spike + virt + opentitan + sifive_e + sifive_u + + + + + + + + + + + hvm + + 64 + /usr/bin/qemu-system-riscv64 + spike + virt + sifive_e + sifive_u + microchip-icicle-kit + + + + + + + + + + + hvm + + 64 + /usr/bin/qemu-system-s390x + s390-ccw-virtio-5.2 + s390-ccw-virtio + s390-ccw-virtio-4.0 + s390-ccw-virtio-3.1 + s390-ccw-virtio-2.6 + s390-ccw-virtio-2.12 + s390-ccw-virtio-2.9 + s390-ccw-virtio-5.1 + s390-ccw-virtio-3.0 + s390-ccw-virtio-4.2 + s390-ccw-virtio-2.5 + s390-ccw-virtio-2.11 + s390-ccw-virtio-2.8 + s390-ccw-virtio-5.0 + s390-ccw-virtio-4.1 + s390-ccw-virtio-2.4 + s390-ccw-virtio-2.10 + s390-ccw-virtio-2.7 + + + + + + + + + + + hvm + + 32 + /usr/bin/qemu-system-sh4 + shix + r2d + + + + + + + + + + + hvm + + 64 + /usr/bin/qemu-system-sh4eb + shix + r2d + + + + + + + + + + + hvm + + 32 + /usr/bin/qemu-system-sparc + SS-5 + SS-20 + LX + SPARCClassic + leon3_generic + SPARCbook + SS-4 + SS-600MP + SS-10 + Voyager + + + + + + + + + + + hvm + + 64 + /usr/bin/qemu-system-sparc64 + sun4u + niagara + sun4v + + + + + + + + + + + hvm + + 64 + /usr/bin/qemu-system-x86_64 + pc-i440fx-5.2 + pc + pc-q35-5.2 + q35 + pc-i440fx-2.12 + pc-i440fx-2.0 + pc-q35-4.2 + pc-i440fx-2.5 + pc-i440fx-4.2 + pc-i440fx-1.5 + pc-q35-2.7 + pc-i440fx-2.2 + pc-1.1 + pc-i440fx-2.7 + pc-q35-2.4 + pc-q35-2.10 + pc-i440fx-1.7 + pc-q35-5.1 + pc-q35-2.9 + pc-i440fx-2.11 + pc-q35-3.1 + pc-q35-4.1 + pc-i440fx-2.4 + pc-1.3 + pc-i440fx-4.1 + pc-i440fx-5.1 + pc-i440fx-2.9 + isapc + pc-i440fx-1.4 + pc-q35-2.6 + pc-i440fx-3.1 + pc-q35-2.12 + pc-i440fx-2.1 + pc-1.0 + pc-i440fx-2.6 + pc-q35-4.0.1 + pc-i440fx-1.6 + pc-q35-5.0 + pc-q35-2.8 + pc-i440fx-2.10 + pc-q35-3.0 + pc-q35-4.0 + microvm + pc-i440fx-2.3 + pc-1.2 + pc-i440fx-4.0 + pc-i440fx-5.0 + pc-i440fx-2.8 + pc-q35-2.5 + pc-i440fx-3.0 + pc-q35-2.11 + + + + + + + + + + + + + + hvm + + 32 + /usr/bin/qemu-system-xtensa + sim + kc705 + ml605 + ml605-nommu + virt + lx60-nommu + lx200 + lx200-nommu + lx60 + kc705-nommu + + + + + + + + + + + hvm + + 32 + /usr/bin/qemu-system-xtensaeb + sim + kc705 + ml605 + ml605-nommu + virt + lx60-nommu + lx200 + lx200-nommu + lx60 + kc705-nommu + + + + + + + + + + + + diff --git a/src/test/resources/libvirt/xml/qemu-kvm_capabilities_no-guests.xml b/src/test/resources/libvirt/xml/qemu-kvm_capabilities_no-guests.xml new file mode 100644 index 0000000..e25da30 --- /dev/null +++ b/src/test/resources/libvirt/xml/qemu-kvm_capabilities_no-guests.xml @@ -0,0 +1,82 @@ + + + + 9b2f12af-1fba-444c-b72b-9cbc43fb3ca5 + + x86_64 + Skylake-Client-IBRS + Intel + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + tcp + rdma + + + + + + 16161320 + 4040330 + 0 + 0 + + + + + + + + + + + + + + + + + none + 0 + + + + + + diff --git a/src/test/resources/libvirt/xml/qemu-kvm_capabilities_no-iommu.xml b/src/test/resources/libvirt/xml/qemu-kvm_capabilities_no-iommu.xml new file mode 100644 index 0000000..485341f --- /dev/null +++ b/src/test/resources/libvirt/xml/qemu-kvm_capabilities_no-iommu.xml @@ -0,0 +1,985 @@ + + + + 9b2f12af-1fba-444c-b72b-9cbc43fb3ca5 + + x86_64 + Skylake-Client-IBRS + Intel + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + tcp + rdma + + + + + + 16161320 + 4040330 + 0 + 0 + + + + + + + + + + + + + + + + + none + 0 + + + + + hvm + + 64 + /usr/bin/qemu-system-alpha + clipper + + + + + + + + + + + hvm + + 32 + /usr/bin/qemu-system-arm + integratorcp + ast2600-evb + borzoi + spitz + virt-2.7 + nuri + mcimx7d-sabre + romulus-bmc + virt-3.0 + virt-5.0 + npcm750-evb + virt-2.10 + musca-b1 + virt-2.8 + realview-pbx-a9 + versatileab + kzm + musca-a + virt-3.1 + mcimx6ul-evk + virt-5.1 + smdkc210 + sx1 + virt-2.11 + imx25-pdk + virt-2.9 + orangepi-pc + z2 + virt-5.2 + virt + xilinx-zynq-a9 + tosa + mps2-an500 + virt-2.12 + mps2-an521 + sabrelite + mps2-an511 + canon-a1100 + realview-eb + emcraft-sf2 + realview-pb-a8 + virt-4.0 + raspi1ap + palmetto-bmc + sx1-v1 + n810 + tacoma-bmc + n800 + virt-4.1 + quanta-gsj + versatilepb + terrier + mainstone + realview-eb-mpcore + supermicrox11-bmc + virt-4.2 + witherspoon-bmc + swift-bmc + vexpress-a9 + midway + musicpal + lm3s811evb + lm3s6965evb + microbit + mps2-an505 + mps2-an385 + cubieboard + verdex + netduino2 + mps2-an386 + raspi2b + raspi2 + vexpress-a15 + sonorapass-bmc + cheetah + virt-2.6 + ast2500-evb + highbank + akita + connex + netduinoplus2 + collie + raspi0 + + + + + + + + + + + hvm + + 32 + /usr/bin/qemu-system-arm + integratorcp + ast2600-evb + borzoi + spitz + virt-2.7 + nuri + mcimx7d-sabre + romulus-bmc + virt-3.0 + virt-5.0 + npcm750-evb + virt-2.10 + musca-b1 + virt-2.8 + realview-pbx-a9 + versatileab + kzm + musca-a + virt-3.1 + mcimx6ul-evk + virt-5.1 + smdkc210 + sx1 + virt-2.11 + imx25-pdk + virt-2.9 + orangepi-pc + z2 + virt-5.2 + virt + xilinx-zynq-a9 + tosa + mps2-an500 + virt-2.12 + mps2-an521 + sabrelite + mps2-an511 + canon-a1100 + realview-eb + emcraft-sf2 + realview-pb-a8 + virt-4.0 + raspi1ap + palmetto-bmc + sx1-v1 + n810 + tacoma-bmc + n800 + virt-4.1 + quanta-gsj + versatilepb + terrier + mainstone + realview-eb-mpcore + supermicrox11-bmc + virt-4.2 + witherspoon-bmc + swift-bmc + vexpress-a9 + midway + musicpal + lm3s811evb + lm3s6965evb + microbit + mps2-an505 + mps2-an385 + cubieboard + verdex + netduino2 + mps2-an386 + raspi2b + raspi2 + vexpress-a15 + sonorapass-bmc + cheetah + virt-2.6 + ast2500-evb + highbank + akita + connex + netduinoplus2 + collie + raspi0 + + + + + + + + + + + hvm + + 64 + /usr/bin/qemu-system-aarch64 + integratorcp + ast2600-evb + borzoi + spitz + virt-2.7 + nuri + mcimx7d-sabre + romulus-bmc + virt-3.0 + virt-5.0 + npcm750-evb + virt-2.10 + musca-b1 + virt-2.8 + realview-pbx-a9 + versatileab + kzm + musca-a + virt-3.1 + mcimx6ul-evk + virt-5.1 + smdkc210 + sx1 + virt-2.11 + imx25-pdk + virt-2.9 + orangepi-pc + z2 + virt-5.2 + virt + xilinx-zynq-a9 + xlnx-zcu102 + tosa + mps2-an500 + virt-2.12 + mps2-an521 + sabrelite + mps2-an511 + canon-a1100 + realview-eb + emcraft-sf2 + realview-pb-a8 + sbsa-ref + virt-4.0 + raspi1ap + palmetto-bmc + sx1-v1 + n810 + tacoma-bmc + n800 + virt-4.1 + quanta-gsj + versatilepb + terrier + mainstone + realview-eb-mpcore + supermicrox11-bmc + virt-4.2 + witherspoon-bmc + swift-bmc + vexpress-a9 + midway + musicpal + lm3s811evb + lm3s6965evb + microbit + mps2-an505 + mps2-an385 + raspi3ap + cubieboard + verdex + netduino2 + xlnx-versal-virt + mps2-an386 + raspi3b + raspi3 + raspi2b + raspi2 + vexpress-a15 + sonorapass-bmc + cheetah + virt-2.6 + ast2500-evb + highbank + akita + connex + netduinoplus2 + collie + raspi0 + + + + + + + + + + + + hvm + + 32 + /usr/bin/qemu-system-cris + axis-dev88 + + + + + + + + + + + hvm + + 32 + /usr/bin/qemu-system-i386 + pc-i440fx-5.2 + pc + pc-q35-5.2 + q35 + pc-i440fx-2.12 + pc-i440fx-2.0 + pc-q35-4.2 + pc-i440fx-2.5 + pc-i440fx-4.2 + pc-i440fx-1.5 + pc-q35-2.7 + pc-i440fx-2.2 + pc-1.1 + pc-i440fx-2.7 + pc-q35-2.4 + pc-q35-2.10 + pc-i440fx-1.7 + pc-q35-5.1 + pc-q35-2.9 + pc-i440fx-2.11 + pc-q35-3.1 + pc-q35-4.1 + pc-i440fx-2.4 + pc-1.3 + pc-i440fx-4.1 + pc-i440fx-5.1 + pc-i440fx-2.9 + isapc + pc-i440fx-1.4 + pc-q35-2.6 + pc-i440fx-3.1 + pc-q35-2.12 + pc-i440fx-2.1 + pc-1.0 + pc-i440fx-2.6 + pc-q35-4.0.1 + pc-i440fx-1.6 + pc-q35-5.0 + pc-q35-2.8 + pc-i440fx-2.10 + pc-q35-3.0 + pc-q35-4.0 + microvm + pc-i440fx-2.3 + pc-1.2 + pc-i440fx-4.0 + pc-i440fx-5.0 + pc-i440fx-2.8 + pc-q35-2.5 + pc-i440fx-3.0 + pc-q35-2.11 + + + + + + + + + + + + + + + + hvm + + 32 + /usr/bin/qemu-system-m68k + mcf5208evb + an5206 + q800 + next-cube + + + + + + + + + + + hvm + + 32 + /usr/bin/qemu-system-microblaze + petalogix-s3adsp1800 + petalogix-ml605 + xlnx-zynqmp-pmu + + + + + + + + + + + hvm + + 32 + /usr/bin/qemu-system-microblazeel + petalogix-s3adsp1800 + petalogix-ml605 + xlnx-zynqmp-pmu + + + + + + + + + + + hvm + + 32 + /usr/bin/qemu-system-mips + malta + mipssim + + + + + + + + + + + hvm + + 32 + /usr/bin/qemu-system-mipsel + malta + mipssim + + + + + + + + + + + hvm + + 64 + /usr/bin/qemu-system-mips64 + malta + pica61 + mipssim + magnum + + + + + + + + + + + hvm + + 64 + /usr/bin/qemu-system-mips64el + malta + mipssim + pica61 + magnum + boston + fuloong2e + fulong2e + + + + + + + + + + + hvm + + 32 + /usr/bin/qemu-system-ppc + g3beige + virtex-ml507 + mac99 + ppce500 + sam460ex + bamboo + 40p + ref405ep + mpc8544ds + taihu + + + + + + + + + + + hvm + + 64 + /usr/bin/qemu-system-ppc64 + pseries-5.2 + pseries + powernv9 + powernv + taihu + pseries-4.1 + mpc8544ds + pseries-2.5 + powernv10 + pseries-4.2 + pseries-2.6 + ppce500 + pseries-2.7 + pseries-3.0 + pseries-5.0 + 40p + pseries-2.8 + pseries-3.1 + pseries-5.1 + pseries-2.9 + bamboo + g3beige + pseries-2.12-sxxm + pseries-2.10 + virtex-ml507 + pseries-2.11 + pseries-2.1 + pseries-2.12 + pseries-2.2 + mac99 + sam460ex + ref405ep + pseries-2.3 + powernv8 + pseries-4.0 + pseries-2.4 + + + + + + + + + + + hvm + + 64 + /usr/bin/qemu-system-ppc64 + pseries-5.2 + pseries + powernv9 + powernv + taihu + pseries-4.1 + mpc8544ds + pseries-2.5 + powernv10 + pseries-4.2 + pseries-2.6 + ppce500 + pseries-2.7 + pseries-3.0 + pseries-5.0 + 40p + pseries-2.8 + pseries-3.1 + pseries-5.1 + pseries-2.9 + bamboo + g3beige + pseries-2.12-sxxm + pseries-2.10 + virtex-ml507 + pseries-2.11 + pseries-2.1 + pseries-2.12 + pseries-2.2 + mac99 + sam460ex + ref405ep + pseries-2.3 + powernv8 + pseries-4.0 + pseries-2.4 + + + + + + + + + + + hvm + + 32 + /usr/bin/qemu-system-riscv32 + spike + virt + opentitan + sifive_e + sifive_u + + + + + + + + + + + hvm + + 64 + /usr/bin/qemu-system-riscv64 + spike + virt + sifive_e + sifive_u + microchip-icicle-kit + + + + + + + + + + + hvm + + 64 + /usr/bin/qemu-system-s390x + s390-ccw-virtio-5.2 + s390-ccw-virtio + s390-ccw-virtio-4.0 + s390-ccw-virtio-3.1 + s390-ccw-virtio-2.6 + s390-ccw-virtio-2.12 + s390-ccw-virtio-2.9 + s390-ccw-virtio-5.1 + s390-ccw-virtio-3.0 + s390-ccw-virtio-4.2 + s390-ccw-virtio-2.5 + s390-ccw-virtio-2.11 + s390-ccw-virtio-2.8 + s390-ccw-virtio-5.0 + s390-ccw-virtio-4.1 + s390-ccw-virtio-2.4 + s390-ccw-virtio-2.10 + s390-ccw-virtio-2.7 + + + + + + + + + + + hvm + + 32 + /usr/bin/qemu-system-sh4 + shix + r2d + + + + + + + + + + + hvm + + 64 + /usr/bin/qemu-system-sh4eb + shix + r2d + + + + + + + + + + + hvm + + 32 + /usr/bin/qemu-system-sparc + SS-5 + SS-20 + LX + SPARCClassic + leon3_generic + SPARCbook + SS-4 + SS-600MP + SS-10 + Voyager + + + + + + + + + + + hvm + + 64 + /usr/bin/qemu-system-sparc64 + sun4u + niagara + sun4v + + + + + + + + + + + hvm + + 64 + /usr/bin/qemu-system-x86_64 + pc-i440fx-5.2 + pc + pc-q35-5.2 + q35 + pc-i440fx-2.12 + pc-i440fx-2.0 + pc-q35-4.2 + pc-i440fx-2.5 + pc-i440fx-4.2 + pc-i440fx-1.5 + pc-q35-2.7 + pc-i440fx-2.2 + pc-1.1 + pc-i440fx-2.7 + pc-q35-2.4 + pc-q35-2.10 + pc-i440fx-1.7 + pc-q35-5.1 + pc-q35-2.9 + pc-i440fx-2.11 + pc-q35-3.1 + pc-q35-4.1 + pc-i440fx-2.4 + pc-1.3 + pc-i440fx-4.1 + pc-i440fx-5.1 + pc-i440fx-2.9 + isapc + pc-i440fx-1.4 + pc-q35-2.6 + pc-i440fx-3.1 + pc-q35-2.12 + pc-i440fx-2.1 + pc-1.0 + pc-i440fx-2.6 + pc-q35-4.0.1 + pc-i440fx-1.6 + pc-q35-5.0 + pc-q35-2.8 + pc-i440fx-2.10 + pc-q35-3.0 + pc-q35-4.0 + microvm + pc-i440fx-2.3 + pc-1.2 + pc-i440fx-4.0 + pc-i440fx-5.0 + pc-i440fx-2.8 + pc-q35-2.5 + pc-i440fx-3.0 + pc-q35-2.11 + + + + + + + + + + + + + + hvm + + 32 + /usr/bin/qemu-system-xtensa + sim + kc705 + ml605 + ml605-nommu + virt + lx60-nommu + lx200 + lx200-nommu + lx60 + kc705-nommu + + + + + + + + + + + hvm + + 32 + /usr/bin/qemu-system-xtensaeb + sim + kc705 + ml605 + ml605-nommu + virt + lx60-nommu + lx200 + lx200-nommu + lx60 + kc705-nommu + + + + + + + + + + + + -- cgit v1.2.3-55-g7522 From 696fd71f026994e71a70097dba6dc0e37e996f32 Mon Sep 17 00:00:00 2001 From: Manuel Bentele Date: Tue, 23 Mar 2021 14:53:54 +0100 Subject: Add support for emulator binary in Libvirt domain XML documents --- src/main/java/org/openslx/libvirt/domain/Domain.java | 20 ++++++++++++++++++++ .../java/org/openslx/libvirt/domain/DomainTest.java | 17 +++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/src/main/java/org/openslx/libvirt/domain/Domain.java b/src/main/java/org/openslx/libvirt/domain/Domain.java index 9611c59..ca3df77 100644 --- a/src/main/java/org/openslx/libvirt/domain/Domain.java +++ b/src/main/java/org/openslx/libvirt/domain/Domain.java @@ -636,6 +636,26 @@ public class Domain extends LibvirtXmlDocument this.getRootXmlNode().setXmlElementAttributeValue( "cpu", "check", check.toString() ); } + /** + * Returns the file name of the emulator binary defined in the Libvirt domain XML document. + * + * @return file name of the emulator binary. + */ + public String getDevicesEmulator() + { + return this.getRootXmlNode().getXmlElementValue( "devices/emulator" ); + } + + /** + * Sets the file name of the emulator binary in the Libvirt domain XML document. + * + * @param emulator file name of the emulator binary. + */ + public void setDevicesEmulator( String emulator ) + { + this.getRootXmlNode().setXmlElementValue( "devices/emulator", emulator ); + } + /** * Returns virtual machine devices defined in the Libvirt domain XML document. * diff --git a/src/test/java/org/openslx/libvirt/domain/DomainTest.java b/src/test/java/org/openslx/libvirt/domain/DomainTest.java index 84f6a32..1712b68 100644 --- a/src/test/java/org/openslx/libvirt/domain/DomainTest.java +++ b/src/test/java/org/openslx/libvirt/domain/DomainTest.java @@ -280,6 +280,23 @@ public class DomainTest assertEquals( CpuCheck.NONE.toString(), vm.getCpuCheck().toString() ); } + @Test + @DisplayName( "Get VM emulator binary from libvirt XML file" ) + public void testGetDevicesEmulator() + { + Domain vm = this.newDomainInstance( "qemu-kvm_default-ubuntu-20-04-vm.xml" ); + assertEquals( "/usr/bin/qemu-system-x86_64", vm.getDevicesEmulator() ); + } + + @Test + @DisplayName( "Set VM emulator binary in libvirt XML file" ) + public void testSetDevicesEmulator() + { + Domain vm = this.newDomainInstance( "qemu-kvm_default-ubuntu-20-04-vm.xml" ); + vm.setDevicesEmulator( "/usr/bin/qemu-system-i386" ); + assertEquals( "/usr/bin/qemu-system-i386", vm.getDevicesEmulator() ); + } + @Test @DisplayName( "Get all VM devices from libvirt XML file" ) public void testGetDevices() -- cgit v1.2.3-55-g7522 From c2d5e99c47dcc7e6942e47377b2c7bc522c0b642 Mon Sep 17 00:00:00 2001 From: Manuel Bentele Date: Wed, 24 Mar 2021 12:34:42 +0100 Subject: Add MAC address for network interfaces in Libvirt domain XML documents --- .../openslx/libvirt/domain/device/Interface.java | 34 ++++++++++++++++++++-- 1 file changed, 31 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/openslx/libvirt/domain/device/Interface.java b/src/main/java/org/openslx/libvirt/domain/device/Interface.java index b09c7da..dae3c11 100644 --- a/src/main/java/org/openslx/libvirt/domain/device/Interface.java +++ b/src/main/java/org/openslx/libvirt/domain/device/Interface.java @@ -59,16 +59,16 @@ public class Interface extends Device { return Type.fromString( this.getXmlElementAttributeValue( "type" ) ); } - + /** * Sets type of the network device. * * @return type of the network device. */ - public void setType(Type type) + public void setType( Type type ) { String source = this.getSource(); - + // change type and set source again this.setXmlElementAttributeValue( "type", type.toString() ); this.setSource( source ); @@ -118,6 +118,26 @@ public class Interface extends Device } } + /** + * Returns MAC address of the network device. + * + * @return MAC address of the network device. + */ + public String getMacAddress() + { + return this.getXmlElementAttributeValue( "mac", "address" ); + } + + /** + * Sets MAC address of the network device. + * + * @param macAddress MAC address for the network device. + */ + public void setMacAddress( String macAddress ) + { + this.setXmlElementAttributeValue( "mac", "address", macAddress ); + } + /** * Removes boot oder entry of the network interface device. */ @@ -134,6 +154,14 @@ public class Interface extends Device this.removeXmlElement( "source" ); } + /** + * Removes MAC address of the network interface device. + */ + public void removeMacAddress() + { + this.removeXmlElement( "mac" ); + } + /** * Creates a non-existent network interface device as Libvirt XML device element. * -- cgit v1.2.3-55-g7522 From 936887890b6517d844331c7a37a1dc56c6a47da1 Mon Sep 17 00:00:00 2001 From: Manuel Bentele Date: Wed, 24 Mar 2021 12:35:37 +0100 Subject: Add parallel and serial devices to Libvirt domain XML documents --- .../java/org/openslx/libvirt/domain/Domain.java | 44 ++++++ .../org/openslx/libvirt/domain/device/Device.java | 14 ++ .../openslx/libvirt/domain/device/Parallel.java | 158 +++++++++++++++++++++ .../org/openslx/libvirt/domain/device/Serial.java | 156 ++++++++++++++++++++ .../org/openslx/libvirt/domain/DomainTest.java | 18 ++- 5 files changed, 389 insertions(+), 1 deletion(-) create mode 100644 src/main/java/org/openslx/libvirt/domain/device/Parallel.java create mode 100644 src/main/java/org/openslx/libvirt/domain/device/Serial.java diff --git a/src/main/java/org/openslx/libvirt/domain/Domain.java b/src/main/java/org/openslx/libvirt/domain/Domain.java index ca3df77..e399340 100644 --- a/src/main/java/org/openslx/libvirt/domain/Domain.java +++ b/src/main/java/org/openslx/libvirt/domain/Domain.java @@ -28,6 +28,8 @@ import org.openslx.libvirt.domain.device.Hostdev; import org.openslx.libvirt.domain.device.Interface; import org.openslx.libvirt.domain.device.InterfaceBridge; import org.openslx.libvirt.domain.device.InterfaceNetwork; +import org.openslx.libvirt.domain.device.Parallel; +import org.openslx.libvirt.domain.device.Serial; import org.openslx.libvirt.domain.device.Sound; import org.openslx.libvirt.domain.device.Video; import org.openslx.libvirt.xml.LibvirtXmlDocument; @@ -853,6 +855,28 @@ public class Domain extends LibvirtXmlDocument return Domain.filterDevices( Graphics.class, this.getDevices() ); } + /** + * Returns list of virtual machine parallel port devices specified in the Libvirt domain XML + * document. + * + * @return list of virtual machine parallel port devices. + */ + public ArrayList getParallelDevices() + { + return Domain.filterDevices( Parallel.class, this.getDevices() ); + } + + /** + * Returns list of virtual machine serial port devices specified in the Libvirt domain XML + * document. + * + * @return list of virtual machine serial port devices. + */ + public ArrayList getSerialDevices() + { + return Domain.filterDevices( Serial.class, this.getDevices() ); + } + /** * Returns list of virtual machine sound devices specified in the Libvirt domain XML document. * @@ -1086,6 +1110,26 @@ public class Domain extends LibvirtXmlDocument return GraphicsVnc.class.cast( this.addDevice( new GraphicsVnc() ) ); } + /** + * Adds a virtual machine parallel port device to the Libvirt domain XML document. + * + * @return reference to the added parallel port device if creation was successful. + */ + public Parallel addParallelDevice() + { + return Parallel.class.cast( this.addDevice( new Parallel() ) ); + } + + /** + * Adds a virtual machine serial port device to the Libvirt domain XML document. + * + * @return reference to the added serial port device if creation was successful. + */ + public Serial addSerialDevice() + { + return Serial.class.cast( this.addDevice( new Serial() ) ); + } + /** * Adds a virtual machine sound device to the Libvirt domain XML document. * diff --git a/src/main/java/org/openslx/libvirt/domain/device/Device.java b/src/main/java/org/openslx/libvirt/domain/device/Device.java index 5c26c55..b7403cd 100644 --- a/src/main/java/org/openslx/libvirt/domain/device/Device.java +++ b/src/main/java/org/openslx/libvirt/domain/device/Device.java @@ -86,6 +86,12 @@ public class Device extends LibvirtXmlNode } else if ( device instanceof Graphics ) { LibvirtXmlNode xmlNode = Device.createDeviceElement( xmlParentNode, Type.GRAPHICS ); createdDevice = Graphics.createInstance( Graphics.class.cast( device ), xmlNode ); + } else if ( device instanceof Parallel ) { + LibvirtXmlNode xmlNode = Device.createDeviceElement( xmlParentNode, Type.PARALLEL ); + createdDevice = Parallel.createInstance( xmlNode ); + } else if ( device instanceof Serial ) { + LibvirtXmlNode xmlNode = Device.createDeviceElement( xmlParentNode, Type.SERIAL ); + createdDevice = Serial.createInstance( xmlNode ); } else if ( device instanceof Sound ) { LibvirtXmlNode xmlNode = Device.createDeviceElement( xmlParentNode, Type.SOUND ); createdDevice = Sound.createInstance( xmlNode ); @@ -134,6 +140,12 @@ public class Device extends LibvirtXmlNode case GRAPHICS: device = Graphics.newInstance( xmlNode ); break; + case PARALLEL: + device = Parallel.newInstance( xmlNode ); + break; + case SERIAL: + device = Serial.newInstance( xmlNode ); + break; case SOUND: device = Sound.newInstance( xmlNode ); break; @@ -160,6 +172,8 @@ public class Device extends LibvirtXmlNode HOSTDEV ( "hostdev" ), INTERFACE ( "interface" ), GRAPHICS ( "graphics" ), + PARALLEL ( "parallel" ), + SERIAL ( "serial" ), SOUND ( "sound" ), VIDEO ( "video" ); // @formatter:on diff --git a/src/main/java/org/openslx/libvirt/domain/device/Parallel.java b/src/main/java/org/openslx/libvirt/domain/device/Parallel.java new file mode 100644 index 0000000..7db60ca --- /dev/null +++ b/src/main/java/org/openslx/libvirt/domain/device/Parallel.java @@ -0,0 +1,158 @@ +package org.openslx.libvirt.domain.device; + +import org.openslx.libvirt.xml.LibvirtXmlNode; + +/** + * A parallel port device node in a Libvirt domain XML document. + * + * @author Manuel Bentele + * @version 1.0 + */ +public class Parallel extends Device +{ + /** + * Creates an empty parallel port device. + */ + public Parallel() + { + super(); + } + + /** + * Creates a parallel port device representing an existing Libvirt XML parallel port device + * element. + * + * @param xmlNode existing Libvirt XML parallel port device element. + */ + public Parallel( LibvirtXmlNode xmlNode ) + { + super( xmlNode ); + } + + /** + * Returns the type of the parallel port device. + * + * @return type of the parallel port device. + */ + public Type getType() + { + final String type = this.getXmlElementAttributeValue( "type" ); + return Type.fromString( type ); + } + + /** + * Sets the type for the parallel port device. + * + * @param type type for the parallel port device. + */ + public void setType( Type type ) + { + this.setXmlElementAttributeValue( "type", type.toString() ); + } + + /** + * Returns the source of the parallel port device. + * + * @return source of the parallel port device. + */ + public String getSource() + { + return this.getXmlElementAttributeValue( "source", "path" ); + } + + /** + * Sets the source for the parallel port device. + * + * @param source source for the parallel port device. + */ + public void setSource( String source ) + { + this.setXmlElementAttributeValue( "source", "path", source ); + } + + /** + * Creates a non-existent parallel port device as Libvirt XML parallel port device element. + * + * @param xmlNode Libvirt XML node of the Libvirt XML parallel port device that is created. + * @return created parallel port device instance. + */ + public static Parallel createInstance( LibvirtXmlNode xmlNode ) + { + return Parallel.newInstance( xmlNode ); + } + + /** + * Creates a parallel port device representing an existing Libvirt XML parallel port device + * element. + * + * @param xmlNode existing Libvirt XML parallel port device element. + * @return parallel port device instance. + */ + public static Parallel newInstance( LibvirtXmlNode xmlNode ) + { + return new Parallel( xmlNode ); + } + + /** + * Type of parallel port device. + * + * @author Manuel Bentele + * @version 1.0 + */ + public enum Type + { + // @formatter:off + DEV ( "dev" ), + FILE ( "file" ), + PIPE ( "pipe" ), + UNIX ( "unix" ), + TCP ( "tcp" ), + UDP ( "udp" ), + NULL ( "null" ), + STDIO ( "stdio" ), + VC ( "vc" ), + PTY ( "pty" ), + SPICEVMC ( "spicevmc" ), + SPICEPORT( "spiceport" ), + NMDM ( "nmdm" ); + // @formatter:on + + /** + * Name of the parallel port device type. + */ + private String type; + + /** + * Creates parallel port device type. + * + * @param type valid name of the parallel port device type in a Libvirt domain XML document. + */ + Type( String type ) + { + this.type = type; + } + + @Override + public String toString() + { + return this.type; + } + + /** + * Creates parallel port device type from its name with error check. + * + * @param type name of the parallel port device type in a Libvirt domain XML document. + * @return valid parallel port device type. + */ + public static Type fromString( String type ) + { + for ( Type t : Type.values() ) { + if ( t.type.equalsIgnoreCase( type ) ) { + return t; + } + } + + return null; + } + } +} diff --git a/src/main/java/org/openslx/libvirt/domain/device/Serial.java b/src/main/java/org/openslx/libvirt/domain/device/Serial.java new file mode 100644 index 0000000..54be26e --- /dev/null +++ b/src/main/java/org/openslx/libvirt/domain/device/Serial.java @@ -0,0 +1,156 @@ +package org.openslx.libvirt.domain.device; + +import org.openslx.libvirt.xml.LibvirtXmlNode; + +/** + * A serial port device node in a Libvirt domain XML document. + * + * @author Manuel Bentele + * @version 1.0 + */ +public class Serial extends Device +{ + /** + * Creates an empty serial port device. + */ + public Serial() + { + super(); + } + + /** + * Creates a serial port device representing an existing Libvirt XML serial port device element. + * + * @param xmlNode existing Libvirt XML serial port device element. + */ + public Serial( LibvirtXmlNode xmlNode ) + { + super( xmlNode ); + } + + /** + * Returns the type of the serial port device. + * + * @return type of the serial port device. + */ + public Type getType() + { + final String type = this.getXmlElementAttributeValue( "type" ); + return Type.fromString( type ); + } + + /** + * Sets the type for the serial port device. + * + * @param type type for the serial port device. + */ + public void setType( Type type ) + { + this.setXmlElementAttributeValue( "type", type.toString() ); + } + + /** + * Returns the source of the serial port device. + * + * @return source of the serial port device. + */ + public String getSource() + { + return this.getXmlElementAttributeValue( "source", "path" ); + } + + /** + * Sets the source for the serial port device. + * + * @param source source for the serial port device. + */ + public void setSource( String source ) + { + this.setXmlElementAttributeValue( "source", "path", source ); + } + + /** + * Creates a non-existent serial port device as Libvirt XML serial port device element. + * + * @param xmlNode Libvirt XML node of the Libvirt XML serial port device that is created. + * @return created serial port device instance. + */ + public static Serial createInstance( LibvirtXmlNode xmlNode ) + { + return Serial.newInstance( xmlNode ); + } + + /** + * Creates a serial port device representing an existing Libvirt XML serial port device element. + * + * @param xmlNode existing Libvirt XML serial port device element. + * @return serial port device instance. + */ + public static Serial newInstance( LibvirtXmlNode xmlNode ) + { + return new Serial( xmlNode ); + } + + /** + * Type of serial port device. + * + * @author Manuel Bentele + * @version 1.0 + */ + public enum Type + { + // @formatter:off + DEV ( "dev" ), + FILE ( "file" ), + PIPE ( "pipe" ), + UNIX ( "unix" ), + TCP ( "tcp" ), + UDP ( "udp" ), + NULL ( "null" ), + STDIO ( "stdio" ), + VC ( "vc" ), + PTY ( "pty" ), + SPICEVMC ( "spicevmc" ), + SPICEPORT( "spiceport" ), + NMDM ( "nmdm" ); + // @formatter:on + + /** + * Name of the serial port device type. + */ + private String type; + + /** + * Creates serial port device type. + * + * @param type valid name of the serial port device type in a Libvirt domain XML document. + */ + Type( String type ) + { + this.type = type; + } + + @Override + public String toString() + { + return this.type; + } + + /** + * Creates serial port device type from its name with error check. + * + * @param type name of the serial port device type in a Libvirt domain XML document. + * @return valid serial port device type. + */ + public static Type fromString( String type ) + { + for ( Type t : Type.values() ) { + if ( t.type.equalsIgnoreCase( type ) ) { + return t; + } + } + + return null; + } + } +} diff --git a/src/test/java/org/openslx/libvirt/domain/DomainTest.java b/src/test/java/org/openslx/libvirt/domain/DomainTest.java index 1712b68..b4e0187 100644 --- a/src/test/java/org/openslx/libvirt/domain/DomainTest.java +++ b/src/test/java/org/openslx/libvirt/domain/DomainTest.java @@ -302,7 +302,7 @@ public class DomainTest public void testGetDevices() { Domain vm = this.newDomainInstance( "qemu-kvm_default-ubuntu-20-04-vm.xml" ); - assertEquals( 21, vm.getDevices().size() ); + assertEquals( 22, vm.getDevices().size() ); } @Test @@ -345,6 +345,22 @@ public class DomainTest assertEquals( 1, vm.getGraphicDevices().size() ); } + @Test + @DisplayName( "Get all VM parallel port devices from libvirt XML file" ) + public void testGetParallelDevices() + { + Domain vm = this.newDomainInstance( "qemu-kvm_default-ubuntu-20-04-vm.xml" ); + assertEquals( 0, vm.getParallelDevices().size() ); + } + + @Test + @DisplayName( "Get all VM serial port devices from libvirt XML file" ) + public void testGetSerialDevices() + { + Domain vm = this.newDomainInstance( "qemu-kvm_default-ubuntu-20-04-vm.xml" ); + assertEquals( 1, vm.getSerialDevices().size() ); + } + @Test @DisplayName( "Get all VM sound devices from libvirt XML file" ) public void testGetSoundDevices() -- cgit v1.2.3-55-g7522 From 2d012afbaf72794ad8ff16cc7ac50bc2e05b0c74 Mon Sep 17 00:00:00 2001 From: Manuel Bentele Date: Wed, 24 Mar 2021 15:20:33 +0100 Subject: Add shared folder support to Libvirt domain XML documents --- .../java/org/openslx/libvirt/domain/Domain.java | 22 ++ .../org/openslx/libvirt/domain/device/Device.java | 7 + .../openslx/libvirt/domain/device/FileSystem.java | 292 +++++++++++++++++++++ .../org/openslx/libvirt/domain/DomainTest.java | 8 + 4 files changed, 329 insertions(+) create mode 100644 src/main/java/org/openslx/libvirt/domain/device/FileSystem.java diff --git a/src/main/java/org/openslx/libvirt/domain/Domain.java b/src/main/java/org/openslx/libvirt/domain/Domain.java index e399340..f29fcd0 100644 --- a/src/main/java/org/openslx/libvirt/domain/Domain.java +++ b/src/main/java/org/openslx/libvirt/domain/Domain.java @@ -20,6 +20,7 @@ import org.openslx.libvirt.domain.device.Disk; 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.FileSystem; import org.openslx.libvirt.domain.device.Graphics; import org.openslx.libvirt.domain.device.GraphicsSdl; import org.openslx.libvirt.domain.device.GraphicsSpice; @@ -824,6 +825,17 @@ public class Domain extends LibvirtXmlDocument return Domain.filterDevices( DiskStorage.class, this.getDevices() ); } + /** + * Returns list of virtual machine file system devices specified in the Libvirt domain XML + * document. + * + * @return list of virtual machine file system devices. + */ + public ArrayList getFileSystemDevices() + { + return Domain.filterDevices( FileSystem.class, this.getDevices() ); + } + /** * Returns list of virtual machine hostdev devices specified in the Libvirt domain XML document. * @@ -1030,6 +1042,16 @@ public class Domain extends LibvirtXmlDocument return DiskStorage.class.cast( this.addDevice( new DiskStorage() ) ); } + /** + * Adds a virtual machine file system device to the Libvirt domain XML document. + * + * @return reference to the added file system device if creation was successful. + */ + public FileSystem addFileSystemDevice() + { + return FileSystem.class.cast( this.addDevice( new FileSystem() ) ); + } + /** * Adds a virtual machine disk device to the Libvirt domain XML document. * diff --git a/src/main/java/org/openslx/libvirt/domain/device/Device.java b/src/main/java/org/openslx/libvirt/domain/device/Device.java index b7403cd..151592a 100644 --- a/src/main/java/org/openslx/libvirt/domain/device/Device.java +++ b/src/main/java/org/openslx/libvirt/domain/device/Device.java @@ -77,6 +77,9 @@ public class Device extends LibvirtXmlNode } else if ( device instanceof Disk ) { LibvirtXmlNode xmlNode = Device.createDeviceElement( xmlParentNode, Type.DISK ); createdDevice = Disk.createInstance( Disk.class.cast( device ), xmlNode ); + } else if ( device instanceof FileSystem ) { + LibvirtXmlNode xmlNode = Device.createDeviceElement( xmlParentNode, Type.FILESYSTEM ); + createdDevice = FileSystem.createInstance( FileSystem.class.cast( device ), xmlNode ); } else if ( device instanceof Hostdev ) { LibvirtXmlNode xmlNode = Device.createDeviceElement( xmlParentNode, Type.HOSTDEV ); createdDevice = Hostdev.createInstance( Hostdev.class.cast( device ), xmlNode ); @@ -131,6 +134,9 @@ public class Device extends LibvirtXmlNode case DISK: device = Disk.newInstance( xmlNode ); break; + case FILESYSTEM: + device = FileSystem.newInstance( xmlNode ); + break; case HOSTDEV: device = Hostdev.newInstance( xmlNode ); break; @@ -169,6 +175,7 @@ public class Device extends LibvirtXmlNode // @formatter:off CONTROLLER( "controller" ), DISK ( "disk" ), + FILESYSTEM( "filesystem" ), HOSTDEV ( "hostdev" ), INTERFACE ( "interface" ), GRAPHICS ( "graphics" ), diff --git a/src/main/java/org/openslx/libvirt/domain/device/FileSystem.java b/src/main/java/org/openslx/libvirt/domain/device/FileSystem.java new file mode 100644 index 0000000..9ec8caf --- /dev/null +++ b/src/main/java/org/openslx/libvirt/domain/device/FileSystem.java @@ -0,0 +1,292 @@ +package org.openslx.libvirt.domain.device; + +import org.openslx.libvirt.xml.LibvirtXmlNode; + +/** + * A file system device node in a Libvirt domain XML document. + * + * @author Manuel Bentele + * @version 1.0 + */ +public class FileSystem extends Device +{ + /** + * Creates an empty file system device. + */ + public FileSystem() + { + super(); + } + + /** + * Creates a file system device representing an existing Libvirt XML file system device element. + * + * @param xmlNode existing Libvirt XML file system device element. + */ + public FileSystem( LibvirtXmlNode xmlNode ) + { + super( xmlNode ); + } + + /** + * Returns access mode of the file system device. + * + * @return access mode of the file system device. + */ + public AccessMode getAccessMode() + { + final String mode = this.getXmlElementAttributeValue( "accessmode" ); + return AccessMode.fromString( mode ); + } + + /** + * Sets access mode for the file system device. + * + * @param mode access mode for the file system device. + */ + public void setAccessMode( AccessMode mode ) + { + this.setXmlElementAttributeValue( "accessmode", mode.toString() ); + } + + /** + * Returns type of the file system device. + * + * @return type of the file system device. + */ + public Type getType() + { + final String type = this.getXmlElementAttributeValue( "type" ); + return Type.fromString( type ); + } + + /** + * Sets type for the file system device. + * + * @param type type for the file system device. + */ + public void setType( Type type ) + { + this.setXmlElementAttributeValue( "type", type.toString() ); + } + + /** + * Returns source of the file system device. + * + * @return source of the file system device. + */ + public String getSource() + { + final Type type = this.getType(); + String source = null; + + switch ( type ) { + case BIND: + source = this.getXmlElementAttributeValue( "source", "dir" ); + break; + case BLOCK: + source = this.getXmlElementAttributeValue( "source", "dev" ); + break; + case FILE: + source = this.getXmlElementAttributeValue( "source", "file" ); + break; + case MOUNT: + source = this.getXmlElementAttributeValue( "source", "dir" ); + break; + case RAM: + source = this.getXmlElementAttributeValue( "source", "usage" ); + break; + case TEMPLATE: + source = this.getXmlElementAttributeValue( "source", "name" ); + break; + } + + return source; + } + + /** + * Sets source for the file system device. + * + * @param source source for the file system device. + */ + public void setSource( String source ) + { + Type type = this.getType(); + + // remove all attributes from sub-element 'source' + this.removeXmlElementAttributes( "source" ); + + switch ( type ) { + case BIND: + this.setXmlElementAttributeValue( "source", "dir", source ); + break; + case BLOCK: + this.setXmlElementAttributeValue( "source", "dev", source ); + break; + case FILE: + this.setXmlElementAttributeValue( "source", "file", source ); + break; + case MOUNT: + this.setXmlElementAttributeValue( "source", "dir", source ); + break; + case RAM: + this.setXmlElementAttributeValue( "source", "usage", source ); + break; + case TEMPLATE: + this.setXmlElementAttributeValue( "source", "name", source ); + break; + } + } + + /** + * Returns target of the file system device. + * + * @return target of the file system device. + */ + public String getTarget() + { + return this.getXmlElementAttributeValue( "target", "dir" ); + } + + /** + * Sets target for the file system device. + * + * @param target target for the file system device. + */ + public void setTarget( String target ) + { + this.setXmlElementAttributeValue( "target", "dir", target ); + } + + /** + * Creates a non-existent file system device as Libvirt XML device element. + * + * @param xmlNode Libvirt XML node of the Libvirt XML device that is created. + * @return created file system device instance. + */ + public static FileSystem createInstance( LibvirtXmlNode xmlNode ) + { + return FileSystem.newInstance( xmlNode ); + } + + /** + * Creates a file system device representing an existing Libvirt XML file system device element. + * + * @param xmlNode existing Libvirt XML file system device element. + * @return file system device instance. + */ + public static FileSystem newInstance( LibvirtXmlNode xmlNode ) + { + return new FileSystem( xmlNode ); + } + + /** + * Access mode for the file system device. + * + * @author Manuel Bentele + * @version 1.0 + */ + public enum AccessMode + { + // @formatter:off + PASSTHROUGH( "passthrough" ), + MAPPED ( "mapped" ), + SQUASH ( "squash" ); + // @formatter:on + + /** + * Name of the file system device access mode. + */ + private String mode; + + /** + * Creates file system device access mode. + * + * @param mode valid name of the file system device access mode in a Libvirt domain XML + * document. + */ + AccessMode( String mode ) + { + this.mode = mode; + } + + @Override + public String toString() + { + return this.mode; + } + + /** + * Creates file system device access mode from its name with error check. + * + * @param mode name of the file system device access mode in a Libvirt domain XML document. + * @return valid file system device access mode. + */ + public static AccessMode fromString( String mode ) + { + for ( AccessMode a : AccessMode.values() ) { + if ( a.mode.equalsIgnoreCase( mode ) ) { + return a; + } + } + + return null; + } + } + + /** + * Type of file system device. + * + * @author Manuel Bentele + * @version 1.0 + */ + public enum Type + { + // @formatter:off + MOUNT ( "mount" ), + TEMPLATE( "template" ), + FILE ( "file" ), + BLOCK ( "block" ), + RAM ( "ram" ), + BIND ( "bind" ); + // @formatter:on + + /** + * Name of the file system device type. + */ + private String type; + + /** + * Creates file system device type. + * + * @param type valid name of the file system device type in a Libvirt domain XML document. + */ + Type( String type ) + { + this.type = type; + } + + @Override + public String toString() + { + return this.type; + } + + /** + * Creates file system device type from its name with error check. + * + * @param type name of the file system device type in a Libvirt domain XML document. + * @return valid file system device type. + */ + public static Type fromString( String type ) + { + for ( Type t : Type.values() ) { + if ( t.type.equalsIgnoreCase( type ) ) { + return t; + } + } + + return null; + } + } +} diff --git a/src/test/java/org/openslx/libvirt/domain/DomainTest.java b/src/test/java/org/openslx/libvirt/domain/DomainTest.java index b4e0187..aa556f9 100644 --- a/src/test/java/org/openslx/libvirt/domain/DomainTest.java +++ b/src/test/java/org/openslx/libvirt/domain/DomainTest.java @@ -321,6 +321,14 @@ public class DomainTest assertEquals( 3, vm.getDiskDevices().size() ); } + @Test + @DisplayName( "Get all VM file system devices from libvirt XML file" ) + public void testGetFileSystemDevices() + { + Domain vm = this.newDomainInstance( "qemu-kvm_default-ubuntu-20-04-vm.xml" ); + assertEquals( 0, vm.getFileSystemDevices().size() ); + } + @Test @DisplayName( "Get all VM hostdev devices from libvirt XML file" ) public void testGetHostdevDevices() -- cgit v1.2.3-55-g7522 From 9b1ab8ea115c88bbcecadbf53d420a09240d6ba8 Mon Sep 17 00:00:00 2001 From: Manuel Bentele Date: Thu, 25 Mar 2021 11:01:52 +0100 Subject: Fix issues related to a XPath query used in the Libvirt device lookup The issue occurs if a Libvirt device lookup via getDevices() takes place after a device node was removed. After the removal, a bunch of empty XML text nodes remain which leads to problems in the underlying XML element nodes. Those nodes are queried with the help of relative XPath expressions which depend on valid XML element nodes. This patch restricts queries of underlying child nodes to valid XML element nodes avoiding the occurence of XPath runtime exceptions. --- src/main/java/org/openslx/libvirt/domain/Domain.java | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/main/java/org/openslx/libvirt/domain/Domain.java b/src/main/java/org/openslx/libvirt/domain/Domain.java index f29fcd0..727da13 100644 --- a/src/main/java/org/openslx/libvirt/domain/Domain.java +++ b/src/main/java/org/openslx/libvirt/domain/Domain.java @@ -674,12 +674,14 @@ public class Domain extends LibvirtXmlDocument NodeList devicesElements = devicesNode.getChildNodes(); for ( int i = 0; i < devicesElements.getLength(); i++ ) { - LibvirtXmlNode deviceNode = null; - deviceNode = new LibvirtXmlNode( this.getRootXmlNode().getXmlDocument(), devicesElements.item( i ) ); - Device device = Device.newInstance( deviceNode ); - - if ( device != null ) { - devices.add( device ); + final Node childNode = devicesElements.item( i ); + if ( childNode.getNodeType() == Node.ELEMENT_NODE ) { + LibvirtXmlNode deviceNode = new LibvirtXmlNode( this.getRootXmlNode().getXmlDocument(), childNode ); + Device device = Device.newInstance( deviceNode ); + + if ( device != null ) { + devices.add( device ); + } } } } -- cgit v1.2.3-55-g7522 From 91985237fe58e1a4683f7bc254b0d2dd9e0b035b Mon Sep 17 00:00:00 2001 From: Manuel Bentele Date: Fri, 26 Mar 2021 14:49:57 +0100 Subject: Do not remove UUID if QEMU VM config is requested by stateless client --- src/main/java/org/openslx/vm/QemuMetaData.java | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/main/java/org/openslx/vm/QemuMetaData.java b/src/main/java/org/openslx/vm/QemuMetaData.java index c780429..6867166 100644 --- a/src/main/java/org/openslx/vm/QemuMetaData.java +++ b/src/main/java/org/openslx/vm/QemuMetaData.java @@ -333,9 +333,6 @@ public class QemuMetaData extends @Override public byte[] getFilteredDefinitionArray() { - // remove UUID in Libvirt domain XML configuration - this.vmConfig.removeUuid(); - // removes all specified boot order entries this.vmConfig.removeBootOrder(); -- cgit v1.2.3-55-g7522 From 31d7181f4e14a95807434fc971a6d18b00f83ac5 Mon Sep 17 00:00:00 2001 From: Manuel Bentele Date: Fri, 26 Mar 2021 14:54:36 +0100 Subject: Always filter device paths in QEMU VM config (privacy filters) --- src/main/java/org/openslx/vm/QemuMetaData.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/openslx/vm/QemuMetaData.java b/src/main/java/org/openslx/vm/QemuMetaData.java index 6867166..bd288a4 100644 --- a/src/main/java/org/openslx/vm/QemuMetaData.java +++ b/src/main/java/org/openslx/vm/QemuMetaData.java @@ -313,6 +313,10 @@ public class QemuMetaData extends for ( DiskStorage storageDiskDevice : this.vmConfig.getDiskStorageDevices() ) { this.addHddMetaData( storageDiskDevice ); } + + // start of privacy filters to filter out sensitive information like name of users in absolute paths, ... + // removes all referenced storage files of all specified CDROMs, Floppy drives and HDDs + this.vmConfig.removeDiskDevicesStorage(); } /** @@ -336,9 +340,6 @@ public class QemuMetaData extends // removes all specified boot order entries this.vmConfig.removeBootOrder(); - // removes all referenced storage files of all specified CDROMs, Floppy drives and HDDs - this.vmConfig.removeDiskDevicesStorage(); - // removes all source networks of all specified network interfaces this.vmConfig.removeInterfaceDevicesSource(); -- cgit v1.2.3-55-g7522 From 7aa2380b3bc33ad6b1a892b1b3491c93eee8edbb Mon Sep 17 00:00:00 2001 From: Manuel Bentele Date: Fri, 26 Mar 2021 16:22:54 +0100 Subject: Fix issues in filtering sources of Libvirt network interfaces --- .../java/org/openslx/libvirt/domain/Domain.java | 3 +- .../org/openslx/libvirt/domain/device/Disk.java | 4 +- src/test/java/org/openslx/vm/QemuMetaDataTest.java | 104 +++++++++++++++++---- 3 files changed, 88 insertions(+), 23 deletions(-) diff --git a/src/main/java/org/openslx/libvirt/domain/Domain.java b/src/main/java/org/openslx/libvirt/domain/Domain.java index 727da13..dbc60e6 100644 --- a/src/main/java/org/openslx/libvirt/domain/Domain.java +++ b/src/main/java/org/openslx/libvirt/domain/Domain.java @@ -1216,7 +1216,8 @@ public class Domain extends LibvirtXmlDocument public void removeInterfaceDevicesSource() { for ( Interface interfaceDevice : this.getInterfaceDevices() ) { - interfaceDevice.removeSource(); + // set empty source to preserve the XML attribute (to prevent XML validation errors) + interfaceDevice.setSource( "" ); } } } diff --git a/src/main/java/org/openslx/libvirt/domain/device/Disk.java b/src/main/java/org/openslx/libvirt/domain/device/Disk.java index 464e7b6..d9007f5 100644 --- a/src/main/java/org/openslx/libvirt/domain/device/Disk.java +++ b/src/main/java/org/openslx/libvirt/domain/device/Disk.java @@ -68,7 +68,7 @@ public class Disk extends Device storageSource = this.getXmlElementAttributeValue( "source", "file" ); break; case BLOCK: - storageSource = this.getXmlElementAttributeValue( "source", "bdev" ); + storageSource = this.getXmlElementAttributeValue( "source", "dev" ); break; } @@ -96,7 +96,7 @@ public class Disk extends Device this.setXmlElementAttributeValue( "source", "file", source ); break; case BLOCK: - this.setXmlElementAttributeValue( "source", "bdev", source ); + this.setXmlElementAttributeValue( "source", "dev", source ); break; } } diff --git a/src/test/java/org/openslx/vm/QemuMetaDataTest.java b/src/test/java/org/openslx/vm/QemuMetaDataTest.java index 3217fda..a3053a1 100644 --- a/src/test/java/org/openslx/vm/QemuMetaDataTest.java +++ b/src/test/java/org/openslx/vm/QemuMetaDataTest.java @@ -1,5 +1,6 @@ package org.openslx.vm; +import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertTrue; @@ -19,6 +20,7 @@ import org.apache.log4j.LogManager; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.function.Executable; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.Arguments; import org.junit.jupiter.params.provider.MethodSource; @@ -58,64 +60,94 @@ public class QemuMetaDataTest @Test @DisplayName( "Test display name from VM configuration" ) - public void testQemuMetaDataGetDisplayName() throws UnsupportedVirtualizerFormatException, IOException + public void testQemuMetaDataGetDisplayName() + throws UnsupportedVirtualizerFormatException, IOException, NoSuchFieldException, SecurityException, + IllegalArgumentException, IllegalAccessException { File file = LibvirtXmlTestResources.getLibvirtXmlFile( "qemu-kvm_default-archlinux-vm.xml" ); QemuMetaData vmConfig = new QemuMetaData( null, file ); + final Domain vmLibvirtDomainConfig = QemuMetaDataTest.getPrivateDomainFromQemuMetaData( vmConfig ); + final String displayName = vmConfig.getDisplayName(); assertEquals( "archlinux", displayName ); + + assertDoesNotThrow​( () -> vmLibvirtDomainConfig.validateXml() ); } @Test @DisplayName( "Test machine snapshot state from VM configuration" ) - public void testQemuMetaDataIsMachineSnapshot() throws UnsupportedVirtualizerFormatException, IOException + public void testQemuMetaDataIsMachineSnapshot() + throws UnsupportedVirtualizerFormatException, IOException, NoSuchFieldException, SecurityException, + IllegalArgumentException, IllegalAccessException { File file = LibvirtXmlTestResources.getLibvirtXmlFile( "qemu-kvm_default-archlinux-vm.xml" ); QemuMetaData vmConfig = new QemuMetaData( null, file ); + final Domain vmLibvirtDomainConfig = QemuMetaDataTest.getPrivateDomainFromQemuMetaData( vmConfig ); + final boolean isVmSnapshot = vmConfig.isMachineSnapshot(); assertEquals( false, isVmSnapshot ); + + assertDoesNotThrow​( () -> vmLibvirtDomainConfig.validateXml() ); } @Test @DisplayName( "Test supported image formats from VM configuration" ) - public void testQemuMetaDataGetSupportedImageFormats() throws UnsupportedVirtualizerFormatException, IOException + public void testQemuMetaDataGetSupportedImageFormats() + throws UnsupportedVirtualizerFormatException, IOException, NoSuchFieldException, SecurityException, + IllegalArgumentException, IllegalAccessException { File file = LibvirtXmlTestResources.getLibvirtXmlFile( "qemu-kvm_default-archlinux-vm.xml" ); QemuMetaData vmConfig = new QemuMetaData( null, file ); + final Domain vmLibvirtDomainConfig = QemuMetaDataTest.getPrivateDomainFromQemuMetaData( vmConfig ); + final List supportedImageFormats = vmConfig.getSupportedImageFormats(); assertNotNull( supportedImageFormats ); assertEquals( 3, supportedImageFormats.size() ); assertEquals( true, supportedImageFormats .containsAll( Arrays.asList( ImageFormat.QCOW2, ImageFormat.VMDK, ImageFormat.VDI ) ) ); + + assertDoesNotThrow​( () -> vmLibvirtDomainConfig.validateXml() ); } @Test @DisplayName( "Test output of HDDs from VM configuration" ) - public void testQemuMetaDataGetHdds() throws UnsupportedVirtualizerFormatException, IOException + public void testQemuMetaDataGetHdds() + throws UnsupportedVirtualizerFormatException, IOException, NoSuchFieldException, SecurityException, + IllegalArgumentException, IllegalAccessException { File file = LibvirtXmlTestResources.getLibvirtXmlFile( "qemu-kvm_default-archlinux-vm.xml" ); QemuMetaData vmConfig = new QemuMetaData( null, file ); + final Domain vmLibvirtDomainConfig = QemuMetaDataTest.getPrivateDomainFromQemuMetaData( vmConfig ); + final List hdds = vmConfig.getHdds(); assertNotNull( hdds ); assertEquals( 1, hdds.size() ); assertEquals( "/var/lib/libvirt/images/archlinux.qcow2", hdds.get( 0 ).diskImage ); + + assertDoesNotThrow​( () -> vmLibvirtDomainConfig.validateXml() ); } @Test @DisplayName( "Test output of unfiltered VM configuration" ) - public void testQemuMetaDataGetDefinitionArray() throws UnsupportedVirtualizerFormatException, IOException + public void testQemuMetaDataGetDefinitionArray() + throws UnsupportedVirtualizerFormatException, IOException, NoSuchFieldException, SecurityException, + IllegalArgumentException, IllegalAccessException { File file = LibvirtXmlTestResources.getLibvirtXmlFile( "qemu-kvm_default-archlinux-vm.xml" ); QemuMetaData vmConfig = new QemuMetaData( null, file ); + final Domain vmLibvirtDomainConfig = QemuMetaDataTest.getPrivateDomainFromQemuMetaData( vmConfig ); + + final int numberOfDeletedElements = 1; + final String unfilteredXmlConfig = new String( vmConfig.getDefinitionArray(), StandardCharsets.UTF_8 ); final String originalXmlConfig = FileUtils.readFileToString( file, StandardCharsets.UTF_8 ); @@ -124,17 +156,23 @@ public class QemuMetaDataTest final int lengthUnfilteredXmlConfig = unfilteredXmlConfig.split( System.lineSeparator() ).length; final int lengthOriginalXmlConfig = originalXmlConfig.split( System.lineSeparator() ).length; - assertEquals( lengthOriginalXmlConfig, lengthUnfilteredXmlConfig ); + assertEquals( lengthOriginalXmlConfig, lengthUnfilteredXmlConfig + numberOfDeletedElements ); + + assertDoesNotThrow​( () -> vmLibvirtDomainConfig.validateXml() ); } @Test @DisplayName( "Test output of filtered VM configuration" ) - public void testQemuMetaDataGetFilteredDefinitionArray() throws UnsupportedVirtualizerFormatException, IOException + public void testQemuMetaDataGetFilteredDefinitionArray() + throws UnsupportedVirtualizerFormatException, IOException, NoSuchFieldException, SecurityException, + IllegalArgumentException, IllegalAccessException { File file = LibvirtXmlTestResources.getLibvirtXmlFile( "qemu-kvm_default-archlinux-vm.xml" ); QemuMetaData vmConfig = new QemuMetaData( null, file ); - final int numberOfDeletedElements = 4; + final Domain vmLibvirtDomainConfig = QemuMetaDataTest.getPrivateDomainFromQemuMetaData( vmConfig ); + + final int numberOfDeletedElements = 2; final String filteredXmlConfig = new String( vmConfig.getFilteredDefinitionArray(), StandardCharsets.UTF_8 ); final String originalXmlConfig = FileUtils.readFileToString( file, StandardCharsets.UTF_8 ); @@ -145,6 +183,8 @@ public class QemuMetaDataTest final int lengthOriginalXmlConfig = originalXmlConfig.split( System.lineSeparator() ).length; assertEquals( lengthOriginalXmlConfig, lengthFilteredXmlConfig + numberOfDeletedElements ); + + assertDoesNotThrow​( () -> vmLibvirtDomainConfig.validateXml() ); } @ParameterizedTest @@ -158,7 +198,7 @@ public class QemuMetaDataTest File file = LibvirtXmlTestResources.getLibvirtXmlFile( xmlFileName ); QemuMetaData vmConfig = new QemuMetaData( null, file ); - Domain vmLibvirtDomainConfig = QemuMetaDataTest.getPrivateDomainFromQemuMetaData( vmConfig ); + final Domain vmLibvirtDomainConfig = QemuMetaDataTest.getPrivateDomainFromQemuMetaData( vmConfig ); final int numHddsLibvirtDomainXmlBeforeAdd = vmLibvirtDomainConfig.getDiskStorageDevices().size(); final int numHddsQemuMetaDataBeforeAdd = vmConfig.hdds.size(); @@ -184,6 +224,8 @@ public class QemuMetaDataTest DiskStorage addedStorageDevice = vmLibvirtDomainConfig.getDiskStorageDevices().get( 0 ); assertEquals( diskFile.getAbsolutePath(), addedStorageDevice.getStorageSource() ); + + assertDoesNotThrow​( () -> vmLibvirtDomainConfig.validateXml() ); } @ParameterizedTest @@ -197,7 +239,7 @@ public class QemuMetaDataTest File file = LibvirtXmlTestResources.getLibvirtXmlFile( xmlFileName ); QemuMetaData vmConfig = new QemuMetaData( null, file ); - Domain vmLibvirtDomainConfig = QemuMetaDataTest.getPrivateDomainFromQemuMetaData( vmConfig ); + final Domain vmLibvirtDomainConfig = QemuMetaDataTest.getPrivateDomainFromQemuMetaData( vmConfig ); final int numCdromsLibvirtDomainXmlBeforeAdd = vmLibvirtDomainConfig.getDiskCdromDevices().size(); @@ -210,6 +252,8 @@ public class QemuMetaDataTest DiskCdrom addedCdromDevice = vmLibvirtDomainConfig.getDiskCdromDevices().get( 0 ); assertEquals( diskFile.getAbsolutePath(), addedCdromDevice.getStorageSource() ); + + assertDoesNotThrow​( () -> vmLibvirtDomainConfig.validateXml() ); } @ParameterizedTest @@ -222,7 +266,7 @@ public class QemuMetaDataTest File file = LibvirtXmlTestResources.getLibvirtXmlFile( xmlFileName ); QemuMetaData vmConfig = new QemuMetaData( null, file ); - Domain vmLibvirtDomainConfig = QemuMetaDataTest.getPrivateDomainFromQemuMetaData( vmConfig ); + final Domain vmLibvirtDomainConfig = QemuMetaDataTest.getPrivateDomainFromQemuMetaData( vmConfig ); final int numCdromsLibvirtDomainXmlBeforeAdd = vmLibvirtDomainConfig.getDiskCdromDevices().size(); @@ -235,6 +279,8 @@ public class QemuMetaDataTest DiskCdrom addedCdromDevice = vmLibvirtDomainConfig.getDiskCdromDevices().get( 0 ); assertEquals( QemuMetaData.CDROM_DEFAULT_PHYSICAL_DRIVE, addedCdromDevice.getStorageSource() ); + + assertDoesNotThrow​( () -> vmLibvirtDomainConfig.validateXml() ); } @ParameterizedTest @@ -248,7 +294,7 @@ public class QemuMetaDataTest File file = LibvirtXmlTestResources.getLibvirtXmlFile( xmlFileName ); QemuMetaData vmConfig = new QemuMetaData( null, file ); - Domain vmLibvirtDomainConfig = QemuMetaDataTest.getPrivateDomainFromQemuMetaData( vmConfig ); + final Domain vmLibvirtDomainConfig = QemuMetaDataTest.getPrivateDomainFromQemuMetaData( vmConfig ); final int numFloppiesLibvirtDomainXmlBeforeAdd = vmLibvirtDomainConfig.getDiskFloppyDevices().size(); @@ -262,6 +308,8 @@ public class QemuMetaDataTest DiskFloppy addedFloppyDevice = vmLibvirtDomainConfig.getDiskFloppyDevices().get( 0 ); assertTrue( addedFloppyDevice.isReadOnly() ); assertEquals( diskFile.getAbsolutePath(), addedFloppyDevice.getStorageSource() ); + + assertDoesNotThrow​( () -> vmLibvirtDomainConfig.validateXml() ); } @ParameterizedTest @@ -274,11 +322,13 @@ public class QemuMetaDataTest File file = LibvirtXmlTestResources.getLibvirtXmlFile( "qemu-kvm_default-archlinux-vm.xml" ); QemuMetaData vmConfig = new QemuMetaData( null, file ); - Domain vmLibvirtDomainConfig = QemuMetaDataTest.getPrivateDomainFromQemuMetaData( vmConfig ); + final Domain vmLibvirtDomainConfig = QemuMetaDataTest.getPrivateDomainFromQemuMetaData( vmConfig ); vmConfig.addCpuCoreCount( coreCount ); assertEquals( coreCount, vmLibvirtDomainConfig.getVCpu() ); + + assertDoesNotThrow​( () -> vmLibvirtDomainConfig.validateXml() ); } @ParameterizedTest @@ -291,7 +341,7 @@ public class QemuMetaDataTest File file = LibvirtXmlTestResources.getLibvirtXmlFile( xmlFileName ); QemuMetaData vmConfig = new QemuMetaData( null, file ); - Domain vmLibvirtDomainConfig = QemuMetaDataTest.getPrivateDomainFromQemuMetaData( vmConfig ); + final Domain vmLibvirtDomainConfig = QemuMetaDataTest.getPrivateDomainFromQemuMetaData( vmConfig ); SoundCardType soundCardType = vmConfig.getSoundCard(); @@ -300,6 +350,8 @@ public class QemuMetaDataTest } else { assertEquals( SoundCardType.HD_AUDIO, soundCardType ); } + + assertDoesNotThrow​( () -> vmLibvirtDomainConfig.validateXml() ); } @ParameterizedTest @@ -312,7 +364,7 @@ public class QemuMetaDataTest File file = LibvirtXmlTestResources.getLibvirtXmlFile( xmlFileName ); QemuMetaData vmConfig = new QemuMetaData( null, file ); - Domain vmLibvirtDomainConfig = QemuMetaDataTest.getPrivateDomainFromQemuMetaData( vmConfig ); + final Domain vmLibvirtDomainConfig = QemuMetaDataTest.getPrivateDomainFromQemuMetaData( vmConfig ); final int numSoundDevsLibvirtDomainXmlBeforeAdd = vmLibvirtDomainConfig.getSoundDevices().size(); @@ -325,6 +377,8 @@ public class QemuMetaDataTest Sound addedSoundDevice = vmLibvirtDomainConfig.getSoundDevices().get( 0 ); assertEquals( Sound.Model.SB16, addedSoundDevice.getModel() ); + + assertDoesNotThrow​( () -> vmLibvirtDomainConfig.validateXml() ); } @ParameterizedTest @@ -337,7 +391,7 @@ public class QemuMetaDataTest File file = LibvirtXmlTestResources.getLibvirtXmlFile( xmlFileName ); QemuMetaData vmConfig = new QemuMetaData( null, file ); - Domain vmLibvirtDomainConfig = QemuMetaDataTest.getPrivateDomainFromQemuMetaData( vmConfig ); + final Domain vmLibvirtDomainConfig = QemuMetaDataTest.getPrivateDomainFromQemuMetaData( vmConfig ); EthernetDevType ethernetDeviceType = vmConfig.getEthernetDevType( 0 ); @@ -346,6 +400,8 @@ public class QemuMetaDataTest } else { assertEquals( EthernetDevType.PARAVIRT, ethernetDeviceType ); } + + assertDoesNotThrow​( () -> vmLibvirtDomainConfig.validateXml() ); } @ParameterizedTest @@ -358,7 +414,7 @@ public class QemuMetaDataTest File file = LibvirtXmlTestResources.getLibvirtXmlFile( xmlFileName ); QemuMetaData vmConfig = new QemuMetaData( null, file ); - Domain vmLibvirtDomainConfig = QemuMetaDataTest.getPrivateDomainFromQemuMetaData( vmConfig ); + final Domain vmLibvirtDomainConfig = QemuMetaDataTest.getPrivateDomainFromQemuMetaData( vmConfig ); vmConfig.setEthernetDevType( 0, EthernetDevType.E1000E ); @@ -366,6 +422,8 @@ public class QemuMetaDataTest Interface addedEthernetDevice = vmLibvirtDomainConfig.getInterfaceDevices().get( 0 ); assertEquals( Interface.Model.E1000E, addedEthernetDevice.getModel() ); } + + assertDoesNotThrow​( () -> vmLibvirtDomainConfig.validateXml() ); } @ParameterizedTest @@ -378,7 +436,7 @@ public class QemuMetaDataTest File file = LibvirtXmlTestResources.getLibvirtXmlFile( xmlFileName ); QemuMetaData vmConfig = new QemuMetaData( null, file ); - Domain vmLibvirtDomainConfig = QemuMetaDataTest.getPrivateDomainFromQemuMetaData( vmConfig ); + final Domain vmLibvirtDomainConfig = QemuMetaDataTest.getPrivateDomainFromQemuMetaData( vmConfig ); UsbSpeed maxUsbSpeed = vmConfig.getMaxUsbSpeed(); @@ -387,6 +445,8 @@ public class QemuMetaDataTest } else { assertEquals( UsbSpeed.USB3_0, maxUsbSpeed ); } + + assertDoesNotThrow​( () -> vmLibvirtDomainConfig.validateXml() ); } @ParameterizedTest @@ -399,7 +459,7 @@ public class QemuMetaDataTest File file = LibvirtXmlTestResources.getLibvirtXmlFile( xmlFileName ); QemuMetaData vmConfig = new QemuMetaData( null, file ); - Domain vmLibvirtDomainConfig = QemuMetaDataTest.getPrivateDomainFromQemuMetaData( vmConfig ); + final Domain vmLibvirtDomainConfig = QemuMetaDataTest.getPrivateDomainFromQemuMetaData( vmConfig ); final int numUsbControllersLibvirtDomainXmlBeforeAdd = vmLibvirtDomainConfig.getUsbControllerDevices().size(); @@ -412,6 +472,8 @@ public class QemuMetaDataTest ControllerUsb addedUsbControllerDevice = vmLibvirtDomainConfig.getUsbControllerDevices().get( 0 ); assertEquals( ControllerUsb.Model.ICH9_EHCI1, addedUsbControllerDevice.getModel() ); + + assertDoesNotThrow​( () -> vmLibvirtDomainConfig.validateXml() ); } static Stream configAndEthernetTypeProvider() @@ -435,7 +497,7 @@ public class QemuMetaDataTest File file = LibvirtXmlTestResources.getLibvirtXmlFile( xmlFileName ); QemuMetaData vmConfig = new QemuMetaData( null, file ); - Domain vmLibvirtDomainConfig = QemuMetaDataTest.getPrivateDomainFromQemuMetaData( vmConfig ); + final Domain vmLibvirtDomainConfig = QemuMetaDataTest.getPrivateDomainFromQemuMetaData( vmConfig ); final int numEthernetDevsLibvirtDomainXmlBeforeAdd = vmLibvirtDomainConfig.getInterfaceDevices().size(); @@ -464,5 +526,7 @@ public class QemuMetaDataTest assertEquals( QemuMetaData.NETWORK_DEFAULT_NAT, addedEthernetDevice.getSource() ); break; } + + assertDoesNotThrow​( () -> vmLibvirtDomainConfig.validateXml() ); } } -- cgit v1.2.3-55-g7522 From be9fcc35d87eb5455937799248473c30a1d6afa8 Mon Sep 17 00:00:00 2001 From: Manuel Bentele Date: Mon, 12 Apr 2021 07:58:12 +0200 Subject: Removed invalid symbol in function call syntax --- src/test/java/org/openslx/vm/QemuMetaDataTest.java | 37 +++++++++++----------- 1 file changed, 18 insertions(+), 19 deletions(-) diff --git a/src/test/java/org/openslx/vm/QemuMetaDataTest.java b/src/test/java/org/openslx/vm/QemuMetaDataTest.java index a3053a1..869d0f5 100644 --- a/src/test/java/org/openslx/vm/QemuMetaDataTest.java +++ b/src/test/java/org/openslx/vm/QemuMetaDataTest.java @@ -20,7 +20,6 @@ import org.apache.log4j.LogManager; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.function.Executable; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.Arguments; import org.junit.jupiter.params.provider.MethodSource; @@ -73,7 +72,7 @@ public class QemuMetaDataTest assertEquals( "archlinux", displayName ); - assertDoesNotThrow​( () -> vmLibvirtDomainConfig.validateXml() ); + assertDoesNotThrow( () -> vmLibvirtDomainConfig.validateXml() ); } @Test @@ -91,7 +90,7 @@ public class QemuMetaDataTest assertEquals( false, isVmSnapshot ); - assertDoesNotThrow​( () -> vmLibvirtDomainConfig.validateXml() ); + assertDoesNotThrow( () -> vmLibvirtDomainConfig.validateXml() ); } @Test @@ -112,7 +111,7 @@ public class QemuMetaDataTest assertEquals( true, supportedImageFormats .containsAll( Arrays.asList( ImageFormat.QCOW2, ImageFormat.VMDK, ImageFormat.VDI ) ) ); - assertDoesNotThrow​( () -> vmLibvirtDomainConfig.validateXml() ); + assertDoesNotThrow( () -> vmLibvirtDomainConfig.validateXml() ); } @Test @@ -132,7 +131,7 @@ public class QemuMetaDataTest assertEquals( 1, hdds.size() ); assertEquals( "/var/lib/libvirt/images/archlinux.qcow2", hdds.get( 0 ).diskImage ); - assertDoesNotThrow​( () -> vmLibvirtDomainConfig.validateXml() ); + assertDoesNotThrow( () -> vmLibvirtDomainConfig.validateXml() ); } @Test @@ -158,7 +157,7 @@ public class QemuMetaDataTest assertEquals( lengthOriginalXmlConfig, lengthUnfilteredXmlConfig + numberOfDeletedElements ); - assertDoesNotThrow​( () -> vmLibvirtDomainConfig.validateXml() ); + assertDoesNotThrow( () -> vmLibvirtDomainConfig.validateXml() ); } @Test @@ -184,7 +183,7 @@ public class QemuMetaDataTest assertEquals( lengthOriginalXmlConfig, lengthFilteredXmlConfig + numberOfDeletedElements ); - assertDoesNotThrow​( () -> vmLibvirtDomainConfig.validateXml() ); + assertDoesNotThrow( () -> vmLibvirtDomainConfig.validateXml() ); } @ParameterizedTest @@ -225,7 +224,7 @@ public class QemuMetaDataTest DiskStorage addedStorageDevice = vmLibvirtDomainConfig.getDiskStorageDevices().get( 0 ); assertEquals( diskFile.getAbsolutePath(), addedStorageDevice.getStorageSource() ); - assertDoesNotThrow​( () -> vmLibvirtDomainConfig.validateXml() ); + assertDoesNotThrow( () -> vmLibvirtDomainConfig.validateXml() ); } @ParameterizedTest @@ -253,7 +252,7 @@ public class QemuMetaDataTest DiskCdrom addedCdromDevice = vmLibvirtDomainConfig.getDiskCdromDevices().get( 0 ); assertEquals( diskFile.getAbsolutePath(), addedCdromDevice.getStorageSource() ); - assertDoesNotThrow​( () -> vmLibvirtDomainConfig.validateXml() ); + assertDoesNotThrow( () -> vmLibvirtDomainConfig.validateXml() ); } @ParameterizedTest @@ -280,7 +279,7 @@ public class QemuMetaDataTest DiskCdrom addedCdromDevice = vmLibvirtDomainConfig.getDiskCdromDevices().get( 0 ); assertEquals( QemuMetaData.CDROM_DEFAULT_PHYSICAL_DRIVE, addedCdromDevice.getStorageSource() ); - assertDoesNotThrow​( () -> vmLibvirtDomainConfig.validateXml() ); + assertDoesNotThrow( () -> vmLibvirtDomainConfig.validateXml() ); } @ParameterizedTest @@ -309,7 +308,7 @@ public class QemuMetaDataTest assertTrue( addedFloppyDevice.isReadOnly() ); assertEquals( diskFile.getAbsolutePath(), addedFloppyDevice.getStorageSource() ); - assertDoesNotThrow​( () -> vmLibvirtDomainConfig.validateXml() ); + assertDoesNotThrow( () -> vmLibvirtDomainConfig.validateXml() ); } @ParameterizedTest @@ -328,7 +327,7 @@ public class QemuMetaDataTest assertEquals( coreCount, vmLibvirtDomainConfig.getVCpu() ); - assertDoesNotThrow​( () -> vmLibvirtDomainConfig.validateXml() ); + assertDoesNotThrow( () -> vmLibvirtDomainConfig.validateXml() ); } @ParameterizedTest @@ -351,7 +350,7 @@ public class QemuMetaDataTest assertEquals( SoundCardType.HD_AUDIO, soundCardType ); } - assertDoesNotThrow​( () -> vmLibvirtDomainConfig.validateXml() ); + assertDoesNotThrow( () -> vmLibvirtDomainConfig.validateXml() ); } @ParameterizedTest @@ -378,7 +377,7 @@ public class QemuMetaDataTest Sound addedSoundDevice = vmLibvirtDomainConfig.getSoundDevices().get( 0 ); assertEquals( Sound.Model.SB16, addedSoundDevice.getModel() ); - assertDoesNotThrow​( () -> vmLibvirtDomainConfig.validateXml() ); + assertDoesNotThrow( () -> vmLibvirtDomainConfig.validateXml() ); } @ParameterizedTest @@ -401,7 +400,7 @@ public class QemuMetaDataTest assertEquals( EthernetDevType.PARAVIRT, ethernetDeviceType ); } - assertDoesNotThrow​( () -> vmLibvirtDomainConfig.validateXml() ); + assertDoesNotThrow( () -> vmLibvirtDomainConfig.validateXml() ); } @ParameterizedTest @@ -423,7 +422,7 @@ public class QemuMetaDataTest assertEquals( Interface.Model.E1000E, addedEthernetDevice.getModel() ); } - assertDoesNotThrow​( () -> vmLibvirtDomainConfig.validateXml() ); + assertDoesNotThrow( () -> vmLibvirtDomainConfig.validateXml() ); } @ParameterizedTest @@ -446,7 +445,7 @@ public class QemuMetaDataTest assertEquals( UsbSpeed.USB3_0, maxUsbSpeed ); } - assertDoesNotThrow​( () -> vmLibvirtDomainConfig.validateXml() ); + assertDoesNotThrow( () -> vmLibvirtDomainConfig.validateXml() ); } @ParameterizedTest @@ -473,7 +472,7 @@ public class QemuMetaDataTest ControllerUsb addedUsbControllerDevice = vmLibvirtDomainConfig.getUsbControllerDevices().get( 0 ); assertEquals( ControllerUsb.Model.ICH9_EHCI1, addedUsbControllerDevice.getModel() ); - assertDoesNotThrow​( () -> vmLibvirtDomainConfig.validateXml() ); + assertDoesNotThrow( () -> vmLibvirtDomainConfig.validateXml() ); } static Stream configAndEthernetTypeProvider() @@ -527,6 +526,6 @@ public class QemuMetaDataTest break; } - assertDoesNotThrow​( () -> vmLibvirtDomainConfig.validateXml() ); + assertDoesNotThrow( () -> vmLibvirtDomainConfig.validateXml() ); } } -- cgit v1.2.3-55-g7522 From acf39f2540affb287d6222b82fbc913f8c86d709 Mon Sep 17 00:00:00 2001 From: Manuel Bentele Date: Mon, 12 Apr 2021 10:54:57 +0200 Subject: Fix issue in VmMetaData factory method wrt. QemuMetaData class --- src/main/java/org/openslx/vm/QemuMetaData.java | 40 ++++++++++++++++++++---- src/main/java/org/openslx/vm/VboxMetaData.java | 1 - src/main/java/org/openslx/vm/VmMetaData.java | 32 +++++++++++-------- src/main/java/org/openslx/vm/VmwareMetaData.java | 2 -- 4 files changed, 53 insertions(+), 22 deletions(-) diff --git a/src/main/java/org/openslx/vm/QemuMetaData.java b/src/main/java/org/openslx/vm/QemuMetaData.java index bd288a4..3209925 100644 --- a/src/main/java/org/openslx/vm/QemuMetaData.java +++ b/src/main/java/org/openslx/vm/QemuMetaData.java @@ -282,6 +282,7 @@ public class QemuMetaData extends * * @param osList list of operating systems. * @param file image file for the QEMU hypervisor. + * * @throws UnsupportedVirtualizerFormatException Libvirt XML configuration cannot be processed. */ public QemuMetaData( List osList, File file ) throws UnsupportedVirtualizerFormatException @@ -291,17 +292,44 @@ public class QemuMetaData extends try { // read and parse Libvirt domain XML configuration document this.vmConfig = new Domain( file ); - } catch ( LibvirtXmlDocumentException e ) { - throw new UnsupportedVirtualizerFormatException( e.getLocalizedMessage() ); - } catch ( LibvirtXmlSerializationException e ) { + } catch ( LibvirtXmlDocumentException | LibvirtXmlSerializationException | LibvirtXmlValidationException e ) { throw new UnsupportedVirtualizerFormatException( e.getLocalizedMessage() ); - } catch ( LibvirtXmlValidationException e ) { + } + + // parse VM config and initialize fields of QemuMetaData class + this.parseVmConfig(); + } + + /** + * Creates new virtual machine configuration (managed by Libvirt) for the QEMU hypervisor. + * + * @param osList list of operating systems. + * @param vmContent file content for the QEMU hypervisor. + * @param length number of bytes of the file content. + * + * @throws UnsupportedVirtualizerFormatException Libvirt XML configuration cannot be processed. + */ + public QemuMetaData( List osList, byte[] vmContent, int length ) + throws UnsupportedVirtualizerFormatException + { + super( osList ); + + try { + // read and parse Libvirt domain XML configuration document + this.vmConfig = new Domain( new String( vmContent ) ); + } catch ( LibvirtXmlDocumentException | LibvirtXmlSerializationException | LibvirtXmlValidationException e ) { throw new UnsupportedVirtualizerFormatException( e.getLocalizedMessage() ); } - // register virtual hardware models for graphical editing of virtual devices (GPU, sound, USB, ...) - this.registerVirtualHW(); + // parse VM config and initialize fields of QemuMetaData class + this.parseVmConfig(); + } + /** + * Parses Libvirt domain XML configuration to initialize QEMU metadata. + */ + private void parseVmConfig() + { // set display name of VM this.displayName = vmConfig.getName(); diff --git a/src/main/java/org/openslx/vm/VboxMetaData.java b/src/main/java/org/openslx/vm/VboxMetaData.java index a6ac14d..326291b 100644 --- a/src/main/java/org/openslx/vm/VboxMetaData.java +++ b/src/main/java/org/openslx/vm/VboxMetaData.java @@ -120,7 +120,6 @@ public class VboxMetaData extends VmMetaData public VmMetaData( List osList ) { this.osList = osList; + + // register virtual hardware models for graphical editing of virtual devices (GPU, sound, USB, ...) + this.registerVirtualHW(); } /** @@ -319,14 +322,15 @@ public abstract class VmMetaData } try { return new QemuMetaData( osList, file ); - } catch ( Exception e ) { - LOGGER.info( "Not a Qemu file", e ); + } catch ( UnsupportedVirtualizerFormatException e ) { + LOGGER.info( "Not a Libvirt file", e ); } try { return new DockerMetaDataDummy(osList, file); } catch ( Exception e ) { LOGGER.info( "Not a tar.gz file, for docker container", e ); } + LOGGER.error( "Could not detect any known virtualizer format" ); return null; } @@ -340,29 +344,31 @@ public abstract class VmMetaData * @return VmMetaData object representing the relevant parts of the given machine description * @throws IOException */ - public static VmMetaData getInstance( List osList, byte[] vmContent, int length ) throws IOException + public static VmMetaData getInstance( List osList, byte[] vmContent, int length ) + throws IOException { - Map exceptions = new HashMap<>(); try { return new VmwareMetaData( osList, vmContent, length ); } catch ( UnsupportedVirtualizerFormatException e ) { - exceptions.put( "Not a VMware file", e ); + LOGGER.info( "Not a VMware file", e ); } try { return new VboxMetaData( osList, vmContent, length ); } catch ( UnsupportedVirtualizerFormatException e ) { - exceptions.put( "Not a VirtualBox file", e ); + LOGGER.info( "Not a VirtualBox file", e ); + } + try { + return new QemuMetaData( osList, vmContent, length ); + } catch ( UnsupportedVirtualizerFormatException e ) { + LOGGER.info( "Not a Libvirt file", e ); } try { - return new DockerMetaDataDummy(osList, vmContent, length); - } catch (UnsupportedVirtualizerFormatException e) { - exceptions.put( "Not tar.gz file for DockerMetaDataDummy ", e); + return new DockerMetaDataDummy( osList, vmContent, length ); + } catch ( UnsupportedVirtualizerFormatException e ) { + LOGGER.info( "Not a tar.gz file, for docker container", e ); } - // TODO QEmu -- hack above expects qcow2 file, so we can't do anything here yet + LOGGER.error( "Could not detect any known virtualizer format" ); - for ( Entry e : exceptions.entrySet() ) { - LOGGER.error( e.getKey(), e.getValue() ); - } return null; } diff --git a/src/main/java/org/openslx/vm/VmwareMetaData.java b/src/main/java/org/openslx/vm/VmwareMetaData.java index 9bbe581..cebff17 100644 --- a/src/main/java/org/openslx/vm/VmwareMetaData.java +++ b/src/main/java/org/openslx/vm/VmwareMetaData.java @@ -136,8 +136,6 @@ public class VmwareMetaData extends VmMetaData entry : config.entrySet() ) { handleLoadEntry( entry ); } -- cgit v1.2.3-55-g7522 From f2b0667b55afbc51bc8de4652e7ce4403fbb9bed Mon Sep 17 00:00:00 2001 From: Manuel Bentele Date: Mon, 12 Apr 2021 11:43:29 +0200 Subject: Adjusts network bridge names for Libvirt networking --- src/main/java/org/openslx/vm/QemuMetaData.java | 32 +++++++++++----------- src/test/java/org/openslx/vm/QemuMetaDataTest.java | 10 +++---- 2 files changed, 21 insertions(+), 21 deletions(-) diff --git a/src/main/java/org/openslx/vm/QemuMetaData.java b/src/main/java/org/openslx/vm/QemuMetaData.java index 3209925..e758d64 100644 --- a/src/main/java/org/openslx/vm/QemuMetaData.java +++ b/src/main/java/org/openslx/vm/QemuMetaData.java @@ -227,19 +227,19 @@ public class QemuMetaData extends VmMetaData { /** - * Default bridge name of the network bridge connected to the LAN. + * Name of the network bridge for the LAN. */ - public static final String NETWORK_DEFAULT_BRIDGE = "brBwLehrpool"; + public static final String NETWORK_BRIDGE_LAN_DEFAULT = "br0"; /** - * Default network name of the isolated host network (host only). + * Name of the network bridge for the default NAT network. */ - public static final String NETWORK_DEFAULT_HOST_ONLY = "host"; + public static final String NETWORK_BRIDGE_NAT_DEFAULT = "nat1"; /** - * Default network name of the NAT network. + * Name of the network for the isolated host network (host only). */ - public static final String NETWORK_DEFAULT_NAT = "nat"; + public static final String NETWORK_BRIDGE_HOST_ONLY_DEFAULT = "vsw2"; /** * Default physical CDROM drive of the hypervisor host. @@ -799,19 +799,19 @@ public class QemuMetaData extends // add network bridge interface device interfaceDevice = this.vmConfig.addInterfaceBridgeDevice(); interfaceDevice.setModel( defaultNetworkDeviceModel ); - interfaceDevice.setSource( QemuMetaData.NETWORK_DEFAULT_BRIDGE ); + interfaceDevice.setSource( QemuMetaData.NETWORK_BRIDGE_LAN_DEFAULT ); break; case HOST_ONLY: // add network interface device with link to the isolated host network - interfaceDevice = this.vmConfig.addInterfaceNetworkDevice(); + interfaceDevice = this.vmConfig.addInterfaceBridgeDevice(); interfaceDevice.setModel( defaultNetworkDeviceModel ); - interfaceDevice.setSource( QemuMetaData.NETWORK_DEFAULT_HOST_ONLY ); + interfaceDevice.setSource( QemuMetaData.NETWORK_BRIDGE_HOST_ONLY_DEFAULT ); break; case NAT: // add network interface device with link to the NAT network - interfaceDevice = this.vmConfig.addInterfaceNetworkDevice(); + interfaceDevice = this.vmConfig.addInterfaceBridgeDevice(); interfaceDevice.setModel( defaultNetworkDeviceModel ); - interfaceDevice.setSource( QemuMetaData.NETWORK_DEFAULT_NAT ); + interfaceDevice.setSource( QemuMetaData.NETWORK_BRIDGE_NAT_DEFAULT ); break; } } else { @@ -819,15 +819,15 @@ public class QemuMetaData extends switch ( type ) { case BRIDGED: interfaceDevice.setType( Interface.Type.BRIDGE ); - interfaceDevice.setSource( QemuMetaData.NETWORK_DEFAULT_BRIDGE ); + interfaceDevice.setSource( QemuMetaData.NETWORK_BRIDGE_LAN_DEFAULT ); break; case HOST_ONLY: - interfaceDevice.setType( Interface.Type.NETWORK ); - interfaceDevice.setSource( QemuMetaData.NETWORK_DEFAULT_HOST_ONLY ); + interfaceDevice.setType( Interface.Type.BRIDGE ); + interfaceDevice.setSource( QemuMetaData.NETWORK_BRIDGE_HOST_ONLY_DEFAULT ); break; case NAT: - interfaceDevice.setType( Interface.Type.NETWORK ); - interfaceDevice.setSource( QemuMetaData.NETWORK_DEFAULT_NAT ); + interfaceDevice.setType( Interface.Type.BRIDGE ); + interfaceDevice.setSource( QemuMetaData.NETWORK_BRIDGE_NAT_DEFAULT ); break; } } diff --git a/src/test/java/org/openslx/vm/QemuMetaDataTest.java b/src/test/java/org/openslx/vm/QemuMetaDataTest.java index 869d0f5..30607db 100644 --- a/src/test/java/org/openslx/vm/QemuMetaDataTest.java +++ b/src/test/java/org/openslx/vm/QemuMetaDataTest.java @@ -512,17 +512,17 @@ public class QemuMetaDataTest case BRIDGED: assertEquals( Interface.Type.BRIDGE, addedEthernetDevice.getType() ); assertEquals( Interface.Model.VIRTIO, addedEthernetDevice.getModel() ); - assertEquals( QemuMetaData.NETWORK_DEFAULT_BRIDGE, addedEthernetDevice.getSource() ); + assertEquals( QemuMetaData.NETWORK_BRIDGE_LAN_DEFAULT, addedEthernetDevice.getSource() ); break; case HOST_ONLY: - assertEquals( Interface.Type.NETWORK, addedEthernetDevice.getType() ); + assertEquals( Interface.Type.BRIDGE, addedEthernetDevice.getType() ); assertEquals( Interface.Model.VIRTIO, addedEthernetDevice.getModel() ); - assertEquals( QemuMetaData.NETWORK_DEFAULT_HOST_ONLY, addedEthernetDevice.getSource() ); + assertEquals( QemuMetaData.NETWORK_BRIDGE_HOST_ONLY_DEFAULT, addedEthernetDevice.getSource() ); break; case NAT: - assertEquals( Interface.Type.NETWORK, addedEthernetDevice.getType() ); + assertEquals( Interface.Type.BRIDGE, addedEthernetDevice.getType() ); assertEquals( Interface.Model.VIRTIO, addedEthernetDevice.getModel() ); - assertEquals( QemuMetaData.NETWORK_DEFAULT_NAT, addedEthernetDevice.getSource() ); + assertEquals( QemuMetaData.NETWORK_BRIDGE_NAT_DEFAULT, addedEthernetDevice.getSource() ); break; } -- cgit v1.2.3-55-g7522 From e702466dcac81e0428d8ac4e9146084c03388f4a Mon Sep 17 00:00:00 2001 From: Manuel Bentele Date: Thu, 15 Apr 2021 10:06:46 +0200 Subject: Add representation of used virtualization systems --- .../virtualization/virtualizer/Virtualizer.java | 60 ++++++++++++++++++++++ .../virtualizer/VirtualizerDocker.java | 43 ++++++++++++++++ .../virtualizer/VirtualizerQemu.java | 43 ++++++++++++++++ .../virtualizer/VirtualizerVirtualBox.java | 44 ++++++++++++++++ .../virtualizer/VirtualizerVmware.java | 43 ++++++++++++++++ 5 files changed, 233 insertions(+) create mode 100644 src/main/java/org/openslx/virtualization/virtualizer/Virtualizer.java create mode 100644 src/main/java/org/openslx/virtualization/virtualizer/VirtualizerDocker.java create mode 100644 src/main/java/org/openslx/virtualization/virtualizer/VirtualizerQemu.java create mode 100644 src/main/java/org/openslx/virtualization/virtualizer/VirtualizerVirtualBox.java create mode 100644 src/main/java/org/openslx/virtualization/virtualizer/VirtualizerVmware.java diff --git a/src/main/java/org/openslx/virtualization/virtualizer/Virtualizer.java b/src/main/java/org/openslx/virtualization/virtualizer/Virtualizer.java new file mode 100644 index 0000000..e74d15e --- /dev/null +++ b/src/main/java/org/openslx/virtualization/virtualizer/Virtualizer.java @@ -0,0 +1,60 @@ +package org.openslx.virtualization.virtualizer; + +import java.util.List; + +import org.openslx.vm.disk.DiskImage.ImageFormat; + +/** + * Representation of a virtualization system. + * + * The virtualization system can be for example a virtual machine hypervisor (like VirtualBox), a + * container for operating systems or applications (like LXC or Docker), or a runtime environment + * (like Wine). + * + * @author Manuel Bentele + * @version 1.0 + */ +public abstract class Virtualizer +{ + /** + * Internal data representation for the virtualizer. + */ + protected final org.openslx.bwlp.thrift.iface.Virtualizer internalVirtualizer; + + /** + * Creates a new virtualizer. + * + * @param internalVirtualizer internal data representation for the new virtualizer. + */ + public Virtualizer( org.openslx.bwlp.thrift.iface.Virtualizer internalVirtualizer ) + { + this.internalVirtualizer = internalVirtualizer; + } + + /** + * Returns the identifier of the virtualizer. + * + * @return identifier of the virtualizer. + */ + public String getId() + { + return this.internalVirtualizer.getVirtId(); + } + + /** + * Returns the name of the virtualizer. + * + * @return name of the virtualizer. + */ + public String getName() + { + return this.internalVirtualizer.getVirtName(); + } + + /** + * Returns a list of supported disk image formats by the virtualizer. + * + * @return list of supported disk image formats by the virtualizer. + */ + public abstract List getSupportedImageFormats(); +} diff --git a/src/main/java/org/openslx/virtualization/virtualizer/VirtualizerDocker.java b/src/main/java/org/openslx/virtualization/virtualizer/VirtualizerDocker.java new file mode 100644 index 0000000..524209c --- /dev/null +++ b/src/main/java/org/openslx/virtualization/virtualizer/VirtualizerDocker.java @@ -0,0 +1,43 @@ +package org.openslx.virtualization.virtualizer; + +import java.util.Arrays; +import java.util.Collections; +import java.util.List; + +import org.openslx.thrifthelper.TConst; +import org.openslx.vm.disk.DiskImage; +import org.openslx.vm.disk.DiskImage.ImageFormat; + +/** + * Representation of the Docker virtualizer for application containers. + * + * @author Manuel Bentele + * @version 1.0 + */ +public class VirtualizerDocker extends Virtualizer +{ + /** + * Name of the Docker virtualizer. + */ + private static final String VIRTUALIZER_NAME = "Docker"; + + /** + * List of supported image formats by the Docker virtualizer. + */ + private static final List VIRTUALIZER_SUPPORTED_IMAGE_FORMATS = Collections + .unmodifiableList( Arrays.asList( ImageFormat.NONE ) ); + + /** + * Creates a new Docker virtualizer. + */ + public VirtualizerDocker() + { + super( new org.openslx.bwlp.thrift.iface.Virtualizer( TConst.VIRT_DOCKER, VirtualizerDocker.VIRTUALIZER_NAME ) ); + } + + @Override + public List getSupportedImageFormats() + { + return VirtualizerDocker.VIRTUALIZER_SUPPORTED_IMAGE_FORMATS; + } +} diff --git a/src/main/java/org/openslx/virtualization/virtualizer/VirtualizerQemu.java b/src/main/java/org/openslx/virtualization/virtualizer/VirtualizerQemu.java new file mode 100644 index 0000000..731209b --- /dev/null +++ b/src/main/java/org/openslx/virtualization/virtualizer/VirtualizerQemu.java @@ -0,0 +1,43 @@ +package org.openslx.virtualization.virtualizer; + +import java.util.Arrays; +import java.util.Collections; +import java.util.List; + +import org.openslx.thrifthelper.TConst; +import org.openslx.vm.disk.DiskImage; +import org.openslx.vm.disk.DiskImage.ImageFormat; + +/** + * Representation of the QEMU virtualizer for virtual machines. + * + * @author Manuel Bentele + * @version 1.0 + */ +public class VirtualizerQemu extends Virtualizer +{ + /** + * Name of the QEMU virtualizer. + */ + private static final String VIRTUALIZER_NAME = "QEMU"; + + /** + * List of supported image formats by the QEMU virtualizer. + */ + private static final List VIRTUALIZER_SUPPORTED_IMAGE_FORMATS = Collections + .unmodifiableList( Arrays.asList( ImageFormat.QCOW2, ImageFormat.VMDK, ImageFormat.VDI ) ); + + /** + * Creates a new QEMU virtualizer. + */ + public VirtualizerQemu() + { + super( new org.openslx.bwlp.thrift.iface.Virtualizer( TConst.VIRT_QEMU, VirtualizerQemu.VIRTUALIZER_NAME ) ); + } + + @Override + public List getSupportedImageFormats() + { + return VirtualizerQemu.VIRTUALIZER_SUPPORTED_IMAGE_FORMATS; + } +} diff --git a/src/main/java/org/openslx/virtualization/virtualizer/VirtualizerVirtualBox.java b/src/main/java/org/openslx/virtualization/virtualizer/VirtualizerVirtualBox.java new file mode 100644 index 0000000..77662ab --- /dev/null +++ b/src/main/java/org/openslx/virtualization/virtualizer/VirtualizerVirtualBox.java @@ -0,0 +1,44 @@ +package org.openslx.virtualization.virtualizer; + +import java.util.Arrays; +import java.util.Collections; +import java.util.List; + +import org.openslx.thrifthelper.TConst; +import org.openslx.vm.disk.DiskImage; +import org.openslx.vm.disk.DiskImage.ImageFormat; + +/** + * Representation of the VirtualBox virtualizer for virtual machines. + * + * @author Manuel Bentele + * @version 1.0 + */ +public class VirtualizerVirtualBox extends Virtualizer +{ + /** + * Name of the VirtualBox virtualizer. + */ + private static final String VIRTUALIZER_NAME = "VirtualBox"; + + /** + * List of supported image formats by the VirtualBox virtualizer. + */ + private static final List VIRTUALIZER_SUPPORTED_IMAGE_FORMATS = Collections + .unmodifiableList( Arrays.asList( ImageFormat.VDI ) ); + + /** + * Creates a new VirtualBox virtualizer. + */ + public VirtualizerVirtualBox() + { + super( new org.openslx.bwlp.thrift.iface.Virtualizer( TConst.VIRT_VIRTUALBOX, + VirtualizerVirtualBox.VIRTUALIZER_NAME ) ); + } + + @Override + public List getSupportedImageFormats() + { + return VirtualizerVirtualBox.VIRTUALIZER_SUPPORTED_IMAGE_FORMATS; + } +} diff --git a/src/main/java/org/openslx/virtualization/virtualizer/VirtualizerVmware.java b/src/main/java/org/openslx/virtualization/virtualizer/VirtualizerVmware.java new file mode 100644 index 0000000..7b766eb --- /dev/null +++ b/src/main/java/org/openslx/virtualization/virtualizer/VirtualizerVmware.java @@ -0,0 +1,43 @@ +package org.openslx.virtualization.virtualizer; + +import java.util.Arrays; +import java.util.Collections; +import java.util.List; + +import org.openslx.thrifthelper.TConst; +import org.openslx.vm.disk.DiskImage; +import org.openslx.vm.disk.DiskImage.ImageFormat; + +/** + * Representation of the VMware virtualizer for virtual machines. + * + * @author Manuel Bentele + * @version 1.0 + */ +public class VirtualizerVmware extends Virtualizer +{ + /** + * Name of the VMware virtualizer. + */ + private static final String VIRTUALIZER_NAME = "VMware"; + + /** + * List of supported image formats by the VMware virtualizer. + */ + private static final List VIRTUALIZER_SUPPORTED_IMAGE_FORMATS = Collections + .unmodifiableList( Arrays.asList( ImageFormat.VMDK ) ); + + /** + * Creates a new VMware virtualizer. + */ + public VirtualizerVmware() + { + super( new org.openslx.bwlp.thrift.iface.Virtualizer( TConst.VIRT_VMWARE, VirtualizerVmware.VIRTUALIZER_NAME ) ); + } + + @Override + public List getSupportedImageFormats() + { + return VirtualizerVmware.VIRTUALIZER_SUPPORTED_IMAGE_FORMATS; + } +} -- cgit v1.2.3-55-g7522 From 90d94a479e5af0d884c63643f1266dc0a6596318 Mon Sep 17 00:00:00 2001 From: Manuel Bentele Date: Thu, 15 Apr 2021 14:01:47 +0200 Subject: Add generic transformation library to transform configs --- .../transformation/Transformation.java | 65 +++++++++ .../transformation/TransformationException.java | 25 ++++ .../transformation/TransformationFunction.java | 39 ++++++ .../transformation/TransformationGeneric.java | 25 ++++ .../transformation/TransformationManager.java | 146 +++++++++++++++++++++ .../transformation/TransformationSpecific.java | 43 ++++++ 6 files changed, 343 insertions(+) create mode 100644 src/main/java/org/openslx/virtualization/configuration/transformation/Transformation.java create mode 100644 src/main/java/org/openslx/virtualization/configuration/transformation/TransformationException.java create mode 100644 src/main/java/org/openslx/virtualization/configuration/transformation/TransformationFunction.java create mode 100644 src/main/java/org/openslx/virtualization/configuration/transformation/TransformationGeneric.java create mode 100644 src/main/java/org/openslx/virtualization/configuration/transformation/TransformationManager.java create mode 100644 src/main/java/org/openslx/virtualization/configuration/transformation/TransformationSpecific.java diff --git a/src/main/java/org/openslx/virtualization/configuration/transformation/Transformation.java b/src/main/java/org/openslx/virtualization/configuration/transformation/Transformation.java new file mode 100644 index 0000000..af0e181 --- /dev/null +++ b/src/main/java/org/openslx/virtualization/configuration/transformation/Transformation.java @@ -0,0 +1,65 @@ +package org.openslx.virtualization.configuration.transformation; + +/** + * Represents a transformation that transforms (alters) a given configuration with specified input + * arguments. + * + * @author Manuel Bentele + * @version 1.0 + * + * @param type of the configuration which will be transformed. + * @param type of input arguments for the transformation. + */ +public abstract class Transformation implements TransformationFunction +{ + /** + * Name of the transformation. + */ + private final String name; + + /** + * State of the transformation. + */ + private boolean enabled; + + /** + * Creates a transformation. + * + * @param name comprehensible name for the transformation. + */ + public Transformation( String name ) + { + this.name = name; + this.setEnabled( true ); + } + + /** + * Returns the name of the transformation. + * + * @return name of the transformation. + */ + public String getName() + { + return this.name; + } + + /** + * Returns the state of the transformation. + * + * @return state of the transformation. + */ + public boolean isEnabled() + { + return this.enabled; + } + + /** + * Sets the state for the transformation. + * + * @param enabled state for the transformation. + */ + public void setEnabled( boolean enabled ) + { + this.enabled = enabled; + } +} diff --git a/src/main/java/org/openslx/virtualization/configuration/transformation/TransformationException.java b/src/main/java/org/openslx/virtualization/configuration/transformation/TransformationException.java new file mode 100644 index 0000000..72f320d --- /dev/null +++ b/src/main/java/org/openslx/virtualization/configuration/transformation/TransformationException.java @@ -0,0 +1,25 @@ +package org.openslx.virtualization.configuration.transformation; + +/** + * An exception of a transformation error. + * + * @author Manuel Bentele + * @version 1.0 + */ +public class TransformationException extends Exception +{ + /** + * Version for serialization. + */ + private static final long serialVersionUID = 7293420658901349154L; + + /** + * Creates a transformation exception including an error message. + * + * @param errorMsg message to describe the exception. + */ + public TransformationException( String errorMsg ) + { + super( errorMsg ); + } +} diff --git a/src/main/java/org/openslx/virtualization/configuration/transformation/TransformationFunction.java b/src/main/java/org/openslx/virtualization/configuration/transformation/TransformationFunction.java new file mode 100644 index 0000000..b5be7a0 --- /dev/null +++ b/src/main/java/org/openslx/virtualization/configuration/transformation/TransformationFunction.java @@ -0,0 +1,39 @@ +package org.openslx.virtualization.configuration.transformation; + +/** + * Represents a transformation operation that transforms (alters) a given configuration with + * specified input arguments and returns no result. + * + * @author Manuel Bentele + * @version 1.0 + * + * @param type of the configuration which will be transformed. + * @param type of input arguments for the transformation. + */ +@FunctionalInterface +public interface TransformationFunction +{ + /** + * Transforms a given configuration with the specified input arguments. + * + * @param config configuration which will be transformed. + * @param args input arguments for the transformation. + * + * @throws TransformationException transformation of the configuration failed. + */ + public void transform( T config, R args ) throws TransformationException; + + /** + * Applies the transformation function {@link #transform(Object, Object)} to the given + * configuration and specified input arguments. + * + * @param config configuration which will be transformed. + * @param args input arguments for the transformation. + * + * @throws TransformationException transformation of the configuration failed. + */ + public default void apply( T config, R args ) throws TransformationException + { + this.transform( config, args ); + } +} diff --git a/src/main/java/org/openslx/virtualization/configuration/transformation/TransformationGeneric.java b/src/main/java/org/openslx/virtualization/configuration/transformation/TransformationGeneric.java new file mode 100644 index 0000000..4ad36c7 --- /dev/null +++ b/src/main/java/org/openslx/virtualization/configuration/transformation/TransformationGeneric.java @@ -0,0 +1,25 @@ +package org.openslx.virtualization.configuration.transformation; + +/** + * Represents a generic transformation that transforms (alters) a given configuration with specified + * input arguments. The generic transformation does not depend on any external states of a + * virtualizer. + * + * @author Manuel Bentele + * @version 1.0 + * + * @param type of the configuration which will be transformed. + * @param type of input arguments for the transformation. + */ +public abstract class TransformationGeneric extends Transformation +{ + /** + * Create a generic transformation. + * + * @param name comprehensible name for the transformation. + */ + public TransformationGeneric( String name ) + { + super( name ); + } +} diff --git a/src/main/java/org/openslx/virtualization/configuration/transformation/TransformationManager.java b/src/main/java/org/openslx/virtualization/configuration/transformation/TransformationManager.java new file mode 100644 index 0000000..ce0ad96 --- /dev/null +++ b/src/main/java/org/openslx/virtualization/configuration/transformation/TransformationManager.java @@ -0,0 +1,146 @@ +package org.openslx.virtualization.configuration.transformation; + +import java.util.ArrayList; + +/** + * A transformation manager is a class to manage several transformations and their application. + * + * Transformations can be registered at the transformation manager. The transformation manager has + * the ability to apply all registered transformations on a given configuration and specified input + * arguments. + * + * @author Manuel Bentele + * @version 1.0 + * + * @param type of the configuration which will be transformed by all transformations. + * @param type of input arguments for all transformations. + */ +public class TransformationManager +{ + /** + * List of registered transformations. + */ + private ArrayList> transformations; + + /** + * Reference to the configuration that will be transformed (altered). + */ + private T config; + + /** + * Reference to the input arguments for all registered transformations. + */ + private R args; + + /** + * Create a transformation manager. + * + * @param config configuration which will be transformed. + * @param args input arguments for all registered transformations. + */ + public TransformationManager( T config, R args ) + { + this.transformations = new ArrayList>(); + this.config = config; + this.args = args; + } + + /** + * Registers and enables a transformation. + * + * @param transformation existing transformation that will be registered and enabled. + */ + public void register( Transformation transformation ) + { + this.register( transformation, true ); + } + + /** + * Registers a transformation and sets its state. + * + * @param transformation existing transformation that will be registered. + * @param enabled state for the existing transformation that will be set. + */ + public void register( Transformation transformation, boolean enabled ) + { + transformation.setEnabled( enabled ); + this.transformations.add( transformation ); + } + + /** + * Registers a transformation function as a new transformation and enables the registered + * transformation. + * + * @param name comprehensible name for the transformation. + * @param function transformation operation for the transformation. + */ + public void register( String name, TransformationFunction function ) + { + this.register( name, function, true ); + } + + /** + * Registers a transformation function as a new transformation and sets the state of the + * registered transformation. + * + * @param name comprehensible name for the transformation. + * @param function transformation operation for the transformation. + * @param enabled state for the transformation. + */ + public void register( String name, TransformationFunction function, boolean enabled ) + { + this.register( new Transformation( name ) { + @Override + public void transform( T document, R args ) throws TransformationException + { + function.apply( document, args ); + } + }, enabled ); + } + + /** + * Applies all registered transformations, whose state is set to enabled, to the + * referenced configuration and input arguments. + * + * @throws TransformationException transformation of the configuration failed. + */ + public void transform() throws TransformationException + { + for ( Transformation transformation : this.transformations ) { + try { + transformation.apply( this.config, this.args ); + } catch ( TransformationException e ) { + final String errorMsg = new String( + "Error in configuration filter '" + transformation.getName() + "':" + e.getLocalizedMessage() ); + throw new TransformationException( errorMsg ); + } + } + } + + /** + * Returns a human readable summary of all registered transformations. + * + * @return human readable summary of all registered transformations. + */ + private String showTransformations() + { + String transformationSummary = new String(); + final int maxFilterNumCharacters = ( this.transformations.size() + 1 ) / 10; + + for ( int i = 0; i < this.transformations.size(); i++ ) { + final Transformation transformation = this.transformations.get( i ); + final String paddedNumber = String.format( "%-" + maxFilterNumCharacters + "s", i + 1 ); + final String transformationState = transformation.isEnabled() ? "[ active ]" : "[inactive]"; + transformationSummary += paddedNumber + ": " + transformationState + " "; + transformationSummary += transformation.getName() + System.lineSeparator(); + } + + return transformationSummary; + } + + @Override + public String toString() + { + return this.showTransformations(); + } +} diff --git a/src/main/java/org/openslx/virtualization/configuration/transformation/TransformationSpecific.java b/src/main/java/org/openslx/virtualization/configuration/transformation/TransformationSpecific.java new file mode 100644 index 0000000..5b13f45 --- /dev/null +++ b/src/main/java/org/openslx/virtualization/configuration/transformation/TransformationSpecific.java @@ -0,0 +1,43 @@ +package org.openslx.virtualization.configuration.transformation; + +/** + * Represents a specific transformation that transforms (alters) a given configuration with + * specified input arguments. The specific transformation depends on external states of a + * specified virtualizer. + * + * @author Manuel Bentele + * @version 1.0 + * + * @param type of the configuration which will be transformed. + * @param type of input arguments for the transformation. + * @param type of the external input source. + */ +public abstract class TransformationSpecific extends Transformation +{ + /** + * Reference to virtualizer to query external states. + */ + private final H virtualizer; + + /** + * Create a specific transformation. + * + * @param name comprehensible name for the transformation. + */ + public TransformationSpecific( String name, H virtualizer ) + { + super( name ); + + this.virtualizer = virtualizer; + } + + /** + * Returns the referenced virtualizer of the transformation. + * + * @return referenced virtualizer of the transformation. + */ + public H getVirtualizer() + { + return this.virtualizer; + } +} -- cgit v1.2.3-55-g7522 From 07661b83665c2db556d26dcc11c9ad380878b0ff Mon Sep 17 00:00:00 2001 From: Manuel Bentele Date: Thu, 15 Apr 2021 15:05:15 +0200 Subject: Move VmMetaData classes to new virtualization config directories --- src/main/java/org/openslx/util/ThriftUtil.java | 2 +- .../UnsupportedVirtualizerFormatException.java | 13 + .../virtualization/configuration/VmMetaData.java | 429 ++++++++++ .../container/DockerMetaDataDummy.java | 221 ++++++ .../configuration/machine/KeyValuePair.java | 13 + .../configuration/machine/QemuMetaData.java | 883 +++++++++++++++++++++ .../configuration/machine/QemuMetaDataUtils.java | 191 +++++ .../configuration/machine/VboxConfig.java | 632 +++++++++++++++ .../configuration/machine/VboxMetaData.java | 537 +++++++++++++ .../configuration/machine/VmwareConfig.java | 277 +++++++ .../configuration/machine/VmwareMetaData.java | 684 ++++++++++++++++ .../java/org/openslx/vm/DockerMetaDataDummy.java | 219 ----- src/main/java/org/openslx/vm/KeyValuePair.java | 13 - src/main/java/org/openslx/vm/QemuMetaData.java | 881 -------------------- .../java/org/openslx/vm/QemuMetaDataUtils.java | 191 ----- .../vm/UnsupportedVirtualizerFormatException.java | 13 - src/main/java/org/openslx/vm/VboxConfig.java | 631 --------------- src/main/java/org/openslx/vm/VboxMetaData.java | 535 ------------- src/main/java/org/openslx/vm/VmMetaData.java | 425 ---------- src/main/java/org/openslx/vm/VmwareConfig.java | 276 ------- src/main/java/org/openslx/vm/VmwareMetaData.java | 682 ---------------- .../java/org/openslx/vm/disk/DiskImageVmdk.java | 4 +- .../configuration/machine/QemuMetaDataTest.java | 533 +++++++++++++ src/test/java/org/openslx/vm/QemuMetaDataTest.java | 531 ------------- 24 files changed, 4416 insertions(+), 4400 deletions(-) create mode 100644 src/main/java/org/openslx/virtualization/configuration/UnsupportedVirtualizerFormatException.java create mode 100644 src/main/java/org/openslx/virtualization/configuration/VmMetaData.java create mode 100644 src/main/java/org/openslx/virtualization/configuration/container/DockerMetaDataDummy.java create mode 100644 src/main/java/org/openslx/virtualization/configuration/machine/KeyValuePair.java create mode 100644 src/main/java/org/openslx/virtualization/configuration/machine/QemuMetaData.java create mode 100644 src/main/java/org/openslx/virtualization/configuration/machine/QemuMetaDataUtils.java create mode 100644 src/main/java/org/openslx/virtualization/configuration/machine/VboxConfig.java create mode 100644 src/main/java/org/openslx/virtualization/configuration/machine/VboxMetaData.java create mode 100644 src/main/java/org/openslx/virtualization/configuration/machine/VmwareConfig.java create mode 100644 src/main/java/org/openslx/virtualization/configuration/machine/VmwareMetaData.java delete mode 100644 src/main/java/org/openslx/vm/DockerMetaDataDummy.java delete mode 100644 src/main/java/org/openslx/vm/KeyValuePair.java delete mode 100644 src/main/java/org/openslx/vm/QemuMetaData.java delete mode 100644 src/main/java/org/openslx/vm/QemuMetaDataUtils.java delete mode 100644 src/main/java/org/openslx/vm/UnsupportedVirtualizerFormatException.java delete mode 100644 src/main/java/org/openslx/vm/VboxConfig.java delete mode 100644 src/main/java/org/openslx/vm/VboxMetaData.java delete mode 100644 src/main/java/org/openslx/vm/VmMetaData.java delete mode 100644 src/main/java/org/openslx/vm/VmwareConfig.java delete mode 100644 src/main/java/org/openslx/vm/VmwareMetaData.java create mode 100644 src/test/java/org/openslx/virtualization/configuration/machine/QemuMetaDataTest.java delete mode 100644 src/test/java/org/openslx/vm/QemuMetaDataTest.java diff --git a/src/main/java/org/openslx/util/ThriftUtil.java b/src/main/java/org/openslx/util/ThriftUtil.java index 3c2c9ea..2cfc770 100644 --- a/src/main/java/org/openslx/util/ThriftUtil.java +++ b/src/main/java/org/openslx/util/ThriftUtil.java @@ -7,7 +7,7 @@ import java.nio.ByteBuffer; import java.util.ArrayList; import java.util.List; -import org.openslx.vm.VmwareConfig; +import org.openslx.virtualization.configuration.machine.VmwareConfig; public class ThriftUtil { diff --git a/src/main/java/org/openslx/virtualization/configuration/UnsupportedVirtualizerFormatException.java b/src/main/java/org/openslx/virtualization/configuration/UnsupportedVirtualizerFormatException.java new file mode 100644 index 0000000..3040669 --- /dev/null +++ b/src/main/java/org/openslx/virtualization/configuration/UnsupportedVirtualizerFormatException.java @@ -0,0 +1,13 @@ +package org.openslx.virtualization.configuration; + +public class UnsupportedVirtualizerFormatException extends Exception +{ + /** + * Version for serialization. + */ + private static final long serialVersionUID = 5794121065945636839L; + + public UnsupportedVirtualizerFormatException(String message) { + super(message); + } +} \ No newline at end of file diff --git a/src/main/java/org/openslx/virtualization/configuration/VmMetaData.java b/src/main/java/org/openslx/virtualization/configuration/VmMetaData.java new file mode 100644 index 0000000..ae94fe0 --- /dev/null +++ b/src/main/java/org/openslx/virtualization/configuration/VmMetaData.java @@ -0,0 +1,429 @@ +package org.openslx.virtualization.configuration; + +import java.io.File; +import java.io.IOException; +import java.nio.ByteBuffer; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; + +import org.apache.log4j.Logger; +import org.openslx.bwlp.thrift.iface.OperatingSystem; +import org.openslx.bwlp.thrift.iface.Virtualizer; +import org.openslx.virtualization.configuration.container.DockerMetaDataDummy; +import org.openslx.virtualization.configuration.machine.QemuMetaData; +import org.openslx.virtualization.configuration.machine.VboxMetaData; +import org.openslx.virtualization.configuration.machine.VmwareMetaData; +import org.openslx.vm.disk.DiskImage; + +/** + * Describes a configured virtual machine. This class is parsed from a machine + * description, like a *.vmx for VMware machines. + */ +public abstract class VmMetaData +{ + private static final Logger LOGGER = Logger.getLogger( VmMetaData.class ); + + /* + * Helper types + */ + protected Map soundCards = new HashMap<>(); + protected Map ddacc = new HashMap<>(); + protected Map hwversion = new HashMap<>(); + protected Map networkCards = new HashMap<>(); + protected Map usbSpeeds = new HashMap<>(); + + /** + * 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 hardware version - currently only in use for VMPlayer + */ + public static enum HWVersion + { + NONE( "(invalid)" ), + THREE( " 3 (Workstation 4/5, Player 1)" ), + FOUR( " 4 (Workstation 4/5, Player 1/2, Fusion 1)" ), + SIX( " 6 (Workstation 6)" ), + SEVEN( " 7 (Workstation 6.5/7, Player 3, Fusion 2/3)" ), + EIGHT( " 8 (Workstation 8, Player/Fusion 4)" ), + NINE( " 9 (Workstation 9, Player/Fusion 5)" ), + TEN( "10 (Workstation 10, Player/Fusion 6)" ), + ELEVEN( "11 (Workstation 11, Player/Fusion 7)" ), + TWELVE( "12 (Workstation/Player 12, Fusion 8)" ), + FOURTEEN( "14 (Workstation/Player 14, Fusion 10)"), + FIFTEEN( "15 (Workstation/Player 15, Fusion 11)"), + FIFTEEN_ONE( "16 (Workstation/Player 15.1, Fusion 11.1)"), + SIXTEEN( "17 (Workstation/Player 16, Fusion 12)"), + SIXTEEN_ONE( "18 (Workstation/Player 16.1, Fusion 12.1)"), + DEFAULT( "default" ); + + public final String displayName; + + private HWVersion( 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 + { + SCSI, IDE, SATA, NVME; + } + + public static class HardDisk + { + public final String chipsetDriver; + public final DriveBusType bus; + public final String diskImage; + + public HardDisk( String chipsetDriver, DriveBusType bus, String diskImage ) + { + this.chipsetDriver = chipsetDriver; + this.bus = bus; + this.diskImage = diskImage; + } + } + + public static enum EtherType + { + NAT, BRIDGED, HOST_ONLY; + } + /* + * Members + */ + + protected final List hdds = new ArrayList(); + + private final List osList; + + private OperatingSystem os = null; + + protected String displayName = null; + + protected boolean isMachineSnapshot; + + /* + * Getters for virtual hardware + */ + public List getSupportedSoundCards() + { + ArrayList availables = new ArrayList( soundCards.keySet() ); + Collections.sort( availables ); + return availables; + } + + public List getSupportedDDAccs() + { + ArrayList availables = new ArrayList( ddacc.keySet() ); + Collections.sort( availables ); + return availables; + } + + public List getSupportedHWVersions() + { + ArrayList availables = new ArrayList( hwversion.keySet() ); + Collections.sort( availables ); + return availables; + } + + public List getSupportedEthernetDevices() + { + ArrayList availables = new ArrayList( networkCards.keySet() ); + Collections.sort( availables ); + return availables; + } + + public List getSupportedUsbSpeeds() + { + ArrayList availables = new ArrayList<>( usbSpeeds.keySet() ); + Collections.sort( availables ); + return availables; + } + + /** + * Get operating system of this VM. + */ + public OperatingSystem getOs() + { + return os; + } + + /** + * Get all hard disks of this VM. + */ + public List getHdds() + { + return Collections.unmodifiableList( hdds ); + } + + /** + * Get display name of VM. + */ + public String getDisplayName() + { + return displayName; + } + + /* + * Getter for isMachineSnapshot + */ + public boolean isMachineSnapshot() + { + return isMachineSnapshot; + } + + /** + * This method should return a minimal representation of the input meta data. + * The representation is platform dependent, and should be stripped of all + * non-essential configuration, such as CD/DVD/FLoppy drives, serial or parallel + * ports, shared folders, or anything else that could be considered sensible + * information (absolute paths containing the local user's name). + */ + public abstract byte[] getFilteredDefinitionArray(); + + public final ByteBuffer getFilteredDefinition() + { + return ByteBuffer.wrap( getFilteredDefinitionArray() ); + } + + /* + * Methods + */ + + public VmMetaData( List osList ) + { + this.osList = osList; + + // register virtual hardware models for graphical editing of virtual devices (GPU, sound, USB, ...) + this.registerVirtualHW(); + } + + /** + * Called from subclass to set the OS. If the OS cannot be determined from the + * given parameters, it will not be set. + * + * @param virtId + * virtualizer, eg "vmware" for VMware + * @param virtOsId + * the os identifier used by the virtualizer, eg. windows7-64 for + * 64bit Windows 7 on VMware + */ + protected final void setOs( String virtId, String virtOsId ) + { + OperatingSystem lazyMatch = null; + for ( OperatingSystem os : osList ) { + if ( os.getVirtualizerOsId() == null ) + continue; + for ( Entry entry : os.getVirtualizerOsId().entrySet() ) { + if ( !entry.getValue().equals( virtOsId ) ) + continue; + if ( entry.getKey().equals( virtId ) ) { + this.os = os; + return; + } else { + lazyMatch = os; + } + } + } + this.os = lazyMatch; + } + + /** + * Returns list of image formats supported by the VM's hypervisor. + * + * @return list of image formats. + */ + public abstract List getSupportedImageFormats(); + + /** + * Apply config options that are desired when locally editing a VM. for vmware, + * this disables automatic DPI scaling of the guest. + */ + public abstract void applySettingsForLocalEdit(); + + /** + * Returns a VmMetaData instance of the given machine description given as file + * + * @param osList List of supported operating systems + * @param file VM's machine description file to get the metadata instance from + * @return VmMetaData object representing the relevant parts of the given machine description + */ + public static VmMetaData getInstance( List osList, File file ) + throws IOException + { + try { + return new VmwareMetaData( osList, file ); + } catch ( UnsupportedVirtualizerFormatException e ) { + LOGGER.info( "Not a VMware file", e ); + } + try { + return new VboxMetaData( osList, file ); + } catch ( UnsupportedVirtualizerFormatException e ) { + LOGGER.info( "Not a VirtualBox file", e ); + } + try { + return new QemuMetaData( osList, file ); + } catch ( UnsupportedVirtualizerFormatException e ) { + LOGGER.info( "Not a Libvirt file", e ); + } + try { + return new DockerMetaDataDummy(osList, file); + } catch ( Exception e ) { + LOGGER.info( "Not a tar.gz file, for docker container", e ); + } + + LOGGER.error( "Could not detect any known virtualizer format" ); + return null; + } + + /** + * Returns a VmMetaData instance of the given machine description given as a byte array + * + * @param osList List of supported operating systems + * @param vmContent VM's machine description as byte array (e.g. stored in DB) + * @param length length of the byte array given as vmContent + * @return VmMetaData object representing the relevant parts of the given machine description + * @throws IOException + */ + public static VmMetaData getInstance( List osList, byte[] vmContent, int length ) + throws IOException + { + try { + return new VmwareMetaData( osList, vmContent, length ); + } catch ( UnsupportedVirtualizerFormatException e ) { + LOGGER.info( "Not a VMware file", e ); + } + try { + return new VboxMetaData( osList, vmContent, length ); + } catch ( UnsupportedVirtualizerFormatException e ) { + LOGGER.info( "Not a VirtualBox file", e ); + } + try { + return new QemuMetaData( osList, vmContent, length ); + } catch ( UnsupportedVirtualizerFormatException e ) { + LOGGER.info( "Not a Libvirt file", e ); + } + try { + return new DockerMetaDataDummy( osList, vmContent, length ); + } catch ( UnsupportedVirtualizerFormatException e ) { + LOGGER.info( "Not a tar.gz file, for docker container", e ); + } + + LOGGER.error( "Could not detect any known virtualizer format" ); + return null; + } + + public abstract boolean addHddTemplate( File diskImage, String hddMode, String redoDir ); + + public abstract boolean addHddTemplate( String diskImagePath, String hddMode, String redoDir ); + + public abstract boolean addDefaultNat(); + + public abstract void setOs( String vendorOsId ); + + public abstract boolean addDisplayName( String name ); + + public abstract boolean addRam( int mem ); + + public abstract void addFloppy( int index, String image, boolean readOnly ); + + 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 setHWVersion( HWVersion type ); + + public abstract HWVersion getHWVersion(); + + 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[] getDefinitionArray(); + + public abstract boolean addEthernet( EtherType type ); + + public abstract Virtualizer getVirtualizer(); + + public abstract boolean tweakForNonPersistent(); + + /** + * Function used to register virtual devices + */ + public abstract void registerVirtualHW(); +} diff --git a/src/main/java/org/openslx/virtualization/configuration/container/DockerMetaDataDummy.java b/src/main/java/org/openslx/virtualization/configuration/container/DockerMetaDataDummy.java new file mode 100644 index 0000000..321953e --- /dev/null +++ b/src/main/java/org/openslx/virtualization/configuration/container/DockerMetaDataDummy.java @@ -0,0 +1,221 @@ +package org.openslx.virtualization.configuration.container; + +import org.apache.log4j.Logger; +import org.openslx.bwlp.thrift.iface.OperatingSystem; +import org.openslx.bwlp.thrift.iface.Virtualizer; +import org.openslx.thrifthelper.TConst; +import org.openslx.virtualization.configuration.UnsupportedVirtualizerFormatException; +import org.openslx.virtualization.configuration.VmMetaData; +import org.openslx.vm.disk.DiskImage; +import org.openslx.vm.disk.DiskImage.ImageFormat; + +import java.io.BufferedInputStream; +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; + +class DockerSoundCardMeta +{ +} + +class DockerDDAccelMeta +{ +} + +class DockerHWVersionMeta +{ +} + +class DockerEthernetDevTypeMeta +{ +} + +class DockerUsbSpeedMeta +{ +} + +public class DockerMetaDataDummy extends VmMetaData { + + /** + * List of supported image formats by the Docker hypervisor. + */ + private static final List SUPPORTED_IMAGE_FORMATS = Collections.unmodifiableList( + Arrays.asList( ImageFormat.NONE ) ); + + private static final Logger LOGGER = Logger.getLogger( DockerMetaDataDummy.class); + + private final Virtualizer virtualizer = new Virtualizer(TConst.VIRT_DOCKER, "Docker"); + + /** + * containerDefinition is a serialized tar.gz archive and represents a + * ContainerDefinition. This archive contains a serialized Container Recipe (e.g. Dockerfile) + * and a ContainerMeta witch is serialized as a json file. + *

+ * See ContainerDefintion in tutor-module (bwsuite). + *

+ * This field is in vm context the machine description e.g. vmware = vmx. + * This field will be stored in table imageversion.virtualizerconfig + */ + private byte[] containerDefinition; + + public DockerMetaDataDummy(List osList, File file) throws UnsupportedVirtualizerFormatException { + super(osList); + + BufferedInputStream bis = null; + + try { + bis = new BufferedInputStream(new FileInputStream(file)); + containerDefinition = new byte[(int) file.length()]; + bis.read(containerDefinition); + + checkIsTarGz(); + } catch (IOException | UnsupportedVirtualizerFormatException e) { + LOGGER.error("Couldn't read dockerfile", e); + } finally { + try { + bis.close(); + } catch ( IOException e ) { + LOGGER.warn( "Could not close the input stream!" ); + } + } + } + + public DockerMetaDataDummy(List osList, byte[] vmContent, int length) + throws UnsupportedVirtualizerFormatException { + super(osList); + + containerDefinition = vmContent; + + checkIsTarGz(); + } + + /* + TODO This is just a simple check to prevent the workflow from considering any content as acceptable. + */ + /** + * Checks if the first two bytes of the content identifies a tar.gz archive. + * The first byte is 31 == 0x1f, the second byte has to be -117 == 0x8b. + * + * @throws UnsupportedVirtualizerFormatException + */ + private void checkIsTarGz() throws UnsupportedVirtualizerFormatException { + if (!((31 == containerDefinition[0]) && (-117 == containerDefinition[1]))) { + LOGGER.warn("Not Supported Content."); + throw new UnsupportedVirtualizerFormatException( + "DockerMetaDataDummy: Not tar.gz encoded content!"); + } + } + + @Override public byte[] getFilteredDefinitionArray() { + return containerDefinition; + } + + @Override + public List getSupportedImageFormats() + { + return DockerMetaDataDummy.SUPPORTED_IMAGE_FORMATS; + } + + @Override public void applySettingsForLocalEdit() { + + } + + @Override public boolean addHddTemplate(File diskImage, String hddMode, String redoDir) { + return false; + } + + @Override public boolean addHddTemplate(String diskImagePath, String hddMode, String redoDir) { + return false; + } + + @Override public boolean addDefaultNat() { + return false; + } + + @Override public void setOs(String vendorOsId) { + + } + + @Override public boolean addDisplayName(String name) { + return false; + } + + @Override public boolean addRam(int mem) { + return false; + } + + @Override public void addFloppy(int index, String image, boolean readOnly) { + + } + + @Override public boolean addCdrom(String image) { + return false; + } + + @Override public boolean addCpuCoreCount(int nrOfCores) { + 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 setHWVersion(HWVersion type) { + + } + + @Override public HWVersion getHWVersion() { + return HWVersion.DEFAULT; + } + + @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[] getDefinitionArray() { + return new byte[0]; + } + + @Override public boolean addEthernet(EtherType type) { + return false; + } + + @Override public Virtualizer getVirtualizer() { + return virtualizer; + } + + @Override public boolean tweakForNonPersistent() { + return false; + } + + @Override public void registerVirtualHW() { + + } +} diff --git a/src/main/java/org/openslx/virtualization/configuration/machine/KeyValuePair.java b/src/main/java/org/openslx/virtualization/configuration/machine/KeyValuePair.java new file mode 100644 index 0000000..ecd4f2a --- /dev/null +++ b/src/main/java/org/openslx/virtualization/configuration/machine/KeyValuePair.java @@ -0,0 +1,13 @@ +package org.openslx.virtualization.configuration.machine; + +class KeyValuePair +{ + public final String key; + public final String value; + + public KeyValuePair( String key, String value ) + { + this.key = key; + this.value = value; + } +} \ No newline at end of file diff --git a/src/main/java/org/openslx/virtualization/configuration/machine/QemuMetaData.java b/src/main/java/org/openslx/virtualization/configuration/machine/QemuMetaData.java new file mode 100644 index 0000000..5dd86be --- /dev/null +++ b/src/main/java/org/openslx/virtualization/configuration/machine/QemuMetaData.java @@ -0,0 +1,883 @@ +package org.openslx.virtualization.configuration.machine; + +import java.io.File; +import java.math.BigInteger; +import java.nio.charset.StandardCharsets; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import java.util.Map.Entry; + +import org.openslx.bwlp.thrift.iface.OperatingSystem; +import org.openslx.bwlp.thrift.iface.Virtualizer; +import org.openslx.libvirt.domain.Domain; +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.domain.device.DiskCdrom; +import org.openslx.libvirt.domain.device.DiskFloppy; +import org.openslx.libvirt.domain.device.DiskStorage; +import org.openslx.libvirt.domain.device.Graphics; +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.xml.LibvirtXmlDocumentException; +import org.openslx.libvirt.xml.LibvirtXmlSerializationException; +import org.openslx.libvirt.xml.LibvirtXmlValidationException; +import org.openslx.thrifthelper.TConst; +import org.openslx.virtualization.configuration.UnsupportedVirtualizerFormatException; +import org.openslx.virtualization.configuration.VmMetaData; +import org.openslx.vm.disk.DiskImage; +import org.openslx.vm.disk.DiskImage.ImageFormat; + +/** + * 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 version of a QEMU virtual machine configuration. + * + * @author Manuel Bentele + * @version 1.0 + */ +class QemuHWVersionMeta +{ + /** + * Stores the version of a QEMU virtual machine configuration. + */ + private final int version; + + /** + * Creates metadata to describe the version of a QEMU virtual machine configuration. + * + * @param version version of the QEMU virtual machine configuration. + */ + public QemuHWVersionMeta( int version ) + { + this.version = version; + } + + /** + * Returns version of the QEMU virtual machine configuration. + * + * @return version of the QEMU virtual machine configuration. + */ + public int getVersion() + { + return this.version; + } +} + +/** + * 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 QemuMetaData extends + VmMetaData +{ + /** + * Name of the network bridge for the LAN. + */ + public static final String NETWORK_BRIDGE_LAN_DEFAULT = "br0"; + + /** + * Name of the network bridge for the default NAT network. + */ + public static final String NETWORK_BRIDGE_NAT_DEFAULT = "nat1"; + + /** + * Name of the network for the isolated host network (host only). + */ + public static final String NETWORK_BRIDGE_HOST_ONLY_DEFAULT = "vsw2"; + + /** + * Default physical CDROM drive of the hypervisor host. + */ + public static final String CDROM_DEFAULT_PHYSICAL_DRIVE = "/dev/sr0"; + + /** + * List of supported image formats by the QEMU hypervisor. + */ + private static final List SUPPORTED_IMAGE_FORMATS = Collections.unmodifiableList( + Arrays.asList( ImageFormat.QCOW2, ImageFormat.VMDK, ImageFormat.VDI ) ); + + /** + * Representation of a QEMU hypervisor (managed by Libvirt). + */ + private static final Virtualizer VIRTUALIZER = new Virtualizer( TConst.VIRT_QEMU, "QEMU" ); + + /** + * Libvirt XML configuration file to modify configuration of virtual machine for QEMU. + */ + private Domain vmConfig = null; + + /** + * Stores current index of added HDD device to the Libvirt XML configuration file. + */ + private int vmDeviceIndexHddAdd = 0; + + /** + * Stores current index of added CDROM device to the Libvirt XML configuration file. + */ + private int vmDeviceIndexCdromAdd = 0; + + /** + * Stores current index of added ethernet device to the Libvirt XML configuration file. + */ + private int vmDeviceIndexEthernetAdd = 0; + + /** + * Creates new virtual machine configuration (managed by Libvirt) for the QEMU hypervisor. + * + * @param osList list of operating systems. + * @param file image file for the QEMU hypervisor. + * + * @throws UnsupportedVirtualizerFormatException Libvirt XML configuration cannot be processed. + */ + public QemuMetaData( List osList, File file ) throws UnsupportedVirtualizerFormatException + { + super( osList ); + + try { + // read and parse Libvirt domain XML configuration document + this.vmConfig = new Domain( file ); + } catch ( LibvirtXmlDocumentException | LibvirtXmlSerializationException | LibvirtXmlValidationException e ) { + throw new UnsupportedVirtualizerFormatException( e.getLocalizedMessage() ); + } + + // parse VM config and initialize fields of QemuMetaData class + this.parseVmConfig(); + } + + /** + * Creates new virtual machine configuration (managed by Libvirt) for the QEMU hypervisor. + * + * @param osList list of operating systems. + * @param vmContent file content for the QEMU hypervisor. + * @param length number of bytes of the file content. + * + * @throws UnsupportedVirtualizerFormatException Libvirt XML configuration cannot be processed. + */ + public QemuMetaData( List osList, byte[] vmContent, int length ) + throws UnsupportedVirtualizerFormatException + { + super( osList ); + + try { + // read and parse Libvirt domain XML configuration document + this.vmConfig = new Domain( new String( vmContent ) ); + } catch ( LibvirtXmlDocumentException | LibvirtXmlSerializationException | LibvirtXmlValidationException e ) { + throw new UnsupportedVirtualizerFormatException( e.getLocalizedMessage() ); + } + + // parse VM config and initialize fields of QemuMetaData class + this.parseVmConfig(); + } + + /** + * Parses Libvirt domain XML configuration to initialize QEMU metadata. + */ + private void parseVmConfig() + { + // set display name of VM + this.displayName = vmConfig.getName(); + + // this property cannot be checked with the Libvirt domain XML configuration + // to check if machine is in a paused/suspended state, look in the QEMU qcow2 image for snapshots and machine states + this.isMachineSnapshot = false; + + // add HDDs, SSDs to QEMU metadata + for ( DiskStorage storageDiskDevice : this.vmConfig.getDiskStorageDevices() ) { + this.addHddMetaData( storageDiskDevice ); + } + + // start of privacy filters to filter out sensitive information like name of users in absolute paths, ... + // removes all referenced storage files of all specified CDROMs, Floppy drives and HDDs + this.vmConfig.removeDiskDevicesStorage(); + } + + /** + * Adds an existing and observed storage disk device to the HDD metadata. + * + * @param storageDiskDevice existing and observed storage disk that should be added to the + * metadata. + */ + private void addHddMetaData( DiskStorage storageDiskDevice ) + { + String hddChipsetModel = null; + DriveBusType hddChipsetBus = QemuMetaDataUtils.convertBusType( storageDiskDevice.getBusType() ); + String hddImagePath = storageDiskDevice.getStorageSource(); + + this.hdds.add( new HardDisk( hddChipsetModel, hddChipsetBus, hddImagePath ) ); + } + + @Override + public byte[] getFilteredDefinitionArray() + { + // removes all specified boot order entries + this.vmConfig.removeBootOrder(); + + // removes all source networks of all specified network interfaces + this.vmConfig.removeInterfaceDevicesSource(); + + // output filtered Libvirt domain XML configuration + String configuration = this.vmConfig.toString(); + return configuration.getBytes( StandardCharsets.UTF_8 ); + } + + @Override + public List getSupportedImageFormats() + { + return QemuMetaData.SUPPORTED_IMAGE_FORMATS; + } + + @Override + public void applySettingsForLocalEdit() + { + // NOT implemented yet + } + + @Override + public boolean addHddTemplate( File diskImage, String hddMode, String redoDir ) + { + return this.addHddTemplate( diskImage.getAbsolutePath(), hddMode, redoDir ); + } + + @Override + public boolean addHddTemplate( String diskImagePath, String hddMode, String redoDir ) + { + return this.addHddTemplate( this.vmDeviceIndexHddAdd++, diskImagePath, hddMode, redoDir ); + } + + /** + * Adds hard disk drive (HDD) to the QEMU virtual machine configuration. + * + * @param index current index of HDD to be added to the virtual machine configuration. + * @param diskImagePath path to the virtual disk image for the HDD. + * @param hddMode operation mode of the HDD. + * @param redoDir directory for the redo log if an independent non-persistent + * hddMode is set. + * @return result state of adding the HDD. + */ + public boolean addHddTemplate( int index, String diskImagePath, String hddMode, String redoDir ) + { + ArrayList storageDiskDevices = this.vmConfig.getDiskStorageDevices(); + DiskStorage storageDiskDevice = QemuMetaDataUtils.getArrayIndex( storageDiskDevices, index ); + + if ( storageDiskDevice == null ) { + // HDD does not exist, so create new storage (HDD) device + storageDiskDevice = this.vmConfig.addDiskStorageDevice(); + storageDiskDevice.setReadOnly( false ); + storageDiskDevice.setBusType( BusType.VIRTIO ); + String targetDevName = QemuMetaDataUtils.createAlphabeticalDeviceName( "vd", index ); + storageDiskDevice.setTargetDevice( targetDevName ); + storageDiskDevice.setStorage( StorageType.FILE, diskImagePath ); + + // add new created HDD to the metadata of the QemuMetaData object, too + this.addHddMetaData( storageDiskDevice ); + } else { + // HDD exists, so update existing storage (HDD) device + storageDiskDevice.setStorage( StorageType.FILE, diskImagePath ); + } + + return false; + } + + @Override + public boolean addDefaultNat() + { + return this.addEthernet( EtherType.NAT ); + } + + @Override + public void setOs( String vendorOsId ) + { + this.setOs( vendorOsId ); + } + + @Override + public boolean addDisplayName( String name ) + { + this.vmConfig.setName( name ); + + final boolean statusName = this.vmConfig.getName().equals( name ); + + return statusName; + } + + @Override + public boolean addRam( int mem ) + { + BigInteger memory = BigInteger.valueOf( mem ); + + this.vmConfig.setMemory( memory ); + this.vmConfig.setCurrentMemory( memory ); + + final boolean isMemorySet = this.vmConfig.getMemory().toString().equals( memory.toString() ); + final boolean isCurrentMemorySet = this.vmConfig.getCurrentMemory().toString().equals( memory.toString() ); + + return isMemorySet && isCurrentMemorySet; + } + + @Override + public void addFloppy( int index, String image, boolean readOnly ) + { + ArrayList floppyDiskDevices = this.vmConfig.getDiskFloppyDevices(); + DiskFloppy floppyDiskDevice = QemuMetaDataUtils.getArrayIndex( floppyDiskDevices, index ); + + if ( floppyDiskDevice == null ) { + // floppy device does not exist, so create new floppy device + floppyDiskDevice = this.vmConfig.addDiskFloppyDevice(); + floppyDiskDevice.setBusType( BusType.FDC ); + String targetDevName = QemuMetaDataUtils.createAlphabeticalDeviceName( "fd", index ); + floppyDiskDevice.setTargetDevice( targetDevName ); + floppyDiskDevice.setReadOnly( readOnly ); + floppyDiskDevice.setStorage( StorageType.FILE, image ); + } else { + // floppy device exists, so update existing floppy device + floppyDiskDevice.setReadOnly( readOnly ); + floppyDiskDevice.setStorage( StorageType.FILE, image ); + } + } + + @Override + public boolean addCdrom( String image ) + { + return this.addCdrom( this.vmDeviceIndexCdromAdd++, image ); + } + + /** + * Adds CDROM drive to the QEMU virtual machine configuration. + * + * @param index current index of CDROM drive to be added to the virtual machine configuration. + * @param image path to a virtual image that will be inserted as CDROM into the drive. + * @return result state of adding the CDROM drive. + */ + public boolean addCdrom( int index, String image ) + { + ArrayList cdromDiskDevices = this.vmConfig.getDiskCdromDevices(); + DiskCdrom cdromDiskDevice = QemuMetaDataUtils.getArrayIndex( cdromDiskDevices, index ); + + if ( cdromDiskDevice == null ) { + // CDROM device does not exist, so create new CDROM device + cdromDiskDevice = this.vmConfig.addDiskCdromDevice(); + cdromDiskDevice.setBusType( BusType.SATA ); + String targetDevName = QemuMetaDataUtils.createAlphabeticalDeviceName( "sd", index ); + cdromDiskDevice.setTargetDevice( targetDevName ); + cdromDiskDevice.setReadOnly( true ); + + if ( image == null ) { + cdromDiskDevice.setStorage( StorageType.BLOCK, CDROM_DEFAULT_PHYSICAL_DRIVE ); + } else { + cdromDiskDevice.setStorage( StorageType.FILE, image ); + } + } else { + // CDROM device exists, so update existing CDROM device + cdromDiskDevice.setReadOnly( true ); + + if ( image == null ) { + cdromDiskDevice.setStorage( StorageType.BLOCK, CDROM_DEFAULT_PHYSICAL_DRIVE ); + } else { + cdromDiskDevice.setStorage( StorageType.FILE, image ); + } + } + + return false; + } + + @Override + public boolean addCpuCoreCount( int nrOfCores ) + { + this.vmConfig.setVCpu( nrOfCores ); + + boolean isVCpuSet = this.vmConfig.getVCpu() == nrOfCores; + + return isVCpuSet; + } + + @Override + public void setSoundCard( SoundCardType type ) + { + QemuSoundCardMeta soundDeviceConfig = this.soundCards.get( type ); + ArrayList 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 ); + } + } + } + + @Override + public SoundCardType getSoundCard() + { + ArrayList 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 = QemuMetaDataUtils.convertSoundDeviceModel( soundDeviceModel ); + } + + return soundDeviceType; + } + + @Override + public void setDDAcceleration( DDAcceleration type ) + { + QemuDDAccelMeta accelerationConfig = this.ddacc.get( type ); + ArrayList graphicDevices = this.vmConfig.getGraphicDevices(); + ArrayList

- * See ContainerDefintion in tutor-module (bwsuite). - *

- * This field is in vm context the machine description e.g. vmware = vmx. - * This field will be stored in table imageversion.virtualizerconfig - */ - private byte[] containerDefinition; - - public DockerMetaDataDummy(List osList, File file) throws UnsupportedVirtualizerFormatException { - super(osList); - - BufferedInputStream bis = null; - - try { - bis = new BufferedInputStream(new FileInputStream(file)); - containerDefinition = new byte[(int) file.length()]; - bis.read(containerDefinition); - - checkIsTarGz(); - } catch (IOException | UnsupportedVirtualizerFormatException e) { - LOGGER.error("Couldn't read dockerfile", e); - } finally { - try { - bis.close(); - } catch ( IOException e ) { - LOGGER.warn( "Could not close the input stream!" ); - } - } - } - - public DockerMetaDataDummy(List osList, byte[] vmContent, int length) - throws UnsupportedVirtualizerFormatException { - super(osList); - - containerDefinition = vmContent; - - checkIsTarGz(); - } - - /* - TODO This is just a simple check to prevent the workflow from considering any content as acceptable. - */ - /** - * Checks if the first two bytes of the content identifies a tar.gz archive. - * The first byte is 31 == 0x1f, the second byte has to be -117 == 0x8b. - * - * @throws UnsupportedVirtualizerFormatException - */ - private void checkIsTarGz() throws UnsupportedVirtualizerFormatException { - if (!((31 == containerDefinition[0]) && (-117 == containerDefinition[1]))) { - LOGGER.warn("Not Supported Content."); - throw new UnsupportedVirtualizerFormatException( - "DockerMetaDataDummy: Not tar.gz encoded content!"); - } - } - - @Override public byte[] getFilteredDefinitionArray() { - return containerDefinition; - } - - @Override - public List getSupportedImageFormats() - { - return DockerMetaDataDummy.SUPPORTED_IMAGE_FORMATS; - } - - @Override public void applySettingsForLocalEdit() { - - } - - @Override public boolean addHddTemplate(File diskImage, String hddMode, String redoDir) { - return false; - } - - @Override public boolean addHddTemplate(String diskImagePath, String hddMode, String redoDir) { - return false; - } - - @Override public boolean addDefaultNat() { - return false; - } - - @Override public void setOs(String vendorOsId) { - - } - - @Override public boolean addDisplayName(String name) { - return false; - } - - @Override public boolean addRam(int mem) { - return false; - } - - @Override public void addFloppy(int index, String image, boolean readOnly) { - - } - - @Override public boolean addCdrom(String image) { - return false; - } - - @Override public boolean addCpuCoreCount(int nrOfCores) { - 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 setHWVersion(HWVersion type) { - - } - - @Override public HWVersion getHWVersion() { - return HWVersion.DEFAULT; - } - - @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[] getDefinitionArray() { - return new byte[0]; - } - - @Override public boolean addEthernet(EtherType type) { - return false; - } - - @Override public Virtualizer getVirtualizer() { - return virtualizer; - } - - @Override public boolean tweakForNonPersistent() { - return false; - } - - @Override public void registerVirtualHW() { - - } -} diff --git a/src/main/java/org/openslx/vm/KeyValuePair.java b/src/main/java/org/openslx/vm/KeyValuePair.java deleted file mode 100644 index c5650ec..0000000 --- a/src/main/java/org/openslx/vm/KeyValuePair.java +++ /dev/null @@ -1,13 +0,0 @@ -package org.openslx.vm; - -class KeyValuePair -{ - public final String key; - public final String value; - - public KeyValuePair( String key, String value ) - { - this.key = key; - this.value = value; - } -} \ No newline at end of file diff --git a/src/main/java/org/openslx/vm/QemuMetaData.java b/src/main/java/org/openslx/vm/QemuMetaData.java deleted file mode 100644 index e758d64..0000000 --- a/src/main/java/org/openslx/vm/QemuMetaData.java +++ /dev/null @@ -1,881 +0,0 @@ -package org.openslx.vm; - -import java.io.File; -import java.math.BigInteger; -import java.nio.charset.StandardCharsets; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.List; -import java.util.Map.Entry; - -import org.openslx.bwlp.thrift.iface.OperatingSystem; -import org.openslx.bwlp.thrift.iface.Virtualizer; -import org.openslx.libvirt.domain.Domain; -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.domain.device.DiskCdrom; -import org.openslx.libvirt.domain.device.DiskFloppy; -import org.openslx.libvirt.domain.device.DiskStorage; -import org.openslx.libvirt.domain.device.Graphics; -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.xml.LibvirtXmlDocumentException; -import org.openslx.libvirt.xml.LibvirtXmlSerializationException; -import org.openslx.libvirt.xml.LibvirtXmlValidationException; -import org.openslx.thrifthelper.TConst; -import org.openslx.vm.disk.DiskImage; -import org.openslx.vm.disk.DiskImage.ImageFormat; - -/** - * 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 version of a QEMU virtual machine configuration. - * - * @author Manuel Bentele - * @version 1.0 - */ -class QemuHWVersionMeta -{ - /** - * Stores the version of a QEMU virtual machine configuration. - */ - private final int version; - - /** - * Creates metadata to describe the version of a QEMU virtual machine configuration. - * - * @param version version of the QEMU virtual machine configuration. - */ - public QemuHWVersionMeta( int version ) - { - this.version = version; - } - - /** - * Returns version of the QEMU virtual machine configuration. - * - * @return version of the QEMU virtual machine configuration. - */ - public int getVersion() - { - return this.version; - } -} - -/** - * 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 QemuMetaData extends - VmMetaData -{ - /** - * Name of the network bridge for the LAN. - */ - public static final String NETWORK_BRIDGE_LAN_DEFAULT = "br0"; - - /** - * Name of the network bridge for the default NAT network. - */ - public static final String NETWORK_BRIDGE_NAT_DEFAULT = "nat1"; - - /** - * Name of the network for the isolated host network (host only). - */ - public static final String NETWORK_BRIDGE_HOST_ONLY_DEFAULT = "vsw2"; - - /** - * Default physical CDROM drive of the hypervisor host. - */ - public static final String CDROM_DEFAULT_PHYSICAL_DRIVE = "/dev/sr0"; - - /** - * List of supported image formats by the QEMU hypervisor. - */ - private static final List SUPPORTED_IMAGE_FORMATS = Collections.unmodifiableList( - Arrays.asList( ImageFormat.QCOW2, ImageFormat.VMDK, ImageFormat.VDI ) ); - - /** - * Representation of a QEMU hypervisor (managed by Libvirt). - */ - private static final Virtualizer VIRTUALIZER = new Virtualizer( TConst.VIRT_QEMU, "QEMU" ); - - /** - * Libvirt XML configuration file to modify configuration of virtual machine for QEMU. - */ - private Domain vmConfig = null; - - /** - * Stores current index of added HDD device to the Libvirt XML configuration file. - */ - private int vmDeviceIndexHddAdd = 0; - - /** - * Stores current index of added CDROM device to the Libvirt XML configuration file. - */ - private int vmDeviceIndexCdromAdd = 0; - - /** - * Stores current index of added ethernet device to the Libvirt XML configuration file. - */ - private int vmDeviceIndexEthernetAdd = 0; - - /** - * Creates new virtual machine configuration (managed by Libvirt) for the QEMU hypervisor. - * - * @param osList list of operating systems. - * @param file image file for the QEMU hypervisor. - * - * @throws UnsupportedVirtualizerFormatException Libvirt XML configuration cannot be processed. - */ - public QemuMetaData( List osList, File file ) throws UnsupportedVirtualizerFormatException - { - super( osList ); - - try { - // read and parse Libvirt domain XML configuration document - this.vmConfig = new Domain( file ); - } catch ( LibvirtXmlDocumentException | LibvirtXmlSerializationException | LibvirtXmlValidationException e ) { - throw new UnsupportedVirtualizerFormatException( e.getLocalizedMessage() ); - } - - // parse VM config and initialize fields of QemuMetaData class - this.parseVmConfig(); - } - - /** - * Creates new virtual machine configuration (managed by Libvirt) for the QEMU hypervisor. - * - * @param osList list of operating systems. - * @param vmContent file content for the QEMU hypervisor. - * @param length number of bytes of the file content. - * - * @throws UnsupportedVirtualizerFormatException Libvirt XML configuration cannot be processed. - */ - public QemuMetaData( List osList, byte[] vmContent, int length ) - throws UnsupportedVirtualizerFormatException - { - super( osList ); - - try { - // read and parse Libvirt domain XML configuration document - this.vmConfig = new Domain( new String( vmContent ) ); - } catch ( LibvirtXmlDocumentException | LibvirtXmlSerializationException | LibvirtXmlValidationException e ) { - throw new UnsupportedVirtualizerFormatException( e.getLocalizedMessage() ); - } - - // parse VM config and initialize fields of QemuMetaData class - this.parseVmConfig(); - } - - /** - * Parses Libvirt domain XML configuration to initialize QEMU metadata. - */ - private void parseVmConfig() - { - // set display name of VM - this.displayName = vmConfig.getName(); - - // this property cannot be checked with the Libvirt domain XML configuration - // to check if machine is in a paused/suspended state, look in the QEMU qcow2 image for snapshots and machine states - this.isMachineSnapshot = false; - - // add HDDs, SSDs to QEMU metadata - for ( DiskStorage storageDiskDevice : this.vmConfig.getDiskStorageDevices() ) { - this.addHddMetaData( storageDiskDevice ); - } - - // start of privacy filters to filter out sensitive information like name of users in absolute paths, ... - // removes all referenced storage files of all specified CDROMs, Floppy drives and HDDs - this.vmConfig.removeDiskDevicesStorage(); - } - - /** - * Adds an existing and observed storage disk device to the HDD metadata. - * - * @param storageDiskDevice existing and observed storage disk that should be added to the - * metadata. - */ - private void addHddMetaData( DiskStorage storageDiskDevice ) - { - String hddChipsetModel = null; - DriveBusType hddChipsetBus = QemuMetaDataUtils.convertBusType( storageDiskDevice.getBusType() ); - String hddImagePath = storageDiskDevice.getStorageSource(); - - this.hdds.add( new HardDisk( hddChipsetModel, hddChipsetBus, hddImagePath ) ); - } - - @Override - public byte[] getFilteredDefinitionArray() - { - // removes all specified boot order entries - this.vmConfig.removeBootOrder(); - - // removes all source networks of all specified network interfaces - this.vmConfig.removeInterfaceDevicesSource(); - - // output filtered Libvirt domain XML configuration - String configuration = this.vmConfig.toString(); - return configuration.getBytes( StandardCharsets.UTF_8 ); - } - - @Override - public List getSupportedImageFormats() - { - return QemuMetaData.SUPPORTED_IMAGE_FORMATS; - } - - @Override - public void applySettingsForLocalEdit() - { - // NOT implemented yet - } - - @Override - public boolean addHddTemplate( File diskImage, String hddMode, String redoDir ) - { - return this.addHddTemplate( diskImage.getAbsolutePath(), hddMode, redoDir ); - } - - @Override - public boolean addHddTemplate( String diskImagePath, String hddMode, String redoDir ) - { - return this.addHddTemplate( this.vmDeviceIndexHddAdd++, diskImagePath, hddMode, redoDir ); - } - - /** - * Adds hard disk drive (HDD) to the QEMU virtual machine configuration. - * - * @param index current index of HDD to be added to the virtual machine configuration. - * @param diskImagePath path to the virtual disk image for the HDD. - * @param hddMode operation mode of the HDD. - * @param redoDir directory for the redo log if an independent non-persistent - * hddMode is set. - * @return result state of adding the HDD. - */ - public boolean addHddTemplate( int index, String diskImagePath, String hddMode, String redoDir ) - { - ArrayList storageDiskDevices = this.vmConfig.getDiskStorageDevices(); - DiskStorage storageDiskDevice = QemuMetaDataUtils.getArrayIndex( storageDiskDevices, index ); - - if ( storageDiskDevice == null ) { - // HDD does not exist, so create new storage (HDD) device - storageDiskDevice = this.vmConfig.addDiskStorageDevice(); - storageDiskDevice.setReadOnly( false ); - storageDiskDevice.setBusType( BusType.VIRTIO ); - String targetDevName = QemuMetaDataUtils.createAlphabeticalDeviceName( "vd", index ); - storageDiskDevice.setTargetDevice( targetDevName ); - storageDiskDevice.setStorage( StorageType.FILE, diskImagePath ); - - // add new created HDD to the metadata of the QemuMetaData object, too - this.addHddMetaData( storageDiskDevice ); - } else { - // HDD exists, so update existing storage (HDD) device - storageDiskDevice.setStorage( StorageType.FILE, diskImagePath ); - } - - return false; - } - - @Override - public boolean addDefaultNat() - { - return this.addEthernet( EtherType.NAT ); - } - - @Override - public void setOs( String vendorOsId ) - { - this.setOs( vendorOsId ); - } - - @Override - public boolean addDisplayName( String name ) - { - this.vmConfig.setName( name ); - - final boolean statusName = this.vmConfig.getName().equals( name ); - - return statusName; - } - - @Override - public boolean addRam( int mem ) - { - BigInteger memory = BigInteger.valueOf( mem ); - - this.vmConfig.setMemory( memory ); - this.vmConfig.setCurrentMemory( memory ); - - final boolean isMemorySet = this.vmConfig.getMemory().toString().equals( memory.toString() ); - final boolean isCurrentMemorySet = this.vmConfig.getCurrentMemory().toString().equals( memory.toString() ); - - return isMemorySet && isCurrentMemorySet; - } - - @Override - public void addFloppy( int index, String image, boolean readOnly ) - { - ArrayList floppyDiskDevices = this.vmConfig.getDiskFloppyDevices(); - DiskFloppy floppyDiskDevice = QemuMetaDataUtils.getArrayIndex( floppyDiskDevices, index ); - - if ( floppyDiskDevice == null ) { - // floppy device does not exist, so create new floppy device - floppyDiskDevice = this.vmConfig.addDiskFloppyDevice(); - floppyDiskDevice.setBusType( BusType.FDC ); - String targetDevName = QemuMetaDataUtils.createAlphabeticalDeviceName( "fd", index ); - floppyDiskDevice.setTargetDevice( targetDevName ); - floppyDiskDevice.setReadOnly( readOnly ); - floppyDiskDevice.setStorage( StorageType.FILE, image ); - } else { - // floppy device exists, so update existing floppy device - floppyDiskDevice.setReadOnly( readOnly ); - floppyDiskDevice.setStorage( StorageType.FILE, image ); - } - } - - @Override - public boolean addCdrom( String image ) - { - return this.addCdrom( this.vmDeviceIndexCdromAdd++, image ); - } - - /** - * Adds CDROM drive to the QEMU virtual machine configuration. - * - * @param index current index of CDROM drive to be added to the virtual machine configuration. - * @param image path to a virtual image that will be inserted as CDROM into the drive. - * @return result state of adding the CDROM drive. - */ - public boolean addCdrom( int index, String image ) - { - ArrayList cdromDiskDevices = this.vmConfig.getDiskCdromDevices(); - DiskCdrom cdromDiskDevice = QemuMetaDataUtils.getArrayIndex( cdromDiskDevices, index ); - - if ( cdromDiskDevice == null ) { - // CDROM device does not exist, so create new CDROM device - cdromDiskDevice = this.vmConfig.addDiskCdromDevice(); - cdromDiskDevice.setBusType( BusType.SATA ); - String targetDevName = QemuMetaDataUtils.createAlphabeticalDeviceName( "sd", index ); - cdromDiskDevice.setTargetDevice( targetDevName ); - cdromDiskDevice.setReadOnly( true ); - - if ( image == null ) { - cdromDiskDevice.setStorage( StorageType.BLOCK, CDROM_DEFAULT_PHYSICAL_DRIVE ); - } else { - cdromDiskDevice.setStorage( StorageType.FILE, image ); - } - } else { - // CDROM device exists, so update existing CDROM device - cdromDiskDevice.setReadOnly( true ); - - if ( image == null ) { - cdromDiskDevice.setStorage( StorageType.BLOCK, CDROM_DEFAULT_PHYSICAL_DRIVE ); - } else { - cdromDiskDevice.setStorage( StorageType.FILE, image ); - } - } - - return false; - } - - @Override - public boolean addCpuCoreCount( int nrOfCores ) - { - this.vmConfig.setVCpu( nrOfCores ); - - boolean isVCpuSet = this.vmConfig.getVCpu() == nrOfCores; - - return isVCpuSet; - } - - @Override - public void setSoundCard( SoundCardType type ) - { - QemuSoundCardMeta soundDeviceConfig = this.soundCards.get( type ); - ArrayList 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 ); - } - } - } - - @Override - public SoundCardType getSoundCard() - { - ArrayList 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 = QemuMetaDataUtils.convertSoundDeviceModel( soundDeviceModel ); - } - - return soundDeviceType; - } - - @Override - public void setDDAcceleration( DDAcceleration type ) - { - QemuDDAccelMeta accelerationConfig = this.ddacc.get( type ); - ArrayList graphicDevices = this.vmConfig.getGraphicDevices(); - ArrayList

+ * See ContainerDefintion in tutor-module (bwsuite). + *

+ * This field is in vm context the machine description e.g. vmware = vmx. + * This field will be stored in table imageversion.virtualizerconfig + */ + private byte[] containerDefinition; + + public VirtualizationConfigurationDocker(List osList, File file) throws VirtualizationConfigurationException { + super(osList); + + BufferedInputStream bis = null; + + try { + bis = new BufferedInputStream(new FileInputStream(file)); + containerDefinition = new byte[(int) file.length()]; + bis.read(containerDefinition); + + checkIsTarGz(); + } catch (IOException | VirtualizationConfigurationException e) { + LOGGER.error("Couldn't read dockerfile", e); + } finally { + try { + bis.close(); + } catch ( IOException e ) { + LOGGER.warn( "Could not close the input stream!" ); + } + } + } + + public VirtualizationConfigurationDocker(List osList, byte[] vmContent, int length) + throws VirtualizationConfigurationException { + super(osList); + + containerDefinition = vmContent; + + checkIsTarGz(); + } + + /* + TODO This is just a simple check to prevent the workflow from considering any content as acceptable. + */ + /** + * Checks if the first two bytes of the content identifies a tar.gz archive. + * The first byte is 31 == 0x1f, the second byte has to be -117 == 0x8b. + * + * @throws VirtualizationConfigurationException + */ + private void checkIsTarGz() throws VirtualizationConfigurationException { + if (!((31 == containerDefinition[0]) && (-117 == containerDefinition[1]))) { + LOGGER.warn("Not Supported Content."); + throw new VirtualizationConfigurationException( + "DockerMetaDataDummy: Not tar.gz encoded content!"); + } + } + + @Override public byte[] getFilteredDefinitionArray() { + return containerDefinition; + } + + @Override + public List getSupportedImageFormats() + { + return VirtualizationConfigurationDocker.SUPPORTED_IMAGE_FORMATS; + } + + @Override public void applySettingsForLocalEdit() { + + } + + @Override public boolean addHddTemplate(File diskImage, String hddMode, String redoDir) { + return false; + } + + @Override public boolean addHddTemplate(String diskImagePath, String hddMode, String redoDir) { + return false; + } + + @Override public boolean addDefaultNat() { + return false; + } + + @Override public void setOs(String vendorOsId) { + + } + + @Override public boolean addDisplayName(String name) { + return false; + } + + @Override public boolean addRam(int mem) { + return false; + } + + @Override public void addFloppy(int index, String image, boolean readOnly) { + + } + + @Override public boolean addCdrom(String image) { + return false; + } + + @Override public boolean addCpuCoreCount(int nrOfCores) { + 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 setHWVersion(HWVersion type) { + + } + + @Override public HWVersion getHWVersion() { + return HWVersion.DEFAULT; + } + + @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[] getDefinitionArray() { + return new byte[0]; + } + + @Override public boolean addEthernet(EtherType type) { + return false; + } + + @Override public Virtualizer getVirtualizer() { + return virtualizer; + } + + @Override public boolean tweakForNonPersistent() { + return false; + } + + @Override public void registerVirtualHW() { + + } +} diff --git a/src/main/java/org/openslx/virtualization/configuration/VirtualizationConfigurationException.java b/src/main/java/org/openslx/virtualization/configuration/VirtualizationConfigurationException.java new file mode 100644 index 0000000..2d401b1 --- /dev/null +++ b/src/main/java/org/openslx/virtualization/configuration/VirtualizationConfigurationException.java @@ -0,0 +1,13 @@ +package org.openslx.virtualization.configuration; + +public class VirtualizationConfigurationException extends Exception +{ + /** + * Version for serialization. + */ + private static final long serialVersionUID = 5794121065945636839L; + + public VirtualizationConfigurationException(String message) { + super(message); + } +} \ No newline at end of file diff --git a/src/main/java/org/openslx/virtualization/configuration/VirtualizationConfigurationQemu.java b/src/main/java/org/openslx/virtualization/configuration/VirtualizationConfigurationQemu.java new file mode 100644 index 0000000..91bb9ae --- /dev/null +++ b/src/main/java/org/openslx/virtualization/configuration/VirtualizationConfigurationQemu.java @@ -0,0 +1,881 @@ +package org.openslx.virtualization.configuration; + +import java.io.File; +import java.math.BigInteger; +import java.nio.charset.StandardCharsets; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import java.util.Map.Entry; + +import org.openslx.bwlp.thrift.iface.OperatingSystem; +import org.openslx.bwlp.thrift.iface.Virtualizer; +import org.openslx.libvirt.domain.Domain; +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.domain.device.DiskCdrom; +import org.openslx.libvirt.domain.device.DiskFloppy; +import org.openslx.libvirt.domain.device.DiskStorage; +import org.openslx.libvirt.domain.device.Graphics; +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.xml.LibvirtXmlDocumentException; +import org.openslx.libvirt.xml.LibvirtXmlSerializationException; +import org.openslx.libvirt.xml.LibvirtXmlValidationException; +import org.openslx.thrifthelper.TConst; +import org.openslx.vm.disk.DiskImage; +import org.openslx.vm.disk.DiskImage.ImageFormat; + +/** + * 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 version of a QEMU virtual machine configuration. + * + * @author Manuel Bentele + * @version 1.0 + */ +class QemuHWVersionMeta +{ + /** + * Stores the version of a QEMU virtual machine configuration. + */ + private final int version; + + /** + * Creates metadata to describe the version of a QEMU virtual machine configuration. + * + * @param version version of the QEMU virtual machine configuration. + */ + public QemuHWVersionMeta( int version ) + { + this.version = version; + } + + /** + * Returns version of the QEMU virtual machine configuration. + * + * @return version of the QEMU virtual machine configuration. + */ + public int getVersion() + { + return this.version; + } +} + +/** + * 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 +{ + /** + * Name of the network bridge for the LAN. + */ + public static final String NETWORK_BRIDGE_LAN_DEFAULT = "br0"; + + /** + * Name of the network bridge for the default NAT network. + */ + public static final String NETWORK_BRIDGE_NAT_DEFAULT = "nat1"; + + /** + * Name of the network for the isolated host network (host only). + */ + public static final String NETWORK_BRIDGE_HOST_ONLY_DEFAULT = "vsw2"; + + /** + * Default physical CDROM drive of the hypervisor host. + */ + public static final String CDROM_DEFAULT_PHYSICAL_DRIVE = "/dev/sr0"; + + /** + * List of supported image formats by the QEMU hypervisor. + */ + private static final List SUPPORTED_IMAGE_FORMATS = Collections.unmodifiableList( + Arrays.asList( ImageFormat.QCOW2, ImageFormat.VMDK, ImageFormat.VDI ) ); + + /** + * Representation of a QEMU hypervisor (managed by Libvirt). + */ + private static final Virtualizer VIRTUALIZER = new Virtualizer( TConst.VIRT_QEMU, "QEMU" ); + + /** + * Libvirt XML configuration file to modify configuration of virtual machine for QEMU. + */ + private Domain vmConfig = null; + + /** + * Stores current index of added HDD device to the Libvirt XML configuration file. + */ + private int vmDeviceIndexHddAdd = 0; + + /** + * Stores current index of added CDROM device to the Libvirt XML configuration file. + */ + private int vmDeviceIndexCdromAdd = 0; + + /** + * Stores current index of added ethernet device to the Libvirt XML configuration file. + */ + private int vmDeviceIndexEthernetAdd = 0; + + /** + * Creates new virtual machine configuration (managed by Libvirt) for the QEMU hypervisor. + * + * @param osList list of operating systems. + * @param file image file for the QEMU hypervisor. + * + * @throws VirtualizationConfigurationException Libvirt XML configuration cannot be processed. + */ + public VirtualizationConfigurationQemu( List osList, File file ) throws VirtualizationConfigurationException + { + super( osList ); + + try { + // read and parse Libvirt domain XML configuration document + this.vmConfig = new Domain( file ); + } catch ( LibvirtXmlDocumentException | LibvirtXmlSerializationException | LibvirtXmlValidationException e ) { + throw new VirtualizationConfigurationException( e.getLocalizedMessage() ); + } + + // parse VM config and initialize fields of QemuMetaData class + this.parseVmConfig(); + } + + /** + * Creates new virtual machine configuration (managed by Libvirt) for the QEMU hypervisor. + * + * @param osList list of operating systems. + * @param vmContent file content for the QEMU hypervisor. + * @param length number of bytes of the file content. + * + * @throws VirtualizationConfigurationException Libvirt XML configuration cannot be processed. + */ + public VirtualizationConfigurationQemu( List osList, byte[] vmContent, int length ) + throws VirtualizationConfigurationException + { + super( osList ); + + try { + // read and parse Libvirt domain XML configuration document + this.vmConfig = new Domain( new String( vmContent ) ); + } catch ( LibvirtXmlDocumentException | LibvirtXmlSerializationException | LibvirtXmlValidationException e ) { + throw new VirtualizationConfigurationException( e.getLocalizedMessage() ); + } + + // parse VM config and initialize fields of QemuMetaData class + this.parseVmConfig(); + } + + /** + * Parses Libvirt domain XML configuration to initialize QEMU metadata. + */ + private void parseVmConfig() + { + // set display name of VM + this.displayName = vmConfig.getName(); + + // this property cannot be checked with the Libvirt domain XML configuration + // to check if machine is in a paused/suspended state, look in the QEMU qcow2 image for snapshots and machine states + this.isMachineSnapshot = false; + + // add HDDs, SSDs to QEMU metadata + for ( DiskStorage storageDiskDevice : this.vmConfig.getDiskStorageDevices() ) { + this.addHddMetaData( storageDiskDevice ); + } + + // start of privacy filters to filter out sensitive information like name of users in absolute paths, ... + // removes all referenced storage files of all specified CDROMs, Floppy drives and HDDs + this.vmConfig.removeDiskDevicesStorage(); + } + + /** + * Adds an existing and observed storage disk device to the HDD metadata. + * + * @param storageDiskDevice existing and observed storage disk that should be added to the + * metadata. + */ + private void addHddMetaData( DiskStorage storageDiskDevice ) + { + String hddChipsetModel = null; + DriveBusType hddChipsetBus = VirtualizationConfigurationQemuUtils.convertBusType( storageDiskDevice.getBusType() ); + String hddImagePath = storageDiskDevice.getStorageSource(); + + this.hdds.add( new HardDisk( hddChipsetModel, hddChipsetBus, hddImagePath ) ); + } + + @Override + public byte[] getFilteredDefinitionArray() + { + // removes all specified boot order entries + this.vmConfig.removeBootOrder(); + + // removes all source networks of all specified network interfaces + this.vmConfig.removeInterfaceDevicesSource(); + + // output filtered Libvirt domain XML configuration + String configuration = this.vmConfig.toString(); + return configuration.getBytes( StandardCharsets.UTF_8 ); + } + + @Override + public List getSupportedImageFormats() + { + return VirtualizationConfigurationQemu.SUPPORTED_IMAGE_FORMATS; + } + + @Override + public void applySettingsForLocalEdit() + { + // NOT implemented yet + } + + @Override + public boolean addHddTemplate( File diskImage, String hddMode, String redoDir ) + { + return this.addHddTemplate( diskImage.getAbsolutePath(), hddMode, redoDir ); + } + + @Override + public boolean addHddTemplate( String diskImagePath, String hddMode, String redoDir ) + { + return this.addHddTemplate( this.vmDeviceIndexHddAdd++, diskImagePath, hddMode, redoDir ); + } + + /** + * Adds hard disk drive (HDD) to the QEMU virtual machine configuration. + * + * @param index current index of HDD to be added to the virtual machine configuration. + * @param diskImagePath path to the virtual disk image for the HDD. + * @param hddMode operation mode of the HDD. + * @param redoDir directory for the redo log if an independent non-persistent + * hddMode is set. + * @return result state of adding the HDD. + */ + public boolean addHddTemplate( int index, String diskImagePath, String hddMode, String redoDir ) + { + ArrayList storageDiskDevices = this.vmConfig.getDiskStorageDevices(); + DiskStorage storageDiskDevice = VirtualizationConfigurationQemuUtils.getArrayIndex( storageDiskDevices, index ); + + if ( storageDiskDevice == null ) { + // HDD does not exist, so create new storage (HDD) device + storageDiskDevice = this.vmConfig.addDiskStorageDevice(); + storageDiskDevice.setReadOnly( false ); + storageDiskDevice.setBusType( BusType.VIRTIO ); + String targetDevName = VirtualizationConfigurationQemuUtils.createAlphabeticalDeviceName( "vd", index ); + storageDiskDevice.setTargetDevice( targetDevName ); + storageDiskDevice.setStorage( StorageType.FILE, diskImagePath ); + + // add new created HDD to the metadata of the QemuMetaData object, too + this.addHddMetaData( storageDiskDevice ); + } else { + // HDD exists, so update existing storage (HDD) device + storageDiskDevice.setStorage( StorageType.FILE, diskImagePath ); + } + + return false; + } + + @Override + public boolean addDefaultNat() + { + return this.addEthernet( EtherType.NAT ); + } + + @Override + public void setOs( String vendorOsId ) + { + this.setOs( vendorOsId ); + } + + @Override + public boolean addDisplayName( String name ) + { + this.vmConfig.setName( name ); + + final boolean statusName = this.vmConfig.getName().equals( name ); + + return statusName; + } + + @Override + public boolean addRam( int mem ) + { + BigInteger memory = BigInteger.valueOf( mem ); + + this.vmConfig.setMemory( memory ); + this.vmConfig.setCurrentMemory( memory ); + + final boolean isMemorySet = this.vmConfig.getMemory().toString().equals( memory.toString() ); + final boolean isCurrentMemorySet = this.vmConfig.getCurrentMemory().toString().equals( memory.toString() ); + + return isMemorySet && isCurrentMemorySet; + } + + @Override + public void addFloppy( int index, String image, boolean readOnly ) + { + ArrayList floppyDiskDevices = this.vmConfig.getDiskFloppyDevices(); + DiskFloppy floppyDiskDevice = VirtualizationConfigurationQemuUtils.getArrayIndex( floppyDiskDevices, index ); + + if ( floppyDiskDevice == null ) { + // floppy device does not exist, so create new floppy device + floppyDiskDevice = this.vmConfig.addDiskFloppyDevice(); + floppyDiskDevice.setBusType( BusType.FDC ); + String targetDevName = VirtualizationConfigurationQemuUtils.createAlphabeticalDeviceName( "fd", index ); + floppyDiskDevice.setTargetDevice( targetDevName ); + floppyDiskDevice.setReadOnly( readOnly ); + floppyDiskDevice.setStorage( StorageType.FILE, image ); + } else { + // floppy device exists, so update existing floppy device + floppyDiskDevice.setReadOnly( readOnly ); + floppyDiskDevice.setStorage( StorageType.FILE, image ); + } + } + + @Override + public boolean addCdrom( String image ) + { + return this.addCdrom( this.vmDeviceIndexCdromAdd++, image ); + } + + /** + * Adds CDROM drive to the QEMU virtual machine configuration. + * + * @param index current index of CDROM drive to be added to the virtual machine configuration. + * @param image path to a virtual image that will be inserted as CDROM into the drive. + * @return result state of adding the CDROM drive. + */ + public boolean addCdrom( int index, String image ) + { + ArrayList cdromDiskDevices = this.vmConfig.getDiskCdromDevices(); + DiskCdrom cdromDiskDevice = VirtualizationConfigurationQemuUtils.getArrayIndex( cdromDiskDevices, index ); + + if ( cdromDiskDevice == null ) { + // CDROM device does not exist, so create new CDROM device + cdromDiskDevice = this.vmConfig.addDiskCdromDevice(); + cdromDiskDevice.setBusType( BusType.SATA ); + String targetDevName = VirtualizationConfigurationQemuUtils.createAlphabeticalDeviceName( "sd", index ); + cdromDiskDevice.setTargetDevice( targetDevName ); + cdromDiskDevice.setReadOnly( true ); + + if ( image == null ) { + cdromDiskDevice.setStorage( StorageType.BLOCK, CDROM_DEFAULT_PHYSICAL_DRIVE ); + } else { + cdromDiskDevice.setStorage( StorageType.FILE, image ); + } + } else { + // CDROM device exists, so update existing CDROM device + cdromDiskDevice.setReadOnly( true ); + + if ( image == null ) { + cdromDiskDevice.setStorage( StorageType.BLOCK, CDROM_DEFAULT_PHYSICAL_DRIVE ); + } else { + cdromDiskDevice.setStorage( StorageType.FILE, image ); + } + } + + return false; + } + + @Override + public boolean addCpuCoreCount( int nrOfCores ) + { + this.vmConfig.setVCpu( nrOfCores ); + + boolean isVCpuSet = this.vmConfig.getVCpu() == nrOfCores; + + return isVCpuSet; + } + + @Override + public void setSoundCard( SoundCardType type ) + { + QemuSoundCardMeta soundDeviceConfig = this.soundCards.get( type ); + ArrayList 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 ); + } + } + } + + @Override + public SoundCardType getSoundCard() + { + ArrayList 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 graphicDevices = this.vmConfig.getGraphicDevices(); + ArrayList

- * See ContainerDefintion in tutor-module (bwsuite). - *

- * This field is in vm context the machine description e.g. vmware = vmx. - * This field will be stored in table imageversion.virtualizerconfig - */ - private byte[] containerDefinition; - - public DockerMetaDataDummy(List osList, File file) throws UnsupportedVirtualizerFormatException { - super(osList); - - BufferedInputStream bis = null; - - try { - bis = new BufferedInputStream(new FileInputStream(file)); - containerDefinition = new byte[(int) file.length()]; - bis.read(containerDefinition); - - checkIsTarGz(); - } catch (IOException | UnsupportedVirtualizerFormatException e) { - LOGGER.error("Couldn't read dockerfile", e); - } finally { - try { - bis.close(); - } catch ( IOException e ) { - LOGGER.warn( "Could not close the input stream!" ); - } - } - } - - public DockerMetaDataDummy(List osList, byte[] vmContent, int length) - throws UnsupportedVirtualizerFormatException { - super(osList); - - containerDefinition = vmContent; - - checkIsTarGz(); - } - - /* - TODO This is just a simple check to prevent the workflow from considering any content as acceptable. - */ - /** - * Checks if the first two bytes of the content identifies a tar.gz archive. - * The first byte is 31 == 0x1f, the second byte has to be -117 == 0x8b. - * - * @throws UnsupportedVirtualizerFormatException - */ - private void checkIsTarGz() throws UnsupportedVirtualizerFormatException { - if (!((31 == containerDefinition[0]) && (-117 == containerDefinition[1]))) { - LOGGER.warn("Not Supported Content."); - throw new UnsupportedVirtualizerFormatException( - "DockerMetaDataDummy: Not tar.gz encoded content!"); - } - } - - @Override public byte[] getFilteredDefinitionArray() { - return containerDefinition; - } - - @Override - public List getSupportedImageFormats() - { - return DockerMetaDataDummy.SUPPORTED_IMAGE_FORMATS; - } - - @Override public void applySettingsForLocalEdit() { - - } - - @Override public boolean addHddTemplate(File diskImage, String hddMode, String redoDir) { - return false; - } - - @Override public boolean addHddTemplate(String diskImagePath, String hddMode, String redoDir) { - return false; - } - - @Override public boolean addDefaultNat() { - return false; - } - - @Override public void setOs(String vendorOsId) { - - } - - @Override public boolean addDisplayName(String name) { - return false; - } - - @Override public boolean addRam(int mem) { - return false; - } - - @Override public void addFloppy(int index, String image, boolean readOnly) { - - } - - @Override public boolean addCdrom(String image) { - return false; - } - - @Override public boolean addCpuCoreCount(int nrOfCores) { - 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 setHWVersion(HWVersion type) { - - } - - @Override public HWVersion getHWVersion() { - return HWVersion.DEFAULT; - } - - @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[] getDefinitionArray() { - return new byte[0]; - } - - @Override public boolean addEthernet(EtherType type) { - return false; - } - - @Override public Virtualizer getVirtualizer() { - return virtualizer; - } - - @Override public boolean tweakForNonPersistent() { - return false; - } - - @Override public void registerVirtualHW() { - - } -} diff --git a/src/main/java/org/openslx/virtualization/configuration/machine/KeyValuePair.java b/src/main/java/org/openslx/virtualization/configuration/machine/KeyValuePair.java deleted file mode 100644 index ecd4f2a..0000000 --- a/src/main/java/org/openslx/virtualization/configuration/machine/KeyValuePair.java +++ /dev/null @@ -1,13 +0,0 @@ -package org.openslx.virtualization.configuration.machine; - -class KeyValuePair -{ - public final String key; - public final String value; - - public KeyValuePair( String key, String value ) - { - this.key = key; - this.value = value; - } -} \ No newline at end of file diff --git a/src/main/java/org/openslx/virtualization/configuration/machine/QemuMetaData.java b/src/main/java/org/openslx/virtualization/configuration/machine/QemuMetaData.java deleted file mode 100644 index 5dd86be..0000000 --- a/src/main/java/org/openslx/virtualization/configuration/machine/QemuMetaData.java +++ /dev/null @@ -1,883 +0,0 @@ -package org.openslx.virtualization.configuration.machine; - -import java.io.File; -import java.math.BigInteger; -import java.nio.charset.StandardCharsets; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.List; -import java.util.Map.Entry; - -import org.openslx.bwlp.thrift.iface.OperatingSystem; -import org.openslx.bwlp.thrift.iface.Virtualizer; -import org.openslx.libvirt.domain.Domain; -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.domain.device.DiskCdrom; -import org.openslx.libvirt.domain.device.DiskFloppy; -import org.openslx.libvirt.domain.device.DiskStorage; -import org.openslx.libvirt.domain.device.Graphics; -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.xml.LibvirtXmlDocumentException; -import org.openslx.libvirt.xml.LibvirtXmlSerializationException; -import org.openslx.libvirt.xml.LibvirtXmlValidationException; -import org.openslx.thrifthelper.TConst; -import org.openslx.virtualization.configuration.UnsupportedVirtualizerFormatException; -import org.openslx.virtualization.configuration.VmMetaData; -import org.openslx.vm.disk.DiskImage; -import org.openslx.vm.disk.DiskImage.ImageFormat; - -/** - * 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 version of a QEMU virtual machine configuration. - * - * @author Manuel Bentele - * @version 1.0 - */ -class QemuHWVersionMeta -{ - /** - * Stores the version of a QEMU virtual machine configuration. - */ - private final int version; - - /** - * Creates metadata to describe the version of a QEMU virtual machine configuration. - * - * @param version version of the QEMU virtual machine configuration. - */ - public QemuHWVersionMeta( int version ) - { - this.version = version; - } - - /** - * Returns version of the QEMU virtual machine configuration. - * - * @return version of the QEMU virtual machine configuration. - */ - public int getVersion() - { - return this.version; - } -} - -/** - * 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 QemuMetaData extends - VmMetaData -{ - /** - * Name of the network bridge for the LAN. - */ - public static final String NETWORK_BRIDGE_LAN_DEFAULT = "br0"; - - /** - * Name of the network bridge for the default NAT network. - */ - public static final String NETWORK_BRIDGE_NAT_DEFAULT = "nat1"; - - /** - * Name of the network for the isolated host network (host only). - */ - public static final String NETWORK_BRIDGE_HOST_ONLY_DEFAULT = "vsw2"; - - /** - * Default physical CDROM drive of the hypervisor host. - */ - public static final String CDROM_DEFAULT_PHYSICAL_DRIVE = "/dev/sr0"; - - /** - * List of supported image formats by the QEMU hypervisor. - */ - private static final List SUPPORTED_IMAGE_FORMATS = Collections.unmodifiableList( - Arrays.asList( ImageFormat.QCOW2, ImageFormat.VMDK, ImageFormat.VDI ) ); - - /** - * Representation of a QEMU hypervisor (managed by Libvirt). - */ - private static final Virtualizer VIRTUALIZER = new Virtualizer( TConst.VIRT_QEMU, "QEMU" ); - - /** - * Libvirt XML configuration file to modify configuration of virtual machine for QEMU. - */ - private Domain vmConfig = null; - - /** - * Stores current index of added HDD device to the Libvirt XML configuration file. - */ - private int vmDeviceIndexHddAdd = 0; - - /** - * Stores current index of added CDROM device to the Libvirt XML configuration file. - */ - private int vmDeviceIndexCdromAdd = 0; - - /** - * Stores current index of added ethernet device to the Libvirt XML configuration file. - */ - private int vmDeviceIndexEthernetAdd = 0; - - /** - * Creates new virtual machine configuration (managed by Libvirt) for the QEMU hypervisor. - * - * @param osList list of operating systems. - * @param file image file for the QEMU hypervisor. - * - * @throws UnsupportedVirtualizerFormatException Libvirt XML configuration cannot be processed. - */ - public QemuMetaData( List osList, File file ) throws UnsupportedVirtualizerFormatException - { - super( osList ); - - try { - // read and parse Libvirt domain XML configuration document - this.vmConfig = new Domain( file ); - } catch ( LibvirtXmlDocumentException | LibvirtXmlSerializationException | LibvirtXmlValidationException e ) { - throw new UnsupportedVirtualizerFormatException( e.getLocalizedMessage() ); - } - - // parse VM config and initialize fields of QemuMetaData class - this.parseVmConfig(); - } - - /** - * Creates new virtual machine configuration (managed by Libvirt) for the QEMU hypervisor. - * - * @param osList list of operating systems. - * @param vmContent file content for the QEMU hypervisor. - * @param length number of bytes of the file content. - * - * @throws UnsupportedVirtualizerFormatException Libvirt XML configuration cannot be processed. - */ - public QemuMetaData( List osList, byte[] vmContent, int length ) - throws UnsupportedVirtualizerFormatException - { - super( osList ); - - try { - // read and parse Libvirt domain XML configuration document - this.vmConfig = new Domain( new String( vmContent ) ); - } catch ( LibvirtXmlDocumentException | LibvirtXmlSerializationException | LibvirtXmlValidationException e ) { - throw new UnsupportedVirtualizerFormatException( e.getLocalizedMessage() ); - } - - // parse VM config and initialize fields of QemuMetaData class - this.parseVmConfig(); - } - - /** - * Parses Libvirt domain XML configuration to initialize QEMU metadata. - */ - private void parseVmConfig() - { - // set display name of VM - this.displayName = vmConfig.getName(); - - // this property cannot be checked with the Libvirt domain XML configuration - // to check if machine is in a paused/suspended state, look in the QEMU qcow2 image for snapshots and machine states - this.isMachineSnapshot = false; - - // add HDDs, SSDs to QEMU metadata - for ( DiskStorage storageDiskDevice : this.vmConfig.getDiskStorageDevices() ) { - this.addHddMetaData( storageDiskDevice ); - } - - // start of privacy filters to filter out sensitive information like name of users in absolute paths, ... - // removes all referenced storage files of all specified CDROMs, Floppy drives and HDDs - this.vmConfig.removeDiskDevicesStorage(); - } - - /** - * Adds an existing and observed storage disk device to the HDD metadata. - * - * @param storageDiskDevice existing and observed storage disk that should be added to the - * metadata. - */ - private void addHddMetaData( DiskStorage storageDiskDevice ) - { - String hddChipsetModel = null; - DriveBusType hddChipsetBus = QemuMetaDataUtils.convertBusType( storageDiskDevice.getBusType() ); - String hddImagePath = storageDiskDevice.getStorageSource(); - - this.hdds.add( new HardDisk( hddChipsetModel, hddChipsetBus, hddImagePath ) ); - } - - @Override - public byte[] getFilteredDefinitionArray() - { - // removes all specified boot order entries - this.vmConfig.removeBootOrder(); - - // removes all source networks of all specified network interfaces - this.vmConfig.removeInterfaceDevicesSource(); - - // output filtered Libvirt domain XML configuration - String configuration = this.vmConfig.toString(); - return configuration.getBytes( StandardCharsets.UTF_8 ); - } - - @Override - public List getSupportedImageFormats() - { - return QemuMetaData.SUPPORTED_IMAGE_FORMATS; - } - - @Override - public void applySettingsForLocalEdit() - { - // NOT implemented yet - } - - @Override - public boolean addHddTemplate( File diskImage, String hddMode, String redoDir ) - { - return this.addHddTemplate( diskImage.getAbsolutePath(), hddMode, redoDir ); - } - - @Override - public boolean addHddTemplate( String diskImagePath, String hddMode, String redoDir ) - { - return this.addHddTemplate( this.vmDeviceIndexHddAdd++, diskImagePath, hddMode, redoDir ); - } - - /** - * Adds hard disk drive (HDD) to the QEMU virtual machine configuration. - * - * @param index current index of HDD to be added to the virtual machine configuration. - * @param diskImagePath path to the virtual disk image for the HDD. - * @param hddMode operation mode of the HDD. - * @param redoDir directory for the redo log if an independent non-persistent - * hddMode is set. - * @return result state of adding the HDD. - */ - public boolean addHddTemplate( int index, String diskImagePath, String hddMode, String redoDir ) - { - ArrayList storageDiskDevices = this.vmConfig.getDiskStorageDevices(); - DiskStorage storageDiskDevice = QemuMetaDataUtils.getArrayIndex( storageDiskDevices, index ); - - if ( storageDiskDevice == null ) { - // HDD does not exist, so create new storage (HDD) device - storageDiskDevice = this.vmConfig.addDiskStorageDevice(); - storageDiskDevice.setReadOnly( false ); - storageDiskDevice.setBusType( BusType.VIRTIO ); - String targetDevName = QemuMetaDataUtils.createAlphabeticalDeviceName( "vd", index ); - storageDiskDevice.setTargetDevice( targetDevName ); - storageDiskDevice.setStorage( StorageType.FILE, diskImagePath ); - - // add new created HDD to the metadata of the QemuMetaData object, too - this.addHddMetaData( storageDiskDevice ); - } else { - // HDD exists, so update existing storage (HDD) device - storageDiskDevice.setStorage( StorageType.FILE, diskImagePath ); - } - - return false; - } - - @Override - public boolean addDefaultNat() - { - return this.addEthernet( EtherType.NAT ); - } - - @Override - public void setOs( String vendorOsId ) - { - this.setOs( vendorOsId ); - } - - @Override - public boolean addDisplayName( String name ) - { - this.vmConfig.setName( name ); - - final boolean statusName = this.vmConfig.getName().equals( name ); - - return statusName; - } - - @Override - public boolean addRam( int mem ) - { - BigInteger memory = BigInteger.valueOf( mem ); - - this.vmConfig.setMemory( memory ); - this.vmConfig.setCurrentMemory( memory ); - - final boolean isMemorySet = this.vmConfig.getMemory().toString().equals( memory.toString() ); - final boolean isCurrentMemorySet = this.vmConfig.getCurrentMemory().toString().equals( memory.toString() ); - - return isMemorySet && isCurrentMemorySet; - } - - @Override - public void addFloppy( int index, String image, boolean readOnly ) - { - ArrayList floppyDiskDevices = this.vmConfig.getDiskFloppyDevices(); - DiskFloppy floppyDiskDevice = QemuMetaDataUtils.getArrayIndex( floppyDiskDevices, index ); - - if ( floppyDiskDevice == null ) { - // floppy device does not exist, so create new floppy device - floppyDiskDevice = this.vmConfig.addDiskFloppyDevice(); - floppyDiskDevice.setBusType( BusType.FDC ); - String targetDevName = QemuMetaDataUtils.createAlphabeticalDeviceName( "fd", index ); - floppyDiskDevice.setTargetDevice( targetDevName ); - floppyDiskDevice.setReadOnly( readOnly ); - floppyDiskDevice.setStorage( StorageType.FILE, image ); - } else { - // floppy device exists, so update existing floppy device - floppyDiskDevice.setReadOnly( readOnly ); - floppyDiskDevice.setStorage( StorageType.FILE, image ); - } - } - - @Override - public boolean addCdrom( String image ) - { - return this.addCdrom( this.vmDeviceIndexCdromAdd++, image ); - } - - /** - * Adds CDROM drive to the QEMU virtual machine configuration. - * - * @param index current index of CDROM drive to be added to the virtual machine configuration. - * @param image path to a virtual image that will be inserted as CDROM into the drive. - * @return result state of adding the CDROM drive. - */ - public boolean addCdrom( int index, String image ) - { - ArrayList cdromDiskDevices = this.vmConfig.getDiskCdromDevices(); - DiskCdrom cdromDiskDevice = QemuMetaDataUtils.getArrayIndex( cdromDiskDevices, index ); - - if ( cdromDiskDevice == null ) { - // CDROM device does not exist, so create new CDROM device - cdromDiskDevice = this.vmConfig.addDiskCdromDevice(); - cdromDiskDevice.setBusType( BusType.SATA ); - String targetDevName = QemuMetaDataUtils.createAlphabeticalDeviceName( "sd", index ); - cdromDiskDevice.setTargetDevice( targetDevName ); - cdromDiskDevice.setReadOnly( true ); - - if ( image == null ) { - cdromDiskDevice.setStorage( StorageType.BLOCK, CDROM_DEFAULT_PHYSICAL_DRIVE ); - } else { - cdromDiskDevice.setStorage( StorageType.FILE, image ); - } - } else { - // CDROM device exists, so update existing CDROM device - cdromDiskDevice.setReadOnly( true ); - - if ( image == null ) { - cdromDiskDevice.setStorage( StorageType.BLOCK, CDROM_DEFAULT_PHYSICAL_DRIVE ); - } else { - cdromDiskDevice.setStorage( StorageType.FILE, image ); - } - } - - return false; - } - - @Override - public boolean addCpuCoreCount( int nrOfCores ) - { - this.vmConfig.setVCpu( nrOfCores ); - - boolean isVCpuSet = this.vmConfig.getVCpu() == nrOfCores; - - return isVCpuSet; - } - - @Override - public void setSoundCard( SoundCardType type ) - { - QemuSoundCardMeta soundDeviceConfig = this.soundCards.get( type ); - ArrayList 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 ); - } - } - } - - @Override - public SoundCardType getSoundCard() - { - ArrayList 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 = QemuMetaDataUtils.convertSoundDeviceModel( soundDeviceModel ); - } - - return soundDeviceType; - } - - @Override - public void setDDAcceleration( DDAcceleration type ) - { - QemuDDAccelMeta accelerationConfig = this.ddacc.get( type ); - ArrayList graphicDevices = this.vmConfig.getGraphicDevices(); - ArrayList

+ + +
+ + +
+ + + +
+ + + + +
+ + + + +
+ + + + +
+ + + + +
+ + + + +
+ + + + +
+ + + + +
+ + + + + +
+ + + + + + + + + + + +
+ + + +
+ + +
+ + + + + + + + +
+ +