[virt-tools-list] [virt-manager][PATCH ] Add option to control whether to leave VM running when closing console.

Leonardo Garcia lagarcia at linux.vnet.ibm.com
Fri Jun 28 17:49:41 UTC 2013


From: Leonardo Garcia <lagarcia at br.ibm.com>

It is sometimes counter intuitive for a desktop user that the virtual machine
continues to run when they left the console viewer application. They are used
that when they close an application all the resources being used by it are also
freed up, and from their perspective, the console viewer is just one more
application running.
---
 data/org.virt-manager.virt-manager.gschema.xml |    6 ++
 ui/vmm-preferences.ui                          |   87 +++++++++++++++++-------
 virtManager/config.py                          |    8 ++
 virtManager/details.py                         |    3 +
 virtManager/preferences.py                     |    7 ++
 5 files changed, 85 insertions(+), 26 deletions(-)

diff --git a/data/org.virt-manager.virt-manager.gschema.xml b/data/org.virt-manager.virt-manager.gschema.xml
index d086a64..188e5f9 100644
--- a/data/org.virt-manager.virt-manager.gschema.xml
+++ b/data/org.virt-manager.virt-manager.gschema.xml
@@ -149,6 +149,12 @@
       <description>Whether to enable menu accelerators while connected to the guest graphical console.</description>
     </key>
 
+    <key name="enable-leave-vm-running" type="b">
+      <default>true</default>
+      <summary>Leave VM running after closing console viewer</summary>
+      <description>Whether to leave VM running after closing the console viewer</description>
+    </key>
+
     <key name="scaling" type="i">
       <default>1</default>
       <summary>When to scale the VM graphical console</summary>
diff --git a/ui/vmm-preferences.ui b/ui/vmm-preferences.ui
index 61ba17b..62ebbdb 100644
--- a/ui/vmm-preferences.ui
+++ b/ui/vmm-preferences.ui
@@ -416,38 +416,73 @@
                               </packing>
                             </child>
                             <child>
-                              <object class="GtkHBox" id="hbox1">
+                              <object class="GtkAlignment" id="alignment3">
                                 <property name="visible">True</property>
                                 <property name="can_focus">False</property>
-                                <property name="spacing">6</property>
                                 <child>
-                                  <object class="GtkLabel" id="label15">
+                                  <object class="GtkTable" id="table2">
                                     <property name="visible">True</property>
                                     <property name="can_focus">False</property>
-                                    <property name="tooltip_text" translatable="yes">When the guest graphical console has keyboard focus, do not disable shortcuts for console window menus (Alt+F -> File, etc.) Normally these are disabled to ensure that typing in the guest does not accidentally perform an operation in virt-manager's console window.</property>
-                                    <property name="label" translatable="yes">Don't disable console shortcuts:</property>
-                                  </object>
-                                  <packing>
-                                    <property name="expand">False</property>
-                                    <property name="fill">True</property>
-                                    <property name="position">0</property>
-                                  </packing>
-                                </child>
-                                <child>
-                                  <object class="GtkCheckButton" id="prefs-console-accels">
-                                    <property name="visible">True</property>
-                                    <property name="can_focus">True</property>
-                                    <property name="receives_default">False</property>
-                                    <property name="tooltip_text" translatable="yes">When the guest graphical console has keyboard focus, do not disable shortcuts for console window menus (Alt+F -> File, etc.) Normally these are disabled to ensure that typing in the guest does not accidentally perform an operation in virt-manager's console window.</property>
-                                    <property name="xalign">0.5</property>
-                                    <property name="draw_indicator">True</property>
-                                    <signal name="toggled" handler="on_prefs_console_accels_toggled" swapped="no"/>
+                                    <property name="n_rows">2</property>
+                                    <property name="n_columns">2</property>
+                                    <child>
+                                      <object class="GtkLabel" id="label15">
+                                        <property name="visible">True</property>
+                                        <property name="can_focus">False</property>
+                                        <property name="has_tooltip">True</property>
+                                        <property name="tooltip_markup" translatable="yes">When the guest graphical console has keyboard focus, do not disable shortcuts for console window menus (Alt+F -&gt; File, etc.) Normally these are disabled to ensure that typing in the guest does not accidentally perform an operation in virt-manager&apos;s console window.</property>
+                                        <property name="tooltip_text" translatable="yes">When the guest graphical console has keyboard focus, do not disable shortcuts for console window menus (Alt+F -> File, etc.) Normally these are disabled to ensure that typing in the guest does not accidentally perform an operation in virt-manager's console window.</property>
+                                        <property name="xalign">0</property>
+                                        <property name="label" translatable="yes">Don't disable console shortcuts:</property>
+                                      </object>
+                                    </child>
+                                    <child>
+                                      <object class="GtkCheckButton" id="prefs-console-leave-vm-running">
+                                        <property name="visible">True</property>
+                                        <property name="can_focus">True</property>
+                                        <property name="receives_default">False</property>
+                                        <property name="has_tooltip">True</property>
+                                        <property name="xalign">0</property>
+                                        <property name="draw_indicator">True</property>
+                                        <signal name="toggled" handler="on_prefs_console_leave_vm_running_toggled" swapped="no"/>
+                                      </object>
+                                      <packing>
+                                        <property name="left_attach">1</property>
+                                        <property name="right_attach">2</property>
+                                        <property name="top_attach">1</property>
+                                        <property name="bottom_attach">2</property>
+                                      </packing>
+                                    </child>
+                                    <child>
+                                      <object class="GtkCheckButton" id="prefs-console-accels">
+                                        <property name="visible">True</property>
+                                        <property name="can_focus">True</property>
+                                        <property name="receives_default">False</property>
+                                        <property name="has_tooltip">True</property>
+                                        <property name="tooltip_markup" translatable="yes">When the guest graphical console has keyboard focus, do not disable shortcuts for console window menus (Alt+F -&gt; File, etc.) Normally these are disabled to ensure that typing in the guest does not accidentally perform an operation in virt-manager&apos;s console window.</property>
+                                        <property name="tooltip_text" translatable="yes">When the guest graphical console has keyboard focus, do not disable shortcuts for console window menus (Alt+F -> File, etc.) Normally these are disabled to ensure that typing in the guest does not accidentally perform an operation in virt-manager's console window.</property>
+                                        <property name="xalign">0</property>
+                                        <property name="draw_indicator">True</property>
+                                        <signal name="toggled" handler="on_prefs_console_accels_toggled" swapped="no"/>
+                                      </object>
+                                      <packing>
+                                        <property name="left_attach">1</property>
+                                        <property name="right_attach">2</property>
+                                      </packing>
+                                    </child>
+                                    <child>
+                                      <object class="GtkLabel" id="label10">
+                                        <property name="visible">True</property>
+                                        <property name="can_focus">False</property>
+                                        <property name="xalign">0</property>
+                                        <property name="label" translatable="yes">Leave VM running when closing console:</property>
+                                      </object>
+                                      <packing>
+                                        <property name="top_attach">1</property>
+                                        <property name="bottom_attach">2</property>
+                                      </packing>
+                                    </child>
                                   </object>
