Repository: cloudstack Updated Branches: refs/heads/master 5c0979fff -> 4db186ef6
CLOUDSTACK-9720: [VMware] template_spool_ref table is not getting updated with correct template physical size in template_size column. Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/8676b202 Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/8676b202 Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/8676b202 Branch: refs/heads/master Commit: 8676b202767d8e8d94e6891a23e0261b07afd2af Parents: 850c07c Author: Suresh Kumar Anaparti <[email protected]> Authored: Fri Dec 30 03:01:12 2016 +0530 Committer: Suresh Kumar Anaparti <[email protected]> Committed: Mon Mar 13 00:48:49 2017 +0530 ---------------------------------------------------------------------- .../storage/resource/VmwareStorageProcessor.java | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cloudstack/blob/8676b202/plugins/hypervisors/vmware/src/com/cloud/storage/resource/VmwareStorageProcessor.java ---------------------------------------------------------------------- diff --git a/plugins/hypervisors/vmware/src/com/cloud/storage/resource/VmwareStorageProcessor.java b/plugins/hypervisors/vmware/src/com/cloud/storage/resource/VmwareStorageProcessor.java index 1d33b16..8026575 100644 --- a/plugins/hypervisors/vmware/src/com/cloud/storage/resource/VmwareStorageProcessor.java +++ b/plugins/hypervisors/vmware/src/com/cloud/storage/resource/VmwareStorageProcessor.java @@ -182,7 +182,7 @@ public class VmwareStorageProcessor implements StorageProcessor { return null; } - private VirtualMachineMO copyTemplateFromSecondaryToPrimary(VmwareHypervisorHost hyperHost, DatastoreMO datastoreMo, String secondaryStorageUrl, + private Pair<VirtualMachineMO, Long> copyTemplateFromSecondaryToPrimary(VmwareHypervisorHost hyperHost, DatastoreMO datastoreMo, String secondaryStorageUrl, String templatePathAtSecondaryStorage, String templateName, String templateUuid, boolean createSnapshot, Integer nfsVersion) throws Exception { s_logger.info("Executing copyTemplateFromSecondaryToPrimary. secondaryStorage: " + secondaryStorageUrl + ", templatePathAtSecondaryStorage: " + @@ -229,6 +229,12 @@ public class VmwareStorageProcessor implements StorageProcessor { throw new Exception(msg); } + OVAProcessor processor = new OVAProcessor(); + Map<String, Object> params = new HashMap<String, Object>(); + params.put(StorageLayer.InstanceConfigKey, _storage); + processor.configure("OVA Processor", params); + long virtualSize = processor.getTemplateVirtualSize(secondaryMountPoint + "/" + templatePathAtSecondaryStorage, templateName); + if (createSnapshot) { if (vmMo.createSnapshot("cloud.template.base", "Base snapshot", false, false)) { // the same template may be deployed with multiple copies at per-datastore per-host basis, @@ -246,7 +252,7 @@ public class VmwareStorageProcessor implements StorageProcessor { } } - return vmMo; + return new Pair<VirtualMachineMO, Long>(vmMo, new Long(virtualSize)); } @Override @@ -322,6 +328,7 @@ public class VmwareStorageProcessor implements StorageProcessor { DatacenterMO dcMo = new DatacenterMO(context, hyperHost.getHyperHostDatacenter()); VirtualMachineMO templateMo = VmwareHelper.pickOneVmOnRunningHost(dcMo.findVmByNameAndLabel(templateUuidName), true); DatastoreMO dsMo = null; + Pair<VirtualMachineMO, Long> vmInfo = null; if (templateMo == null) { if (s_logger.isInfoEnabled()) { @@ -343,9 +350,10 @@ public class VmwareStorageProcessor implements StorageProcessor { dsMo = new DatastoreMO(context, morDs); if (managed) { - VirtualMachineMO vmMo = copyTemplateFromSecondaryToPrimary(hyperHost, dsMo, secondaryStorageUrl, templateInfo.first(), templateInfo.second(), + vmInfo = copyTemplateFromSecondaryToPrimary(hyperHost, dsMo, secondaryStorageUrl, templateInfo.first(), templateInfo.second(), managedStoragePoolRootVolumeName, false, _nfsVersion); + VirtualMachineMO vmMo = vmInfo.first(); vmMo.unregisterVm(); String[] vmwareLayoutFilePair = VmwareStorageLayoutHelper.getVmdkFilePairDatastorePath(dsMo, managedStoragePoolRootVolumeName, @@ -360,7 +368,7 @@ public class VmwareStorageProcessor implements StorageProcessor { dsMo.deleteFolder(folderToDelete, dcMo.getMor()); } else { - copyTemplateFromSecondaryToPrimary(hyperHost, dsMo, secondaryStorageUrl, templateInfo.first(), templateInfo.second(), + vmInfo = copyTemplateFromSecondaryToPrimary(hyperHost, dsMo, secondaryStorageUrl, templateInfo.first(), templateInfo.second(), templateUuidName, true, _nfsVersion); } } else { @@ -378,7 +386,7 @@ public class VmwareStorageProcessor implements StorageProcessor { else { newTemplate.setPath(templateUuidName); } - newTemplate.setSize(new Long(0)); // TODO: replace 0 with correct template physical_size. + newTemplate.setSize((vmInfo != null)? vmInfo.second() : new Long(0)); return new CopyCmdAnswer(newTemplate); } catch (Throwable e) {
