Search in sources :

Example 21 with TemplateResponse

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

the class TemplateJoinDaoImpl method newUpdateResponse.

// TODO: This is to keep compatibility with 4.1 API, where updateTemplateCmd and updateIsoCmd will return a simpler TemplateResponse
// compared to listTemplates and listIsos.
@Override
public TemplateResponse newUpdateResponse(final TemplateJoinVO result) {
    final TemplateResponse response = new TemplateResponse();
    response.setId(result.getUuid());
    response.setName(result.getName());
    response.setDisplayText(result.getDisplayText());
    response.setPublic(result.isPublicTemplate());
    response.setCreated(result.getCreated());
    response.setFormat(result.getFormat());
    response.setOsTypeId(result.getGuestOSUuid());
    response.setOsTypeName(result.getGuestOSName());
    response.setBootable(result.isBootable());
    response.setHypervisor(result.getHypervisorType().toString());
    // populate owner.
    ApiResponseHelper.populateOwner(response, result);
    // populate domain
    response.setDomainId(result.getDomainUuid());
    response.setDomainName(result.getDomainName());
    // set details map
    if (result.getDetailName() != null) {
        final Map<String, String> details = new HashMap<>();
        details.put(result.getDetailName(), result.getDetailValue());
        response.setDetails(details);
    }
    // update tag information
    final long tag_id = result.getTagId();
    if (tag_id > 0) {
        final ResourceTagJoinVO vtag = ApiDBUtils.findResourceTagViewById(tag_id);
        if (vtag != null) {
            response.addTag(ApiDBUtils.newResourceTagResponse(vtag, false));
        }
    }
    response.setObjectName("iso");
    return response;
}
Also used : HashMap(java.util.HashMap) TemplateResponse(com.cloud.api.response.TemplateResponse) ResourceTagJoinVO(com.cloud.api.query.vo.ResourceTagJoinVO)

Example 22 with TemplateResponse

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

the class CreateTemplateCmd method execute.

@Override
public void execute() {
    CallContext.current().setEventDetails("Template Id: " + getEntityId() + (getSnapshotId() == null ? " from volume Id: " + getVolumeId() : " from snapshot Id: " + getSnapshotId()));
    VirtualMachineTemplate template = null;
    template = _templateService.createPrivateTemplate(this);
    if (template != null) {
        final List<TemplateResponse> templateResponses = _responseGenerator.createTemplateResponses(ResponseView.Restricted, template.getId(), snapshotId, volumeId, false);
        TemplateResponse response = new TemplateResponse();
        if (templateResponses != null && !templateResponses.isEmpty()) {
            response = templateResponses.get(0);
        }
        response.setResponseName(getCommandName());
        setResponseObject(response);
    } else {
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to create private template");
    }
}
Also used : VirtualMachineTemplate(com.cloud.template.VirtualMachineTemplate) ServerApiException(com.cloud.api.ServerApiException) TemplateResponse(com.cloud.api.response.TemplateResponse)

Example 23 with TemplateResponse

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

the class RegisterTemplateCmd method execute.

@Override
public void execute() throws ResourceAllocationException {
    try {
        final VirtualMachineTemplate template = _templateService.registerTemplate(this);
        if (template != null) {
            final ListResponse<TemplateResponse> response = new ListResponse<>();
            final List<TemplateResponse> templateResponses = _responseGenerator.createTemplateResponses(ResponseView.Restricted, template, zoneId, false);
            response.setResponses(templateResponses);
            response.setResponseName(getCommandName());
            setResponseObject(response);
        } else {
            throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to register template");
        }
    } catch (final URISyntaxException ex1) {
        s_logger.info(ex1.toString());
        throw new ServerApiException(ApiErrorCode.PARAM_ERROR, ex1.getMessage());
    }
}
Also used : VirtualMachineTemplate(com.cloud.template.VirtualMachineTemplate) ListResponse(com.cloud.api.response.ListResponse) ServerApiException(com.cloud.api.ServerApiException) TemplateResponse(com.cloud.api.response.TemplateResponse) URISyntaxException(java.net.URISyntaxException)

Example 24 with TemplateResponse

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

the class UpdateTemplateCmd method execute.

@Override
public void execute() {
    final VirtualMachineTemplate result = _templateService.updateTemplate(this);
    if (result != null) {
        final TemplateResponse response = _responseGenerator.createTemplateUpdateResponse(ResponseView.Restricted, result);
        response.setObjectName("template");
        // Template can be either USER or ROUTING type
        response.setTemplateType(result.getTemplateType().toString());
        response.setResponseName(getCommandName());
        setResponseObject(response);
    } else {
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to update template");
    }
}
Also used : VirtualMachineTemplate(com.cloud.template.VirtualMachineTemplate) ServerApiException(com.cloud.api.ServerApiException) TemplateResponse(com.cloud.api.response.TemplateResponse)

Example 25 with TemplateResponse

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

the class RegisterIsoCmd method execute.

// ///////////////////////////////////////////////////
// ///////////// API Implementation///////////////////
// ///////////////////////////////////////////////////
@Override
public void execute() throws ResourceAllocationException {
    final VirtualMachineTemplate template = _templateService.registerIso(this);
    if (template != null) {
        final ListResponse<TemplateResponse> response = new ListResponse<>();
        final List<TemplateResponse> templateResponses = _responseGenerator.createIsoResponses(ResponseView.Restricted, template, zoneId, false);
        response.setResponses(templateResponses);
        response.setResponseName(getCommandName());
        setResponseObject(response);
    } else {
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to register ISO");
    }
}
Also used : VirtualMachineTemplate(com.cloud.template.VirtualMachineTemplate) ListResponse(com.cloud.api.response.ListResponse) ServerApiException(com.cloud.api.ServerApiException) TemplateResponse(com.cloud.api.response.TemplateResponse)

Aggregations

TemplateResponse (com.cloud.api.response.TemplateResponse)28 VirtualMachineTemplate (com.cloud.template.VirtualMachineTemplate)20 ServerApiException (com.cloud.api.ServerApiException)18 ListResponse (com.cloud.api.response.ListResponse)10 TemplateJoinVO (com.cloud.api.query.vo.TemplateJoinVO)5 ArrayList (java.util.ArrayList)5 ResourceTagJoinVO (com.cloud.api.query.vo.ResourceTagJoinVO)3 StorageUnavailableException (com.cloud.exception.StorageUnavailableException)3 URISyntaxException (java.net.URISyntaxException)3 ResponseView (com.cloud.api.ResponseObject.ResponseView)2 Account (com.cloud.user.Account)2 HashMap (java.util.HashMap)2 Hashtable (java.util.Hashtable)2 List (java.util.List)2 ListIsosCmdByAdmin (com.cloud.api.command.admin.iso.ListIsosCmdByAdmin)1 ListTemplatesCmdByAdmin (com.cloud.api.command.admin.template.ListTemplatesCmdByAdmin)1 LinkedHashMap (java.util.LinkedHashMap)1