[virt-tools-list] [PATCH 5/5] gfxdetails: add local-only option

Marc-André Lureau marcandre.lureau at redhat.com
Thu Apr 28 12:22:11 UTC 2016


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           | 106 +++++++++++++++++++++++++++++----------------
 virtManager/addhardware.py |   4 +-
 virtManager/details.py     |  12 ++++-
 virtManager/domain.py      |   4 +-
 virtManager/gfxdetails.py  |  42 ++++++++++++++----
 5 files changed, 118 insertions(+), 50 deletions(-)

diff --git a/ui/gfxdetails.ui b/ui/gfxdetails.ui
index 87c50f9..fe8d64f 100644
--- a/ui/gfxdetails.ui
+++ b/ui/gfxdetails.ui
@@ -67,63 +67,49 @@
       </object>
       <packing>
         <property name="left_attach">1</property>
-        <property name="top_attach">4</property>
+        <property name="top_attach">5</property>
       </packing>
     </child>
     <child>
       <object class="GtkLabel" id="label429">
         <property name="visible">True</property>
         <property name="can_focus">False</property>
-        <property name="xalign">1</property>
         <property name="label" translatable="yes">_Type:</property>
         <property name="use_underline">True</property>
         <property name="mnemonic_widget">graphics-type</property>
-      </object>
-      <packing>
-        <property name="left_attach">0</property>
-        <property name="top_attach">0</property>
-      </packing>
-    </child>
-    <child>
-      <object class="GtkLabel" id="label430">
-        <property name="visible">True</property>
-        <property name="can_focus">False</property>
         <property name="xalign">1</property>
-        <property name="label" translatable="yes">Addr_ess:</property>
-        <property name="use_underline">True</property>
-        <property name="mnemonic_widget">graphics-address</property>
       </object>
       <packing>
         <property name="left_attach">0</property>
-        <property name="top_attach">1</property>
+        <property name="top_attach">0</property>
       </packing>
     </child>
     <child>
       <object class="GtkLabel" id="label432">
         <property name="visible">True</property>
         <property name="can_focus">False</property>
-        <property name="xalign">1</property>
         <property name="label" translatable="yes">Pa_ssword:</property>
         <property name="use_underline">True</property>
         <property name="mnemonic_widget">graphics-password-chk</property>
+        <property name="xalign">1</property>
       </object>
       <packing>
         <property name="left_attach">0</property>
-        <property name="top_attach">4</property>
+        <property name="top_attach">5</property>
       </packing>
     </child>
     <child>
       <object class="GtkLabel" id="label431">
         <property name="visible">True</property>
         <property name="can_focus">False</property>
-        <property name="xalign">1</property>
         <property name="label" translatable="yes">_Port:</property>
         <property name="use_underline">True</property>
         <property name="mnemonic_widget">graphics-port-auto</property>
+        <property name="xalign">1</property>
       </object>
       <packing>
         <property name="left_attach">0</property>
-        <property name="top_attach">2</property>
+        <property name="top_attach">3</property>
       </packing>
     </child>
     <child>
@@ -136,16 +122,16 @@
           <object class="GtkLabel" id="label29">
             <property name="visible">True</property>
             <property name="can_focus">False</property>
-            <property name="xalign">1</property>
             <property name="label" translatable="yes">T_LS port:</property>
             <property name="use_underline">True</property>
             <property name="mnemonic_widget">graphics-tlsport-auto</property>
+            <property name="xalign">1</property>
           </object>
         </child>
       </object>
       <packing>
         <property name="left_attach">0</property>
-        <property name="top_attach">3</property>
+        <property name="top_attach">4</property>
       </packing>
     </child>
     <child>
@@ -193,21 +179,21 @@
       </object>
       <packing>
         <property name="left_attach">1</property>
-        <property name="top_attach">3</property>
+        <property name="top_attach">4</property>
       </packing>
     </child>
     <child>
       <object class="GtkLabel" id="label12">
         <property name="visible">True</property>
         <property name="can_focus">False</property>
-        <property name="xalign">1</property>
         <property name="label" translatable="yes">Ke_ymap:</property>
         <property name="use_underline">True</property>
         <property name="mnemonic_widget">graphics-keymap</property>
