console: Select the first embeddable graphics device as graphical console

Currently, when there are multiple graphics devices, the first graphics
device is always selected as the graphical console. For the following
configuration:

    <graphics type="egl-headless">
      <gl rendernode="/dev/dri/renderD128"/>
    </graphics>
    <graphics type="spice" autoport="yes">
      <listen type="address"/>
      <image compression="off"/>
      <gl enable="no"/>
    </graphics>

virt-manager will report an error:

    Cannot display graphical console type 'egl-headless'

The patch will iterate through all graphics devices to try to select the
first embeddable graphics device as graphical console.

Signed-off-by: Feng Jiang <jiangfeng@kylinos.cn>
Signed-off-by: Liming Sun <sunliming@kylinos.cn>
Reviewed-by: Cole Robinson <crobinso@redhat.com>
This commit is contained in:
Feng Jiang 2023-01-30 15:49:24 +08:00 committed by Cole Robinson
parent d83074a001
commit 409e4bf2d1

View File

@ -221,15 +221,23 @@ class _ConsoleMenu:
from ..device.gfxdetails import vmmGraphicsDetails
ret = []
preferred = None
for idx, dev in enumerate(devs):
label = (_("Graphical Console") + " " +
vmmGraphicsDetails.graphics_pretty_type_simple(dev.type))
tooltip = None
if idx > 0:
label += " %s" % (idx + 1)
tooltip = None
if dev.type not in self.embeddable_graphics():
tooltip = _("virt-manager cannot display graphical "
"console type '%s'") % (dev.type)
elif preferred is not None:
tooltip = _("virt-manager does not support more "
"than one graphical console")
else:
preferred = idx
ret.append([label, dev, tooltip])
return ret
@ -689,9 +697,10 @@ class vmmConsolePages(vmmGObjectUI):
ginfo = None
try:
gdevs = self.vm.xmlobj.devices.graphics
gdev = gdevs and gdevs[0] or None
if gdev:
ginfo = ConnectionInfo(self.vm.conn, gdev, 0)
for idx, dev in enumerate(gdevs):
if dev.type in self._consolemenu.embeddable_graphics():
ginfo = ConnectionInfo(self.vm.conn, gdevs[idx], idx)
break
except Exception as e: # pragma: no cover
# We can fail here if VM is destroyed: xen is a bit racy
# and can't handle domain lookups that soon after