[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[virt-tools-list] [virt-manager][PATCH v4] Add delete VM option in console viewer.



From: Leonardo Garcia <lagarcia br ibm com>

---
 ui/vmm-details.ui      |   16 ++++++++++++++++
 virtManager/details.py |   11 +++++++++++
 virtManager/engine.py  |   16 ++++++++++++++++
 virtManager/manager.py |   17 ++---------------
 4 files changed, 45 insertions(+), 15 deletions(-)

diff --git a/ui/vmm-details.ui b/ui/vmm-details.ui
index ddb2a71..c523372 100644
--- a/ui/vmm-details.ui
+++ b/ui/vmm-details.ui
@@ -184,6 +184,7 @@
                 <property name="can_focus">False</property>
                 <property name="label" translatable="yes">Virtual _Machine</property>
                 <property name="use_underline">True</property>
+                <signal name="activate" handler="on_details_menu_vm" swapped="no"/>
                 <child type="submenu">
                   <object class="GtkMenu" id="virtual_machine1_menu">
                     <property name="can_focus">False</property>
@@ -314,6 +315,21 @@
                       </object>
                     </child>
                     <child>
+                      <object class="GtkMenuItem" id="details-menu-delete">
+                        <property name="visible">True</property>
+                        <property name="can_focus">False</property>
+                        <property name="label" translatable="yes">_Delete...</property>
+                        <property name="use_underline">True</property>
+                        <signal name="activate" handler="on_details_menu_delete_activate" swapped="no"/>
+                      </object>
+                    </child>
+                    <child>
+                      <object class="GtkSeparatorMenuItem" id="separator2">
+                        <property name="visible">True</property>
+                        <property name="can_focus">False</property>
+                      </object>
+                    </child>
+                    <child>
                       <object class="GtkMenuItem" id="details-menu-vm-screenshot">
                         <property name="visible">True</property>
                         <property name="can_focus">False</property>
diff --git a/virtManager/details.py b/virtManager/details.py
index fb4b493..b40ea47 100644
--- a/virtManager/details.py
+++ b/virtManager/details.py
@@ -329,6 +329,7 @@ class vmmDetails(vmmGObjectUI):
         "action-exit-app": (GObject.SignalFlags.RUN_FIRST, None, []),
         "action-view-manager": (GObject.SignalFlags.RUN_FIRST, None, []),
         "action-migrate-domain": (GObject.SignalFlags.RUN_FIRST, None, [str, str]),
+        "action-delete-domain": (GObject.SignalFlags.RUN_FIRST, None, [str, str]),
         "action-clone-domain": (GObject.SignalFlags.RUN_FIRST, None, [str, str]),
         "details-closed": (GObject.SignalFlags.RUN_FIRST, None, []),
         "details-opened": (GObject.SignalFlags.RUN_FIRST, None, []),
@@ -403,6 +404,7 @@ class vmmDetails(vmmGObjectUI):
             "on_details_customize_finish_clicked": self.customize_finish,
             "on_details_cancel_customize_clicked": self.close,
 
+            "on_details_menu_vm": self.update_vm_menu,
             "on_details_menu_run_activate": self.control_vm_run,
             "on_details_menu_poweroff_activate": self.control_vm_shutdown,
             "on_details_menu_reboot_activate": self.control_vm_reboot,
@@ -412,6 +414,7 @@ class vmmDetails(vmmGObjectUI):
             "on_details_menu_pause_activate": self.control_vm_pause,
             "on_details_menu_clone_activate": self.control_vm_clone,
             "on_details_menu_migrate_activate": self.control_vm_migrate,
+            "on_details_menu_delete_activate": self.control_vm_delete,
             "on_details_menu_screenshot_activate": self.control_vm_screenshot,
             "on_details_menu_view_toolbar_activate": self.toggle_toolbar,
             "on_details_menu_view_manager_activate": self.view_manager,
@@ -1548,6 +1551,10 @@ class vmmDetails(vmmGObjectUI):
                       self.vm.get_uuid())
 
 
+    def update_vm_menu(self, src_ignore):
+        delete = bool(self.vm and self.vm.is_runable())
+        self.widget("details-menu-delete").set_sensitive(delete)
+
     def control_vm_run(self, src_ignore):
         self.emit("action-run-domain",
                   self.vm.conn.get_uri(), self.vm.get_uuid())
@@ -1580,6 +1587,10 @@ class vmmDetails(vmmGObjectUI):
         self.emit("action-migrate-domain",
                   self.vm.conn.get_uri(), self.vm.get_uuid())
 
+    def control_vm_delete(self, src_ignore):
+        self.emit("action-delete-domain",
+                  self.vm.conn.get_uri(), self.vm.get_uuid())
+
     def control_vm_screenshot(self, src):
         ignore = src
         try:
diff --git a/virtManager/engine.py b/virtManager/engine.py
index 8950451..a8dbfba 100644
--- a/virtManager/engine.py
+++ b/virtManager/engine.py
@@ -48,6 +48,7 @@ from virtManager.create import vmmCreate
 from virtManager.host import vmmHost
 from virtManager.error import vmmErrorDialog
 from virtManager.systray import vmmSystray