-                                  <packing>
-                                    <property name="expand">False</property>
-                                    <property name="fill">True</property>
-                                    <property name="position">1</property>
-                                  </packing>
                                 </child>
                               </object>
                               <packing>
diff --git a/virtManager/config.py b/virtManager/config.py
index 19e030c..321e3b0 100644
--- a/virtManager/config.py
+++ b/virtManager/config.py
@@ -364,6 +364,14 @@ class vmmConfig(object):
     def set_console_accels(self, pref):
         self.conf.set("/console/enable-accels", pref)
 
+    def get_console_leave_vm_running(self):
+        console_pref = self.conf.get("/console/enable-leave-vm-running")
+        if console_pref is None:
+            console_pref = True
+        return console_pref
+    def set_console_leave_vm_running(self, pref):
+        self.conf.set("/console/enable-leave-vm-running", pref)
+
     def on_console_scaling_changed(self, cb):
         return self.conf.notify_add("/console/scaling", cb)
     def get_console_scaling(self):
diff --git a/virtManager/details.py b/virtManager/details.py
index b2d496e..e4d54af 100644
--- a/virtManager/details.py
+++ b/virtManager/details.py
@@ -597,6 +597,9 @@ class vmmDetails(vmmGObjectUI):
         if not self.is_visible():
             return
 
+        if not self.config.get_console_leave_vm_running():
+            self.control_vm_shutdown(self)
+
         self.topwin.hide()
         if (self.console.viewer and
             self.console.viewer.display and
diff --git a/virtManager/preferences.py b/virtManager/preferences.py
index 1c64f48..db80338 100644
--- a/virtManager/preferences.py
+++ b/virtManager/preferences.py
@@ -38,6 +38,7 @@ class vmmPreferences(vmmGObjectUI):
         self.refresh_view_system_tray()
         self.refresh_update_interval()
         self.refresh_console_accels()
+        self.refresh_console_leave_vm_running()
         self.refresh_console_scaling()
         self.refresh_new_vm_sound()
         self.refresh_graphics_type()
@@ -57,6 +58,7 @@ class vmmPreferences(vmmGObjectUI):
             "on_prefs_system_tray_toggled" : self.change_view_system_tray,
             "on_prefs_stats_update_interval_changed": self.change_update_interval,
             "on_prefs_console_accels_toggled": self.change_console_accels,
+            "on_prefs_console_leave_vm_running_toggled": self.change_console_leave_vm_running,
             "on_prefs_console_scaling_changed": self.change_console_scaling,
             "on_prefs_close_clicked": self.close,
             "on_vmm_preferences_delete_event": self.close,
@@ -104,6 +106,9 @@ class vmmPreferences(vmmGObjectUI):
     def refresh_console_accels(self):
         self.widget("prefs-console-accels").set_active(
             self.config.get_console_accels())
+    def refresh_console_leave_vm_running(self):
+        self.widget("prefs-console-leave-vm-running").set_active(
+            self.config.get_console_leave_vm_running())
     def refresh_console_scaling(self):
         val = self.config.get_console_scaling()
         if val is None:
@@ -255,6 +260,8 @@ class vmmPreferences(vmmGObjectUI):
 
     def change_console_accels(self, src):
         self.config.set_console_accels(src.get_active())
+    def change_console_leave_vm_running(self, src):
+        self.config.set_console_leave_vm_running(src.get_active())
     def change_console_scaling(self, box):
         self.config.set_console_scaling(box.get_active())
 
-- 
1.7.1




More information about the virt-tools-list mailing list