+        <property name="xalign">1</property>
       </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 +214,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,55 +262,55 @@
       </object>
       <packing>
         <property name="left_attach">1</property>
-        <property name="top_attach">2</property>
+        <property name="top_attach">3</property>
       </packing>
     </child>
     <child>
       <object class="GtkLabel" id="label1">
         <property name="visible">True</property>
         <property name="can_focus">False</property>
-        <property name="xalign">1</property>
         <property name="label" translatable="yes">Display:</property>
+        <property name="xalign">1</property>
       </object>
       <packing>
         <property name="left_attach">0</property>
-        <property name="top_attach">6</property>
+        <property name="top_attach">7</property>
       </packing>
     </child>
     <child>
       <object class="GtkLabel" id="label2">
         <property name="visible">True</property>
         <property name="can_focus">False</property>
-        <property name="xalign">1</property>
         <property name="label" translatable="yes">XAuth:</property>
+        <property name="xalign">1</property>
       </object>
       <packing>
         <property name="left_attach">0</property>
-        <property name="top_attach">7</property>
+        <property name="top_attach">8</property>
       </packing>
     </child>
     <child>
       <object class="GtkLabel" id="graphics-display">
         <property name="visible">True</property>
         <property name="can_focus">False</property>
-        <property name="xalign">0</property>
         <property name="label" translatable="yes">label</property>
+        <property name="xalign">0</property>
       </object>
       <packing>
         <property name="left_attach">1</property>
-        <property name="top_attach">6</property>
+        <property name="top_attach">7</property>
       </packing>
     </child>
     <child>
       <object class="GtkLabel" id="graphics-xauth">
         <property name="visible">True</property>
         <property name="can_focus">False</property>
-        <property name="xalign">0</property>
         <property name="label" translatable="yes">label</property>
+        <property name="xalign">0</property>
       </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 +328,7 @@
       </object>
       <packing>
         <property name="left_attach">1</property>
-        <property name="top_attach">1</property>
+        <property name="top_attach">2</property>
       </packing>
     </child>
     <child>
@@ -371,7 +357,7 @@
       </object>
       <packing>
         <property name="left_attach">0</property>
-        <property name="top_attach">8</property>
+        <property name="top_attach">9</property>
       </packing>
     </child>
     <child>
@@ -389,7 +375,51 @@
       </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="label430">
+        <property name="visible">True</property>
+        <property name="can_focus">False</property>
+        <property name="label" translatable="yes">Addr_ess:</property>
+        <property name="use_underline">True</property>
+        <property name="mnemonic_widget">graphics-address</property>
+        <property name="xalign">1</property>
+      </object>
+      <packing>
+        <property name="left_attach">0</property>
+        <property name="top_attach">2</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">Local only:</property>
+        <property name="use_underline">True</property>
+        <property name="mnemonic_widget">graphics-address</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="GtkCheckButton" id="graphics-local-only">
+        <property name="label" translatable="yes">(through local libvirt only)</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_local_only_changed" swapped="no"/>
+      </object>
+      <packing>
+        <property name="left_attach">1</property>
+        <property name="top_attach">1</property>
       </packing>
     </child>
   </object>
diff --git a/virtManager/addhardware.py b/virtManager/addhardware.py
index fbd4494..903cf63 100644
--- a/virtManager/addhardware.py
+++ b/virtManager/addhardware.py
@@ -1560,7 +1560,7 @@ class vmmAddHardware(vmmGObjectUI):
 
     def _validate_page_graphics(self):
         try:
-            (gtype, port,
+            (gtype, autoport, port,
              tlsport, addr, passwd, keymap, gl) = self._gfxdetails.get_values()
 
             self._dev = virtinst.VirtualGraphics(self.conn.get_backend())
@@ -1569,6 +1569,8 @@ class vmmAddHardware(vmmGObjectUI):
             self._dev.passwd = passwd
             self._dev.listen = addr
             self._dev.tlsPort = tlsport
+            if autoport is False:
+                self._dev.autport = autoport
             if keymap:
                 self._dev.keymap = keymap
         except ValueError, e:
diff --git a/virtManager/details.py b/virtManager/details.py
index 189a8d5..a52061f 100644
--- a/virtManager/details.py
+++ b/virtManager/details.py
@@ -91,6 +91,7 @@ EDIT_GFX_ADDRESS,
 EDIT_GFX_TLSPORT,
 EDIT_GFX_PORT,
 EDIT_GFX_OPENGL,
+EDIT_GFX_LOCAL_ONLY,
 
 EDIT_VIDEO_MODEL,
 
@@ -105,7 +106,7 @@ EDIT_FS,
 
 EDIT_HOSTDEV_ROMBAR,
 
-) = range(1, 46)
+) = range(1, 47)
 
 
 # Columns in hw list model
