rafaelweingartner commented on a change in pull request #2146: CLOUDSTACK-4757:
Support OVA files with multiple disks for templates
URL: https://github.com/apache/cloudstack/pull/2146#discussion_r158581743
##########
File path: core/src/com/cloud/storage/template/OVAProcessor.java
##########
@@ -127,7 +158,53 @@ public long getTemplateVirtualSize(String templatePath,
String templateName) thr
}
return virtualSize;
} catch (Exception e) {
- String msg = "Unable to parse OVF XML document to get the virtual
disk size due to" + 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);
+ }
+ }
+
+ public Pair<Long, Long> getDiskDetails(String ovfFilePath, String
diskName) throws InternalErrorException {
+ long virtualSize = 0;
+ long fileSize = 0;
+ String fileId = null;
+ try {
+ Document ovfDoc = null;
+ ovfDoc =
DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(new
File(ovfFilePath));
+ NodeList disks = ovfDoc.getElementsByTagName("Disk");
+ NodeList files = ovfDoc.getElementsByTagName("File");
+ for (int j = 0; j < files.getLength(); j++) {
+ Element file = (Element)files.item(j);
+ if (file.getAttribute("ovf:href").equals(diskName)) {
+ fileSize = Long.parseLong(file.getAttribute("ovf:size"));
+ fileId = file.getAttribute("ovf:id");
+ break;
+ }
+ }
+ for (int i = 0; i < disks.getLength(); i++) {
Review comment:
This code is duplicated....
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services