+from virtManager.delete import vmmDeleteDialog
 
 # Enable this to get a report of leaked objects on app shutdown
 # gtk3/pygobject has issues here as of Fedora 18
@@ -95,6 +96,7 @@ class vmmEngine(vmmGObject):
         self.last_timeout = 0
 
         self.systray = None
+        self.delete_dialog = None
         self.application = Gtk.Application(
                                  application_id="com.redhat.virt-manager",
                                  flags=0)
@@ -376,6 +378,10 @@ class vmmEngine(vmmGObject):
             self.windowMigrate.cleanup()
             self.windowMigrate = None
 
+        if self.delete_dialog:
+            self.delete_dialog.cleanup()
+            self.delete_dialog = None
+
         # Do this last, so any manually 'disconnected' signals
         # take precedence over cleanup signal removal
         for uri in self.conns:
@@ -605,6 +611,7 @@ class vmmEngine(vmmGObject):
         obj.connect("action-exit-app", self.exit_app)
         obj.connect("action-view-manager", self._do_show_manager)
         obj.connect("action-migrate-domain", self._do_show_migrate)
+        obj.connect("action-delete-domain", self._do_delete_domain)
         obj.connect("action-clone-domain", self._do_show_clone)
         obj.connect("details-opened", self.increment_window_counter)
         obj.connect("details-closed", self.decrement_window_counter)
@@ -648,6 +655,7 @@ class vmmEngine(vmmGObject):
         obj.connect("action-reset-domain", self._do_reset_domain)
         obj.connect("action-save-domain", self._do_save_domain)
         obj.connect("action-migrate-domain", self._do_show_migrate)
+        obj.connect("action-delete-domain", self._do_delete_domain)
         obj.connect("action-clone-domain", self._do_show_clone)
         obj.connect("action-show-vm", self._do_show_vm)
         obj.connect("action-show-preferences", self._do_show_preferences)
@@ -991,3 +999,11 @@ class vmmEngine(vmmGObject):
         logging.debug("Resetting vm '%s'", vm.get_name())
         vmmAsyncJob.simple_async_noshow(vm.reset, [], src,
                                         _("Error resetting domain"))
+
+    def _do_delete_domain(self, src, uri, uuid):
+        conn = self._lookup_conn(uri)
+        vm = conn.get_vm(uuid)
+
+        if not self.delete_dialog:
+            self.delete_dialog = vmmDeleteDialog()
+        self.delete_dialog.show(vm, src.topwin)
\ No newline at end of file
diff --git a/virtManager/manager.py b/virtManager/manager.py
index 3620268..6b6ceb1 100644
--- a/virtManager/manager.py
+++ b/virtManager/manager.py
@@ -32,7 +32,6 @@ from virtManager import packageutils
 from virtManager import uihelpers
 from virtManager.connection import vmmConnection
 from virtManager.baseclass import vmmGObjectUI
-from virtManager.delete import vmmDeleteDialog
 from virtManager.graphwidgets import CellRendererSparkline
 from virtManager import util as util
 
@@ -95,6 +94,7 @@ class vmmManager(vmmGObjectUI):
         "action-destroy-domain": (GObject.SignalFlags.RUN_FIRST, None, [str, str]),
         "action-save-domain": (GObject.SignalFlags.RUN_FIRST, None, [str, str]),
         "action-migrate-domain": (GObject.SignalFlags.RUN_FIRST, None, [str, str]),
+        "action-delete-domain": (GObject.SignalFlags.RUN_FIRST, None, [str, str]),
         "action-clone-domain": (GObject.SignalFlags.RUN_FIRST, None, [str, str]),
         "action-exit-app": (GObject.SignalFlags.RUN_FIRST, None, []),
         "manager-closed": (GObject.SignalFlags.RUN_FIRST, None, []),
@@ -106,7 +106,6 @@ class vmmManager(vmmGObjectUI):
     def __init__(self):
         vmmGObjectUI.__init__(self, "vmm-manager.ui", "vmm-manager")
 
-        self.delete_dialog = None
         self.ignore_pause = False
 
         # Mapping of VM UUID -> tree model rows to
@@ -227,10 +226,6 @@ class vmmManager(vmmGObjectUI):
         self.hostcpucol = None
         self.netcol = None
 
-        if self.delete_dialog:
-            self.delete_dialog.cleanup()
-            self.delete_dialog = None
-
         self.vmmenu.destroy()
         self.vmmenu = None
         self.vmmenu_items = None
@@ -586,7 +581,7 @@ class vmmManager(vmmGObjectUI):
         if vm is None:
             self._do_delete_conn(conn)
         else:
-            self._do_delete_vm(vm)
+            self.emit("action-delete-domain", conn.get_uri(), vm.get_uuid())
 
     def _do_delete_conn(self, conn):
         if conn is None:
@@ -599,14 +594,6 @@ class vmmManager(vmmGObjectUI):
 
         self.emit("remove-conn", conn.get_uri())
 
-    def _do_delete_vm(self, vm):
-        if vm.is_active():
-            return
-
-        if not self.delete_dialog:
-            self.delete_dialog = vmmDeleteDialog()
-        self.delete_dialog.show(vm, self.topwin)
-
     def set_pause_state(self, state):
         src = self.widget("vm-pause")
         try:
-- 
1.7.1


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]