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());
}
}
}
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());
}
}
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();
}));
}
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);
}
}
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;
}
Aggregations