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

[virt-tools-list] [RFC Patch] Support job cancellation for migration, save functions



# HG changeset patch
# User Wen Congyang <wency cn fujitsu com>
# Date 1291088831 -28800
# Node ID 5cb32ed0871c72cd715214e83df8725d74ba9e9e
# Parent  b81696db7c272544f20dd62709ced7bdc9aea0a8
Support job cancellation for migration, save functions

If we cancel migration or save function, we receive a error.
I don't know how to avoid this...

diff -r b81696db7c27 -r 5cb32ed0871c src/virtManager/asyncjob.py
--- a/src/virtManager/asyncjob.py	Mon Nov 29 15:00:41 2010 +0800
+++ b/src/virtManager/asyncjob.py	Tue Nov 30 11:47:11 2010 +0800
@@ -40,6 +40,7 @@
 class vmmAsyncJob(gobject.GObject):
 
     def __init__(self, config, callback, args=None,
+                 cancel_back=None, cancel_args=None,
                  text=_("Please wait a few moments..."),
                  title=_("Operation in progress"),
                  run_main=True):
@@ -50,6 +51,16 @@
         self.window = gtk.glade.XML(config.get_glade_dir() + \
                                     "/vmm-progress.glade",
                                     "vmm-progress", domain="virt-manager")
+        self.window.signal_autoconnect({
+            "on_async_job_delete_event" : self.cancel,
+            "on_async_job_cancel_clicked" : self.cancel,
+        })
+        self.cancel_job = cancel_back
+        self.cancel_args = cancel_args
+        if self.cancel_job:
+            self.window.get_widget("cancel-async-job").set_sensitive(True)
+        else:
+            self.window.get_widget("cancel-async-job").set_sensitive(False)
         self.window.get_widget("pbar-text").set_text(text)
 
         self.topwin = self.window.get_widget("vmm-progress")
@@ -91,6 +102,10 @@
 
         self.topwin.destroy()
 
+    def cancel(self, ignore1=None, ignore2=None):
+        if self.cancel_job:
+            self.cancel_job(*self.cancel_args)
+
     def pulse_pbar(self, progress="", stage=None):
         gtk.gdk.threads_enter()
         try:
diff -r b81696db7c27 -r 5cb32ed0871c src/virtManager/domain.py
--- a/src/virtManager/domain.py	Mon Nov 29 15:00:41 2010 +0800
+++ b/src/virtManager/domain.py	Tue Nov 30 11:47:11 2010 +0800
@@ -1001,6 +1001,9 @@
         if self.get_autostart() != val:
             self._backend.setAutostart(val)
 
+    def abort_job(self):
+        self._backend.abortJob()
+
     def migrate_set_max_downtime(self, max_downtime, flag=0):
         self._backend.migrateSetMaxDowntime(max_downtime, flag)
 
diff -r b81696db7c27 -r 5cb32ed0871c src/virtManager/engine.py
--- a/src/virtManager/engine.py	Mon Nov 29 15:00:41 2010 +0800
+++ b/src/virtManager/engine.py	Tue Nov 30 11:47:11 2010 +0800
@@ -829,7 +829,7 @@
                 return
 
         progWin = vmmAsyncJob(self.config, self._save_callback,
-                              [vm, path],
+                              [vm, path], self._save_cancel, [vm],
                               _("Saving Virtual Machine"))
         progWin.run()
         error, details = progWin.get_error()
@@ -837,6 +837,10 @@
         if error is not None:
             src.err.show_err(_("Error saving domain: %s") % error, details)
 
+    def _save_cancel(self, vm):
+        vm.abort_job()
+        return
+
     def _save_callback(self, vm, file_to_save, asyncjob):
         try:
             conn = util.dup_conn(self.config, vm.connection,
diff -r b81696db7c27 -r 5cb32ed0871c src/virtManager/migrate.py
--- a/src/virtManager/migrate.py	Mon Nov 29 15:00:41 2010 +0800
+++ b/src/virtManager/migrate.py	Tue Nov 30 11:47:11 2010 +0800
@@ -450,7 +450,7 @@
 
         progWin = vmmAsyncJob(self.config, self._async_migrate,
                               [self.vm, destconn, uri, rate, live, secure,
-                               max_downtime],
+                               max_downtime], self.cancel_migration, [self.vm],
                               title=_("Migrating VM '%s'" % self.vm.get_name()),
                               text=(_("Migrating VM '%s' from %s to %s. "
                                       "This may take awhile.") %
@@ -484,6 +484,10 @@
             logging.warning("Error setting migrate downtime: %s" % e)
             return False
 
+    def cancel_migration(self, vm):
+        vm.abort_job()
+        return
+
     def _async_migrate(self, origvm, origdconn, migrate_uri, rate, live,
                        secure, max_downtime, asyncjob):
         errinfo = None
diff -r b81696db7c27 -r 5cb32ed0871c src/vmm-progress.glade
--- a/src/vmm-progress.glade	Mon Nov 29 15:00:41 2010 +0800
+++ b/src/vmm-progress.glade	Tue Nov 30 11:47:11 2010 +0800
@@ -12,6 +12,7 @@
     <property name="type_hint">dialog</property>
     <property name="skip_taskbar_hint">True</property>
     <property name="urgency_hint">True</property>
+    <signal name="delete_event" handler="on_async_job_delete_event"/>
     <child>
       <widget class="GtkAlignment" id="alignment134">
         <property name="visible">True</property>
@@ -82,6 +83,40 @@
                 <property name="position">2</property>
               </packing>
             </child>
+            <child>
+              <widget class="GtkHBox" id="hbox1">
+                <property name="visible">True</property>
+                <property name="spacing">12</property>
+                <child>
+                  <widget class="GtkLabel" id="label1">
+                    <property name="visible">True</property>
+                  </widget>
+                  <packing>
+                    <property name="position">0</property>
+                  </packing>
+                </child>
+                <child>
+                  <widget class="GtkButton" id="cancel-async-job">
+                    <property name="label">gtk-cancel</property>
+                    <property name="visible">True</property>
+                    <property name="can_focus">True</property>
+                    <property name="receives_default">True</property>
+                    <property name="use_stock">True</property>
+                    <signal name="clicked" handler="on_async_job_cancel_clicked"/>
+                  </widget>
+                  <packing>
+                    <property name="expand">False</property>
+                    <property name="fill">False</property>
+                    <property name="position">1</property>
+                  </packing>
+                </child>
+              </widget>
+              <packing>
+                <property name="expand">False</property>
+                <property name="fill">False</property>
+                <property name="position">3</property>
+              </packing>
+            </child>
           </widget>
         </child>
       </widget>


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