Search in sources :

Example 1 with Template

use of org.ovirt.engine.api.model.Template in project ovirt-engine by oVirt.

the class TemplateMapper method map.

@Mapping(from = VmTemplate.class, to = Template.class)
public static Template map(VmTemplate entity, Template incoming) {
    Template model = incoming != null ? incoming : new Template();
    mapVmBaseEntityToModel(model, entity);
    if (entity.getVmInit() != null) {
        model.setInitialization(InitializationMapper.map(entity.getVmInit(), null));
    }
    if (entity.getStatus() != null) {
        model.setStatus(mapTemplateStatus(entity.getStatus()));
    }
    if (entity.getDefaultBootSequence() != null || entity.getKernelUrl() != null || entity.getInitrdUrl() != null || entity.getKernelParams() != null) {
        OperatingSystem os = new OperatingSystem();
        os.setType(SimpleDependencyInjector.getInstance().get(OsRepository.class).getUniqueOsNames().get(entity.getOsId()));
        if (entity.getDefaultBootSequence() != null) {
            Boot boot = VmMapper.map(entity.getDefaultBootSequence(), null);
            os.setBoot(boot);
        }
        os.setKernel(entity.getKernelUrl());
        os.setInitrd(entity.getInitrdUrl());
        os.setCmdline(entity.getKernelParams());
        model.setOs(os);
    }
    if (entity.getClusterArch() != null) {
        model.getCpu().setArchitecture(CPUMapper.map(entity.getClusterArch(), null));
    }
    model.setDisplay(DisplayMapper.map(entity, null));
    model.getDisplay().setDisconnectAction(map(entity.getConsoleDisconnectAction(), null).toString());
    TemplateVersion version = new TemplateVersion();
    version.setVersionName(entity.getTemplateVersionName());
    version.setVersionNumber(entity.getTemplateVersionNumber());
    Template baseTemplate = new Template();
    baseTemplate.setId(entity.getBaseTemplateId().toString());
    version.setBaseTemplate(baseTemplate);
    model.setVersion(version);
    return model;
}
Also used : OperatingSystem(org.ovirt.engine.api.model.OperatingSystem) OsRepository(org.ovirt.engine.core.common.osinfo.OsRepository) TemplateVersion(org.ovirt.engine.api.model.TemplateVersion) Boot(org.ovirt.engine.api.model.Boot) Template(org.ovirt.engine.api.model.Template) VmTemplate(org.ovirt.engine.core.common.businessentities.VmTemplate)

Example 2 with Template

use of org.ovirt.engine.api.model.Template in project ovirt-engine by oVirt.

the class BackendTemplateCdromResource method addParents.

@Override
public Cdrom addParents(Cdrom entity) {
    Template template = new Template();
    template.setId(templateId.toString());
    entity.setTemplate(template);
    return entity;
}
Also used : Template(org.ovirt.engine.api.model.Template) VmTemplate(org.ovirt.engine.core.common.businessentities.VmTemplate)

Example 3 with Template

use of org.ovirt.engine.api.model.Template in project ovirt-engine by oVirt.

the class BackendTemplateCdromsResource method addParents.

@Override
public Cdrom addParents(Cdrom entity) {
    Template template = new Template();
    template.setId(templateId.toString());
    entity.setTemplate(template);
    return entity;
}
Also used : Template(org.ovirt.engine.api.model.Template) VmTemplate(org.ovirt.engine.core.common.businessentities.VmTemplate)

Example 4 with Template

use of org.ovirt.engine.api.model.Template in project ovirt-engine by oVirt.

the class BackendTemplateResourceTest method testGetConsoleAware.

public void testGetConsoleAware(boolean allContent) throws Exception {
    setUriInfo(setUpBasicUriExpectations());
    setUpGetEntityExpectations(1);
    setUpGetBallooningExpectations();
    if (allContent) {
        List<String> populates = new ArrayList<>();
        populates.add("true");
        when(httpHeaders.getRequestHeader(BackendResource.POPULATE)).thenReturn(populates);
        setUpGetConsoleExpectations(0);
        setUpGetVirtioScsiExpectations(0);
        setUpGetSoundcardExpectations(0);
        setUpGetRngDeviceExpectations(0);
    }
    setUpGetGraphicsExpectations(1);
    Template response = resource.get();
    verifyModel(response, 0);
    List<String> populateHeader = httpHeaders.getRequestHeader(BackendResource.POPULATE);
    boolean populated = populateHeader != null ? populateHeader.contains("true") : false;
    assertTrue(populated ? response.isSetConsole() : !response.isSetConsole());
}
Also used : ArrayList(java.util.ArrayList) Template(org.ovirt.engine.api.model.Template) VmTemplate(org.ovirt.engine.core.common.businessentities.VmTemplate)

Example 5 with Template

use of org.ovirt.engine.api.model.Template in project ovirt-engine by oVirt.

the class BackendTemplateResourceTest method testUpdateUploadIcon.

@Test
public void testUpdateUploadIcon() throws Exception {
    setUpGetGraphicsExpectations(1);
    setUpGetBallooningExpectations();
    setUpUpdateExpectations();
    setUriInfo(setUpActionExpectations(ActionType.UpdateVmTemplate, UpdateVmTemplateParameters.class, new String[] { "VmLargeIcon" }, new Object[] { VmIcon.typeAndDataToDataUrl(IconTestHelpler.MEDIA_TYPE, IconTestHelpler.DATA_URL) }, true, true));
    final Template model = getRestModel(0);
    model.setLargeIcon(IconTestHelpler.createIconWithData());
    verifyModel(resource.update(model), 0);
}
Also used : UpdateVmTemplateParameters(org.ovirt.engine.core.common.action.UpdateVmTemplateParameters) Template(org.ovirt.engine.api.model.Template) VmTemplate(org.ovirt.engine.core.common.businessentities.VmTemplate) Test(org.junit.Test)

Aggregations

Template (org.ovirt.engine.api.model.Template)57 VmTemplate (org.ovirt.engine.core.common.businessentities.VmTemplate)32 Test (org.junit.Test)21 Response (javax.ws.rs.core.Response)16 AsyncTaskStatus (org.ovirt.engine.core.common.businessentities.AsyncTaskStatus)12 Vm (org.ovirt.engine.api.model.Vm)11 WebApplicationException (javax.ws.rs.WebApplicationException)6 VmPool (org.ovirt.engine.api.model.VmPool)4 Cluster (org.ovirt.engine.api.model.Cluster)3 InstanceType (org.ovirt.engine.api.model.InstanceType)3 TimeZone (org.ovirt.engine.api.model.TimeZone)3 GetVmTemplateParameters (org.ovirt.engine.core.common.queries.GetVmTemplateParameters)3 ArrayList (java.util.ArrayList)2 Boot (org.ovirt.engine.api.model.Boot)2 Host (org.ovirt.engine.api.model.Host)2 OperatingSystem (org.ovirt.engine.api.model.OperatingSystem)2 StorageDomain (org.ovirt.engine.api.model.StorageDomain)2 Tag (org.ovirt.engine.api.model.Tag)2 TemplateVersion (org.ovirt.engine.api.model.TemplateVersion)2 Templates (org.ovirt.engine.api.model.Templates)2