[
https://issues.apache.org/jira/browse/CLOUDSTACK-8746?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14973971#comment-14973971
]
ASF GitHub Bot commented on CLOUDSTACK-8746:
--------------------------------------------
Github user wido commented on a diff in the pull request:
https://github.com/apache/cloudstack/pull/977#discussion_r42975057
--- 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);
+ if (cmdout != 0) {
+ s_logger.debug("Fail to delete the metadata of vm
snapshot: " + snapshotName);
+ }
+ }
+ return vmsnapshots;
+ }
+
+ private static String getTagValue(String tag, Element eElement) {
+ NodeList nlList =
eElement.getElementsByTagName(tag).item(0).getChildNodes();
+ Node nValue = nlList.item(0);
+
+ return nValue.getNodeValue();
+ }
+
+ public void restoreVMSnapshotMetadata(String vmName,
List<Ternary<String, Boolean, String>> vmsnapshots) {
+ s_logger.debug("Restoring the metadata of vm snapshots of vm " +
vmName);
+ for (Ternary<String, Boolean, String> vmsnapshot: vmsnapshots) {
+ s_logger.debug("Restoring vm snapshot " + vmsnapshot.first() +
" on " + vmName + " with XML:\n " + vmsnapshot.third());
+ File tmpCfgFile = null;
+ try {
+ tmpCfgFile = File.createTempFile(vmName + "-", "cfg");
+ final PrintWriter out = new PrintWriter(new
BufferedWriter(new FileWriter(tmpCfgFile)));
+ out.println(vmsnapshot.third());
+ out.close();
+ String cfgFilePath = tmpCfgFile.getAbsolutePath();
+ String cmdvirsh = "virsh snapshot-create --redefine " +
vmName + (vmsnapshot.second()? " --current ":" ") + cfgFilePath;
+ int cmdout =
Script.runSimpleBashScriptForExitValue(cmdvirsh);
--- End diff --
Same goes for this, see my comment above about libvirt-java.
> VM Snapshotting implementation for KVM
> --------------------------------------
>
> Key: CLOUDSTACK-8746
> URL: https://issues.apache.org/jira/browse/CLOUDSTACK-8746
> Project: CloudStack
> Issue Type: Improvement
> Security Level: Public(Anyone can view this level - this is the
> default.)
> Reporter: Wei Zhou
> Assignee: Wei Zhou
>
> Currently it is not supported.
> https://cwiki.apache.org/confluence/display/CLOUDSTACK/VM+Snapshots
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)