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

[virt-tools-list] Add virDomainSetMigrateMaxDowntime support



# HG changeset patch
# User Wen Congyang <wency cn fujitsu com>
# Date 1289353517 -28800
# Node ID 6f13917004fe49d30e125030570cf2dae6dd364c
# Parent  dc89aa7162ee04bbd94aa754434bdd87286efcc8
Add virDomainSetMigrateMaxDowntime support

diff -r dc89aa7162ee -r 6f13917004fe src/virtManager/domain.py
--- a/src/virtManager/domain.py	Wed Oct 20 17:29:17 2010 +0300
+++ b/src/virtManager/domain.py	Wed Nov 10 09:45:17 2010 +0800
@@ -1090,6 +1090,9 @@
         if self.get_autostart() != val:
             self._backend.setAutostart(val)
 
+    def migrate_set_max_downtime(self, max_downtime, flag):
+        self._backend.migrateSetMaxDowntime(max_downtime, flag)
+
     def migrate(self, destconn, interface=None, rate=0,
                 live=False, secure=False):
         newname = None
diff -r dc89aa7162ee -r 6f13917004fe src/virtManager/migrate.py
--- a/src/virtManager/migrate.py	Wed Oct 20 17:29:17 2010 +0300
+++ b/src/virtManager/migrate.py	Wed Nov 10 09:45:17 2010 +0800
@@ -23,6 +23,7 @@
 
 import traceback
 import logging
+import threading
 
 import virtinst
 import libvirt
@@ -129,6 +130,7 @@
 
         self.window.get_widget("migrate-label-name").set_text(name)
         self.window.get_widget("migrate-label-src").set_text(srchost)
+        self.window.get_widget("migrate-max-downtime").set_value(30)
 
         self.window.get_widget("migrate-advanced-expander").set_expanded(False)
         self.window.get_widget("migrate-set-interface").set_active(False)
@@ -207,6 +209,10 @@
 
     def get_config_offline(self):
         return self.window.get_widget("migrate-offline").get_active()
+
+    def get_config_max_downtime(self):
+        return int(self.window.get_widget("migrate-max-downtime").get_value())
+
     def get_config_secure(self):
         return self.window.get_widget("migrate-secure").get_active()
 
@@ -382,6 +388,10 @@
         interface = self.get_config_interface()
         rate = self.get_config_rate()
         port = self.get_config_port()
+        max_downtime = self.get_config_max_downtime()
+
+        if max_downtime < 1:
+            return self.err.val_err(_("max downtime must be greater than 0."))
 
         if self.get_config_interface_enabled() and interface == None:
             return self.err.val_err(_("An interface must be specified."))
@@ -402,6 +412,7 @@
             destconn = self.get_config_destconn()
             srchost = self.vm.get_connection().get_hostname()
             dsthost = destconn.get_qualified_hostname()
+            max_downtime = self.get_config_max_downtime()
             live = not self.get_config_offline()
             secure = self.get_config_secure()
             uri = self.build_migrate_uri(destconn)
@@ -418,7 +429,8 @@
         self.topwin.window.set_cursor(gtk.gdk.Cursor(gtk.gdk.WATCH))
 
         progWin = vmmAsyncJob(self.config, self._async_migrate,
-                              [self.vm, destconn, uri, rate, live, secure],
+                              [self.vm, destconn, uri, rate, live, secure,
+                               max_downtime],
                               title=_("Migrating VM '%s'" % self.vm.get_name()),
                               text=(_("Migrating VM '%s' from %s to %s. "
                                       "This may take awhile.") %
@@ -437,8 +449,24 @@
             destconn.tick(noStatsUpdate=True)
             self.close()
 
+    def _async_set_max_downtime(self, vm, max_downtime, migrate_thread):
+        if (migrate_thread.isAlive()):
+            try:
+                vm.migrate_set_max_downtime(max_downtime, 0)
+                return False
+            except libvirt.libvirtError:
+                # domain is not being migrated
+                # wait 100 milliseconds
+                return True
+            except Exception:
+                logging.warning("setting max_downtime to %lu ms failed."
+                                % max_downtime)
+                return False
+        else:
+            return False
+
     def _async_migrate(self, origvm, origdconn, migrate_uri, rate, live,
-                       secure, asyncjob):
+                       secure, max_downtime, asyncjob):
         errinfo = None
         try:
             try:
@@ -454,7 +482,11 @@
 
                 logging.debug("Migrating vm=%s from %s to %s", vm.get_name(),
                               srcconn.get_uri(), dstconn.get_uri())
+                current_thread = threading.currentThread()
+                timer = util.safe_timeout_add(100, self._async_set_max_downtime,
+                                              vm, max_downtime, current_thread)
                 vm.migrate(dstconn, migrate_uri, rate, live, secure)
+                gobject.source_remove(timer)
             except Exception, e:
                 errinfo = (str(e), ("Unable to migrate guest:\n %s" %
                                     "".join(traceback.format_exc())))
diff -r dc89aa7162ee -r 6f13917004fe src/vmm-migrate.glade
--- a/src/vmm-migrate.glade	Wed Oct 20 17:29:17 2010 +0300
+++ b/src/vmm-migrate.glade	Wed Nov 10 09:45:17 2010 +0800
@@ -68,7 +68,7 @@
                 <child>
                   <widget class="GtkTable" id="table2">
                     <property name="visible">True</property>
-                    <property name="n_rows">4</property>
+                    <property name="n_rows">5</property>
                     <property name="n_columns">2</property>
                     <property name="column_spacing">6</property>
                     <property name="row_spacing">6</property>
@@ -194,6 +194,55 @@
                         <property name="bottom_attach">3</property>
                       </packing>
                     </child>
+                    <child>
+                      <widget class="GtkLabel" id="label1">
+                        <property name="visible">True</property>
+                        <property name="xalign">1</property>
+                        <property name="label" translatable="yes">&lt;span color='#484848'&gt;Max downtime:&lt;/span&gt;</property>
+                        <property name="use_markup">True</property>
+                        <property name="use_underline">True</property>
+                      </widget>
+                      <packing>
+                        <property name="top_attach">4</property>
+                        <property name="bottom_attach">5</property>
+                        <property name="x_options">GTK_FILL</property>
+                      </packing>
+                    </child>
+                    <child>
+                      <widget class="GtkHBox" id="hbox5">
+                        <property name="visible">True</property>
+                        <child>
+                          <widget class="GtkSpinButton" id="migrate-max-downtime">
+                            <property name="visible">True</property>
+                            <property name="can_focus">True</property>
+                            <property name="invisible_char">&#x25CF;</property>
+                            <property name="activates_default">True</property>
+                            <property name="adjustment">30 0 1000000 1 1000 0</property>
+                            <property name="snap_to_ticks">True</property>
+                            <property name="numeric">True</property>
+                          </widget>
+                          <packing>
+                            <property name="position">0</property>
+                          </packing>
+                        </child>
+                        <child>
+                          <widget class="GtkLabel" id="label14">
+                            <property name="visible">True</property>
+                            <property name="xalign">0</property>
+                            <property name="label" translatable="yes">ms</property>
+                          </widget>
+                          <packing>
+                            <property name="position">1</property>
+                          </packing>
+                        </child>
+                      </widget>
+                      <packing>
+                        <property name="left_attach">1</property>
+                        <property name="right_attach">2</property>
+                        <property name="top_attach">4</property>
+                        <property name="bottom_attach">5</property>
+                      </packing>
+                    </child>
                   </widget>
                   <packing>
                     <property name="expand">False</property>


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