Search in sources :

Example 11 with GraphicsInfo

use of org.ovirt.engine.core.common.businessentities.GraphicsInfo in project ovirt-engine by oVirt.

the class BackendVmGraphicsConsolesResource method list.

@Override
public GraphicsConsoles list() {
    GraphicsConsoles consoles = new GraphicsConsoles();
    Map<GraphicsType, GraphicsInfo> graphicsTypeToGraphicsInfo;
    VM entity = loadEntity();
    boolean current = ParametersHelper.getBooleanParameter(httpHeaders, uriInfo, CURRENT, true, false);
    if (current) {
        // from entity dynamic (e.g. what is now present on the VM
        graphicsTypeToGraphicsInfo = extractGraphicsInofs(entity);
    } else {
        // from devices (e.g. what is configured on the VM)
        List<GraphicsType> graphicsTypes = DisplayHelper.getGraphicsTypesForEntity(this, guid, true);
        graphicsTypeToGraphicsInfo = new EnumMap<>(GraphicsType.class);
        for (GraphicsType type : graphicsTypes) {
            graphicsTypeToGraphicsInfo.put(type, null);
        }
    }
    for (Map.Entry<GraphicsType, GraphicsInfo> graphicsInfo : graphicsTypeToGraphicsInfo.entrySet()) {
        consoles.getGraphicsConsoles().add(addLinks(populate(VmMapper.map(graphicsInfo, null), entity)));
    }
    return consoles;
}
Also used : GraphicsType(org.ovirt.engine.core.common.businessentities.GraphicsType) GraphicsConsoles(org.ovirt.engine.api.model.GraphicsConsoles) VM(org.ovirt.engine.core.common.businessentities.VM) GraphicsInfo(org.ovirt.engine.core.common.businessentities.GraphicsInfo) EnumMap(java.util.EnumMap) Map(java.util.Map)

Example 12 with GraphicsInfo

use of org.ovirt.engine.core.common.businessentities.GraphicsInfo 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 13 with GraphicsInfo

use of org.ovirt.engine.core.common.businessentities.GraphicsInfo in project ovirt-engine by oVirt.

the class LibvirtVmXmlBuilder method overrideDevicesForRunOnce.

