Search in sources :

Example 1 with VMSnapshotResponse

use of org.apache.cloudstack.api.response.VMSnapshotResponse in project cloudstack by apache.

the class CreateVMSnapshotCmd method execute.

@Override
public void execute() {
    CallContext.current().setEventDetails("VM Id: " + this._uuidMgr.getUuid(VirtualMachine.class, getVmId()));
    VMSnapshot result = _vmSnapshotService.createVMSnapshot(getVmId(), getEntityId(), getQuiescevm());
    if (result != null) {
        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(org.apache.cloudstack.api.ServerApiException) VMSnapshotResponse(org.apache.cloudstack.api.response.VMSnapshotResponse) VMSnapshot(com.cloud.vm.snapshot.VMSnapshot)

Example 2 with VMSnapshotResponse

use of org.apache.cloudstack.api.response.VMSnapshotResponse in project cloudstack by apache.

the class ListVMSnapshotCmd method execute.

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

Example 3 with VMSnapshotResponse

use of org.apache.cloudstack.api.response.VMSnapshotResponse in project cloudstack by apache.

the class ApiResponseHelper method createVMSnapshotResponse.

@Override
public VMSnapshotResponse createVMSnapshotResponse(VMSnapshot vmSnapshot) {
    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());
    UserVm vm = ApiDBUtils.findUserVmById(vmSnapshot.getVmId());
    if (vm != null) {
        vmSnapshotResponse.setVirtualMachineId(vm.getUuid());
        vmSnapshotResponse.setVirtualMachineName(StringUtils.isEmpty(vm.getDisplayName()) ? vm.getHostName() : vm.getDisplayName());
        vmSnapshotResponse.setHypervisor(vm.getHypervisorType());
        DataCenterVO datacenter = ApiDBUtils.findZoneById(vm.getDataCenterId());
        if (datacenter != null) {
            vmSnapshotResponse.setZoneId(datacenter.getUuid());
            vmSnapshotResponse.setZoneName(datacenter.getName());
        }
    }
    if (vmSnapshot.getParent() != null) {
        VMSnapshot vmSnapshotParent = ApiDBUtils.getVMSnapshotById(vmSnapshot.getParent());
        if (vmSnapshotParent != null) {
            vmSnapshotResponse.setParent(vmSnapshotParent.getUuid());
            vmSnapshotResponse.setParentName(vmSnapshotParent.getDisplayName());
        }
    }
    populateOwner(vmSnapshotResponse, vmSnapshot);
    Project project = ApiDBUtils.findProjectByProjectAccountId(vmSnapshot.getAccountId());
    if (project != null) {
        vmSnapshotResponse.setProjectId(project.getUuid());
        vmSnapshotResponse.setProjectName(project.getName());
    }
    Account account = ApiDBUtils.findAccountById(vmSnapshot.getAccountId());
    if (account != null) {
        vmSnapshotResponse.setAccountName(account.getAccountName());
    }
    DomainVO domain = ApiDBUtils.findDomainById(vmSnapshot.getDomainId());
    if (domain != null) {
        vmSnapshotResponse.setDomainId(domain.getUuid());
        vmSnapshotResponse.setDomainName(domain.getName());
    }
    List<? extends ResourceTag> tags = _resourceTagDao.listBy(vmSnapshot.getId(), ResourceObjectType.VMSnapshot);
    List<ResourceTagResponse> tagResponses = new ArrayList<ResourceTagResponse>();
    for (ResourceTag tag : tags) {
        ResourceTagResponse tagResponse = createResourceTagResponse(tag, false);
        CollectionUtils.addIgnoreNull(tagResponses, tagResponse);
    }
    vmSnapshotResponse.setTags(new HashSet<>(tagResponses));
    vmSnapshotResponse.setHasAnnotation(annotationDao.hasAnnotations(vmSnapshot.getUuid(), AnnotationService.EntityType.VM_SNAPSHOT.name(), _accountMgr.isRootAdmin(CallContext.current().getCallingAccount().getId())));
    vmSnapshotResponse.setCurrent(vmSnapshot.getCurrent());
    vmSnapshotResponse.setType(vmSnapshot.getType().toString());
    vmSnapshotResponse.setObjectName("vmsnapshot");
    return vmSnapshotResponse;
}
Also used : DataCenterVO(com.cloud.dc.DataCenterVO) ProjectAccount(com.cloud.projects.ProjectAccount) UserAccount(com.cloud.user.UserAccount) Account(com.cloud.user.Account) ArrayList(java.util.ArrayList) VMSnapshot(com.cloud.vm.snapshot.VMSnapshot) Project(com.cloud.projects.Project) DomainVO(com.cloud.domain.DomainVO) UserVm(com.cloud.uservm.UserVm) ResourceTag(com.cloud.server.ResourceTag) VMSnapshotResponse(org.apache.cloudstack.api.response.VMSnapshotResponse) ResourceTagResponse(org.apache.cloudstack.api.response.ResourceTagResponse)

Aggregations

VMSnapshot (com.cloud.vm.snapshot.VMSnapshot)3 VMSnapshotResponse (org.apache.cloudstack.api.response.VMSnapshotResponse)3 ArrayList (java.util.ArrayList)2 DataCenterVO (com.cloud.dc.DataCenterVO)1 DomainVO (com.cloud.domain.DomainVO)1 Project (com.cloud.projects.Project)1 ProjectAccount (com.cloud.projects.ProjectAccount)1 ResourceTag (com.cloud.server.ResourceTag)1 Account (com.cloud.user.Account)1 UserAccount (com.cloud.user.UserAccount)1 UserVm (com.cloud.uservm.UserVm)1 List (java.util.List)1 ServerApiException (org.apache.cloudstack.api.ServerApiException)1 ListResponse (org.apache.cloudstack.api.response.ListResponse)1 ResourceTagResponse (org.apache.cloudstack.api.response.ResourceTagResponse)1