Exemplo n.º 1
0
  private static GraphicsDevice getCompatibleGraphics(
      VmDeviceType videoDeviceType, Version clusterVersion, VmBase vmBase) {
    GraphicsDevice graphicsDevice = null;
    GraphicsType compatibleType = null;

    OsRepository osRepository = SimpleDependencyInjector.getInstance().get(OsRepository.class);
    for (Pair<GraphicsType, DisplayType> graphicsDisplayPair :
        osRepository.getGraphicsAndDisplays(vmBase.getOsId(), clusterVersion)) {
      if (graphicsDisplayPair.getSecond().getDefaultVmDeviceType() == videoDeviceType) {
        compatibleType = graphicsDisplayPair.getFirst();

        // previously to spice+vnc, QXL was only used by spice, so prefer spice if available
        if (videoDeviceType == VmDeviceType.QXL && compatibleType == GraphicsType.SPICE) {
          break;
        }
      }
    }

    if (compatibleType != null) {
      graphicsDevice = new GraphicsDevice(compatibleType.getCorrespondingDeviceType());
      graphicsDevice.setId(new VmDeviceId(Guid.newGuid(), vmBase.getId()));
    }

    return graphicsDevice;
  }
Exemplo n.º 2
0
 private void mockDisplayTypes(int osId) {
   Map<Integer, Map<Version, List<Pair<GraphicsType, DisplayType>>>> displayTypeMap =
       new HashMap<>();
   displayTypeMap.put(osId, new HashMap<>());
   displayTypeMap
       .get(osId)
       .put(null, Collections.singletonList(new Pair<>(GraphicsType.SPICE, DisplayType.qxl)));
   when(osRepository.getGraphicsAndDisplays()).thenReturn(displayTypeMap);
 }
Exemplo n.º 3
0
  private void mockOsRepositoryGraphics(
      int osId, Version ver, Pair<GraphicsType, DisplayType> supportedGraphicsAndDisplay) {
    Map<Version, List<Pair<GraphicsType, DisplayType>>> value = new HashMap<>();
    value.put(ver, Collections.singletonList(supportedGraphicsAndDisplay));

    Map<Integer, Map<Version, List<Pair<GraphicsType, DisplayType>>>> g = new HashMap<>();
    g.put(osId, value);
    when(osRepository.getGraphicsAndDisplays()).thenReturn(g);
  }
Exemplo n.º 4
0
 private void setDeviceByResource(XmlNode node, VmDevice vmDevice) {
   int resourceType = getResourceType(node, OvfProperties.VMD_RESOURCE_TYPE);
   int resourceSubType = getResourceType(node, OvfProperties.VMD_SUB_RESOURCE_TYPE);
   if (resourceSubType == -1) {
     // we need special handling for Monitor to define it as vnc or spice
     if (Integer.parseInt(OvfHardware.Monitor) == resourceType) {
       // if default display type is defined in the ovf, set the video device that is suitable for
       // it
       if (defaultDisplayType != null) {
         vmDevice.setDevice(defaultDisplayType.getDefaultVmDeviceType().getName());
       } else {
         // get number of monitors from VirtualQuantity in OVF
         if (selectSingleNode(node, OvfProperties.VMD_VIRTUAL_QUANTITY, _xmlNS) != null
             && !StringUtils.isEmpty(
                 selectSingleNode(node, OvfProperties.VMD_VIRTUAL_QUANTITY, _xmlNS).innerText)) {
           int virtualQuantity =
               Integer.parseInt(
                   selectSingleNode(node, OvfProperties.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(resourceType).getName());
     }
   } else if (Integer.parseInt(OvfHardware.Network) == resourceType) {
     // handle interfaces with different sub types : we have 0-5 as the VmInterfaceType enum
     VmInterfaceType nicType = VmInterfaceType.forValue(resourceSubType);
     if (nicType != null) {
       if (nicType == VmInterfaceType.pciPassthrough) {
         vmDevice.setDevice(VmDeviceType.HOST_DEVICE.getName());
       } else {
         vmDevice.setDevice(VmDeviceType.BRIDGE.getName());
       }
     } else {
       vmDevice.setDevice(VmDeviceType.getoVirtDevice(resourceType).getName());
     }
   }
 }
Exemplo n.º 5
0
  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());
    }
  }