use of com.cloud.legacymodel.communication.answer.CreateVolumeFromSnapshotAnswer in project cosmic by MissionCriticalCloud.
the class LibvirtCreateVolumeFromSnapshotCommandWrapper method execute.
@Override
public Answer execute(final CreateVolumeFromSnapshotCommand command, final LibvirtComputingResource libvirtComputingResource) {
try {
String snapshotPath = command.getSnapshotUuid();
final int index = snapshotPath.lastIndexOf("/");
snapshotPath = snapshotPath.substring(0, index);
final KvmStoragePoolManager storagePoolMgr = libvirtComputingResource.getStoragePoolMgr();
final KvmStoragePool secondaryPool = storagePoolMgr.getStoragePoolByUri(command.getSecondaryStorageUrl() + snapshotPath);
final KvmPhysicalDisk snapshot = secondaryPool.getPhysicalDisk(command.getSnapshotName());
final String primaryUuid = command.getPrimaryStoragePoolNameLabel();
final StorageFilerTO pool = command.getPool();
final KvmStoragePool primaryPool = storagePoolMgr.getStoragePool(pool.getType(), primaryUuid);
final String volUuid = UUID.randomUUID().toString();
final KvmPhysicalDisk disk = storagePoolMgr.copyPhysicalDisk(snapshot, volUuid, primaryPool, 0);
if (disk == null) {
throw new NullPointerException("Disk was not successfully copied to the new storage.");
}
return new CreateVolumeFromSnapshotAnswer(command, true, "", disk.getName());
} catch (final CloudRuntimeException e) {
return new CreateVolumeFromSnapshotAnswer(command, false, e.toString(), null);
} catch (final Exception e) {
return new CreateVolumeFromSnapshotAnswer(command, false, e.toString(), null);
}
}
Aggregations