Search in sources :

Example 1 with Boot

use of org.ovirt.engine.api.model.Boot 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 Boot

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

the class V3OperatingSystemOutAdapter method adapt.

@Override
public V3OperatingSystem adapt(OperatingSystem from) {
    V3OperatingSystem to = new V3OperatingSystem();
    Boot fromBoot = from.getBoot();
    if (fromBoot != null) {
        if (fromBoot.isSetDevices()) {
            List<V3Boot> toBoot = to.getBoot();
            fromBoot.getDevices().getDevices().forEach(device -> {
                V3Boot boot = new V3Boot();
                boot.setDev(device.value());
                toBoot.add(boot);
            });
        }
    }
    if (from.isSetCmdline()) {
        to.setCmdline(from.getCmdline());
    }
    if (from.isSetInitrd()) {
        to.setInitrd(from.getInitrd());
    }
    if (from.isSetKernel()) {
        to.setKernel(from.getKernel());
    }
    if (from.isSetType()) {
        to.setType(from.getType());
    }
    if (from.isSetVersion()) {
        to.setVersion(adaptOut(from.getVersion()));
    }
    return to;
}
Also used : V3Boot(org.ovirt.engine.api.v3.types.V3Boot) V3OperatingSystem(org.ovirt.engine.api.v3.types.V3OperatingSystem) V3Boot(org.ovirt.engine.api.v3.types.V3Boot) Boot(org.ovirt.engine.api.model.Boot)

Example 3 with Boot

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

the class VmMapper method map.

@Mapping(from = BootSequence.class, to = Boot.class)
public static Boot map(BootSequence bootSequence, Boot template) {
    Boot boot = template != null ? template : new Boot();
    Boot.DevicesList list = new Boot.DevicesList();
    boot.setDevices(list);
    List<BootDevice> devices = list.getDevices();
    switch(bootSequence) {
        case C:
            devices.add(BootDevice.HD);
            break;
        case DC:
            devices.add(BootDevice.CDROM);
            devices.add(BootDevice.HD);
            break;
        case N:
            devices.add(BootDevice.NETWORK);
            break;
        case CDN:
            devices.add(BootDevice.HD);
            devices.add(BootDevice.CDROM);
            devices.add(BootDevice.NETWORK);
            break;
        case CND:
            devices.add(BootDevice.HD);
            devices.add(BootDevice.NETWORK);
            devices.add(BootDevice.CDROM);
            break;
        case DCN:
            devices.add(BootDevice.CDROM);
            devices.add(BootDevice.HD);
            devices.add(BootDevice.NETWORK);
            break;
        case DNC:
            devices.add(BootDevice.CDROM);
            devices.add(BootDevice.NETWORK);
            devices.add(BootDevice.HD);
            break;
        case NCD:
            devices.add(BootDevice.NETWORK);
            devices.add(BootDevice.HD);
            devices.add(BootDevice.CDROM);
            break;
        case NDC:
            devices.add(BootDevice.NETWORK);
            devices.add(BootDevice.CDROM);
            devices.add(BootDevice.HD);
            break;
        case CD:
            devices.add(BootDevice.HD);
            devices.add(BootDevice.CDROM);
            break;
        case D:
            devices.add(BootDevice.CDROM);
            break;
        case CN:
            devices.add(BootDevice.HD);
            devices.add(BootDevice.NETWORK);
            break;
        case DN:
            devices.add(BootDevice.CDROM);
            devices.add(BootDevice.NETWORK);
            break;
        case NC:
            devices.add(BootDevice.NETWORK);
            devices.add(BootDevice.HD);
            break;
        case ND:
            devices.add(BootDevice.NETWORK);
            devices.add(BootDevice.CDROM);
            break;
    }
    return boot;
}
Also used : BootDevice(org.ovirt.engine.api.model.BootDevice) Boot(org.ovirt.engine.api.model.Boot)

Example 4 with Boot

use of org.ovirt.engine.api.model.Boot 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 5 with Boot

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

the class VmBaseMapper method mapCommonModelToEntity.

/**
 * Common for VM, template and instance type
 */
