Support Direct Download on Ceph (#11069)

This commit is contained in:
Nicolas Vazquez 2025-06-24 09:19:01 -03:00 committed by GitHub
parent 0bd35a5403
commit 16c60c7528
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -224,10 +224,35 @@ public class LibvirtStorageAdaptor implements StorageAdaptor {
} else {
Script.runSimpleBashScript("mv " + templateFilePath + " " + destinationFile);
}
} else if (destPool.getType() == StoragePoolType.RBD) {
String temporaryExtractFilePath = sourceFile.getParent() + File.separator + templateUuid;
extractDownloadedTemplate(templateFilePath, destPool, temporaryExtractFilePath);
createTemplateOnRBDFromDirectDownloadFile(temporaryExtractFilePath, templateUuid, destPool, timeout);
}
return destPool.getPhysicalDisk(templateUuid);
}
private void createTemplateOnRBDFromDirectDownloadFile(String srcTemplateFilePath, String templateUuid, KVMStoragePool destPool, int timeout) {
try {
QemuImg.PhysicalDiskFormat srcFileFormat = QemuImg.PhysicalDiskFormat.QCOW2;
QemuImgFile srcFile = new QemuImgFile(srcTemplateFilePath, srcFileFormat);
QemuImg qemu = new QemuImg(timeout);
Map<String, String> info = qemu.info(srcFile);
Long virtualSize = Long.parseLong(info.get(QemuImg.VIRTUAL_SIZE));
KVMPhysicalDisk destDisk = new KVMPhysicalDisk(destPool.getSourceDir() + "/" + templateUuid, templateUuid, destPool);
destDisk.setFormat(PhysicalDiskFormat.RAW);
destDisk.setSize(virtualSize);
destDisk.setVirtualSize(virtualSize);
QemuImgFile destFile = new QemuImgFile(KVMPhysicalDisk.RBDStringBuilder(destPool, destDisk.getPath()));
destFile.setFormat(PhysicalDiskFormat.RAW);
qemu.convert(srcFile, destFile);
} catch (LibvirtException | QemuImgException e) {
String err = String.format("Error creating template from direct download file on pool %s: %s", destPool.getUuid(), e.getMessage());
logger.error(err, e);
throw new CloudRuntimeException(err, e);
}
}
public StorageVol getVolume(StoragePool pool, String volName) {
StorageVol vol = null;