[ 
https://issues.apache.org/jira/browse/CLOUDSTACK-4757?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16315892#comment-16315892
 ] 

ASF GitHub Bot commented on CLOUDSTACK-4757:
--------------------------------------------

rhtyd 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_r160093366
 
 

 ##########
 File path: 
engine/storage/image/src/org/apache/cloudstack/storage/image/TemplateServiceImpl.java
 ##########
 @@ -691,6 +723,151 @@ protected Void 
createTemplateCallback(AsyncCallbackDispatcher<TemplateServiceImp
         return null;
     }
 
+
+    protected boolean createDataDiskTemplates(TemplateInfo parentTemplate) {
+        // Get Datadisk template (if any) for OVA
+        List<DatadiskTO> dataDiskTemplates = new ArrayList<DatadiskTO>();
+        ImageStoreEntity tmpltStore = 
(ImageStoreEntity)parentTemplate.getDataStore();
+        dataDiskTemplates = tmpltStore.getDataDiskTemplates(parentTemplate);
+        s_logger.error("MDOVA createDataDiskTemplates Found " + 
dataDiskTemplates.size() + " Datadisk template(s) for template: " + 
parentTemplate.getId());
+        int diskCount = 0;
+        VMTemplateVO templateVO = 
_templateDao.findById(parentTemplate.getId());
+        DataStore imageStore = parentTemplate.getDataStore();
+        Map<String, String> details = new HashMap<String, String>();
+        for (DatadiskTO diskTemplate : dataDiskTemplates) {
+            if (!diskTemplate.isBootable()) {
+                createChildDataDiskTemplate(diskTemplate, templateVO, 
parentTemplate, imageStore, diskCount++);
+                if (!diskTemplate.isIso() && 
details.get(VmDetailConstants.DATA_DISK_CONTROLLER) == null){
+                    details.put(VmDetailConstants.DATA_DISK_CONTROLLER, 
getDiskControllerDetails(diskTemplate));
+                    details.put(VmDetailConstants.DATA_DISK_CONTROLLER + 
diskTemplate.getDiskId(), getDiskControllerDetails(diskTemplate));
+                }
+            } else {
+                finalizeParentTemplate(diskTemplate, templateVO, 
parentTemplate, imageStore, diskCount++);
+                details.put(VmDetailConstants.ROOT_DISK_CONTROLLER, 
getDiskControllerDetails(diskTemplate));
+            }
+        }
+        templateVO.setDetails(details);
+        _templateDao.saveDetails(templateVO);
+        return true;
+    }
+
+    private boolean createChildDataDiskTemplate(DatadiskTO dataDiskTemplate, 
VMTemplateVO template, TemplateInfo parentTemplate, DataStore imageStore, int 
diskCount) {
+        // Make an entry in vm_template table
+        Storage.ImageFormat format = dataDiskTemplate.isIso() ? 
Storage.ImageFormat.ISO : template.getFormat();
+        String suffix = dataDiskTemplate.isIso() ? "-IsoDiskTemplate-" : 
"-DataDiskTemplate-";
+        TemplateType ttype = dataDiskTemplate.isIso() ? TemplateType.ISODISK : 
TemplateType.DATADISK;
+        final long templateId = _templateDao.getNextInSequence(Long.class, 
"id");
+        long guestOsId = dataDiskTemplate.isIso() ? 1 : 0;
+        String templateName = dataDiskTemplate.isIso() ? 
dataDiskTemplate.getPath().substring(dataDiskTemplate.getPath().lastIndexOf(File.separator)
 + 1) : template.getName() + suffix + diskCount;
+        VMTemplateVO templateVO = new VMTemplateVO(templateId, templateName, 
format, false, false, false, ttype, template.getUrl(),
+                template.requiresHvm(), template.getBits(), 
template.getAccountId(), null, templateName, false, guestOsId, false, 
template.getHypervisorType(), null,
+                null, false, false);
+        if (dataDiskTemplate.isIso()){
+            templateVO.setUniqueName(templateName);
+        }
+        templateVO.setParentTemplateId(template.getId());
+        templateVO.setSize(dataDiskTemplate.getVirtualSize());
+        templateVO = _templateDao.persist(templateVO);
+        // Make sync call to create Datadisk templates in image store
+        TemplateApiResult result = null;
+        TemplateInfo dataDiskTemplateInfo = 
imageFactory.getTemplate(templateVO.getId(), imageStore);
+        AsyncCallFuture<TemplateApiResult> future = 
createDatadiskTemplateAsync(parentTemplate, dataDiskTemplateInfo, 
dataDiskTemplate.getPath(), dataDiskTemplate.getDiskId(),
+                dataDiskTemplate.getFileSize(), dataDiskTemplate.isBootable());
+        try {
+            result = future.get();
+            if (result.isSuccess()) {
+                // Make an entry in template_zone_ref table
+                if (imageStore.getScope().getScopeType() == ScopeType.REGION) {
+                    associateTemplateToZone(templateId, null);
+                } else if (imageStore.getScope().getScopeType() == 
ScopeType.ZONE) {
+                    Long zoneId = 
((ImageStoreEntity)imageStore).getDataCenterId();
+                    VMTemplateZoneVO templateZone = new 
VMTemplateZoneVO(zoneId, templateId, new Date());
+                    _vmTemplateZoneDao.persist(templateZone);
+                }
+                
_resourceLimitMgr.incrementResourceCount(template.getAccountId(), 
ResourceType.secondary_storage, templateVO.getSize());
+            } else {
+                s_logger.error("MDOVA createDataDiskTemplates Creation of 
Datadisk: " + templateVO.getId() + " failed: " + result.getResult());
+                // Delete the Datadisk templates that were already created as 
they are now invalid
+                s_logger.debug("Since creation of Datadisk template: " + 
templateVO.getId() + " failed, delete other Datadisk templates that were 
created as part of parent"
+                        + " template download");
+                TemplateInfo parentTemplateInfo = 
imageFactory.getTemplate(templateVO.getParentTemplateId(), imageStore);
+                cleanupDatadiskTemplates(parentTemplateInfo);
+            }
+            return result.isSuccess();
+        } catch (Exception e) {
+            s_logger.error("Creation of Datadisk: " + templateVO.getId() + " 
failed: " + result.getResult(), e);
+            return false;
+        }
+    }
+
+    private boolean finalizeParentTemplate(DatadiskTO dataDiskTemplate, 
VMTemplateVO templateVO, TemplateInfo parentTemplate, DataStore imageStore, int 
diskCount) {
+        TemplateInfo templateInfo = 
imageFactory.getTemplate(templateVO.getId(), imageStore);
+        AsyncCallFuture<TemplateApiResult> templateFuture = 
createDatadiskTemplateAsync(parentTemplate, templateInfo, 
dataDiskTemplate.getPath(), dataDiskTemplate.getDiskId(),
+                dataDiskTemplate.getFileSize(), dataDiskTemplate.isBootable());
+        TemplateApiResult result = null;
+        try {
+            result = templateFuture.get();
+            if (!result.isSuccess()) {
+                s_logger.debug("Since creation of parent template: " + 
templateInfo.getId() + " failed, delete Datadisk templates that were created as 
part of parent"
+                        + " template download");
+                cleanupDatadiskTemplates(templateInfo);
+            }
+            return result.isSuccess();
+        } catch (Exception e) {
+            s_logger.error("Creation of template: " + templateVO.getId() + " 
failed: " + result.getResult(), e);
+            return false;
+        }
+    }
+
+    private String getDiskControllerDetails(DatadiskTO diskTemplate) {
+        String controller = diskTemplate.getDiskController() ;
+        String controlerSubType = diskTemplate.getDiskControllerSubType();
+        if (controller != null) {
 
 Review comment:
   I've simplified this as if-else.

----------------------------------------------------------------
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:
us...@infra.apache.org


> Support OVA files with multiple disks for templates
> ---------------------------------------------------
>
>                 Key: CLOUDSTACK-4757
>                 URL: https://issues.apache.org/jira/browse/CLOUDSTACK-4757
>             Project: CloudStack
>          Issue Type: New Feature
>      Security Level: Public(Anyone can view this level - this is the 
> default.) 
>          Components: Storage Controller
>            Reporter: Likitha Shetty
>            Assignee: Nicolas Vazquez
>            Priority: Minor
>             Fix For: Future
>
>
> CloudStack volumes and templates are one single virtual disk in case of 
> XenServer/XCP and KVM hypervisors since the files used for templates and 
> volumes are virtual disks (VHD, QCOW2). However, VMware volumes and templates 
> are in OVA format, which are archives that can contain a complete VM 
> including multiple VMDKs and other files such as ISOs. And currently, 
> Cloudstack only supports Template creation based on OVA files containing a 
> single disk. If a user creates a template from a OVA file containing more 
> than 1 disk and launches an instance using this template, only the first disk 
> is attached to the new instance and other disks are ignored.
> Similarly with uploaded volumes, attaching an uploaded volume that contains 
> multiple disks to a VM will result in only one VMDK to being attached to the 
> VM.
> This behavior needs to be improved in VMWare to support OVA files with 
> multiple disks for both uploaded volumes and templates. i.e. If a user 
> creates a template from a OVA file containing more than 1 disk and launches 
> an instance using this template, the first disk should be attached to the new 
> instance as the ROOT disk and volumes should be created based on other VMDK 
> disks in the OVA file and should be attached to the instance.



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)

Reply via email to