DataTO srcData = cmd.getSrcTO();
SnapshotObjectTO snapshot = (SnapshotObjectTO) srcData;
DataTO destData = cmd.getDestTO();
PrimaryDataStoreTO pool = (PrimaryDataStoreTO) destData.getDataStore();
DataStoreTO imageStore = srcData.getDataStore();
VolumeObjectTO volume = snapshot.getVolume();
if (!(imageStore instanceof NfsTO)) {
return new CopyCmdAnswer("unsupported protocol");
}
NfsTO nfsImageStore = (NfsTO) imageStore;
String snapshotFullPath = snapshot.getPath();
int index = snapshotFullPath.lastIndexOf("/");
String snapshotPath = snapshotFullPath.substring(0, index);
String snapshotName = snapshotFullPath.substring(index + 1);
KVMStoragePool secondaryPool = storagePoolMgr.getStoragePoolByURI(nfsImageStore.getUrl() + File.separator
+ snapshotPath);
KVMPhysicalDisk snapshotDisk = secondaryPool.getPhysicalDisk(snapshotName);
if (volume.getFormat() == ImageFormat.RAW) {
snapshotDisk.setFormat(PhysicalDiskFormat.RAW);
} else if (volume.getFormat() == ImageFormat.QCOW2) {
snapshotDisk.setFormat(PhysicalDiskFormat.QCOW2);
}
String primaryUuid = pool.getUuid();
KVMStoragePool primaryPool = storagePoolMgr.getStoragePool(pool.getPoolType(), primaryUuid);
String volUuid = UUID.randomUUID().toString();
KVMPhysicalDisk disk = storagePoolMgr.copyPhysicalDisk(snapshotDisk, volUuid, primaryPool);
VolumeObjectTO newVol = new VolumeObjectTO();
newVol.setPath(disk.getName());
newVol.setSize(disk.getVirtualSize());
/**
* We have to force the format of RBD volumes to RAW
*/
if (primaryPool.getType() == StoragePoolType.RBD) {
newVol.setFormat(ImageFormat.RAW);
}
return new CopyCmdAnswer(newVol);
} catch (CloudRuntimeException e) {
return new CopyCmdAnswer(e.toString());