Search in sources :

Example 6 with DisplayType

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

the class OvfReader method setDeviceByResource.

private void setDeviceByResource(XmlNode node, VmDevice vmDevice) {
    String resourceType = selectSingleNode(node, VMD_RESOURCE_TYPE, _xmlNS).innerText;
    XmlNode resourceSubTypeNode = selectSingleNode(node, VMD_SUB_RESOURCE_TYPE, _xmlNS);
    if (resourceSubTypeNode == null) {
        // we need special handling for Monitor to define it as vnc or spice
        if (OvfHardware.Monitor.equals(adjustHardwareResourceType(resourceType))) {
            // get number of monitors from VirtualQuantity in OVF
            if (selectSingleNode(node, VMD_VIRTUAL_QUANTITY, _xmlNS) != null && !StringUtils.isEmpty(selectSingleNode(node, VMD_VIRTUAL_QUANTITY, _xmlNS).innerText)) {
                int virtualQuantity = Integer.parseInt(selectSingleNode(node, VMD_VIRTUAL_QUANTITY, _xmlNS).innerText);
                if (virtualQuantity > 1) {
                    vmDevice.setDevice(VmDeviceType.QXL.getName());
                } else {
                    // get first supported display device
                    List<Pair<GraphicsType, DisplayType>> supportedGraphicsAndDisplays = osRepository.getGraphicsAndDisplays(vmBase.getOsId(), new Version(getVersion()));
                    if (!supportedGraphicsAndDisplays.isEmpty()) {
                        DisplayType firstDisplayType = supportedGraphicsAndDisplays.get(0).getSecond();
                        vmDevice.setDevice(firstDisplayType.getDefaultVmDeviceType().getName());
                    } else {
                        vmDevice.setDevice(VmDeviceType.QXL.getName());
                    }
                }
            } else {
                // default to spice if quantity not found
                vmDevice.setDevice(VmDeviceType.QXL.getName());
            }
        } else {
            vmDevice.setDevice(VmDeviceType.getoVirtDevice(Integer.parseInt(resourceType)).getName());
        }
    } else if (OvfHardware.Network.equals(resourceType)) {
        // handle interfaces with different sub types : we have 0-5 as the VmInterfaceType enum
        Integer nicTypeValue = getVmInterfaceType(resourceSubTypeNode);
        VmInterfaceType nicType = nicTypeValue != null ? VmInterfaceType.forValue(nicTypeValue) : null;
        if (nicType != null) {
            if (nicType == VmInterfaceType.pciPassthrough) {
                vmDevice.setDevice(VmDeviceType.HOST_DEVICE.getName());
            } else {
                vmDevice.setDevice(VmDeviceType.BRIDGE.getName());
            }
        } else {
            vmDevice.setDevice(VmDeviceType.getoVirtDevice(Integer.parseInt(resourceType)).getName());
        }
    }
}
Also used : XmlNode(org.ovirt.engine.core.utils.ovf.xml.XmlNode) DisplayType(org.ovirt.engine.core.common.businessentities.DisplayType) Version(org.ovirt.engine.core.compat.Version) VmInterfaceType(org.ovirt.engine.core.common.businessentities.network.VmInterfaceType) Pair(org.ovirt.engine.core.common.utils.Pair)

Example 7 with DisplayType

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

the class OvfReader method addDefaultGraphicsDevice.

