[virt-tools-list] [PATCH v3 2/2] gfxdetails: add listen option
marcandre.lureau at redhat.com
marcandre.lureau at redhat.com
Fri Nov 18 14:09:46 UTC 2016
From: Marc-André Lureau <marcandre.lureau at redhat.com>
Similarly to virt-install --listen=none, add a checkbox to disable all
extra display server listening interface/ports.
Signed-off-by: Marc-André Lureau <marcandre.lureau at redhat.com>
---
ui/gfxdetails.ui | 45 ++++++++++++++++++++++++++++++++++-----------
virtManager/addhardware.py | 14 +++++++++-----
virtManager/details.py | 7 ++++---
virtManager/domain.py | 11 ++++++++---
virtManager/gfxdetails.py | 38 ++++++++++++++++++++++++++++++--------
virtinst/devicegraphics.py | 16 +++++++++++++++-
6 files changed, 100 insertions(+), 31 deletions(-)
diff --git a/ui/gfxdetails.ui b/ui/gfxdetails.ui
index b6f54aa..84099dd 100644
--- a/ui/gfxdetails.ui
+++ b/ui/gfxdetails.ui
@@ -214,15 +214,11 @@
<object class="GtkComboBox" id="graphics-keymap">
<property name="visible">True</property>
<property name="can_focus">False</property>
- <property name="halign">start</property>
- <property name="hexpand">False</property>
<property name="has_entry">True</property>
<signal name="changed" handler="on_graphics_keymap_changed" swapped="no"/>
<child internal-child="entry">
<object class="GtkEntry" id="combobox-entry">
<property name="can_focus">True</property>
- <property name="halign">start</property>
- <property name="hexpand">False</property>
</object>
</child>
</object>
@@ -328,16 +324,44 @@
</packing>
</child>
<child>
- <object class="GtkComboBox" id="graphics-address">
+ <object class="GtkBox">
<property name="visible">True</property>
<property name="can_focus">False</property>
- <property name="halign">start</property>
- <property name="has_entry">True</property>
- <signal name="changed" handler="on_graphics_address_changed" swapped="no"/>
- <child internal-child="entry">
- <object class="GtkEntry" id="combobox-entry2">
+ <child>
+ <object class="GtkCheckButton" id="graphics-address-listen">
+ <property name="label" translatable="yes">Listen</property>
+ <property name="visible">True</property>
<property name="can_focus">True</property>
+ <property name="receives_default">False</property>
+ <property name="use_underline">True</property>
+ <property name="xalign">0</property>
+ <property name="draw_indicator">True</property>
+ <signal name="toggled" handler="on_graphics_listen_toggled" swapped="no"/>
+ </object>
+ <packing>
+ <property name="expand">True</property>
+ <property name="fill">True</property>
+ <property name="position">0</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkComboBox" id="graphics-address">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="halign">start</property>
+ <property name="has_entry">True</property>
+ <signal name="changed" handler="on_graphics_address_changed" swapped="no"/>
+ <child internal-child="entry">
+ <object class="GtkEntry">
+ <property name="can_focus">True</property>
+ </object>
+ </child>
</object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">True</property>
+ <property name="position">1</property>
+ </packing>
</child>
</object>
<packing>
@@ -349,7 +373,6 @@
<object class="GtkComboBox" id="graphics-type">
<property name="visible">True</property>
<property name="can_focus">False</property>
- <property name="halign">start</property>
<property name="has_entry">True</property>
<signal name="changed" handler="on_graphics_type_changed" swapped="no"/>
<child internal-child="entry">
diff --git a/virtManager/addhardware.py b/virtManager/addhardware.py
index 7a3c8f2..3f868aa 100644
--- a/virtManager/addhardware.py
+++ b/virtManager/addhardware.py
@@ -1541,16 +1541,20 @@ class vmmAddHardware(vmmGObjectUI):
def _validate_page_graphics(self):
try:
- (gtype, port,
- tlsport, addr, passwd, keymap, gl) = self._gfxdetails.get_values()
+ (gtype, port, tlsport, listen,
+ addr, passwd, keymap, gl) = self._gfxdetails.get_values()
self._dev = virtinst.VirtualGraphics(self.conn.get_backend())
self._dev.type = gtype
- self._dev.port = port
self._dev.passwd = passwd
- self._dev.listen = addr
- self._dev.tlsPort = tlsport
self._dev.gl = gl
+
+ if not listen:
+ self._dev.set_listen_none()
+ else:
+ self._dev.listen = addr
+ self._dev.port = port
+ self._dev.tlsPort = tlsport
if keymap:
self._dev.keymap = keymap
except ValueError, e:
diff --git a/virtManager/details.py b/virtManager/details.py
index d803d52..d4e6629 100644
--- a/virtManager/details.py
+++ b/virtManager/details.py
@@ -2135,15 +2135,16 @@ class vmmDetails(vmmGObjectUI):
devobj=devobj)
def config_graphics_apply(self, devobj):
- (gtype, port,
- tlsport, addr, passwd, keymap, gl) = self.gfxdetails.get_values()
+ (gtype, port, tlsport, listen,
+ addr, passwd, keymap, gl) = self.gfxdetails.get_values()
kwargs = {}
if self.edited(EDIT_GFX_PASSWD):
kwargs["passwd"] = passwd
if self.edited(EDIT_GFX_ADDRESS):
- kwargs["listen"] = addr
+ kwargs["listen"] = listen
+ kwargs["addr"] = addr
if self.edited(EDIT_GFX_KEYMAP):
kwargs["keymap"] = keymap
if self.edited(EDIT_GFX_PORT):
diff --git a/virtManager/domain.py b/virtManager/domain.py
index 6e742b9..40b28db 100644
--- a/virtManager/domain.py
+++ b/virtManager/domain.py
@@ -824,7 +824,7 @@ class vmmDomain(vmmLibvirtObject):
self._redefine_xmlobj(xmlobj)
def define_graphics(self, devobj, do_hotplug,
- listen=_SENTINEL, port=_SENTINEL, tlsport=_SENTINEL,
+ listen=_SENTINEL, addr=_SENTINEL, port=_SENTINEL, tlsport=_SENTINEL,
passwd=_SENTINEL, keymap=_SENTINEL, gtype=_SENTINEL,
gl=_SENTINEL):
xmlobj = self._make_xmlobj_to_define()
@@ -832,8 +832,8 @@ class vmmDomain(vmmLibvirtObject):
if not editdev:
return
- if listen != _SENTINEL:
- editdev.listen = listen
+ if addr != _SENTINEL:
+ editdev.listen = addr
if port != _SENTINEL:
editdev.port = port
if tlsport != _SENTINEL:
@@ -846,6 +846,11 @@ class vmmDomain(vmmLibvirtObject):
editdev.type = gtype
if gl != _SENTINEL:
editdev.gl = gl
+ if listen != _SENTINEL:
+ if not listen:
+ editdev.set_listen_none()
+ else:
+ editdev.remove_listen_none()
if do_hotplug:
self.hotplug(device=editdev)
diff --git a/virtManager/gfxdetails.py b/virtManager/gfxdetails.py
index f3cd3a9..ea71aed 100644
--- a/virtManager/gfxdetails.py
+++ b/virtManager/gfxdetails.py
@@ -46,12 +46,13 @@ class vmmGraphicsDetails(vmmGObjectUI):
self.builder.connect_signals({
"on_graphics_type_changed": self._change_graphics_type,
+ "on_graphics_listen_toggled": self._change_graphics_listen,
"on_graphics_port_auto_toggled": self._change_port_auto,
"on_graphics_tlsport_auto_toggled": self._change_tlsport_auto,
"on_graphics_use_password": self._change_password_chk,
"on_graphics_password_changed": lambda ignore: self.emit("changed-password"),
- "on_graphics_address_changed": lambda ignore: self.emit("changed-address"),
+ "on_graphics_address_changed": self._change_graphics_address,
"on_graphics_tlsport_changed": lambda ignore: self.emit("changed-tlsport"),
"on_graphics_port_changed": lambda ignore: self.emit("changed-port"),
"on_graphics_keymap_changed": lambda ignore: self.emit("changed-keymap"),
@@ -129,6 +130,7 @@ class vmmGraphicsDetails(vmmGObjectUI):
self._change_ports()
self.widget("graphics-port-auto").set_active(True)
self.widget("graphics-tlsport-auto").set_active(True)
+ self.widget("graphics-address-listen").set_active(True)
self.widget("graphics-password").set_text("")
self.widget("graphics-password").set_sensitive(False)
self.widget("graphics-password-chk").set_active(False)
@@ -136,6 +138,7 @@ class vmmGraphicsDetails(vmmGObjectUI):
def get_values(self):
gtype = uiutil.get_list_selection(self.widget("graphics-type"))
port, tlsport = self._get_config_graphics_ports()
+ listen = self.widget("graphics-address-listen").get_active()
addr = uiutil.get_list_selection(self.widget("graphics-address"))
keymap = uiutil.get_list_selection(self.widget("graphics-keymap"))
if keymap == "auto":
@@ -147,7 +150,7 @@ class vmmGraphicsDetails(vmmGObjectUI):
gl = self.widget("graphics-opengl").get_active()
- return gtype, port, tlsport, addr, passwd, keymap, gl
+ return gtype, port, tlsport, listen, addr, passwd, keymap, gl
def set_dev(self, gfx):
self.reset_state()
@@ -181,8 +184,12 @@ class vmmGraphicsDetails(vmmGObjectUI):
use_passwd = gfx.passwd is not None
set_port("graphics-port", gfx.port)
- uiutil.set_list_selection(
- self.widget("graphics-address"), gfx.listen)
+ if gfx.has_listen_none():
+ self.widget("graphics-address-listen").set_active(False)
+ else:
+ self.widget("graphics-address-listen").set_active(True)
+ uiutil.set_list_selection(
+ self.widget("graphics-address"), gfx.listen)
uiutil.set_list_selection(
self.widget("graphics-keymap"), gfx.keymap or None)
@@ -211,15 +218,20 @@ class vmmGraphicsDetails(vmmGObjectUI):
#############
def _show_rows_from_type(self):
- hide_all = ["graphics-xauth", "graphics-display", "graphics-address",
+ hide_all = ["graphics-xauth", "graphics-display",
"graphics-password-box", "graphics-keymap", "graphics-port-box",
"graphics-tlsport-box", "graphics-opengl"]
gtype = uiutil.get_list_selection(self.widget("graphics-type"))
+ listen = self.widget("graphics-address-listen").get_active()
+
sdl_rows = ["graphics-xauth", "graphics-display"]
- vnc_rows = ["graphics-password-box", "graphics-address",
- "graphics-port-box", "graphics-keymap"]
- spice_rows = vnc_rows[:] + ["graphics-tlsport-box"]
+ vnc_rows = ["graphics-password-box", "graphics-keymap"]
+ if listen:
+ vnc_rows.extend(["graphics-port-box"])
+ spice_rows = vnc_rows[:]
+ if listen:
+ spice_rows.extend(["graphics-tlsport-box"])
if self.conn.check_support(self.conn.SUPPORT_CONN_SPICE_GL):
spice_rows.extend(["graphics-opengl"])
@@ -238,6 +250,16 @@ class vmmGraphicsDetails(vmmGObjectUI):
self._show_rows_from_type()
self.emit("changed-type")
+ def _change_graphics_address(self, ignore):
+ self._show_rows_from_type()
+ self.emit("changed-address")
+
+ def _change_graphics_listen(self, ignore):
+ active = self.widget("graphics-address-listen").get_active()
+ self.widget("graphics-address").set_visible(active)
+ self._show_rows_from_type()
+ self.emit("changed-address")
+
def _change_port_auto(self, ignore):
self.widget("graphics-port-auto").set_inconsistent(False)
self._change_ports()
diff --git a/virtinst/devicegraphics.py b/virtinst/devicegraphics.py
index 07b554e..e885418 100644
--- a/virtinst/devicegraphics.py
+++ b/virtinst/devicegraphics.py
@@ -202,6 +202,11 @@ class VirtualGraphics(VirtualDevice):
self.remove_child(find_listen[0])
else:
find_listen[0].address = val
+
+ if self.port is None and self.tlsPort is None and self.type == "spice":
+ self.port = -1
+ self.tlsPort = -1
+
return val
listen = XMLProperty("./@listen", set_converter=_set_listen)
@@ -219,16 +224,25 @@ class VirtualGraphics(VirtualDevice):
for listen in self.listens:
self.remove_child(listen)
+ def remove_listen_none(self):
+ for listen in self.listens:
+ if listen.type == "none":
+ self.remove_child(listen)
+
def add_listen(self):
obj = _GraphicsListen(self.conn)
self.add_child(obj)
return obj
+ def has_listen_none(self):
+ return len(self.listens) > 0 and self.listens[0].type == "none"
+
def set_listen_none(self):
self.remove_all_listens()
+ self.listen = None
self.port = None
self.tlsPort = None
- self.autoport = False
+ self.autoport = None
self.socket = None
if self.conn.check_support(
--
2.10.0
More information about the virt-tools-list
mailing list