Skip to content

Commit 16c60c7

Browse files
authored
Support Direct Download on Ceph (#11069)
1 parent 0bd35a5 commit 16c60c7

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/storage/LibvirtStorageAdaptor.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,10 +224,35 @@ public KVMPhysicalDisk createTemplateFromDirectDownloadFile(String templateFileP
224224
} else {
225225
Script.runSimpleBashScript("mv " + templateFilePath + " " + destinationFile);
226226
}
227+
} else if (destPool.getType() == StoragePoolType.RBD) {
228+
String temporaryExtractFilePath = sourceFile.getParent() + File.separator + templateUuid;
229+
extractDownloadedTemplate(templateFilePath, destPool, temporaryExtractFilePath);
230+
createTemplateOnRBDFromDirectDownloadFile(temporaryExtractFilePath, templateUuid, destPool, timeout);
227231
}
228232
return destPool.getPhysicalDisk(templateUuid);
229233
}
230234

235+
private void createTemplateOnRBDFromDirectDownloadFile(String srcTemplateFilePath, String templateUuid, KVMStoragePool destPool, int timeout) {
236+
try {
237+
QemuImg.PhysicalDiskFormat srcFileFormat = QemuImg.PhysicalDiskFormat.QCOW2;
238+
QemuImgFile srcFile = new QemuImgFile(srcTemplateFilePath, srcFileFormat);
239+
QemuImg qemu = new QemuImg(timeout);
240+
Map<String, String> info = qemu.info(srcFile);
241+
Long virtualSize = Long.parseLong(info.get(QemuImg.VIRTUAL_SIZE));
242+
KVMPhysicalDisk destDisk = new KVMPhysicalDisk(destPool.getSourceDir() + "/" + templateUuid, templateUuid, destPool);
243+
destDisk.setFormat(PhysicalDiskFormat.RAW);
244+
destDisk.setSize(virtualSize);
245+
destDisk.setVirtualSize(virtualSize);
246+
QemuImgFile destFile = new QemuImgFile(KVMPhysicalDisk.RBDStringBuilder(destPool, destDisk.getPath()));
247+
destFile.setFormat(PhysicalDiskFormat.RAW);
248+
qemu.convert(srcFile, destFile);
249+
} catch (LibvirtException | QemuImgException e) {
250+
String err = String.format("Error creating template from direct download file on pool %s: %s", destPool.getUuid(), e.getMessage());
251+
logger.error(err, e);
252+
throw new CloudRuntimeException(err, e);
253+
}
254+
}
255+
231256
public StorageVol getVolume(StoragePool pool, String volName) {
232257
StorageVol vol = null;
233258

0 commit comments

Comments
 (0)