diff --git a/core/src/com/cloud/hypervisor/vmware/manager/VmwareStorageManagerImpl.java b/core/src/com/cloud/hypervisor/vmware/manager/VmwareStorageManagerImpl.java index 0d41e5a73ab..88cd8be79c7 100644 --- a/core/src/com/cloud/hypervisor/vmware/manager/VmwareStorageManagerImpl.java +++ b/core/src/com/cloud/hypervisor/vmware/manager/VmwareStorageManagerImpl.java @@ -550,7 +550,7 @@ public class VmwareStorageManagerImpl implements VmwareStorageManager { } } - String tmpSnapshotName = UUID.randomUUID().toString(); + String snapshotUuidName = UUID.randomUUID().toString(); VirtualMachineMO clonedVm = null; try { Pair volumeDeviceInfo = vmMo.getDiskDevice(volumePath, false); @@ -560,7 +560,7 @@ public class VmwareStorageManagerImpl implements VmwareStorageManager { throw new Exception(msg); } - if(!vmMo.createSnapshot(tmpSnapshotName, "Temporary snapshot for template creation", false, false)) { + if(!vmMo.createSnapshot(snapshotUuidName, "Temporary snapshot for template creation", false, false)) { String msg = "Unable to take snapshot for creating template from volume. volume path: " + volumePath; s_logger.error(msg); throw new Exception(msg); @@ -576,17 +576,17 @@ public class VmwareStorageManagerImpl implements VmwareStorageManager { throw new Exception(msg); } - clonedVm.exportVm(secondaryMountPoint + "/" + installPath, templateName, true, false); + clonedVm.exportVm(secondaryMountPoint + "/" + installPath, snapshotUuidName, true, false); - long physicalSize = new File(installFullPath + "/" + templateName + ".ova").length(); + long physicalSize = new File(installFullPath + "/" + snapshotUuidName + ".ova").length(); VmdkProcessor processor = new VmdkProcessor(); Map params = new HashMap(); params.put(StorageLayer.InstanceConfigKey, _storage); processor.configure("VMDK Processor", params); - long virtualSize = processor.getTemplateVirtualSize(installFullPath, templateName); + long virtualSize = processor.getTemplateVirtualSize(installFullPath, snapshotUuidName); - postCreatePrivateTemplate(installFullPath, templateId, templateName, physicalSize, virtualSize); - return new Ternary(installPath + "/" + templateName + ".ova", physicalSize, virtualSize); + postCreatePrivateTemplate(installFullPath, templateId, snapshotUuidName, physicalSize, virtualSize); + return new Ternary(installPath + "/" + snapshotUuidName + ".ova", physicalSize, virtualSize); } finally { if(clonedVm != null) { @@ -594,17 +594,18 @@ public class VmwareStorageManagerImpl implements VmwareStorageManager { clonedVm.destroy(); } - vmMo.removeSnapshot(tmpSnapshotName, false); + vmMo.removeSnapshot(snapshotUuidName, false); } } private Ternary createTemplateFromSnapshot(long accountId, long templateId, String templateName, String secStorageUrl, long volumeId, String backedUpSnapshotUuid) throws Exception { + String snapshotUuidName = UUID.randomUUID().toString(); String secondaryMountPoint = _mountService.getMountPoint(secStorageUrl); String installPath = getTemplateRelativeDirInSecStorage(accountId, templateId); String installFullPath = secondaryMountPoint + "/" + installPath; - String installFullName = installFullPath + "/" + templateName + ".ova"; + String installFullName = installFullPath + "/" + snapshotUuidName + ".ova"; String snapshotFullName = secondaryMountPoint + "/" + getSnapshotRelativeDirInSecStorage(accountId, volumeId) + "/" + backedUpSnapshotUuid + ".ova"; String result; @@ -649,15 +650,15 @@ public class VmwareStorageManagerImpl implements VmwareStorageManager { throw new Exception(msg); } - long physicalSize = new File(installFullPath + "/" + templateName + ".ova").length(); + long physicalSize = new File(installFullPath + "/" + snapshotUuidName + ".ova").length(); VmdkProcessor processor = new VmdkProcessor(); Map params = new HashMap(); params.put(StorageLayer.InstanceConfigKey, _storage); processor.configure("VMDK Processor", params); - long virtualSize = processor.getTemplateVirtualSize(installFullPath, templateName); + long virtualSize = processor.getTemplateVirtualSize(installFullPath, snapshotUuidName); - postCreatePrivateTemplate(installFullPath, templateId, templateName, physicalSize, virtualSize); - return new Ternary(installPath + "/" + templateName + ".ova", physicalSize, virtualSize); + postCreatePrivateTemplate(installFullPath, templateId, snapshotUuidName, physicalSize, virtualSize); + return new Ternary(installPath + "/" + snapshotUuidName + ".ova", physicalSize, virtualSize); } catch(Exception e) { // TODO, clean up left over files