From 1a8e5287fdeff657425aad3e785d3eb3c0e4a39c Mon Sep 17 00:00:00 2001 From: Kelven Yang Date: Tue, 13 Mar 2012 17:28:01 -0700 Subject: [PATCH] Bug 14213: use UUID name in secondary storage for templates. Reviewed-By: edison --- .../manager/VmwareStorageManagerImpl.java | 27 ++++++++++--------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/core/src/com/cloud/hypervisor/vmware/manager/VmwareStorageManagerImpl.java b/core/src/com/cloud/hypervisor/vmware/manager/VmwareStorageManagerImpl.java index 61d21bdc7df..da4a7872ae4 100644 --- a/core/src/com/cloud/hypervisor/vmware/manager/VmwareStorageManagerImpl.java +++ b/core/src/com/cloud/hypervisor/vmware/manager/VmwareStorageManagerImpl.java @@ -491,7 +491,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); @@ -501,7 +501,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); @@ -517,17 +517,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) { @@ -535,17 +535,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; @@ -590,15 +591,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