protected static void mapCommonModelToEntity(org.ovirt.engine.core.common.businessentities.VmBase entity, VmBase model) {
    if (model.isSetName()) {
        entity.setName(model.getName());
    }
    if (model.isSetMemory()) {
        entity.setMemSizeMb((int) (model.getMemory() / BYTES_PER_MB));
    }
    if (model.isSetIo() && model.getIo().isSetThreads()) {
        entity.setNumOfIoThreads(model.getIo().getThreads());
    }
    if (model.isSetDescription()) {
        entity.setDescription(model.getDescription());
    }
    if (model.isSetCpu() && model.getCpu().isSetTopology()) {
        if (model.getCpu().getTopology().getCores() != null) {
            entity.setCpuPerSocket(model.getCpu().getTopology().getCores());
        }
        if (model.getCpu().getTopology().getSockets() != null) {
            entity.setNumOfSockets(model.getCpu().getTopology().getSockets());
        }
        if (model.getCpu().getTopology().getThreads() != null) {
            entity.setThreadsPerCpu(model.getCpu().getTopology().getThreads());
        }
    }
    if (model.isSetHighAvailability()) {
        if (model.getHighAvailability().isSetEnabled()) {
            entity.setAutoStartup(model.getHighAvailability().isEnabled());
        }
        if (model.getHighAvailability().isSetPriority()) {
            entity.setPriority(model.getHighAvailability().getPriority());
        }
    }
    if (model.isSetDisplay()) {
        if (model.getDisplay().isSetType()) {
            // let backend decide which video device to use
            entity.setDefaultDisplayType(null);
        }
        if (model.getDisplay().isSetMonitors()) {
            entity.setNumOfMonitors(model.getDisplay().getMonitors());
        }
        if (model.getDisplay().isSetSingleQxlPci()) {
            entity.setSingleQxlPci(model.getDisplay().isSingleQxlPci());
        }
        if (model.getDisplay().isSetSmartcardEnabled()) {
            entity.setSmartcardEnabled(model.getDisplay().isSmartcardEnabled());
        }
    }
    if (model.isSetMigrationDowntime()) {
        entity.setMigrationDowntime(mapMinusOneToNull(model.getMigrationDowntime()));
    }
    if (model.isSetMigration()) {
        MigrationOptionsMapper.copyMigrationOptions(model.getMigration(), entity);
    }
    if (model.isSetCustomCpuModel()) {
        entity.setCustomCpuName(model.getCustomCpuModel());
    }
    if (model.isSetCustomEmulatedMachine()) {
        entity.setCustomEmulatedMachine(model.getCustomEmulatedMachine());
    }
    if (model.isSetMemoryPolicy() && model.getMemoryPolicy().isSetGuaranteed()) {
        Long memGuaranteed = model.getMemoryPolicy().getGuaranteed() / BYTES_PER_MB;
        entity.setMinAllocatedMem(memGuaranteed.intValue());
    }
    if (model.isSetMemoryPolicy() && model.getMemoryPolicy().isSetMax()) {
        Long maxMemory = model.getMemoryPolicy().getMax() / BYTES_PER_MB;
        entity.setMaxMemorySizeMb(maxMemory.intValue());
    }
    if (model.isSetOs()) {
        Boot boot = model.getOs().getBoot();
        if (boot != null && boot.isSetDevices() && boot.getDevices().isSetDevices()) {
            entity.setDefaultBootSequence(VmMapper.map(model.getOs().getBoot(), null));
        }
    }
    if (model.isSetCustomCompatibilityVersion()) {
        Version entityMappedVersion = VersionMapper.map(model.getCustomCompatibilityVersion());
        entity.setCustomCompatibilityVersion(entityMappedVersion.isNotValid() ? null : entityMappedVersion);
    }
    if (model.isSetLease()) {
        entity.setLeaseStorageDomainId(StorageDomainLeaseMapper.map(model.getLease()));
    }
    if (model.isSetPlacementPolicy()) {
        if (model.getPlacementPolicy().isSetAffinity()) {
            // read migration policy
            entity.setMigrationSupport(map(model.getPlacementPolicy().getAffinity(), null));
        }
        // reset previous dedicated host or hosts
        Set<Guid> hostGuidsSet = new HashSet<>();
        // read multiple hosts if there are few
        if (model.getPlacementPolicy().isSetHosts() && model.getPlacementPolicy().getHosts().getHosts().size() > 0) {
            for (Host currHost : model.getPlacementPolicy().getHosts().getHosts()) {
                Guid hostGuid;
                if (currHost.isSetId()) {
                    hostGuid = Guid.createGuidFromString(currHost.getId());
                } else {
                    continue;
                }
                hostGuidsSet.add(hostGuid);
            }
        }
        entity.setDedicatedVmForVdsList(new LinkedList<>(hostGuidsSet));
    }
}
Also used : Version(org.ovirt.engine.core.compat.Version) Host(org.ovirt.engine.api.model.Host) Guid(org.ovirt.engine.core.compat.Guid) Boot(org.ovirt.engine.api.model.Boot) HashSet(java.util.HashSet)

Aggregations

Boot (org.ovirt.engine.api.model.Boot)7 OperatingSystem (org.ovirt.engine.api.model.OperatingSystem)4 BootDevice (org.ovirt.engine.api.model.BootDevice)2 Host (org.ovirt.engine.api.model.Host)2 Template (org.ovirt.engine.api.model.Template)2 Vm (org.ovirt.engine.api.model.Vm)2 V3Boot (org.ovirt.engine.api.v3.types.V3Boot)2 V3OperatingSystem (org.ovirt.engine.api.v3.types.V3OperatingSystem)2 VmTemplate (org.ovirt.engine.core.common.businessentities.VmTemplate)2 OsRepository (org.ovirt.engine.core.common.osinfo.OsRepository)2 HashSet (java.util.HashSet)1 Test (org.junit.Test)1 Action (org.ovirt.engine.api.model.Action)1 Display (org.ovirt.engine.api.model.Display)1 ExternalHostProvider (org.ovirt.engine.api.model.ExternalHostProvider)1 GuestOperatingSystem (org.ovirt.engine.api.model.GuestOperatingSystem)1 HighAvailability (org.ovirt.engine.api.model.HighAvailability)1 InstanceType (org.ovirt.engine.api.model.InstanceType)1 Kernel (org.ovirt.engine.api.model.Kernel)1 TemplateVersion (org.ovirt.engine.api.model.TemplateVersion)1