Search in sources :

Example 41 with Template

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

the class VmMapper method map.

public static Vm map(org.ovirt.engine.core.common.businessentities.VM entity, Vm template, boolean showDynamicInfo) {
    Vm model = template != null ? template : new Vm();
    mapVmBaseEntityToModel(model, entity.getStaticData());
    if (entity.getVmtGuid() != null) {
        model.setTemplate(new Template());
        model.getTemplate().setId(entity.getVmtGuid().toString());
        // otherwise the value of this property is meaningless and misleading
        if (entity.isStateless()) {
            model.setUseLatestTemplateVersion(entity.isUseLatestVersion());
        }
    }
    if (entity.getOriginalTemplateGuid() != null) {
        model.setOriginalTemplate(new Template());
        model.getOriginalTemplate().setId(entity.getOriginalTemplateGuid().toString());
    }
    if (entity.getInstanceTypeId() != null) {
        model.setInstanceType(new InstanceType());
        model.getInstanceType().setId(entity.getInstanceTypeId().toString());
    }
    if (entity.getStatus() != null) {
        model.setStatus(mapVmStatus(entity.getStatus()));
        if (entity.getStatus() == VMStatus.Paused) {
            model.setStatusDetail(entity.getVmPauseStatus().name().toLowerCase());
        } else if (entity.getStatus() == VMStatus.Down && entity.getBackgroundOperationDescription() != null) {
            model.setStatusDetail(entity.getBackgroundOperationDescription());
        }
    }
    if (entity.getStopReason() != null) {
        model.setStopReason(entity.getStopReason());
    }
    if (entity.getBootSequence() != null || entity.getKernelUrl() != null || entity.getInitrdUrl() != null || entity.getKernelParams() != null) {
        OperatingSystem os = new OperatingSystem();
        os.setType(SimpleDependencyInjector.getInstance().get(OsRepository.class).getUniqueOsNames().get(entity.getVmOsId()));
        os.setKernel(entity.getKernelUrl());
        os.setInitrd(entity.getInitrdUrl());
        os.setCmdline(entity.getKernelParams());
        model.setOs(os);
    }
    if (entity.isUseHostCpuFlags()) {
        model.getCpu().setMode(CpuMode.HOST_PASSTHROUGH);
    }
    model.getCpu().setCpuTune(stringToCpuTune(entity.getCpuPinning()));
    model.getCpu().setArchitecture(CPUMapper.map(entity.getClusterArch(), null));
    if (entity.getVmPoolId() != null) {
        VmPool pool = new VmPool();
        pool.setId(entity.getVmPoolId().toString());
        model.setVmPool(pool);
    }
    model.setDisplay(new Display());
    // and dynamic value (current/last run value, that can be different in case of run-once or edit while running)
    if (showDynamicInfo && entity.getDynamicData() != null && entity.getStatus().isRunningOrPaused()) {
        if (model.getOs() != null && entity.getBootSequence() != null) {
            Boot boot = map(entity.getBootSequence(), null);
            model.getOs().setBoot(boot);
        }
    } else {
        if (model.getOs() != null) {
            Boot boot = map(entity.getDefaultBootSequence(), null);
            model.getOs().setBoot(boot);
        }
    }
    if (entity.hasIllegalImages()) {
        model.setHasIllegalImages(true);
    }
    // fill dynamic data
    if (entity.getDynamicData() != null && !entity.getStatus().isNotRunning()) {
        if (entity.getRunOnVds() != null) {
            model.setHost(new Host());
            model.getHost().setId(entity.getRunOnVds().toString());
        }
        final boolean hasFqdn = entity.getFqdn() != null && !entity.getFqdn().isEmpty();
        if (hasFqdn) {
            model.setFqdn(entity.getFqdn());
        }
        final boolean hasGuestOsVersion = entity.getGuestOsVersion() != null && !entity.getGuestOsVersion().isEmpty();
        if (hasGuestOsVersion) {
            GuestOperatingSystem os = model.getGuestOperatingSystem();
            if (os == null) {
                os = new GuestOperatingSystem();
                model.setGuestOperatingSystem(os);
            }
            os.setArchitecture(entity.getGuestOsArch().name());
            os.setCodename(entity.getGuestOsCodename());
            os.setDistribution(entity.getGuestOsDistribution());
            String kernelVersionString = entity.getGuestOsKernelVersion();
            if (StringUtils.isNotEmpty(kernelVersionString)) {
                org.ovirt.engine.api.model.Version kernelVersion = VersionMapper.fromVersionString(kernelVersionString);
                if (kernelVersion != null) {
                    if (os.getKernel() == null) {
                        os.setKernel(new Kernel());
                    }
                    os.getKernel().setVersion(kernelVersion);
                    os.getKernel().getVersion().setFullVersion(entity.getGuestOsKernelVersion());
                }
            }
            String osVersionString = entity.getGuestOsVersion();
            if (StringUtils.isNotEmpty(osVersionString)) {
                os.setVersion(VersionMapper.fromVersionString(osVersionString));
                if (os.getVersion() != null) {
                    os.getVersion().setFullVersion(entity.getGuestOsVersion());
                }
            }
            os.setFamily(entity.getGuestOsType().name());
        }
        final boolean hasTimezoneName = entity.getGuestOsTimezoneName() != null && !entity.getGuestOsTimezoneName().isEmpty();
        if (hasTimezoneName) {
            TimeZone guestTz = model.getGuestTimeZone();
            if (guestTz == null) {
                guestTz = new TimeZone();
                model.setGuestTimeZone(guestTz);
            }
            guestTz.setName(entity.getGuestOsTimezoneName());
            guestTz.setUtcOffset(TimeZoneMapper.mapUtcOffsetToDisplayString(entity.getGuestOsTimezoneOffset()));
        }
        if (entity.getLastStartTime() != null) {
            model.setStartTime(DateMapper.map(entity.getLastStartTime(), null));
        }
        model.setRunOnce(entity.isRunOnce());
        org.ovirt.engine.core.common.businessentities.GraphicsType graphicsType = deriveGraphicsType(entity.getGraphicsInfos());
        if (graphicsType != null) {
            model.getDisplay().setType(DisplayMapper.map(graphicsType, null));
            GraphicsInfo graphicsInfo = entity.getGraphicsInfos().get(graphicsType);
            model.getDisplay().setAddress(graphicsInfo == null ? null : graphicsInfo.getIp());
            Integer displayPort = graphicsInfo == null ? null : graphicsInfo.getPort();
            model.getDisplay().setPort(displayPort == null || displayPort.equals(-1) ? null : displayPort);
            Integer displaySecurePort = graphicsInfo == null ? null : graphicsInfo.getTlsPort();
            model.getDisplay().setSecurePort(displaySecurePort == null || displaySecurePort.equals(-1) ? null : displaySecurePort);
        }
    }
    if (entity.getLastStopTime() != null) {
        model.setStopTime(DateMapper.map(entity.getLastStopTime(), null));
    }
    model.getDisplay().setMonitors(entity.getNumOfMonitors());
    model.getDisplay().setSingleQxlPci(entity.getSingleQxlPci());
    model.getDisplay().setAllowOverride(entity.getAllowConsoleReconnect());
    model.getDisplay().setSmartcardEnabled(entity.isSmartcardEnabled());
    model.getDisplay().setKeyboardLayout(entity.getDefaultVncKeyboardLayout());
    model.getDisplay().setFileTransferEnabled(entity.isSpiceFileTransferEnabled());
    model.getDisplay().setCopyPasteEnabled(entity.isSpiceCopyPasteEnabled());
    model.getDisplay().setProxy(getEffectiveSpiceProxy(entity));
    model.getDisplay().setDisconnectAction(map(entity.getConsoleDisconnectAction(), null).toString());
    model.setStateless(entity.isStateless());
    model.setDeleteProtected(entity.isDeleteProtected());
    model.setSso(SsoMapper.map(entity.getSsoMethod(), null));
    model.setHighAvailability(new HighAvailability());
    model.getHighAvailability().setEnabled(entity.isAutoStartup());
    model.getHighAvailability().setPriority(entity.getPriority());
    if (entity.getOrigin() != null) {
        model.setOrigin(map(entity.getOrigin(), null));
    }
    if (entity.getVmInit() != null) {
        model.setInitialization(InitializationMapper.map(entity.getVmInit(), null));
    }
    model.setNextRunConfigurationExists(entity.isNextRunConfigurationExists());
    model.setNumaTuneMode(map(entity.getNumaTuneMode(), null));
    if (entity.getProviderId() != null) {
        model.setExternalHostProvider(new ExternalHostProvider());
        model.getExternalHostProvider().setId(entity.getProviderId().toString());
    }
    return model;
}
Also used : GuestOperatingSystem(org.ovirt.engine.api.model.GuestOperatingSystem) OperatingSystem(org.ovirt.engine.api.model.OperatingSystem) ExternalHostProvider(org.ovirt.engine.api.model.ExternalHostProvider) OsRepository(org.ovirt.engine.core.common.osinfo.OsRepository) GraphicsInfo(org.ovirt.engine.core.common.businessentities.GraphicsInfo) Boot(org.ovirt.engine.api.model.Boot) VmTemplate(org.ovirt.engine.core.common.businessentities.VmTemplate) Template(org.ovirt.engine.api.model.Template) Vm(org.ovirt.engine.api.model.Vm) InstanceType(org.ovirt.engine.api.model.InstanceType) Kernel(org.ovirt.engine.api.model.Kernel) GuestOperatingSystem(org.ovirt.engine.api.model.GuestOperatingSystem) Host(org.ovirt.engine.api.model.Host) HighAvailability(org.ovirt.engine.api.model.HighAvailability) TimeZone(org.ovirt.engine.api.model.TimeZone) VmPool(org.ovirt.engine.api.model.VmPool) Display(org.ovirt.engine.api.model.Display)

