summaryrefslogtreecommitdiffstats
path: root/src/main/java/org/openslx/libvirt/capabilities
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/org/openslx/libvirt/capabilities')
-rw-r--r--src/main/java/org/openslx/libvirt/capabilities/Capabilities.java155
-rw-r--r--src/main/java/org/openslx/libvirt/capabilities/cpu/Cpu.java165
-rw-r--r--src/main/java/org/openslx/libvirt/capabilities/cpu/Feature.java51
-rw-r--r--src/main/java/org/openslx/libvirt/capabilities/cpu/Pages.java60
-rw-r--r--src/main/java/org/openslx/libvirt/capabilities/guest/Domain.java53
-rw-r--r--src/main/java/org/openslx/libvirt/capabilities/guest/Guest.java127
-rw-r--r--src/main/java/org/openslx/libvirt/capabilities/guest/Machine.java72
7 files changed, 683 insertions, 0 deletions
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<Guest> getGuests()
+ {
+ final List<Guest> guestList = new ArrayList<Guest>();
+ 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<Feature> getFeatures()
+ {
+ final List<Feature> featureList = new ArrayList<Feature>();
+ 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<Pages> getPages()
+ {
+ final List<Pages> pagesList = new ArrayList<Pages>();
+ 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<Machine> getArchMachines()
+ {
+ final List<Machine> machinesList = new ArrayList<Machine>();
+ 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<Domain> getArchDomains()
+ {
+ final List<Domain> domainList = new ArrayList<Domain>();
+ 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 );
+ }
+}