Search in sources :

Example 1 with VMSnapshotResponse

use of com.cloud.api.response.VMSnapshotResponse in project cosmic by MissionCriticalCloud.

the class ListVMSnapshotCmd method execute.

@Override
public void execute() {
    final List<? extends VMSnapshot> result = _vmSnapshotService.listVMSnapshots(this);
    final ListResponse<VMSnapshotResponse> response = new ListResponse<>();
    final List<VMSnapshotResponse> snapshotResponses = new ArrayList<>();
    for (final VMSnapshot r : result) {
        final VMSnapshotResponse vmSnapshotResponse = _responseGenerator.createVMSnapshotResponse(r);
        vmSnapshotResponse.setObjectName("vmSnapshot");
        snapshotResponses.add(vmSnapshotResponse);
    }
    response.setResponses(snapshotResponses);
    response.setResponseName(getCommandName());
    setResponseObject(response);
}
Also used : ListResponse(com.cloud.api.response.ListResponse) VMSnapshotResponse(com.cloud.api.response.VMSnapshotResponse) ArrayList(java.util.ArrayList) VMSnapshot(com.cloud.vm.snapshot.VMSnapshot)

Example 2 with VMSnapshotResponse

use of com.cloud.api.response.VMSnapshotResponse in project cosmic by MissionCriticalCloud.

the class CreateVMSnapshotCmd method execute.

@Override
public void execute() {
    CallContext.current().setEventDetails("VM Id: " + getVmId());
    final VMSnapshot result = _vmSnapshotService.createVMSnapshot(getVmId(), getEntityId(), isQuiescevm());
    if (result != null) {
        final VMSnapshotResponse response = _responseGenerator.createVMSnapshotResponse(result);
        response.setResponseName(getCommandName());
        setResponseObject(response);
    } else {
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to create vm snapshot due to an internal error creating snapshot for vm " + getVmId());
    }
}
Also used : ServerApiException(com.cloud.api.ServerApiException) VMSnapshotResponse(com.cloud.api.response.VMSnapshotResponse) VMSnapshot(com.cloud.vm.snapshot.VMSnapshot)

Example 3 with VMSnapshotResponse

use of com.cloud.api.response.VMSnapshotResponse in project cosmic by MissionCriticalCloud.

the class ApiResponseHelper method createVMSnapshotResponse.

@Override
public VMSnapshotResponse createVMSnapshotResponse(final VMSnapshot vmSnapshot) {
    final VMSnapshotResponse vmSnapshotResponse = new VMSnapshotResponse();
    vmSnapshotResponse.setId(vmSnapshot.getUuid());
    vmSnapshotResponse.setName(vmSnapshot.getName());
    vmSnapshotResponse.setState(vmSnapshot.getState());
    vmSnapshotResponse.setCreated(vmSnapshot.getCreated());
    vmSnapshotResponse.setDescription(vmSnapshot.getDescription());
    vmSnapshotResponse.setDisplayName(vmSnapshot.getDisplayName());
    final UserVm vm = ApiDBUtils.findUserVmById(vmSnapshot.getVmId());
    if (vm != null) {
        vmSnapshotResponse.setVirtualMachineid(vm.getUuid());
    }
    if (vmSnapshot.getParent() != null) {
        final VMSnapshot vmSnapshotParent = ApiDBUtils.getVMSnapshotById(vmSnapshot.getParent());
        if (vmSnapshotParent != null) {
            vmSnapshotResponse.setParent(vmSnapshotParent.getUuid());
            vmSnapshotResponse.setParentName(vmSnapshotParent.getDisplayName());
        }
    }
    populateOwner(vmSnapshotResponse, vmSnapshot);
    final Project project = ApiDBUtils.findProjectByProjectAccountId(vmSnapshot.getAccountId());
    if (project != null) {
        vmSnapshotResponse.setProjectId(project.getUuid());
        vmSnapshotResponse.setProjectName(project.getName());
    }
    vmSnapshotResponse.setCurrent(vmSnapshot.getCurrent());
    vmSnapshotResponse.setType(vmSnapshot.getType().toString());
    vmSnapshotResponse.setObjectName("vmsnapshot");
    return vmSnapshotResponse;
}
Also used : Project(com.cloud.projects.Project) UserVm(com.cloud.uservm.UserVm) VMSnapshotResponse(com.cloud.api.response.VMSnapshotResponse) VMSnapshot(com.cloud.vm.snapshot.VMSnapshot)

Aggregations

VMSnapshotResponse (com.cloud.api.response.VMSnapshotResponse)3 VMSnapshot (com.cloud.vm.snapshot.VMSnapshot)3 ServerApiException (com.cloud.api.ServerApiException)1 ListResponse (com.cloud.api.response.ListResponse)1 Project (com.cloud.projects.Project)1 UserVm (com.cloud.uservm.UserVm)1 ArrayList (java.util.ArrayList)1