use of com.cloud.agent.api.CreateVolumeFromSnapshotAnswer in project cloudstack by apache.
the class VmwareResource method execute.
protected Answer execute(CreateVolumeFromSnapshotCommand cmd) {
String details = null;
boolean success = false;
String newVolumeName = UUID.randomUUID().toString();
try {
VmwareContext context = getServiceContext();
VmwareManager mgr = context.getStockObject(VmwareManager.CONTEXT_STOCK_NAME);
return mgr.getStorageManager().execute(this, cmd);
} catch (Throwable e) {
details = createLogMessageException(e, cmd);
}
return new CreateVolumeFromSnapshotAnswer(cmd, success, details, newVolumeName);
}
use of com.cloud.agent.api.CreateVolumeFromSnapshotAnswer in project cloudstack by apache.
the class MockStorageManagerImpl method CreateVolumeFromSnapshot.
@Override
public CreateVolumeFromSnapshotAnswer CreateVolumeFromSnapshot(CreateVolumeFromSnapshotCommand cmd) {
TransactionLegacy txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
MockVolumeVO backSnapshot = null;
MockStoragePoolVO primary = null;
try {
txn.start();
backSnapshot = _mockVolumeDao.findByName(cmd.getSnapshotUuid());
if (backSnapshot == null) {
return new CreateVolumeFromSnapshotAnswer(cmd, false, "can't find the backupsnapshot: " + cmd.getSnapshotUuid(), null);
}
primary = _mockStoragePoolDao.findByUuid(cmd.getPrimaryStoragePoolNameLabel());
if (primary == null) {
return new CreateVolumeFromSnapshotAnswer(cmd, false, "can't find the primary storage: " + cmd.getPrimaryStoragePoolNameLabel(), null);
}
txn.commit();
} catch (Exception ex) {
txn.rollback();
throw new CloudRuntimeException("Error when creating volume from snapshot", ex);
} finally {
txn.close();
txn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
txn.close();
}
String uuid = UUID.randomUUID().toString();
MockVolumeVO volume = new MockVolumeVO();
volume.setName(uuid);
volume.setPath(primary.getMountPoint() + uuid);
volume.setPoolId(primary.getId());
volume.setSize(backSnapshot.getSize());
volume.setStatus(Status.DOWNLOADED);
volume.setType(MockVolumeType.VOLUME);
txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
try {
txn.start();
_mockVolumeDao.persist(volume);
txn.commit();
} catch (Exception ex) {
txn.rollback();
throw new CloudRuntimeException("Error when creating volume from snapshot " + volume, ex);
} finally {
txn.close();
txn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
txn.close();
}
return new CreateVolumeFromSnapshotAnswer(cmd, true, null, volume.getPath());
}
use of com.cloud.agent.api.CreateVolumeFromSnapshotAnswer in project CloudStack-archive by CloudStack-extras.
the class MockStorageManagerImpl method CreateVolumeFromSnapshot.
@Override
public CreateVolumeFromSnapshotAnswer CreateVolumeFromSnapshot(CreateVolumeFromSnapshotCommand cmd) {
MockVolumeVO backSnapshot = _mockVolumeDao.findByName(cmd.getSnapshotUuid());
if (backSnapshot == null) {
return new CreateVolumeFromSnapshotAnswer(cmd, false, "can't find the backupsnapshot: " + cmd.getSnapshotUuid(), null);
}
MockStoragePoolVO primary = _mockStoragePoolDao.findByUuid(cmd.getPrimaryStoragePoolNameLabel());
if (primary == null) {
return new CreateVolumeFromSnapshotAnswer(cmd, false, "can't find the primary storage: " + cmd.getPrimaryStoragePoolNameLabel(), null);
}
String uuid = UUID.randomUUID().toString();
MockVolumeVO volume = new MockVolumeVO();
volume.setName(uuid);
volume.setPath(primary.getMountPoint() + uuid);
volume.setPoolId(primary.getId());
volume.setSize(backSnapshot.getSize());
volume.setStatus(Status.DOWNLOADED);
volume.setType(MockVolumeType.VOLUME);
_mockVolumeDao.persist(volume);
return new CreateVolumeFromSnapshotAnswer(cmd, true, null, volume.getPath());
}
use of com.cloud.agent.api.CreateVolumeFromSnapshotAnswer in project CloudStack-archive by CloudStack-extras.
the class LibvirtComputingResource method execute.
protected CreateVolumeFromSnapshotAnswer execute(final CreateVolumeFromSnapshotCommand cmd) {
try {
String snapshotPath = cmd.getSnapshotUuid();
int index = snapshotPath.lastIndexOf("/");
snapshotPath = snapshotPath.substring(0, index);
KVMStoragePool secondaryPool = _storagePoolMgr.getStoragePoolByURI(cmd.getSecondaryStorageUrl() + snapshotPath);
KVMPhysicalDisk snapshot = secondaryPool.getPhysicalDisk(cmd.getSnapshotName());
String primaryUuid = cmd.getPrimaryStoragePoolNameLabel();
KVMStoragePool primaryPool = _storagePoolMgr.getStoragePool(primaryUuid);
String volUuid = UUID.randomUUID().toString();
KVMPhysicalDisk disk = _storagePoolMgr.copyPhysicalDisk(snapshot, volUuid, primaryPool);
return new CreateVolumeFromSnapshotAnswer(cmd, true, "", disk.getName());
} catch (CloudRuntimeException e) {
return new CreateVolumeFromSnapshotAnswer(cmd, false, e.toString(), null);
}
}
use of com.cloud.agent.api.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