virtManager/ui: add listen type option

Similarly to virt-install --listen=none, add a combobox to select
the listen type: "address" or "none" for now, as suggested by Pavel
Hrdina.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
This commit is contained in:
Marc-André Lureau 2017-02-21 17:00:59 +04:00 committed by Cole Robinson
parent 88942028b3
commit 326dc03c23
6 changed files with 117 additions and 37 deletions

View File

@ -67,7 +67,7 @@
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">4</property>
<property name="top_attach">5</property>
</packing>
</child>
<child>
@ -95,7 +95,7 @@
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">1</property>
<property name="top_attach">2</property>
</packing>
</child>
<child>
@ -109,7 +109,7 @@
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">4</property>
<property name="top_attach">5</property>
</packing>
</child>
<child>
@ -123,7 +123,7 @@
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">2</property>
<property name="top_attach">3</property>
</packing>
</child>
<child>
@ -145,7 +145,7 @@
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">3</property>
<property name="top_attach">4</property>
</packing>
</child>
<child>
@ -193,7 +193,7 @@
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">3</property>
<property name="top_attach">4</property>
</packing>
</child>
<child>
@ -207,7 +207,7 @@
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">5</property>
<property name="top_attach">6</property>
</packing>
</child>
<child>
@ -228,7 +228,7 @@
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">5</property>
<property name="top_attach">6</property>
</packing>
</child>
<child>
@ -276,7 +276,7 @@
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">2</property>
<property name="top_attach">3</property>
</packing>
</child>
<child>
@ -288,7 +288,7 @@
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">6</property>
<property name="top_attach">7</property>
</packing>
</child>
<child>
@ -300,7 +300,7 @@
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">7</property>
<property name="top_attach">8</property>
</packing>
</child>
<child>
@ -312,7 +312,7 @@
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">6</property>
<property name="top_attach">7</property>
</packing>
</child>
<child>
@ -324,7 +324,7 @@
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">7</property>
<property name="top_attach">8</property>
</packing>
</child>
<child>
@ -342,7 +342,7 @@
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">1</property>
<property name="top_attach">2</property>
</packing>
</child>
<child>
@ -374,7 +374,7 @@
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">8</property>
<property name="top_attach">9</property>
</packing>
</child>
<child>
@ -390,7 +390,39 @@
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">8</property>
<property name="top_attach">9</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="label4">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">L_isten type:</property>
<property name="use_underline">True</property>
<property name="mnemonic_widget">graphics-listen-type</property>
<property name="xalign">1</property>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">1</property>
</packing>
</child>
<child>
<object class="GtkComboBox" id="graphics-listen-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_listen_type_changed" swapped="no"/>
<child internal-child="entry">
<object class="GtkEntry">
<property name="can_focus">True</property>
</object>
</child>
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">1</property>
</packing>
</child>
</object>

View File

@ -1554,16 +1554,22 @@ 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 or listen == "none":
self._dev.set_listen_none()
elif listen == "address":
self._dev.listen = addr
self._dev.port = port
self._dev.tlsPort = tlsport
else:
raise ValueError(_("invalid listen type"))
if keymap:
self._dev.keymap = keymap
except ValueError, e:

View File