private List<VmDevice> overrideDevicesForRunOnce(List<VmDevice> devices) {
    if (!vm.isRunOnce()) {
        return devices;
    }
    // video device handling
    DisplayType displayType = vm.getDefaultDisplayType();
    if (displayType != null) {
        // remove existing video device
        devices = devices.stream().filter(dev -> dev.getType() != VmDeviceGeneralType.VIDEO).collect(Collectors.toList());
        // add new video device
        if (displayType != DisplayType.none) {
            devices.add(vmInfoBuildUtils.createVideoDeviceByDisplayType(displayType, vm.getId()));
        }
    }
    // graphics device handling
    if (displayType == DisplayType.none || (vm.getGraphicsInfos() != null && !vm.getGraphicsInfos().isEmpty())) {
        // remove existing graphics devices
        devices = devices.stream().filter(dev -> dev.getType() != VmDeviceGeneralType.GRAPHICS).collect(Collectors.toList());
        if (displayType != DisplayType.none) {
            // add new graphics devices
            Map<GraphicsType, GraphicsInfo> infos = vm.getGraphicsInfos();
            Map<String, Object> specParamsFromVm = new HashMap<>();
            vmInfoBuildUtils.addVmGraphicsOptions(infos, specParamsFromVm, vm);
            devices.addAll(vmInfoBuildUtils.createGraphicsDevices(infos, specParamsFromVm, vm.getId()));
        }
    }
    // the user may specify floppy path while there is no device in the database
    if (!StringUtils.isEmpty(vm.getFloppyPath()) && devices.stream().noneMatch(dev -> dev.getDevice().equals(VmDeviceType.FLOPPY.getName()))) {
        devices.add(vmInfoBuildUtils.createFloppyDevice(vm));
    }
    return devices;
}
Also used : GraphicsType(org.ovirt.engine.core.common.businessentities.GraphicsType) Arrays(java.util.Arrays) StringUtils(org.apache.commons.lang.StringUtils) CinderDisk(org.ovirt.engine.core.common.businessentities.storage.CinderDisk) VmType(org.ovirt.engine.core.common.businessentities.VmType) PropagateErrors(org.ovirt.engine.core.common.businessentities.storage.PropagateErrors) VmInterfaceType(org.ovirt.engine.core.common.businessentities.network.VmInterfaceType) LunDisk(org.ovirt.engine.core.common.businessentities.storage.LunDisk) LoggerFactory(org.slf4j.LoggerFactory) GraphicsInfo(org.ovirt.engine.core.common.businessentities.GraphicsInfo) VmCpuCountHelper(org.ovirt.engine.core.common.utils.VmCpuCountHelper) XmlTextWriter(org.ovirt.engine.core.utils.ovf.xml.XmlTextWriter) HugePageUtils(org.ovirt.engine.core.common.utils.HugePageUtils) ChipsetType(org.ovirt.engine.core.common.businessentities.ChipsetType) VmDeviceCommonUtils(org.ovirt.engine.core.common.utils.VmDeviceCommonUtils) Map(java.util.Map) VdsNumaNode(org.ovirt.engine.core.common.businessentities.VdsNumaNode) VmDevice(org.ovirt.engine.core.common.businessentities.VmDevice) StringMapUtils(org.ovirt.engine.core.utils.StringMapUtils) VmDeviceCommonUtils.updateVmDevicesBootOrder(org.ovirt.engine.core.common.utils.VmDeviceCommonUtils.updateVmDevicesBootOrder) VmNic(org.ovirt.engine.core.common.businessentities.network.VmNic) VdsStatistics(org.ovirt.engine.core.common.businessentities.VdsStatistics) Version(org.ovirt.engine.core.compat.Version) MemoizingSupplier(org.ovirt.engine.core.utils.MemoizingSupplier) DisplayType(org.ovirt.engine.core.common.businessentities.DisplayType) NetworkFilter(org.ovirt.engine.core.common.businessentities.network.NetworkFilter) DiskStorageType(org.ovirt.engine.core.common.businessentities.storage.DiskStorageType) VmNumaNode(org.ovirt.engine.core.common.businessentities.VmNumaNode) Collection(java.util.Collection) VmPayload(org.ovirt.engine.core.common.businessentities.VmPayload) Set(java.util.Set) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) HostDevice(org.ovirt.engine.core.common.businessentities.HostDevice) List(java.util.List) Stream(java.util.stream.Stream) DiskInterface(org.ovirt.engine.core.common.businessentities.storage.DiskInterface) Entry(java.util.Map.Entry) Optional(java.util.Optional) GraphicsType(org.ovirt.engine.core.common.businessentities.GraphicsType) NumaSettingFactory(org.ovirt.engine.core.vdsbroker.vdsbroker.NumaSettingFactory) FeatureSupported(org.ovirt.engine.core.common.FeatureSupported) VmDeviceId(org.ovirt.engine.core.common.businessentities.VmDeviceId) VmDeviceType(org.ovirt.engine.core.common.utils.VmDeviceType) ArchitectureType(org.ovirt.engine.core.common.businessentities.ArchitectureType) DiskVmElement(org.ovirt.engine.core.common.businessentities.storage.DiskVmElement) Guid(org.ovirt.engine.core.compat.Guid) HashMap(java.util.HashMap) DiskImage(org.ovirt.engine.core.common.businessentities.storage.DiskImage) NetworkUtils(org.ovirt.engine.core.utils.NetworkUtils) ArrayList(java.util.ArrayList) VmDeviceGeneralType(org.ovirt.engine.core.common.businessentities.VmDeviceGeneralType) VmPropertiesUtils(org.ovirt.engine.core.common.utils.customprop.VmPropertiesUtils) HashSet(java.util.HashSet) ArchStrategyFactory(org.ovirt.engine.core.utils.archstrategy.ArchStrategyFactory) VdsProperties(org.ovirt.engine.core.vdsbroker.vdsbroker.VdsProperties) HugePage(org.ovirt.engine.core.common.businessentities.HugePage) Network(org.ovirt.engine.core.common.businessentities.network.Network) VolumeFormat(org.ovirt.engine.core.common.businessentities.storage.VolumeFormat) Pair(org.ovirt.engine.core.common.utils.Pair) Config(org.ovirt.engine.core.common.config.Config) Logger(org.slf4j.Logger) VmNetworkInterface(org.ovirt.engine.core.common.businessentities.network.VmNetworkInterface) VmHostDevice(org.ovirt.engine.core.common.businessentities.VmHostDevice) VnicProfile(org.ovirt.engine.core.common.businessentities.network.VnicProfile) ConfigValues(org.ovirt.engine.core.common.config.ConfigValues) Disk(org.ovirt.engine.core.common.businessentities.storage.Disk) VM(org.ovirt.engine.core.common.businessentities.VM) NumaTuneMode(org.ovirt.engine.core.common.businessentities.NumaTuneMode) GetControllerIndices(org.ovirt.engine.core.vdsbroker.architecture.GetControllerIndices) IoTuneUtils.ioTuneListFrom(org.ovirt.engine.core.vdsbroker.vdsbroker.IoTuneUtils.ioTuneListFrom) Comparator(java.util.Comparator) Collections(java.util.Collections) StorageQos(org.ovirt.engine.core.common.businessentities.qos.StorageQos) DisplayType(org.ovirt.engine.core.common.businessentities.DisplayType) HashMap(java.util.HashMap) GraphicsInfo(org.ovirt.engine.core.common.businessentities.GraphicsInfo)

Example 14 with GraphicsInfo

