Search in sources :

Example 1 with CreateVolumeFromSnapshotAnswer

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);
    }
}
Also used : KvmStoragePool(com.cloud.agent.resource.kvm.storage.KvmStoragePool) CloudRuntimeException(com.cloud.legacymodel.exceptions.CloudRuntimeException) KvmStoragePoolManager(com.cloud.agent.resource.kvm.storage.KvmStoragePoolManager) KvmPhysicalDisk(com.cloud.agent.resource.kvm.storage.KvmPhysicalDisk) StorageFilerTO(com.cloud.legacymodel.to.StorageFilerTO) CloudRuntimeException(com.cloud.legacymodel.exceptions.CloudRuntimeException) CreateVolumeFromSnapshotAnswer(com.cloud.legacymodel.communication.answer.CreateVolumeFromSnapshotAnswer)

Aggregations

KvmPhysicalDisk (com.cloud.agent.resource.kvm.storage.KvmPhysicalDisk)1 KvmStoragePool (com.cloud.agent.resource.kvm.storage.KvmStoragePool)1 KvmStoragePoolManager (com.cloud.agent.resource.kvm.storage.KvmStoragePoolManager)1 CreateVolumeFromSnapshotAnswer (com.cloud.legacymodel.communication.answer.CreateVolumeFromSnapshotAnswer)1 CloudRuntimeException (com.cloud.legacymodel.exceptions.CloudRuntimeException)1 StorageFilerTO (com.cloud.legacymodel.to.StorageFilerTO)1