mirror of https://github.com/apache/cloudstack.git
bug 11023: recalcuate vmware template virtuali size while upgrate above 2.2.10
This commit is contained in:
parent
645976bd87
commit
17caf6ea25
|
|
@ -650,6 +650,19 @@ public class DownloadManagerImpl implements DownloadManager {
|
|||
}
|
||||
|
||||
TemplateInfo tInfo = loc.getTemplateInfo();
|
||||
|
||||
if ((tInfo.size == tInfo.physicalSize) && (tInfo.installPath.endsWith(ImageFormat.OVA.getFileExtension()))) {
|
||||
try {
|
||||
Processor processor = _processors.get("VMDK Processor");
|
||||
VmdkProcessor vmdkProcessor = (VmdkProcessor)processor;
|
||||
long vSize = vmdkProcessor.getTemplateVirtualSize(path, tInfo.installPath.substring(tInfo.installPath.lastIndexOf(File.separator) + 1));
|
||||
tInfo.size = vSize;
|
||||
loc.updateVirtualSize(vSize);
|
||||
loc.save();
|
||||
} catch (Exception e) {
|
||||
s_logger.error("Unable to get the virtual size of the template: " + tInfo.installPath + " due to " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
result.put(tInfo.templateName, tInfo);
|
||||
s_logger.debug("Added template name: " + tInfo.templateName + ", path: " + tmplt);
|
||||
|
|
|
|||
|
|
@ -187,6 +187,10 @@ public class TemplateLocation {
|
|||
return true;
|
||||
}
|
||||
|
||||
public void updateVirtualSize(long virtualSize) {
|
||||
_props.setProperty("virtualsize", Long.toString(virtualSize));
|
||||
}
|
||||
|
||||
protected boolean checkFormatValidity(FormatInfo info) {
|
||||
return (info.format != null && info.size > 0 && info.virtualSize > 0 && info.filename != null && _storage.exists(_templatePath + info.filename) && _storage.getSize(_templatePath + info.filename) == info.size);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -75,10 +75,19 @@ public class VmdkProcessor implements Processor {
|
|||
FormatInfo info = new FormatInfo();
|
||||
info.format = ImageFormat.OVA;
|
||||
info.filename = templateName + "." + ImageFormat.OVA.getFileExtension();
|
||||
info.size = _storage.getSize(templateFilePath);
|
||||
info.size = _storage.getSize(templateFilePath);
|
||||
info.virtualSize = getTemplateVirtualSize(templatePath, info.filename);
|
||||
|
||||
// delete original OVA file
|
||||
// templateFile.delete();
|
||||
return info;
|
||||
}
|
||||
|
||||
public long getTemplateVirtualSize(String templatePath, String templateName) throws InternalErrorException {
|
||||
// get the virtual size from the OVF file meta data
|
||||
long virtualSize=0;
|
||||
String templateFileFullPath = templatePath.endsWith(File.separator) ? templatePath : templatePath + File.separator;
|
||||
templateFileFullPath += templateName.endsWith(ImageFormat.OVA.getFileExtension()) ? templateName : templateName + "." + ImageFormat.OVA.getFileExtension();
|
||||
String ovfFileName = getOVFFilePath(templateFileFullPath);
|
||||
if(ovfFileName == null) {
|
||||
String msg = "Unable to locate OVF file in template package directory: " + templatePath;
|
||||
|
|
@ -91,7 +100,7 @@ public class VmdkProcessor implements Processor {
|
|||
Element disk = (Element) ovfDoc.getElementsByTagName("Disk").item(0);
|
||||
virtualSize = Long.parseLong(disk.getAttribute("ovf:capacity"));
|
||||
String allocationUnits = disk.getAttribute("ovf:capacityAllocationUnits");
|
||||
if (allocationUnits != null) {
|
||||
if ((virtualSize != 0) && (allocationUnits != null)) {
|
||||
long units = 1;
|
||||
if (allocationUnits.equalsIgnoreCase("KB") || allocationUnits.equalsIgnoreCase("KiloBytes") || allocationUnits.equalsIgnoreCase("byte * 2^10")) {
|
||||
units = 1024;
|
||||
|
|
@ -101,20 +110,17 @@ public class VmdkProcessor implements Processor {
|
|||
units = 1024 * 1024 * 1024;
|
||||
}
|
||||
virtualSize = virtualSize * units;
|
||||
} else {
|
||||
throw new InternalErrorException("Failed to read capacity and capacityAllocationUnits from the OVF file: " + ovfFileName);
|
||||
}
|
||||
return virtualSize;
|
||||
} catch (Exception e) {
|
||||
String msg = "Unable to parse OVF XML document to get the virtual disk size due to"+e;
|
||||
s_logger.error(msg);
|
||||
throw new InternalErrorException(msg);
|
||||
}
|
||||
|
||||
info.virtualSize = virtualSize;
|
||||
|
||||
// delete original OVA file
|
||||
// templateFile.delete();
|
||||
return info;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private String getOVFFilePath(String srcOVAFileName) {
|
||||
File file = new File(srcOVAFileName);
|
||||
assert(_storage != null);
|
||||
|
|
|
|||
Loading…
Reference in New Issue