use of com.cloud.storage.Snapshot in project CloudStack-archive by CloudStack-extras.
the class CreateSnapshotCmd method execute.
@Override
public void execute() {
UserContext.current().setEventDetails("Volume Id: " + getVolumeId());
Snapshot snapshot = _snapshotService.createSnapshot(getVolumeId(), getPolicyId(), getEntityId(), _accountService.getAccount(getEntityOwnerId()));
if (snapshot != null) {
SnapshotResponse response = _responseGenerator.createSnapshotResponse(snapshot);
response.setResponseName(getCommandName());
this.setResponseObject(response);
} else {
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to create snapshot due to an internal error creating snapshot for volume " + volumeId);
}
}
use of com.cloud.storage.Snapshot in project cloudstack by apache.
the class CreateVolumeCmdByAdmin method execute.
@Override
public void execute() {
CallContext.current().setEventDetails("Volume Id: " + getEntityId() + ((getSnapshotId() == null) ? "" : " from snapshot: " + getSnapshotId()));
Volume volume = _volumeService.createVolume(this);
if (volume != null) {
VolumeResponse response = _responseGenerator.createVolumeResponse(ResponseView.Full, volume);
//FIXME - have to be moved to ApiResponseHelper
if (getSnapshotId() != null) {
Snapshot snap = _entityMgr.findById(Snapshot.class, getSnapshotId());
if (snap != null) {
// if the volume was
response.setSnapshotId(snap.getUuid());
// created from a
// snapshot,
// snapshotId will
// be set so we pass
// it back in the
// response
}
}
response.setResponseName(getCommandName());
setResponseObject(response);
} else {
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to create a volume");
}
}
use of com.cloud.storage.Snapshot in project cosmic by MissionCriticalCloud.
the class SnapshotManagerTest method testRevertSnapshotF3.
// vm on KVM, successful
@Test
public void testRevertSnapshotF3() {
when(_vmDao.findById(anyLong())).thenReturn(vmMock);
when(vmMock.getState()).thenReturn(State.Stopped);
when(vmMock.getHypervisorType()).thenReturn(Hypervisor.HypervisorType.KVM);
when(volumeMock.getFormat()).thenReturn(ImageFormat.QCOW2);
when(snapshotStrategy.revertSnapshot(Mockito.any(SnapshotInfo.class))).thenReturn(true);
when(_volumeDao.update(anyLong(), any(VolumeVO.class))).thenReturn(true);
final Snapshot snapshot = _snapshotMgr.revertSnapshot(TEST_SNAPSHOT_ID);
Assert.assertNotNull(snapshot);
}
use of com.cloud.storage.Snapshot in project cosmic by MissionCriticalCloud.
the class SnapshotManagerTest method testRevertSnapshotF2.
// vm on Xenserver, return null
@Test
public void testRevertSnapshotF2() {
when(_vmDao.findById(anyLong())).thenReturn(vmMock);
when(vmMock.getState()).thenReturn(State.Stopped);
when(vmMock.getHypervisorType()).thenReturn(Hypervisor.HypervisorType.XenServer);
when(volumeMock.getFormat()).thenReturn(ImageFormat.VHD);
final Snapshot snapshot = _snapshotMgr.revertSnapshot(TEST_SNAPSHOT_ID);
Assert.assertNull(snapshot);
}
use of com.cloud.storage.Snapshot in project cloudstack by apache.
the class CreateSnapshotCmd method create.
@Override
public void create() throws ResourceAllocationException {
Snapshot snapshot = _volumeService.allocSnapshot(getVolumeId(), getPolicyId(), getSnapshotName(), getLocationType());
if (snapshot != null) {
setEntityId(snapshot.getId());
setEntityUuid(snapshot.getUuid());
} else {
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to create snapshot for volume" + getVolumeUuid());
}
}
Aggregations