@@ -224,10 +224,35 @@ public KVMPhysicalDisk createTemplateFromDirectDownloadFile(String templateFileP
224
224
} else {
225
225
Script .runSimpleBashScript ("mv " + templateFilePath + " " + destinationFile );
226
226
}
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 );
227
231
}
228
232
return destPool .getPhysicalDisk (templateUuid );
229
233
}
230
234
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
+
231
256
public StorageVol getVolume (StoragePool pool , String volName ) {
232
257
StorageVol vol = null ;
233
258
0 commit comments