graphics: move all listen code into one place

Instead of duplicating the code into CLI and GUI move it into graphics
device file which is used from both places.  This also fixes a bug in
virt-xml where changing listen to address was not working.

This also changes behavior to always configure one listen type when
using CLI listen option or GUI.  If user wants to modify only specific
listen type they can use listens[] options from CLI.

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1565968

Reviewed-by: Cole Robinson <crobinso@redhat.com>
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
This commit is contained in:
Pavel Hrdina 2019-02-22 16:32:39 +01:00
parent 9cd405b6ef
commit a0b42327c6
5 changed files with 19 additions and 33 deletions

View File

@ -31,7 +31,6 @@
<listen type="network" network="mynewnet"/>
</graphics>
<graphics type="spice" passwd="newpass" port="6000" tlsPort="6001" listen="1.2.3.4" passwdValidTo="2011-01-07T19:08:00" connected="disconnect" defaultMode="secure">
<listen type="address" address="1.2.3.4"/>
<channel name="inputs" mode="secure"/>
<channel name="main" mode="any"/>
<channel name="record" mode="insecure"/>

View File

@ -1308,7 +1308,7 @@ class vmmAddHardware(vmmGObjectUI):
self._dev.rendernode = rendernode
if not listen or listen == "none":
self._dev.set_listen_none()
self._dev.listen = "none"
elif listen == "address":
self._dev.listen = addr
self._dev.port = port

View File

@ -680,8 +680,11 @@ class vmmDomain(vmmLibvirtObject):
if not editdev:
return
if addr != _SENTINEL:
editdev.listen = addr
if addr != _SENTINEL or listen != _SENTINEL:
if listen == "none":
editdev.listen = listen
else:
editdev.listen = addr
if port != _SENTINEL:
editdev.port = port
if tlsport != _SENTINEL:
@ -696,12 +699,6 @@ class vmmDomain(vmmLibvirtObject):
editdev.gl = gl
if rendernode != _SENTINEL:
editdev.rendernode = rendernode
if listen != _SENTINEL:
listentype = editdev.get_first_listen_type()
if listen == 'none':
editdev.set_listen_none()
elif listentype and listentype == 'none':
editdev.remove_all_listens()
if do_hotplug:
self.hotplug(device=editdev)

View File

@ -2531,16 +2531,6 @@ class ParserGraphics(VirtCLIParser):
return
inst.type = val
def set_listen_cb(self, inst, val, virtarg):
if val == "none":
inst.set_listen_none()
elif val == "socket":
inst.remove_all_listens()
obj = inst.listens.add_new()
obj.type = "socket"
else:
inst.listen = val
def listens_find_inst_cb(self, *args, **kwargs):
cliarg = "listens" # listens[0-9]*
objpropname = "listens" # graphics.listens
@ -2576,7 +2566,7 @@ class ParserGraphics(VirtCLIParser):
cls.add_arg(None, "type", cb=cls.set_type_cb)
cls.add_arg("port", "port")
cls.add_arg("tlsPort", "tlsport")
cls.add_arg("listen", "listen", cb=cls.set_listen_cb)
cls.add_arg("listen", "listen")
cls.add_arg("type", "listens[0-9]*.type",
find_inst_cb=cls.listens_find_inst_cb)
cls.add_arg("address", "listens[0-9]*.address",

View File

@ -141,15 +141,15 @@ class DeviceGraphics(Device):
def _set_listen(self, val):
# Update the corresponding <listen> block
find_listen = [l for l in self.listens if
(l.type == "address" and l.address == self._listen)]
if find_listen:
if val is None:
self.remove_child(find_listen[0])
else:
find_listen[0].address = val
self._listen = val
if val == "none":
self._set_listen_none()
elif val == "socket":
self._remove_all_listens()
obj = self.listens.add_new()
obj.type = "socket"
else:
self._remove_all_listens()
self._listen = val
def _get_listen(self):
return self._listen
_listen = XMLProperty("./@listen")
@ -163,7 +163,7 @@ class DeviceGraphics(Device):
defaultMode = XMLProperty("./@defaultMode")
listens = XMLChildProperty(_GraphicsListen)
def remove_all_listens(self):
def _remove_all_listens(self):
for listen in self.listens:
self.remove_child(listen)
@ -172,8 +172,8 @@ class DeviceGraphics(Device):
return self.listens[0].type
return None
def set_listen_none(self):
self.remove_all_listens()
def _set_listen_none(self):
self._remove_all_listens()
self.listen = None
self.port = None
self.tlsPort = None