CLOUDSTACK-9720: [VMware] template_spool_ref table is not getting updated with correct template physical size in template_size column.

(cherry picked from commit 8676b20276)
Signed-off-by: Rohit Yadav <rohit.yadav@shapeblue.com>
This commit is contained in:
Suresh Kumar Anaparti 2016-12-30 03:01:12 +05:30 committed by Rohit Yadav
parent af9c6b7bdc
commit 0fbbbdb83a
1 changed files with 13 additions and 5 deletions

View File

@ -168,7 +168,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: " +
@ -215,6 +215,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,
@ -232,7 +238,7 @@ public class VmwareStorageProcessor implements StorageProcessor {
}
}
return vmMo;
return new Pair<VirtualMachineMO, Long>(vmMo, new Long(virtualSize));
}
@Override
@ -308,6 +314,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()) {
@ -329,9 +336,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,
@ -346,7 +354,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 {
@ -364,7 +372,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) {