vmMo = hyperHost.findVmOnPeerHyperHost(vmName);
}
if (vmMo == null) {
String msg = "Unable to find VM for DeleteVMSnapshotCommand";
s_logger.debug(msg);
return new DeleteVMSnapshotAnswer(cmd, false, msg);
} else {
if (vmMo.getSnapshotMor(vmSnapshotName) == null) {
s_logger.debug("can not find the snapshot " + vmSnapshotName + ", assume it is already removed");
} else {
if (!vmMo.removeSnapshot(vmSnapshotName, false)) {
String msg = "delete vm snapshot " + vmSnapshotName + " due to error occured in vmware";
s_logger.error(msg);
return new DeleteVMSnapshotAnswer(cmd, false, msg);
}
}
s_logger.debug("snapshot: " + vmSnapshotName + " is removed");
// after removed snapshot, the volumes' paths have been changed for the VM, needs to report new paths to manager
VirtualDisk[] vdisks = vmMo.getAllDiskDevice();
for (int i = 0; i < vdisks.length; i++) {
@SuppressWarnings("deprecation")
List<Pair<String, ManagedObjectReference>> vmdkFiles = vmMo.getDiskDatastorePathChain(vdisks[i], false);
for (Pair<String, ManagedObjectReference> fileItem : vmdkFiles) {
String vmdkName = fileItem.first().split(" ")[1];
if (vmdkName.endsWith(".vmdk")) {
vmdkName = vmdkName.substring(0, vmdkName.length() - (".vmdk").length());
}
if(vmdkName.contains("/")) {
vmdkName = vmdkName.substring(vmdkName.indexOf ("/") + 1,vmdkName.length());
}
String baseName = extractSnapshotBaseFileName(vmdkName);
mapNewDisk.put(baseName, vmdkName);
}
}
for (VolumeTO volumeTo : listVolumeTo) {
String baseName = extractSnapshotBaseFileName(volumeTo.getPath());
String newPath = mapNewDisk.get(baseName);
long size = getVMSnapshotChainSize(context,hyperHost,
baseName + "*.vmdk", volumeTo.getPoolUuid(), newPath);
if(volumeTo.getType()== Volume.Type.ROOT){
// add memory snapshot size
size = size + getVMSnapshotChainSize(context,hyperHost,cmd.getVmName()+"*.vmsn",volumeTo.getPoolUuid(),null);
}
volumeTo.setChainSize(size);
volumeTo.setPath(newPath);
}
return new DeleteVMSnapshotAnswer(cmd, listVolumeTo);
}
} catch (Exception e) {
String msg = e.getMessage();
s_logger.error("failed to delete vm snapshot " + vmSnapshotName + " of vm " + vmName + " due to " + msg);
return new DeleteVMSnapshotAnswer(cmd, false, msg);
}
}