Example 42 with Template

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

the class LinkHelperTest method testStorageDomainTemplateLinks.

@Test
public void testStorageDomainTemplateLinks() throws Exception {
    Template template = new Template();
    template.setId(TEMPLATE_ID);
    template.setStorageDomain(new StorageDomain());
    template.getStorageDomain().setId(STORAGE_DOMAIN_ID);
    template = LinkHelper.addLinks(template);
    assertEquals(STORAGE_DOMAIN_TEMPLATE_HREF, template.getHref());
    assertEquals(STORAGE_DOMAIN_HREF, template.getStorageDomain().getHref());
}
Also used : StorageDomain(org.ovirt.engine.api.model.StorageDomain) Template(org.ovirt.engine.api.model.Template) Test(org.junit.Test)

Example 43 with Template

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

the class BackendVmsResourceTest method testAddNamedCluster.

@Test
public void testAddNamedCluster() throws Exception {
    setUriInfo(setUpBasicUriExpectations());
    setUriInfo(setUpBasicUriExpectations());
    setUpGetPayloadExpectations(1, 2);
    setUpGetBallooningExpectations(1, 2);
    setUpGetGraphicsExpectations(1);
    setUpGetConsoleExpectations(1, 2);
    setUpGetVmOvfExpectations(2);
    setUpGetVirtioScsiExpectations(2);
    setUpGetSoundcardExpectations(1, 2);
    setUpGetRngDeviceExpectations(1, 2);
    setUpGetCertuficateExpectations(1, 2);
    setUpEntityQueryExpectations(QueryType.GetVmTemplate, GetVmTemplateParameters.class, new String[] { "Id" }, new Object[] { GUIDS[1] }, getTemplateEntity(1));
    setUpEntityQueryExpectations(QueryType.GetClusterByName, NameQueryParameters.class, new String[] { "Name" }, new Object[] { NAMES[2] }, setUpCluster(GUIDS[2]));
    setUpCreationExpectations(ActionType.AddVm, AddVmParameters.class, new String[] { "StorageDomainId" }, new Object[] { GUIDS[0] }, true, true, GUIDS[2], QueryType.GetVmByVmId, IdQueryParameters.class, new String[] { "Id" }, new Object[] { GUIDS[2] }, getEntity(2));
    Vm model = getModel(2);
    model.setTemplate(new Template());
    model.getTemplate().setId(GUIDS[1].toString());
    model.setCluster(new org.ovirt.engine.api.model.Cluster());
    model.getCluster().setName(NAMES[2]);
    Response response = collection.add(model);
    assertEquals(201, response.getStatus());
    assertTrue(response.getEntity() instanceof Vm);
    verifyModel((Vm) response.getEntity(), 2);
}
Also used : Response(javax.ws.rs.core.Response) Vm(org.ovirt.engine.api.model.Vm) Template(org.ovirt.engine.api.model.Template) Test(org.junit.Test)

