Skip to content

Commit febc04f

Browse files
nvazquezdhslove
authored andcommitted
Support Direct Download on Ceph (apache#11069)
1 parent f833c7a commit febc04f

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
@@ -226,10 +226,35 @@ public KVMPhysicalDisk createTemplateFromDirectDownloadFile(String templateFileP
226226
} else {
227227
Script.runSimpleBashScript("mv " + templateFilePath + " " + destinationFile);
228228
}
229+
} else if (destPool.getType() == StoragePoolType.RBD) {
230+
String temporaryExtractFilePath = sourceFile.getParent() + File.separator + templateUuid;
231+
extractDownloadedTemplate(templateFilePath, destPool, temporaryExtractFilePath);
232+
createTemplateOnRBDFromDirectDownloadFile(temporaryExtractFilePath, templateUuid, destPool, timeout);
229233
}
230234
return destPool.getPhysicalDisk(templateUuid);
231235
}
232236

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

0 commit comments

Comments
 (0)