diff options
4 files changed, 61 insertions, 8 deletions
diff --git a/src/main/java/org/openslx/libvirt/domain/Domain.java b/src/main/java/org/openslx/libvirt/domain/Domain.java index 9dc7200..a8b57ff 100644 --- a/src/main/java/org/openslx/libvirt/domain/Domain.java +++ b/src/main/java/org/openslx/libvirt/domain/Domain.java @@ -731,6 +731,22 @@ public class Domain extends LibvirtXmlDocument } /** + * Returns if the CPU migratable flag is set in the Libvirt domain XML document. + */ + public boolean getCpuMigratable() + { + return this.getRootXmlNode().getXmlElementAttributeValueAsBool( "cpu", "migratable" ); + } + + /** + * Sets if vCPU is migratable in the Libvirt domain XML document. + */ + public void setCpuMigratable( boolean migratable ) + { + this.getRootXmlNode().setXmlElementAttributeValueOnOff( "cpu", "migratable", migratable ); + } + + /** * CPU checks specifiable for a virtual machine in the Libvirt domain XML document. * * @author Manuel Bentele @@ -1689,4 +1705,32 @@ public class Domain extends LibvirtXmlDocument interfaceDevice.setSource( "" ); } } + + /** + * Remove any existing CPU pinning and numa config + */ + public void resetCpuPin() + { + this.getRootXmlNode().removeXmlElement( "cputune" ); + this.getRootXmlNode().removeXmlElement( "numatune" ); + } + + public void addCpuPin( int virtualCore, int hostCore ) + { + final Element rootElement = Element.class.cast( this.getRootXmlNode().getXmlBaseNode() ); + final Document xmlDocument = this.getRootXmlNode().getXmlDocument(); + Node cpuTune = this.getRootXmlNode().getXmlElement( "cputune" ); + if ( cpuTune == null ) { + cpuTune = xmlDocument.createElement( "cputune" ); + rootElement.appendChild( cpuTune ); + } + Element pin = xmlDocument.createElement( "vcpupin" ); + pin.setAttribute( "vcpu", Integer.toString( virtualCore ) ); + pin.setAttribute( "cpuset", Integer.toString( hostCore ) ); + cpuTune.appendChild( pin ); + Node vcpuNode = this.getRootXmlNode().getXmlElement( "vcpu" ); + if ( vcpuNode instanceof Element ) { + ( (Element)vcpuNode ).setAttribute( "placement", "static" ); + } + } } diff --git a/src/main/java/org/openslx/libvirt/xml/LibvirtXmlEditable.java b/src/main/java/org/openslx/libvirt/xml/LibvirtXmlEditable.java index 5834e58..c97af59 100644 --- a/src/main/java/org/openslx/libvirt/xml/LibvirtXmlEditable.java +++ b/src/main/java/org/openslx/libvirt/xml/LibvirtXmlEditable.java @@ -133,7 +133,7 @@ public interface LibvirtXmlEditable public default boolean getXmlElementAttributeValueAsBool( String attributeName ) { final String attributeValue = this.getXmlElementAttributeValue( attributeName ); - return "yes".equals( attributeValue ) || "on".equals( attributeValue ); + return "yes".equals( attributeValue ) || "on".equals( attributeValue ) || "true".equals( attributeName ); } /** diff --git a/src/main/java/org/openslx/libvirt/xml/LibvirtXmlNode.java b/src/main/java/org/openslx/libvirt/xml/LibvirtXmlNode.java index c4ad2c3..a941acb 100644 --- a/src/main/java/org/openslx/libvirt/xml/LibvirtXmlNode.java +++ b/src/main/java/org/openslx/libvirt/xml/LibvirtXmlNode.java @@ -183,7 +183,7 @@ public class LibvirtXmlNode implements LibvirtXmlCreatable, LibvirtXmlEditable } @Override - public Node getXmlElement( String expression ) + public Element getXmlElement( String expression ) { String completeExpression = null; @@ -196,7 +196,7 @@ public class LibvirtXmlNode implements LibvirtXmlCreatable, LibvirtXmlEditable Node node = this.getXmlNode( completeExpression ); if ( node != null && node.getNodeType() == Node.ELEMENT_NODE ) { - return node; + return (Element)node; } else { return null; } @@ -216,8 +216,8 @@ public class LibvirtXmlNode implements LibvirtXmlCreatable, LibvirtXmlEditable currentNode = this.getXmlNode( partialExpression ); if ( currentNode == null ) { - parentNode.appendChild( this.xmlDocument.createElement( nodeNames[i] ) ); - currentNode = parentNode.getLastChild(); + currentNode = this.xmlDocument.createElement( nodeNames[i] ); + parentNode.appendChild( currentNode ); } parentNode = currentNode; diff --git a/src/main/java/org/openslx/util/XmlHelper.java b/src/main/java/org/openslx/util/XmlHelper.java index f9366e0..90d282b 100644 --- a/src/main/java/org/openslx/util/XmlHelper.java +++ b/src/main/java/org/openslx/util/XmlHelper.java @@ -163,7 +163,12 @@ public class XmlHelper public static Element getOrCreateElement( Document doc, Element parent, String nsUri, String nsName, String name, String attrName, String attrValue ) { - final NodeList childList = parent.getElementsByTagNameNS( nsUri, name ); + final NodeList childList; + if ( nsUri == null ) { + childList = parent.getElementsByTagName( name ); + } else { + childList = parent.getElementsByTagNameNS( nsUri, name ); + } Element element = null; outer: for ( int i = 0; i < childList.getLength(); ++i ) { Node n = childList.item( i ); @@ -187,8 +192,12 @@ public class XmlHelper } if ( element == null ) { // Need a new <qemu:device alias="hostdev0"> - element = doc.createElementNS( nsUri, name ); - element.setPrefix( nsName ); + if ( nsUri == null || nsName == null ) { + element = doc.createElement( name ); + } else { + element = doc.createElementNS( nsUri, name ); + element.setPrefix( nsName ); + } if ( attrName != null && attrValue != null ) { element.setAttribute( attrName, attrValue ); } |