[virt-tools-list] [virt-manager PATCH] graphics: move all listen code into one place
Pavel Hrdina
phrdina at redhat.com
Fri Feb 22 15:44:51 UTC 2019
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
Signed-off-by: Pavel Hrdina <phrdina at redhat.com>
---
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 632ae838..6aea45b6 100644
--- a/tests/xmlparse-xml/change-graphics-out.xml
+++ b/tests/xmlparse-xml/change-graphics-out.xml
@@ -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"/>
diff --git a/virtManager/addhardware.py b/virtManager/addhardware.py
index 69161782..eb6967f9 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 324621de..3f46624c 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 06c6d33e..d56fade8 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 dafae063..c0a28dd6 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 <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
--
2.20.1
More information about the virt-tools-list
mailing list