DaanHoogland commented on a change in pull request #3976: Enable sending
hypervior host name via metadata - VR and Config Drive
URL: https://github.com/apache/cloudstack/pull/3976#discussion_r399309518
##########
File path:
plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtMigrateCommandWrapper.java
##########
@@ -572,4 +606,49 @@ private String getXml(Document doc) throws
TransformerException {
return byteArrayOutputStream.toString();
}
+
+ private String replaceDiskSourceFile(String xmlDesc, String isoPath,
String vmName) throws IOException, SAXException, ParserConfigurationException,
TransformerException {
+ InputStream in = IOUtils.toInputStream(xmlDesc);
+
+ DocumentBuilderFactory docFactory =
DocumentBuilderFactory.newInstance();
+ DocumentBuilder docBuilder = docFactory.newDocumentBuilder();
+ Document doc = docBuilder.parse(in);
+
+ // Get the root element
+ Node domainNode = doc.getFirstChild();
+
+ NodeList domainChildNodes = domainNode.getChildNodes();
+
+ for (int i = 0; i < domainChildNodes.getLength(); i++) {
+ Node domainChildNode = domainChildNodes.item(i);
+
+ if ("devices".equals(domainChildNode.getNodeName())) {
+ NodeList devicesChildNodes = domainChildNode.getChildNodes();
+
+ for (int x = 0; x < devicesChildNodes.getLength(); x++) {
+ Node deviceChildNode = devicesChildNodes.item(x);
+ if ("disk".equals(deviceChildNode.getNodeName())) {
+ Node diskNode = deviceChildNode;
+ String sourceText = getSourceText(diskNode);
+ NodeList diskChildNodes = diskNode.getChildNodes();
+ for (int z = 0; z < diskChildNodes.getLength(); z++) {
+ Node diskChildNode = diskChildNodes.item(z);
+ if ("source".equals(diskChildNode.getNodeName())) {
+ Node sourceNode = diskChildNode;
+ NamedNodeMap sourceNodeAttributes =
sourceNode.getAttributes();
+ Node sourceNodeAttribute =
sourceNodeAttributes.getNamedItem("file");
+ if (
sourceNodeAttribute.getNodeValue().contains(vmName)) {
+ diskNode.removeChild(diskChildNode);
+ Element newChildSourceNode =
doc.createElement("source");
+ newChildSourceNode.setAttribute("file",
isoPath);
+ diskNode.appendChild(newChildSourceNode);
Review comment:
and how about when we are sure we have the right disk, do we just continue
processing or should we escape somehow and not process the rest?
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services