@@ -375,6 +376,8 @@ class vmmDetails(vmmGObjectUI):
         self.widget("graphics-align").add(self.gfxdetails.top_box)
         self.gfxdetails.connect("changed-type",
             lambda *x: self.enable_apply(x, EDIT_GFX_TYPE))
+        self.gfxdetails.connect("changed-local-only",
+            lambda *x: self.enable_apply(x, EDIT_GFX_LOCAL_ONLY))
         self.gfxdetails.connect("changed-port",
             lambda *x: self.enable_apply(x, EDIT_GFX_PORT))
         self.gfxdetails.connect("changed-opengl",
@@ -2133,7 +2136,7 @@ class vmmDetails(vmmGObjectUI):
                                           devobj=devobj)
 
     def config_graphics_apply(self, devobj):
-        (gtype, port,
+        (gtype, autoport, port,
          tlsport, addr, passwd, keymap, gl) = self.gfxdetails.get_values()
 
         kwargs = {}
@@ -2152,6 +2155,11 @@ class vmmDetails(vmmGObjectUI):
             kwargs["tlsport"] = tlsport
         if self.edited(EDIT_GFX_TYPE):
             kwargs["gtype"] = gtype
+        if self.edited(EDIT_GFX_LOCAL_ONLY):
+            kwargs["tlsport"] = tlsport
+            kwargs["port"] = port
+            kwargs["listen"] = addr
+            kwargs["autoport"] = autoport
 
         return vmmAddHardware.change_config_helper(self.vm.define_graphics,
                                           kwargs, self.vm, self.err,
diff --git a/virtManager/domain.py b/virtManager/domain.py
index 66b7465..4853cfd 100644
--- a/virtManager/domain.py
+++ b/virtManager/domain.py
@@ -826,7 +826,7 @@ class vmmDomain(vmmLibvirtObject):
     def define_graphics(self, devobj, do_hotplug,
         listen=_SENTINEL, port=_SENTINEL, tlsport=_SENTINEL,
         passwd=_SENTINEL, keymap=_SENTINEL, gtype=_SENTINEL,
-        gl=_SENTINEL):
+        gl=_SENTINEL, autoport=_SENTINEL):
         xmlobj = self._make_xmlobj_to_define()
         editdev = self._lookup_device_to_define(xmlobj, devobj, do_hotplug)
         if not editdev:
@@ -846,6 +846,8 @@ class vmmDomain(vmmLibvirtObject):
             editdev.type = gtype
         if gl != _SENTINEL:
             editdev.gl = gl
+        if autoport != _SENTINEL:
+            editdev.autoport = autoport
 
         if do_hotplug:
             self.hotplug(device=editdev)
diff --git a/virtManager/gfxdetails.py b/virtManager/gfxdetails.py
index 374eff8..8930650 100644
--- a/virtManager/gfxdetails.py
+++ b/virtManager/gfxdetails.py
@@ -36,6 +36,7 @@ class vmmGraphicsDetails(vmmGObjectUI):
         "changed-address": (GObject.SignalFlags.RUN_FIRST, None, []),
         "changed-keymap": (GObject.SignalFlags.RUN_FIRST, None, []),
         "changed-opengl": (GObject.SignalFlags.RUN_FIRST, None, []),
+        "changed-local-only": (GObject.SignalFlags.RUN_FIRST, None, []),
     }
 
     def __init__(self, vm, builder, topwin):