@ -87,6 +87,7 @@ EDIT_NET_MAC,
EDIT_GFX_PASSWD,
EDIT_GFX_TYPE,
EDIT_GFX_KEYMAP,
EDIT_GFX_LISTEN,
EDIT_GFX_ADDRESS,
EDIT_GFX_TLSPORT,
EDIT_GFX_PORT,
@ -105,7 +106,7 @@ EDIT_FS,
EDIT_HOSTDEV_ROMBAR,
) = range(1, 46)
) = range(1, 47)
# Columns in hw list model
@ -399,6 +400,8 @@ class vmmDetails(vmmGObjectUI):
lambda *x: self.enable_apply(x, EDIT_GFX_OPENGL))
self.gfxdetails.connect("changed-tlsport",
lambda *x: self.enable_apply(x, EDIT_GFX_TLSPORT))
self.gfxdetails.connect("changed-listen",
lambda *x: self.enable_apply(x, EDIT_GFX_LISTEN))
self.gfxdetails.connect("changed-address",
lambda *x: self.enable_apply(x, EDIT_GFX_ADDRESS))
self.gfxdetails.connect("changed-keymap",
@ -2160,22 +2163,24 @@ 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
if self.edited(EDIT_GFX_LISTEN):
kwargs["listen"] = listen
if self.edited(EDIT_GFX_ADDRESS) or self.edited(EDIT_GFX_LISTEN):
kwargs["addr"] = addr
if self.edited(EDIT_GFX_KEYMAP):
kwargs["keymap"] = keymap
if self.edited(EDIT_GFX_PORT):
if self.edited(EDIT_GFX_PORT) or self.edited(EDIT_GFX_LISTEN):
kwargs["port"] = port
if self.edited(EDIT_GFX_OPENGL):
kwargs["gl"] = gl
if self.edited(EDIT_GFX_TLSPORT):
if self.edited(EDIT_GFX_TLSPORT) or self.edited(EDIT_GFX_LISTEN):
kwargs["tlsport"] = tlsport
if self.edited(EDIT_GFX_TYPE):
kwargs["gtype"] = gtype

View File

@ -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,12 @@ class vmmDomain(vmmLibvirtObject):
editdev.type = gtype
if gl != _SENTINEL:
editdev.gl = gl
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

@ -33,6 +33,7 @@ class vmmGraphicsDetails(vmmGObjectUI):
"changed-port": (GObject.SignalFlags.RUN_FIRST, None, []),
"changed-tlsport": (GObject.SignalFlags.RUN_FIRST, None, []),
"changed-type": (GObject.SignalFlags.RUN_FIRST, None, []),
"changed-listen": (GObject.SignalFlags.RUN_FIRST, None, []),
"changed-address": (GObject.SignalFlags.RUN_FIRST, None, []),
"changed-keymap": (GObject.SignalFlags.RUN_FIRST, None, []),
"changed-opengl": (GObject.SignalFlags.RUN_FIRST, None, []),
@ -50,6 +51,7 @@ class vmmGraphicsDetails(vmmGObjectUI):
"on_graphics_tlsport_auto_toggled": self._change_tlsport_auto,
"on_graphics_use_password": self._change_password_chk,
"on_graphics_listen_type_changed": self._change_graphics_listen,
"on_graphics_password_changed": lambda ignore: self.emit("changed-password"),
"on_graphics_address_changed": lambda ignore: self.emit("changed-address"),
"on_graphics_tlsport_changed": lambda ignore: self.emit("changed-tlsport"),
@ -78,6 +80,14 @@ class vmmGraphicsDetails(vmmGObjectUI):
graphics_model.append(["spice", _("Spice server")])
graphics_model.append(["vnc", _("VNC server")])
graphics_listen_list = self.widget("graphics-listen-type")
graphics_listen_model = Gtk.ListStore(str, str)
graphics_listen_list.set_model(graphics_listen_model)
uiutil.init_combo_text_column(graphics_listen_list, 1)
graphics_listen_model.clear()
graphics_listen_model.append(["address", _("Address")])
graphics_listen_model.append(["none", _("None")])
self.widget("graphics-address").set_model(Gtk.ListStore(str, str))
uiutil.init_combo_text_column(self.widget("graphics-address"), 1)
@ -123,6 +133,7 @@ class vmmGraphicsDetails(vmmGObjectUI):
uiutil.set_grid_row_visible(self.widget("graphics-xauth"), False)
self.widget("graphics-type").set_active(0)
self.widget("graphics-listen-type").set_active(0)
self.widget("graphics-address").set_active(0)
self.widget("graphics-keymap").set_active(0)
@ -136,6 +147,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 = uiutil.get_list_selection(self.widget("graphics-listen-type"))
addr = uiutil.get_list_selection(self.widget("graphics-address"))
keymap = uiutil.get_list_selection(self.widget("graphics-keymap"))
if keymap == "auto":
@ -147,7 +159,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 +193,13 @@ 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)
listentype = gfx.get_first_listen_type()
if listentype and listentype == 'none':
uiutil.set_list_selection(self.widget("graphics-listen-type"), 'none')
else:
uiutil.set_list_selection(self.widget("graphics-listen-type"), 'address')
uiutil.set_list_selection(
self.widget("graphics-address"), gfx.listen)
uiutil.set_list_selection(
self.widget("graphics-keymap"), gfx.keymap or None)
@ -216,10 +233,15 @@ class vmmGraphicsDetails(vmmGObjectUI):
"graphics-tlsport-box", "graphics-opengl"]
gtype = uiutil.get_list_selection(self.widget("graphics-type"))
listen = uiutil.get_list_selection(self.widget("graphics-listen-type"))
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 == 'address':
vnc_rows.extend(["graphics-port-box", "graphics-address"])
spice_rows = vnc_rows[:]
if listen == 'address':
spice_rows.extend(["graphics-tlsport-box"])
if self.conn.check_support(self.conn.SUPPORT_CONN_SPICE_GL):
spice_rows.extend(["graphics-opengl"])
@ -238,6 +260,10 @@ class vmmGraphicsDetails(vmmGObjectUI):
self._show_rows_from_type()
self.emit("changed-type")
def _change_graphics_listen(self, ignore):
self._show_rows_from_type()
self.emit("changed-listen")
def _change_port_auto(self, ignore):
self.widget("graphics-port-auto").set_inconsistent(False)
self._change_ports()

View File

@ -224,6 +224,11 @@ class VirtualGraphics(VirtualDevice):
self.add_child(obj)
return obj
def get_first_listen_type(self):
if len(self.listens) > 0:
return self.listens[0].type
return None
def set_listen_none(self):
self.remove_all_listens()
self.listen = None