Github user wido commented on a diff in the pull request: https://github.com/apache/cloudstack/pull/977#discussion_r42975042 --- Diff: plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/LibvirtComputingResource.java --- @@ -3388,4 +3419,83 @@ public String mapRbdDevice(final KVMPhysicalDisk disk){ } return device; } + + public List<Ternary<String, Boolean, String>> cleanVMSnapshotMetadata(Domain dm) throws LibvirtException { + s_logger.debug("Cleaning the metadata of vm snapshots of vm " + dm.getName()); + List<Ternary<String, Boolean, String>> vmsnapshots = new ArrayList<Ternary<String, Boolean, String>>(); + String currentSnapshotName = null; + try { + DomainSnapshot snapshotCurrent = dm.snapshotCurrent(); + String snapshotXML = snapshotCurrent.getXMLDesc(); + snapshotCurrent.free(); + DocumentBuilder builder; + try { + builder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); + + InputSource is = new InputSource(); + is.setCharacterStream(new StringReader(snapshotXML)); + Document doc = builder.parse(is); + Element rootElement = doc.getDocumentElement(); + + currentSnapshotName = getTagValue("name", rootElement); + } catch (ParserConfigurationException e) { + s_logger.debug(e.toString()); + } catch (SAXException e) { + s_logger.debug(e.toString()); + } catch (IOException e) { + s_logger.debug(e.toString()); + } + } catch (LibvirtException e) { + s_logger.debug("Fail to get the current vm snapshot for vm: " + dm.getName() + ", continue"); + } + for (String snapshotName: dm.snapshotListNames()) { + DomainSnapshot snapshot = dm.snapshotLookupByName(snapshotName); + Boolean isCurrent = (currentSnapshotName != null && currentSnapshotName.equals(snapshotName)) ? true: false; + vmsnapshots.add(new Ternary<String, Boolean, String>(snapshotName, isCurrent, snapshot.getXMLDesc())); + snapshot.free(); + } + for (String snapshotName: dm.snapshotListNames()) { + String cmdvirsh = "virsh snapshot-delete --metadata " + dm.getName() + " " + snapshotName; + int cmdout = Script.runSimpleBashScriptForExitValue(cmdvirsh); --- End diff -- Same goes for this, see my comment above about libvirt-java.
--- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastruct...@apache.org or file a JIRA ticket with INFRA. ---