From 7762f1c7d706dfbecebd2ac58ea33a85bbc0d6e8 Mon Sep 17 00:00:00 2001 From: Kelven Yang Date: Wed, 28 Mar 2012 14:06:55 -0700 Subject: [PATCH] bug 14491: use template unique name instead of self-generated UUID name. Reviewed-By: Kelven(with test) --- .../manager/VmwareStorageManagerImpl.java | 34 +++++++++---------- 1 file changed, 16 insertions(+), 18 deletions(-) diff --git a/core/src/com/cloud/hypervisor/vmware/manager/VmwareStorageManagerImpl.java b/core/src/com/cloud/hypervisor/vmware/manager/VmwareStorageManagerImpl.java index 88cd8be79c7..43b910a527a 100644 --- a/core/src/com/cloud/hypervisor/vmware/manager/VmwareStorageManagerImpl.java +++ b/core/src/com/cloud/hypervisor/vmware/manager/VmwareStorageManagerImpl.java @@ -327,13 +327,13 @@ public class VmwareStorageManagerImpl implements VmwareStorageManager { } Ternary result = createTemplateFromVolume(vmMo, - accountId, templateId, cmd.getTemplateName(), + accountId, templateId, cmd.getUniqueName(), secondaryStoragePoolURL, volumePath, hostService.getWorkerName(context, cmd, 0)); return new CreatePrivateTemplateAnswer(cmd, true, null, result.first(), result.third(), result.second(), - cmd.getTemplateName(), ImageFormat.OVA); + cmd.getUniqueName(), ImageFormat.OVA); } catch (Throwable e) { if (e instanceof RemoteException) { @@ -530,7 +530,7 @@ public class VmwareStorageManagerImpl implements VmwareStorageManager { } } - private Ternary createTemplateFromVolume(VirtualMachineMO vmMo, long accountId, long templateId, String templateName, + private Ternary createTemplateFromVolume(VirtualMachineMO vmMo, long accountId, long templateId, String templateUniqueName, String secStorageUrl, String volumePath, String workerVmName) throws Exception { String secondaryMountPoint = _mountService.getMountPoint(secStorageUrl); @@ -550,7 +550,6 @@ public class VmwareStorageManagerImpl implements VmwareStorageManager { } } - String snapshotUuidName = UUID.randomUUID().toString(); VirtualMachineMO clonedVm = null; try { Pair volumeDeviceInfo = vmMo.getDiskDevice(volumePath, false); @@ -560,7 +559,7 @@ public class VmwareStorageManagerImpl implements VmwareStorageManager { throw new Exception(msg); } - if(!vmMo.createSnapshot(snapshotUuidName, "Temporary snapshot for template creation", false, false)) { + if(!vmMo.createSnapshot(templateUniqueName, "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 +575,17 @@ public class VmwareStorageManagerImpl implements VmwareStorageManager { throw new Exception(msg); } - clonedVm.exportVm(secondaryMountPoint + "/" + installPath, snapshotUuidName, true, false); + clonedVm.exportVm(secondaryMountPoint + "/" + installPath, templateUniqueName, true, false); - long physicalSize = new File(installFullPath + "/" + snapshotUuidName + ".ova").length(); + long physicalSize = new File(installFullPath + "/" + templateUniqueName + ".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, snapshotUuidName); + long virtualSize = processor.getTemplateVirtualSize(installFullPath, templateUniqueName); - postCreatePrivateTemplate(installFullPath, templateId, snapshotUuidName, physicalSize, virtualSize); - return new Ternary(installPath + "/" + snapshotUuidName + ".ova", physicalSize, virtualSize); + postCreatePrivateTemplate(installFullPath, templateId, templateUniqueName, physicalSize, virtualSize); + return new Ternary(installPath + "/" + templateUniqueName + ".ova", physicalSize, virtualSize); } finally { if(clonedVm != null) { @@ -594,18 +593,17 @@ public class VmwareStorageManagerImpl implements VmwareStorageManager { clonedVm.destroy(); } - vmMo.removeSnapshot(snapshotUuidName, false); + vmMo.removeSnapshot(templateUniqueName, false); } } - private Ternary createTemplateFromSnapshot(long accountId, long templateId, String templateName, + private Ternary createTemplateFromSnapshot(long accountId, long templateId, String templateUniqueName, 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 + "/" + snapshotUuidName + ".ova"; + String installFullName = installFullPath + "/" + templateUniqueName + ".ova"; String snapshotFullName = secondaryMountPoint + "/" + getSnapshotRelativeDirInSecStorage(accountId, volumeId) + "/" + backedUpSnapshotUuid + ".ova"; String result; @@ -650,15 +648,15 @@ public class VmwareStorageManagerImpl implements VmwareStorageManager { throw new Exception(msg); } - long physicalSize = new File(installFullPath + "/" + snapshotUuidName + ".ova").length(); + long physicalSize = new File(installFullPath + "/" + templateUniqueName + ".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, snapshotUuidName); + long virtualSize = processor.getTemplateVirtualSize(installFullPath, templateUniqueName); - postCreatePrivateTemplate(installFullPath, templateId, snapshotUuidName, physicalSize, virtualSize); - return new Ternary(installPath + "/" + snapshotUuidName + ".ova", physicalSize, virtualSize); + postCreatePrivateTemplate(installFullPath, templateId, templateUniqueName, physicalSize, virtualSize); + return new Ternary(installPath + "/" + templateUniqueName + ".ova", physicalSize, virtualSize); } catch(Exception e) { // TODO, clean up left over files