private void addDefaultGraphicsDevice() {
    VmDevice device = VmDeviceCommonUtils.findVmDeviceByGeneralType(vmBase.getManagedDeviceMap(), VmDeviceGeneralType.GRAPHICS);
    if (device != null) {
        return;
    }
    List<Pair<GraphicsType, DisplayType>> graphicsAndDisplays = osRepository.getGraphicsAndDisplays(vmBase.getOsId(), new Version(getVersion()));
    GraphicsType graphicsType = vmBase.getDefaultDisplayType() == DisplayType.cirrus ? GraphicsType.VNC : GraphicsType.SPICE;
    GraphicsType supportedGraphicsType = null;
    for (Pair<GraphicsType, DisplayType> pair : graphicsAndDisplays) {
        if (pair.getSecond() == vmBase.getDefaultDisplayType()) {
            if (pair.getFirst() == graphicsType) {
                supportedGraphicsType = graphicsType;
                break;
            }
            if (supportedGraphicsType == null) {
                supportedGraphicsType = pair.getFirst();
            }
        }
    }
    if (supportedGraphicsType != null) {
        device = new GraphicsDevice(supportedGraphicsType.getCorrespondingDeviceType());
        device.setId(new VmDeviceId(Guid.newGuid(), vmBase.getId()));
        addManagedVmDevice(device);
    } else {
        log.warn("Cannot find any graphics type for display type {} supported by OS {} in compatibility version {}", vmBase.getDefaultDisplayType().name(), osRepository.getOsName(vmBase.getOsId()), getVersion());
    }
}
Also used : GraphicsType(org.ovirt.engine.core.common.businessentities.GraphicsType) VmDevice(org.ovirt.engine.core.common.businessentities.VmDevice) GraphicsDevice(org.ovirt.engine.core.common.businessentities.GraphicsDevice) DisplayType(org.ovirt.engine.core.common.businessentities.DisplayType) Version(org.ovirt.engine.core.compat.Version) VmDeviceId(org.ovirt.engine.core.common.businessentities.VmDeviceId) Pair(org.ovirt.engine.core.common.utils.Pair)

Example 8 with DisplayType

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

the class InstanceTypeManager method updateDefaultDisplayRelatedFields.

