@Override public long getVirtualSize(File file) { try { long size = getTemplateVirtualSize(file.getParent(), file.getName()); return size; } catch (Exception e) { s_logger.info("[ignored]" + "failed to get virtual template size for ova: " + e.getLocalizedMessage()); } return file.length(); }
@Override public FormatInfo process(String templatePath, ImageFormat format, String templateName) throws InternalErrorException { return process(templatePath, format, templateName, 0); }
info.filename = templateName + "." + ImageFormat.OVA.getFileExtension(); info.size = _storage.getSize(templateFilePath); info.virtualSize = getTemplateVirtualSize(templatePath, info.filename); String ovfFile = getOVFFilePath(templateFileFullPath); try { OVFHelper ovfHelper = new OVFHelper();
processor = new QCOW2Processor(); } else if (format == ImageFormat.OVA) { processor = new OVAProcessor(); } else if (format == ImageFormat.VHD) { processor = new VhdProcessor();
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; s_logger.error(msg); throw new InternalErrorException(msg); } try { Document ovfDoc = null; ovfDoc = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(new File(ovfFileName)); Element disk = (Element)ovfDoc.getElementsByTagName("Disk").item(0); virtualSize = Long.parseLong(disk.getAttribute("ovf:capacity")); String allocationUnits = disk.getAttribute("ovf:capacityAllocationUnits"); virtualSize = OVFHelper.getDiskVirtualSize(virtualSize, allocationUnits, ovfFileName); return virtualSize; } catch (Exception e) { String msg = "getTemplateVirtualSize: Unable to parse OVF XML document " + templatePath + " to get the virtual disk " + templateName + " size due to " + e; s_logger.error(msg); throw new InternalErrorException(msg); } }
_processors.put("QCOW2 Processor", processor); processor = new OVAProcessor(); processor.configure("OVA Processor", params); _processors.put("OVA Processor", processor);
Processor processor = _processors.get("OVA Processor"); OVAProcessor vmdkProcessor = (OVAProcessor)processor; long vSize = vmdkProcessor.getTemplateVirtualSize(path, vInfo.getInstallPath().substring(vInfo.getInstallPath().lastIndexOf(File.separator) + 1)); vInfo.setSize(vSize); loc.updateVirtualSize(vSize);
Processor processor = _processors.get("OVA Processor"); OVAProcessor vmdkProcessor = (OVAProcessor)processor; long vSize = vmdkProcessor.getTemplateVirtualSize(path, tInfo.getInstallPath().substring(tInfo.getInstallPath().lastIndexOf(File.separator) + 1)); tInfo.setSize(vSize); loc.updateVirtualSize(vSize);