guest: convert_to_vnc: optionally add qemu-vdagent

Disabled by default, but maybe we turn it on in the future
when qemu-vdagent supports migration.

Signed-off-by: Cole Robinson <crobinso@redhat.com>
This commit is contained in:
Cole Robinson
2024-09-18 11:48:22 -04:00
committed by Pavel Hrdina
parent d58299ee6b
commit f7988a94e6
7 changed files with 43 additions and 9 deletions

View File

@@ -8,6 +8,9 @@
<boot dev="hd"/> <boot dev="hd"/>
</os> </os>
<devices> <devices>
<channel type="qemu-vdagent">
<target type="virtio" name="com.redhat.spice.0"/>
</channel>
<graphics type="vnc" port="-1"/> <graphics type="vnc" port="-1"/>
<video> <video>
<model type="vga"/> <model type="vga"/>

View File

@@ -13,7 +13,7 @@
<vmport state="off"/> <vmport state="off"/>
</features> </features>
<devices> <devices>
<channel type="spicevmc"> <channel type="qemu-vdagent">
<target type="virtio" name="com.redhat.spice.0"/> <target type="virtio" name="com.redhat.spice.0"/>
</channel> </channel>
<graphics type="spice" port="-1" tlsPort="-1" autoport="yes"> <graphics type="spice" port="-1" tlsPort="-1" autoport="yes">

View File

@@ -13,6 +13,9 @@
<vmport state="off"/> <vmport state="off"/>
</features> </features>
<devices> <devices>
<channel type="qemu-vdagent">
<target type="virtio" name="com.redhat.spice.0"/>
</channel>
<graphics type="vnc" port="5907"/> <graphics type="vnc" port="5907"/>
<sound model="ich9"/> <sound model="ich9"/>
<video> <video>

View File

@@ -12,6 +12,8 @@
<graphics type='spice' port='5907' tlsPort='5901' autoport='no' passwd='sercet' passwdValidTo='2011-05-31T16:11:22' connected='disconnect' keymap='de' listen='127.0.0.1'> <graphics type='spice' port='5907' tlsPort='5901' autoport='no' passwd='sercet' passwdValidTo='2011-05-31T16:11:22' connected='disconnect' keymap='de' listen='127.0.0.1'>
<listen type='socket' socket='/tmp/spice.sock'/> <listen type='socket' socket='/tmp/spice.sock'/>
<listen type='address' address='127.0.0.1'/> <listen type='address' address='127.0.0.1'/>
<clipboard copypaste='no'/>
<mouse mode='client'/>
<gl enable='yes' rendernode='/dev/my/rendernode'/> <gl enable='yes' rendernode='/dev/my/rendernode'/>
</graphics> </graphics>
<graphics type='sdl'/> <graphics type='sdl'/>

View File

@@ -18,6 +18,13 @@
<acceleration accel3d="yes"/> <acceleration accel3d="yes"/>
</model> </model>
</video> </video>
<channel type="qemu-vdagent">
<source>
<clipboard copypaste="no"/>
<mouse mode="client"/>
</source>
<target type="virtio" name="com.redhat.spice.0"/>
</channel>
<graphics type="egl-headless"> <graphics type="egl-headless">
<gl rendernode="/dev/my/rendernode"/> <gl rendernode="/dev/my/rendernode"/>
</graphics> </graphics>

View File

@@ -1220,12 +1220,12 @@ def testConvertToQ35():
def testConvertToVNC(): def testConvertToVNC():
conn = utils.URIs.openconn(utils.URIs.kvm_x86) conn = utils.URIs.openconn(utils.URIs.kvm_x86)
def _test(filename_base): def _test(filename_base, **kwargs):
guest, outfile = _get_test_content(conn, filename_base) guest, outfile = _get_test_content(conn, filename_base)
guest.convert_to_vnc() guest.convert_to_vnc(**kwargs)
_alter_compare(conn, guest.get_xml(), outfile) _alter_compare(conn, guest.get_xml(), outfile)
_test("convert-to-vnc-empty") _test("convert-to-vnc-empty", qemu_vdagent=True)
_test("convert-to-vnc-spice-devices") _test("convert-to-vnc-spice-devices")
_test("convert-to-vnc-spice-manyopts") _test("convert-to-vnc-spice-manyopts", qemu_vdagent=True)
_test("convert-to-vnc-has-vnc") _test("convert-to-vnc-has-vnc", qemu_vdagent=True)

View File

@@ -843,7 +843,7 @@ class Guest(XMLBuilder):
dev.rendernode = spicedev.rendernode dev.rendernode = spicedev.rendernode
self.add_device(dev) self.add_device(dev)
def _convert_to_vnc_graphics(self): def _convert_to_vnc_graphics(self, agent):
""" """
If there's already VNC graphics configured, we leave it intact, If there's already VNC graphics configured, we leave it intact,
but rip out all evidence of other graphics devices. but rip out all evidence of other graphics devices.
@@ -894,6 +894,10 @@ class Guest(XMLBuilder):
dev.add_child(listen) dev.add_child(listen)
dev.set_defaults(self) dev.set_defaults(self)
if agent:
agent.source.clipboard_copypaste = srcdev.clipboard_copypaste
agent.source.mouse_mode = srcdev.mouse_mode
def _convert_to_vnc_video(self): def _convert_to_vnc_video(self):
""" """
If there's no video device, add a default one. If there's no video device, add a default one.
@@ -920,7 +924,18 @@ class Guest(XMLBuilder):
"removing it instead.", dev.model) "removing it instead.", dev.model)
self.remove_device(dev) self.remove_device(dev)
def convert_to_vnc(self): def _add_qemu_vdagent(self):
if any(c for c in self.devices.channel if
c.type == c.TYPE_QEMUVDAGENT):
return
dev = DeviceChannel(self.conn)
dev.type = dev.TYPE_QEMUVDAGENT
dev.set_defaults(self)
self.add_device(dev)
return dev
def convert_to_vnc(self, qemu_vdagent=False):
""" """
Convert existing XML to have one VNC graphics connection. Convert existing XML to have one VNC graphics connection.
""" """
@@ -930,7 +945,11 @@ class Guest(XMLBuilder):
# Could be necessary if XML is in broken state. # Could be necessary if XML is in broken state.
self._force_remove_spice_devices() self._force_remove_spice_devices()
self._convert_to_vnc_graphics() agent = None
if qemu_vdagent:
agent = self._add_qemu_vdagent()
self._convert_to_vnc_graphics(agent)
self._convert_to_vnc_video() self._convert_to_vnc_video()
def set_defaults(self, _guest): def set_defaults(self, _guest):