From a0b42327c6bb587c20628f8bc946c6041f61818a Mon Sep 17 00:00:00 2001 From: Pavel Hrdina Date: Fri, 22 Feb 2019 16:32:39 +0100 Subject: [PATCH] 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 Signed-off-by: Pavel Hrdina --- tests/xmlparse-xml/change-graphics-out.xml | 1 - virtManager/addhardware.py | 2 +- virtManager/domain.py | 13 +++++------- virtinst/cli.py | 12 +---------- virtinst/devices/graphics.py | 24 +++++++++++----------- 5 files changed, 19 insertions(+), 33 deletions(-) diff --git a/tests/xmlparse-xml/change-graphics-out.xml b/tests/xmlparse-xml/change-graphics-out.xml index 632ae8383..6aea45b6a 100644 --- a/tests/xmlparse-xml/change-graphics-out.xml +++ b/tests/xmlparse-xml/change-graphics-out.xml @@ -31,7 +31,6 @@ - diff --git a/virtManager/addhardware.py b/virtManager/addhardware.py index 691617824..eb6967f97 100644 --- a/virtManager/addhardware.py +++ b/virtManager/addhardware.py @@ -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 diff --git a/virtManager/domain.py b/virtManager/domain.py index 324621de9..3f46624cf 100644 --- a/virtManager/domain.py +++ b/virtManager/domain.py @@ -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) diff --git a/virtinst/cli.py b/virtinst/cli.py index 06c6d33e6..d56fade88 100644 --- a/virtinst/cli.py +++ b/virtinst/cli.py @@ -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", diff --git a/virtinst/devices/graphics.py b/virtinst/devices/graphics.py index dafae0632..c0a28dd6b 100644 --- a/virtinst/devices/graphics.py +++ b/virtinst/devices/graphics.py @@ -141,15 +141,15 @@ class DeviceGraphics(Device): def _set_listen(self, val): - # Update the corresponding 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