@@ -46,6 +47,7 @@ class vmmGraphicsDetails(vmmGObjectUI):
 
         self.builder.connect_signals({
             "on_graphics_type_changed": self._change_graphics_type,
+            "on_graphics_local_only_changed": self._change_graphics_local_only,
             "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,
@@ -135,6 +137,7 @@ class vmmGraphicsDetails(vmmGObjectUI):
 
     def get_values(self):
         gtype = uiutil.get_list_selection(self.widget("graphics-type"))
+        local = self.widget("graphics-local-only").get_active()
         port, tlsport = self._get_config_graphics_ports()
         addr = uiutil.get_list_selection(self.widget("graphics-address"))
         keymap = uiutil.get_list_selection(self.widget("graphics-keymap"))
@@ -147,7 +150,14 @@ class vmmGraphicsDetails(vmmGObjectUI):
 
         gl = self.widget("graphics-opengl").get_active()
 
-        return gtype, port, tlsport, addr, passwd, keymap, gl
+        autoport = None
+        if local:
+            port = None
+            tlsport = None
+            addr = None
+            autoport = False
+
+        return gtype, autoport, port, tlsport, addr, passwd, keymap, gl
 
     def set_dev(self, gfx):
         self.reset_state()
@@ -170,6 +180,11 @@ class vmmGraphicsDetails(vmmGObjectUI):
 
             auto.set_label(label)
 
+        def is_local_only(gfx):
+            return (gfx.autoport is False
+                    and gfx.port is None
+                    and gfx.tlsPort is None)
+
         gtype = gfx.type
         is_vnc = (gtype == "vnc")
         is_sdl = (gtype == "sdl")
@@ -179,7 +194,6 @@ class vmmGraphicsDetails(vmmGObjectUI):
 
         if is_vnc or is_spice:
             use_passwd = gfx.passwd is not None
-
             set_port("graphics-port", gfx.port)
             uiutil.set_list_selection(
                 self.widget("graphics-address"), gfx.listen)
@@ -189,6 +203,7 @@ class vmmGraphicsDetails(vmmGObjectUI):
             self.widget("graphics-password").set_text(gfx.passwd or "")
             self.widget("graphics-password-chk").set_active(use_passwd)
             self.widget("graphics-password").set_sensitive(use_passwd)
+            self.widget("graphics-local-only").set_active(is_local_only(gfx))
 
         if is_spice:
             set_port("graphics-tlsport", gfx.tlsPort)
@@ -210,18 +225,25 @@ class vmmGraphicsDetails(vmmGObjectUI):
     # Listeners #
     #############
 
-    def _show_rows_from_type(self):
+    def _show_rows(self):
         hide_all = ["graphics-xauth", "graphics-display", "graphics-address",
             "graphics-password-box", "graphics-keymap", "graphics-port-box",
-            "graphics-tlsport-box", "graphics-opengl"]
+            "graphics-tlsport-box", "graphics-opengl", "graphics-local-only"]
 
         gtype = uiutil.get_list_selection(self.widget("graphics-type"))
+        local = self.widget("graphics-local-only").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", "graphics-opengl"]
+        vnc_rows = ["graphics-password-box", "graphics-keymap",
+            "graphics-local-only"]
+        if not local:
+            vnc_rows = vnc_rows[:] + ["graphics-address", "graphics-port-box"]
+
+        spice_rows = vnc_rows[:]
         if self.conn.check_support(self.conn.SUPPORT_CONN_SPICE_GL):
             spice_rows = spice_rows[:] + ["graphics-opengl"]
+        if not local:
+            spice_rows = spice_rows[:] + ["graphics-tlsport-box"]
 
         rows = []
         if gtype == "sdl":
@@ -235,9 +257,13 @@ class vmmGraphicsDetails(vmmGObjectUI):
             uiutil.set_grid_row_visible(self.widget(row), row in rows)
 
     def _change_graphics_type(self, ignore):
-        self._show_rows_from_type()
+        self._show_rows()
         self.emit("changed-type")
 
+    def _change_graphics_local_only(self, ignore):
+        self._show_rows()
+        self.emit("changed-local-only")
+
     def _change_port_auto(self, ignore):
         self.widget("graphics-port-auto").set_inconsistent(False)
         self._change_ports()
-- 
2.7.4




More information about the virt-tools-list mailing list