protected void updateDefaultDisplayRelatedFields(final VmBase vmBase) {
    // Update display protocol selected item
    final Collection<DisplayType> displayTypes = model.getDisplayType().getItems();
    if (displayTypes == null || displayTypes.isEmpty()) {
        return;
    }
    // graphics
    Frontend.getInstance().runQuery(QueryType.GetGraphicsDevices, new IdQueryParameters(vmBase.getId()), new AsyncQuery<QueryReturnValue>(returnValue -> {
        deactivate();
        List<GraphicsDevice> graphicsDevices = returnValue.getReturnValue();
        model.getIsHeadlessModeEnabled().setEntity(vmBase.getDefaultDisplayType() == DisplayType.none);
        // select display protocol
        // first by default
        DisplayType displayProtocol = displayTypes.iterator().next();
        if (displayTypes.contains(vmBase.getDefaultDisplayType())) {
            // if display types contain DT of a vm, pick this one
            displayProtocol = vmBase.getDefaultDisplayType();
        }
        maybeSetSelectedItem(model.getDisplayType(), displayProtocol);
        Set<GraphicsType> graphicsTypes = new HashSet<>();
        for (GraphicsDevice graphicsDevice : graphicsDevices) {
            graphicsTypes.add(graphicsDevice.getGraphicsType());
        }
        UnitVmModel.GraphicsTypes selected = UnitVmModel.GraphicsTypes.fromGraphicsTypes(graphicsTypes);
        if (selected != null && getModel().getGraphicsType().getItems().contains(selected)) {
            maybeSetSelectedItem(getModel().getGraphicsType(), selected);
        }
        maybeSetSelectedItem(model.getNumOfMonitors(), vmBase.getNumOfMonitors());
        maybeSetSelectedItem(model.getUsbPolicy(), vmBase.getUsbPolicy());
        maybeSetEntity(model.getIsSmartcardEnabled(), vmBase.isSmartcardEnabled());
        maybeSetSingleQxlPci(vmBase);
        activate();
    }));
}
Also used : VmDeviceType(org.ovirt.engine.core.common.utils.VmDeviceType) QueryType(org.ovirt.engine.core.common.queries.QueryType) Guid(org.ovirt.engine.core.compat.Guid) InstanceType(org.ovirt.engine.core.common.businessentities.InstanceType) PriorityUtil(org.ovirt.engine.ui.uicommonweb.models.vms.PriorityUtil) IEventListener(org.ovirt.engine.ui.uicompat.IEventListener) CustomInstanceType(org.ovirt.engine.ui.uicommonweb.models.vms.CustomInstanceType) Event(org.ovirt.engine.ui.uicompat.Event) VmEntityType(org.ovirt.engine.core.common.businessentities.VmEntityType) IdQueryParameters(org.ovirt.engine.core.common.queries.IdQueryParameters) ArrayList(java.util.ArrayList) VmDeviceGeneralType(org.ovirt.engine.core.common.businessentities.VmDeviceGeneralType) EntityModel(org.ovirt.engine.ui.uicommonweb.models.EntityModel) HashSet(java.util.HashSet) Frontend(org.ovirt.engine.ui.frontend.Frontend) VmWatchdogType(org.ovirt.engine.core.common.businessentities.VmWatchdogType) UnitVmModel(org.ovirt.engine.ui.uicommonweb.models.vms.UnitVmModel) VmDeviceCommonUtils(org.ovirt.engine.core.common.utils.VmDeviceCommonUtils) VmDevice(org.ovirt.engine.core.common.businessentities.VmDevice) AsyncQuery(org.ovirt.engine.ui.frontend.AsyncQuery) EventArgs(org.ovirt.engine.ui.uicompat.EventArgs) VmWatchdog(org.ovirt.engine.core.common.businessentities.VmWatchdog) AsyncDataProvider(org.ovirt.engine.ui.uicommonweb.dataprovider.AsyncDataProvider) DisplayType(org.ovirt.engine.core.common.businessentities.DisplayType) QueryParametersBase(org.ovirt.engine.core.common.queries.QueryParametersBase) QueryReturnValue(org.ovirt.engine.core.common.queries.QueryReturnValue) GraphicsDevice(org.ovirt.engine.core.common.businessentities.GraphicsDevice) VmBase(org.ovirt.engine.core.common.businessentities.VmBase) Collection(java.util.Collection) VmTemplate(org.ovirt.engine.core.common.businessentities.VmTemplate) ListModel(org.ovirt.engine.ui.uicommonweb.models.ListModel) Set(java.util.Set) List(java.util.List) VmRngDevice(org.ovirt.engine.core.common.businessentities.VmRngDevice) VirtioScsiUtil(org.ovirt.engine.ui.uicommonweb.models.vms.VirtioScsiUtil) MigrationSupport(org.ovirt.engine.core.common.businessentities.MigrationSupport) GraphicsType(org.ovirt.engine.core.common.businessentities.GraphicsType) QueryReturnValue(org.ovirt.engine.core.common.queries.QueryReturnValue) IdQueryParameters(org.ovirt.engine.core.common.queries.IdQueryParameters) HashSet(java.util.HashSet) Set(java.util.Set) GraphicsDevice(org.ovirt.engine.core.common.businessentities.GraphicsDevice) DisplayType(org.ovirt.engine.core.common.businessentities.DisplayType) ArrayList(java.util.ArrayList) List(java.util.List)

Example 9 with DisplayType

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

the class NonClusterModelBehaviorBase method initDisplayTypes.

protected void initDisplayTypes(DisplayType selected, UnitVmModel.GraphicsTypes selectedGrahicsTypes) {
    getModel().getDisplayType().getSelectedItemChangedEvent().addListener((ev, sender, args) -> enableSinglePCI(getModel().getDisplayType().getSelectedItem() == DisplayType.qxl));
    List<Pair<GraphicsType, DisplayType>> allGraphicsAndDisplays = new ArrayList<>();
    for (GraphicsType graphicsType : GraphicsType.values()) {
        for (DisplayType displayType : DisplayType.values()) {
            if (displayType != DisplayType.none) {
                allGraphicsAndDisplays.add(new Pair<>(graphicsType, displayType));
            }
        }
    }
    getModel().initDisplayModels(allGraphicsAndDisplays);
    initGraphicsModel(selectedGrahicsTypes);
    if (getModel().getDisplayType().getItems().contains(selected)) {
        getModel().getDisplayType().setSelectedItem(selected);
    }
    if (selected == DisplayType.none) {
        getModel().getDisplayType().setSelectedItem(DisplayType.qxl);
        getModel().getGraphicsType().setSelectedItem(UnitVmModel.GraphicsTypes.SPICE);
        getModel().getIsHeadlessModeEnabled().setEntity(true);
    }
}
Also used : GraphicsType(org.ovirt.engine.core.common.businessentities.GraphicsType) DisplayType(org.ovirt.engine.core.common.businessentities.DisplayType) ArrayList(java.util.ArrayList) Pair(org.ovirt.engine.core.common.utils.Pair)