Example 44 with Template

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

the class BackendApiResource method createBlankTemplate.

private Template createBlankTemplate() {
    Template template = new Template();
    String id = "00000000-0000-0000-0000-000000000000";
    template.setId(id);
    template.setHref(getAbsolutePath("templates", id));
    return template;
}
Also used : Template(org.ovirt.engine.api.model.Template)

Example 45 with Template

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

the class PermissionMapper method setObjectId.

/**
 * Completeness of "{entityType}.id" already validated
 */
private static void setObjectId(Permission model, org.ovirt.engine.core.common.businessentities.Permission entity) {
    String id = entity.getObjectId().toString();
    switch(entity.getObjectType()) {
        case System:
            break;
        case StoragePool:
            model.setDataCenter(new DataCenter());
            model.getDataCenter().setId(id);
            break;
        case Cluster:
            model.setCluster(new Cluster());
            model.getCluster().setId(id);
            break;
        case VDS:
            model.setHost(new Host());
            model.getHost().setId(id);
            break;
        case Storage:
            model.setStorageDomain(new StorageDomain());
            model.getStorageDomain().setId(id);
            break;
        case VM:
            model.setVm(new Vm());
            model.getVm().setId(id);
            break;
        case VmPool:
            model.setVmPool(new VmPool());
            model.getVmPool().setId(id);
            break;
        case VmTemplate:
            model.setTemplate(new Template());
            model.getTemplate().setId(id);
            break;
        case Disk:
            model.setDisk(new Disk());
            model.getDisk().setId(id);
            break;
        default:
            assert false;
    }
}
Also used : StorageDomain(org.ovirt.engine.api.model.StorageDomain) DataCenter(org.ovirt.engine.api.model.DataCenter) VmPool(org.ovirt.engine.api.model.VmPool) Vm(org.ovirt.engine.api.model.Vm) Cluster(org.ovirt.engine.api.model.Cluster) Host(org.ovirt.engine.api.model.Host) Disk(org.ovirt.engine.api.model.Disk) Template(org.ovirt.engine.api.model.Template)

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