use of org.ovirt.engine.core.common.businessentities.GraphicsInfo in project ovirt-engine by oVirt.

the class VmInfoBuildUtils method createGraphicsDevices.

public List<VmDevice> createGraphicsDevices(Map<GraphicsType, GraphicsInfo> graphicsInfos, Map<String, Object> extraSpecParams, Guid vmId) {
    final Comparator<GraphicsType> spiceLastComparator = ComparatorUtils.sortLast(GraphicsType.SPICE);
    final List<Entry<GraphicsType, GraphicsInfo>> sortedGraphicsInfos = graphicsInfos.entrySet().stream().sorted(Comparator.comparing(Entry::getKey, spiceLastComparator)).collect(Collectors.toList());
    List<VmDevice> result = new ArrayList<>();
    for (Entry<GraphicsType, GraphicsInfo> graphicsInfo : sortedGraphicsInfos) {
        VmDevice device = new VmDevice();
        device.setId(new VmDeviceId(Guid.newGuid(), vmId));
        device.setType(VmDeviceGeneralType.GRAPHICS);
        device.setDevice(graphicsInfo.getKey().name().toLowerCase());
        device.setPlugged(true);
        device.setAddress("");
        if (extraSpecParams != null) {
            device.setSpecParams(extraSpecParams);
        }
        result.add(device);
    }
    return result;
}
Also used : GraphicsType(org.ovirt.engine.core.common.businessentities.GraphicsType) VmDevice(org.ovirt.engine.core.common.businessentities.VmDevice) Entry(java.util.Map.Entry) ArrayList(java.util.ArrayList) GraphicsInfo(org.ovirt.engine.core.common.businessentities.GraphicsInfo) VmDeviceId(org.ovirt.engine.core.common.businessentities.VmDeviceId)

Example 15 with GraphicsInfo

use of org.ovirt.engine.core.common.businessentities.GraphicsInfo in project ovirt-engine by oVirt.

the class VdsBrokerObjectsBuilder method updateGraphicsInfo.

/**
 * Updates graphics runtime information according displayInfo VDSM structure if it exists.
 *
 * @param vm - VmDynamic to update
 * @param struct - data from VDSM
 * @return true if displayInfo exists, false otherwise
 */
private static boolean updateGraphicsInfo(VmDynamic vm, Map<String, Object> struct) {
    Object displayInfo = struct.get(VdsProperties.displayInfo);
    if (displayInfo == null) {
        return false;
    }
    for (Object info : (Object[]) displayInfo) {
        Map<String, String> infoMap = (Map<String, String>) info;
        GraphicsType graphicsType = GraphicsType.fromString(infoMap.get(VdsProperties.type));
        GraphicsInfo graphicsInfo = new GraphicsInfo();
        graphicsInfo.setIp(infoMap.get(VdsProperties.ipAddress)).setPort(parseIntegerOrNull(infoMap.get(VdsProperties.port))).setTlsPort(parseIntegerOrNull(infoMap.get(VdsProperties.tlsPort)));
        if (graphicsInfo.getPort() != null || graphicsInfo.getTlsPort() != null) {
            vm.getGraphicsInfos().put(graphicsType, graphicsInfo);
        }
    }
    return true;
}
Also used : GraphicsType(org.ovirt.engine.core.common.businessentities.GraphicsType) GraphicsInfo(org.ovirt.engine.core.common.businessentities.GraphicsInfo) Map(java.util.Map) HashMap(java.util.HashMap)

Aggregations

GraphicsInfo (org.ovirt.engine.core.common.businessentities.GraphicsInfo)20 GraphicsType (org.ovirt.engine.core.common.businessentities.GraphicsType)8 VM (org.ovirt.engine.core.common.businessentities.VM)7 Map (java.util.Map)4 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 List (java.util.List)2 Entry (java.util.Map.Entry)2 Vm (org.ovirt.engine.api.model.Vm)2 VmDevice (org.ovirt.engine.core.common.businessentities.VmDevice)2 VmDeviceId (org.ovirt.engine.core.common.businessentities.VmDeviceId)2 ConsoleOptions (org.ovirt.engine.core.common.console.ConsoleOptions)2 ConfigureConsoleOptionsParams (org.ovirt.engine.core.common.queries.ConfigureConsoleOptionsParams)2 QueryReturnValue (org.ovirt.engine.core.common.queries.QueryReturnValue)2 QueryType (org.ovirt.engine.core.common.queries.QueryType)2 Frontend (org.ovirt.engine.ui.frontend.Frontend)2 FrontendUrlUtils (org.ovirt.engine.ui.frontend.utils.FrontendUrlUtils)2 BaseCommandTarget (org.ovirt.engine.ui.uicommonweb.BaseCommandTarget)2 ConsoleUtils (org.ovirt.engine.ui.uicommonweb.ConsoleUtils)2 DynamicMessages (org.ovirt.engine.ui.uicommonweb.DynamicMessages)2