primaryPool = _storagePoolMgr.createStoragePool(cmd.getPool().getUuid(),
cmd.getPool().getHost(), cmd.getPool().getPort(),
cmd.getPool().getPath(), cmd.getPool().getUserInfo(),
cmd.getPool().getType());
} else {
return new CopyVolumeAnswer(cmd, false, e.getMessage(), null, null);
}
}
String volumeName = UUID.randomUUID().toString();
if (copyToSecondary) {
String destVolumeName = volumeName + ".qcow2";
KVMPhysicalDisk volume = primaryPool.getPhysicalDisk(cmd
.getVolumePath());
String volumeDestPath = "/volumes/" + cmd.getVolumeId()
+ File.separator;
secondaryStoragePool = _storagePoolMgr.getStoragePoolByURI(
secondaryStorageUrl);
secondaryStoragePool.createFolder(volumeDestPath);
_storagePoolMgr.deleteStoragePool(secondaryStoragePool.getType(),secondaryStoragePool.getUuid());
secondaryStoragePool = _storagePoolMgr.getStoragePoolByURI(
secondaryStorageUrl
+ volumeDestPath);
_storagePoolMgr.copyPhysicalDisk(volume,
destVolumeName,secondaryStoragePool, 0);
return new CopyVolumeAnswer(cmd, true, null, null, volumeName);
} else {
volumePath = "/volumes/" + cmd.getVolumeId() + File.separator;
secondaryStoragePool = _storagePoolMgr.getStoragePoolByURI(
secondaryStorageUrl
+ volumePath);
KVMPhysicalDisk volume = secondaryStoragePool
.getPhysicalDisk(cmd.getVolumePath() + ".qcow2");
_storagePoolMgr.copyPhysicalDisk(volume, volumeName,
primaryPool, 0);
return new CopyVolumeAnswer(cmd, true, null, null, volumeName);
}
} catch (CloudRuntimeException e) {
return new CopyVolumeAnswer(cmd, false, e.toString(), null, null);
} finally {
if (secondaryStoragePool != null) {
_storagePoolMgr.deleteStoragePool(secondaryStoragePool.getType(),secondaryStoragePool.getUuid());
}
}