Example 10 with DisplayType

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

the class ImportRepoImageCommand method createTemplate.

private Guid createTemplate() {
    VmTemplate blankTemplate = vmTemplateDao.get(VmTemplateHandler.BLANK_VM_TEMPLATE_ID);
    VmStatic masterVm = new VmStatic(blankTemplate);
    DiskImage templateDiskImage = getParameters().getDiskImage();
    String vmTemplateName = getParameters().getTemplateName();
    AddVmTemplateParameters parameters = new AddVmTemplateParameters(masterVm, vmTemplateName, templateDiskImage.getDiskDescription());
    // Setting the user from the parent command, as the session might already be invalid
    parameters.setParametersCurrentUser(getParameters().getParametersCurrentUser());
    // Setting the cluster ID, and other related properties derived from it
    if (getParameters().getClusterId() != null) {
        masterVm.setClusterId(getParameters().getClusterId());
        Cluster vdsGroup = getCluster(masterVm.getClusterId());
        masterVm.setOsId(osRepository.getDefaultOSes().get(vdsGroup.getArchitecture()));
        DisplayType defaultDisplayType = osRepository.getGraphicsAndDisplays(masterVm.getOsId(), vdsGroup.getCompatibilityVersion()).get(0).getSecond();
        masterVm.setDefaultDisplayType(defaultDisplayType);
    }
    parameters.setBalloonEnabled(true);
    ActionReturnValue addVmTemplateReturnValue = Backend.getInstance().runInternalAction(ActionType.AddVmTemplate, parameters, ExecutionHandler.createDefaultContextForTasks(getContext()));
    // No reason for this to return null, but checking just to make sure, and returning the created template, or null if failed
    return addVmTemplateReturnValue.getActionReturnValue() != null ? (Guid) addVmTemplateReturnValue.getActionReturnValue() : null;
}
Also used : DisplayType(org.ovirt.engine.core.common.businessentities.DisplayType) VmTemplate(org.ovirt.engine.core.common.businessentities.VmTemplate) ActionReturnValue(org.ovirt.engine.core.common.action.ActionReturnValue) AddVmTemplateParameters(org.ovirt.engine.core.common.action.AddVmTemplateParameters) Cluster(org.ovirt.engine.core.common.businessentities.Cluster) VmStatic(org.ovirt.engine.core.common.businessentities.VmStatic) DiskImage(org.ovirt.engine.core.common.businessentities.storage.DiskImage)

Aggregations

DisplayType (org.ovirt.engine.core.common.businessentities.DisplayType)14 GraphicsType (org.ovirt.engine.core.common.businessentities.GraphicsType)8 Pair (org.ovirt.engine.core.common.utils.Pair)6 GraphicsDevice (org.ovirt.engine.core.common.businessentities.GraphicsDevice)4 ArrayList (java.util.ArrayList)3 HashSet (java.util.HashSet)3 Map (java.util.Map)3 Set (java.util.Set)3 VmDevice (org.ovirt.engine.core.common.businessentities.VmDevice)3 VmDeviceId (org.ovirt.engine.core.common.businessentities.VmDeviceId)3 VmDeviceType (org.ovirt.engine.core.common.utils.VmDeviceType)3 Version (org.ovirt.engine.core.compat.Version)3 Collection (java.util.Collection)2 List (java.util.List)2 VmDeviceGeneralType (org.ovirt.engine.core.common.businessentities.VmDeviceGeneralType)2 VmTemplate (org.ovirt.engine.core.common.businessentities.VmTemplate)2 VmInterfaceType (org.ovirt.engine.core.common.businessentities.network.VmInterfaceType)2 DiskImage (org.ovirt.engine.core.common.businessentities.storage.DiskImage)2 VmDeviceCommonUtils (org.ovirt.engine.core.common.utils.VmDeviceCommonUtils)2 Guid (org.ovirt.engine.core.compat.Guid)2