DaanHoogland commented on code in PR #9792:
URL: https://github.com/apache/cloudstack/pull/9792#discussion_r1819003390


##########
plugins/storage/volume/linstor/src/main/java/com/cloud/hypervisor/kvm/storage/LinstorStorageAdaptor.java:
##########
@@ -579,8 +583,41 @@ public KVMPhysicalDisk 
createTemplateFromDirectDownloadFile(String templateFileP
                                                                 KVMStoragePool 
destPool, Storage.ImageFormat format,
                                                                 int timeout)
     {
-        s_logger.debug("Linstor: createTemplateFromDirectDownloadFile");
-        return null;
+        s_logger.debug(String.format("Linstor: 
createTemplateFromDirectDownloadFile: %s/%s", templateFilePath, format));
+        {
+            File sourceFile = new File(templateFilePath);
+            if (!sourceFile.exists()) {
+                throw new CloudRuntimeException("Direct download template file 
" + sourceFile +
+                        " does not exist on this host");
+            }
+        }

Review Comment:
   new method?



##########
plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/LibvirtDomainXMLParser.java:
##########
@@ -126,11 +126,15 @@ public boolean parseDomainXML(String domXML) {
                             }
                             def.defFileBasedDisk(diskFile, diskLabel, 
DiskDef.DiskBus.valueOf(bus.toUpperCase()), fmt);
                         } else if (device.equalsIgnoreCase("cdrom")) {
-                            def.defISODisk(diskFile, i+1, diskLabel);
+                            def.defISODisk(diskFile, i+1, diskLabel, 
DiskDef.DiskType.FILE);
                         }
                     } else if (type.equalsIgnoreCase("block")) {
-                        def.defBlockBasedDisk(diskDev, diskLabel,
-                            DiskDef.DiskBus.valueOf(bus.toUpperCase()));
+                        if (device.equalsIgnoreCase("disk")) {
+                            def.defBlockBasedDisk(diskDev, diskLabel,
+                                    
DiskDef.DiskBus.valueOf(bus.toUpperCase()));
+                        } else if (device.equalsIgnoreCase("cdrom")) {
+                            def.defISODisk(diskFile, i+1, diskLabel, 
DiskDef.DiskType.BLOCK);
+                        }

Review Comment:
   can this be a new method?



##########
plugins/storage/volume/linstor/src/main/java/com/cloud/hypervisor/kvm/storage/LinstorStorageAdaptor.java:
##########
@@ -579,8 +583,41 @@ public KVMPhysicalDisk 
createTemplateFromDirectDownloadFile(String templateFileP
                                                                 KVMStoragePool 
destPool, Storage.ImageFormat format,
                                                                 int timeout)
     {
-        s_logger.debug("Linstor: createTemplateFromDirectDownloadFile");
-        return null;
+        s_logger.debug(String.format("Linstor: 
createTemplateFromDirectDownloadFile: %s/%s", templateFilePath, format));
+        {
+            File sourceFile = new File(templateFilePath);
+            if (!sourceFile.exists()) {
+                throw new CloudRuntimeException("Direct download template file 
" + sourceFile +
+                        " does not exist on this host");
+            }
+        }
+        String name = UUID.randomUUID().toString();
+
+        String finalSourcePath = templateFilePath;
+        if (LibvirtStorageAdaptor.isTemplateExtractable(templateFilePath)) {
+            finalSourcePath = templateFilePath.substring(0, 
templateFilePath.lastIndexOf('.'));
+            LibvirtStorageAdaptor.extractDownloadedTemplate(templateFilePath, 
destPool, finalSourcePath);
+        }
+
+        File finalSourceFile = new File(finalSourcePath);
+        final KVMPhysicalDisk dstDisk = destPool.createPhysicalDisk(
+                name, QemuImg.PhysicalDiskFormat.RAW, 
Storage.ProvisioningType.THIN, finalSourceFile.length(), null);
+
+        final DevelopersApi api = getLinstorAPI(destPool);
+        final String rscName = getLinstorRscName(name);
+        try {
+            LinstorUtil.applyAuxProps(api, rscName, finalSourceFile.getName(), 
null);
+        } catch (ApiException apiExc) {
+            s_logger.error(String.format("Error setting aux properties for 
%s", rscName));
+            logLinstorAnswers(apiExc.getApiCallRcList());
+        }
+
+        Script.runSimpleBashScript(
+                String.format("dd if=\"%s\" of=\"%s\" bs=64k 
conv=nocreat,sparse oflag=direct",
+                        finalSourcePath, dstDisk.getPath()));
+
+        Script.runSimpleBashScript("rm " + finalSourcePath);

Review Comment:
   some extra methods could be created for readability here.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscr...@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to