diff options
Diffstat (limited to 'src/main/java/org/openslx/libvirt/capabilities/guest')
3 files changed, 252 insertions, 0 deletions
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 ); + } +} |