Re: [PATCH][RFC](take2)Add "Migrate" to VirtualMachine-menu in the individual VM view

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

 



S.Sakamoto wrote:
> Hi, Cole
> 
> I cleared all the problems about your comment.
> I show the following the summary of this patch
> and a problem about doing "Migrate" from individual VM view.
>

Okay, this looks good, I've committed this:

http://hg.et.redhat.com/virt/applications/virt-manager--devel?cs=f47cf079e311

Though I had a few more small issues with the code. I
worked up a patch (attached) that fixes them.

There was a bug when trying to migrate from the manager
view: the migrate connection list won't update correctly
if clicking around between different VM's on different
connections. The fix was just to populate the migrate
menu on demand, rather than when a new VM was selected.

The other change was to actually list unusable connections
in the migrate list, but have them as inactive list entries:

http://fedorapeople.org/~crobinso/virt-manager/virt-manager-migrate.png

The disabled list entries also have tooltips which explain
why they are disabled. I think this will be more clear to
users if there are invalid connections.

Do you think this is an okay change?

Thanks,
Cole

 details.py |   22 +--------------------
 engine.py  |   63 +++++++++++++++++++++++++++++++++++++++++++++++++------------
 manager.py |   28 +++------------------------
 3 files changed, 57 insertions(+), 56 deletions(-)

diff -r 10a90110ebf3 src/virtManager/details.py
--- a/src/virtManager/details.py	Thu Oct 30 15:56:47 2008 -0400
+++ b/src/virtManager/details.py	Thu Oct 30 16:37:20 2008 -0400
@@ -132,13 +132,8 @@
 
         menu = gtk.Menu()
         self.window.get_widget("control-shutdown").set_menu(menu)
-        
+
         self.migrate_menu_items = {}
-
-        self.migrate_menu_items["(None)"] = gtk.ImageMenuItem(_("(None)"))
-        self.migrate_menu_items["(None)"].show()
-        self.migrate_menu_items["(None)"].set_sensitive(False)
-        self.window.get_widget("details-menu-migrate_menu").add(self.migrate_menu_items["(None)"])
 
         rebootimg = gtk.Image()
         rebootimg.set_from_pixbuf(gtk.gdk.pixbuf_new_from_file_at_size(self.config.get_icon_dir() + "/icon_shutdown.png", 18, 18))
@@ -681,20 +676,7 @@
 
     def set_migrate_menu(self):
         menu = self.window.get_widget("details-menu-migrate_menu")
-        # clear migrate-submenu
-        for submenu_item in menu.get_children():
-            submenu_item_name = submenu_item.get_image().get_stock()[0]
-            menu.remove(self.migrate_menu_items[submenu_item_name])
-
-        available_migrate_hostnames = self.engine.get_available_migrate_hostnames()
-        if len(available_migrate_hostnames) == 0:
-            menu.add(self.migrate_menu_items["(None)"])
-        else:
-            for hostname in available_migrate_hostnames.values():
-                self.migrate_menu_items[hostname] = gtk.ImageMenuItem(hostname)
-                self.migrate_menu_items[hostname].show()
-                self.migrate_menu_items[hostname].connect("activate", self.control_vm_migrate)
-                menu.add(self.migrate_menu_items[hostname])
+        self.engine.populate_migrate_menu(menu, self.control_vm_migrate)
 
     def set_pause_widget_states(self, state):
         try:
diff -r 10a90110ebf3 src/virtManager/engine.py
--- a/src/virtManager/engine.py	Thu Oct 30 15:56:47 2008 -0400
+++ b/src/virtManager/engine.py	Thu Oct 30 16:37:20 2008 -0400
@@ -569,26 +569,65 @@
         migrate_progress.set_title(" ")
         return migrate_progress
 
+    def populate_migrate_menu(self, menu, migrate_func):
+        conns = self.get_available_migrate_hostnames()
+
+        # Clear menu
+        for item in menu:
+            menu.remove(item)
+
+        for key, val_list in conns.items():
+            can_migrate, label, tooltip = val_list
+            mitem = gtk.ImageMenuItem(label)
+            mitem.set_sensitive(can_migrate)
+            mitem.connect("activate", migrate_func)
+            if tooltip:
+                mitem.set_tooltip_text(tooltip)
+            mitem.show()
+
+            menu.add(mitem)
+
+        if len(menu) == 0:
+            mitem = gtk.ImageMenuItem(_("No connections available."))
+            mitem.show()
+            menu.add(mitem)
+
     def get_available_migrate_hostnames(self):
         hostname = self.windowManager.current_connection().get_hostname()
         driver = self.windowManager.current_connection().get_driver()
+        uri = self.windowManager.current_connection().get_uri()
         available_migrate_hostnames = {}
 
+        # Returns list of lists of the form
+        #   [ Can we migrate to this connection?,
+        #     String to use as list entry,
+        #     Tooltip reason ]
+
         # 1. connected(ACTIVE, INACTIVE) host
-        for key in self.connections.keys():
-            if self.connections[key].has_key("connection") is True \
-            and (self.get_connection(key).get_state() == vmmConnection.STATE_ACTIVE or self.get_connection(key).get_state() == vmmConnection.STATE_INACTIVE):
-                available_migrate_hostnames[key] = self.get_connection(key).get_hostname()
+        for key, value in self.connections.items():
+            if not value.has_key("connection"):
+                continue
+            conn = value["connection"]
 
-        # 2. remove source host
-        for key in available_migrate_hostnames.keys():
-            if available_migrate_hostnames[key] == hostname:
-                del available_migrate_hostnames[key]
+            can_migrate = False
+            desc = "%s (%s)" % (conn.get_hostname(), conn.get_driver())
+            reason = ""
 
-        # 3. remove a different host of hypervisor
-        for key in available_migrate_hostnames.keys():
-            if self.get_connection(key).get_driver() != driver:
-                del available_migrate_hostnames[key]
+            if conn.get_driver() != driver:
+                reason = _("Connection hypervisors do not match.")
+            elif conn.get_state() == vmmConnection.STATE_DISCONNECTED:
+                reason = _("Connection is disconnected.")
+            elif key == uri:
+                reason = _("Cannot migrate to same connection.")
+
+                # Explicitly don't include this in the list
+                continue;
+            elif conn.get_state() == vmmConnection.STATE_ACTIVE:
+                # Assumably we can migrate to this connection
+                can_migrate = True
+
+
+            available_migrate_hostnames[key] = [can_migrate, desc, reason]
 
         return available_migrate_hostnames
 
diff -r 10a90110ebf3 src/virtManager/manager.py
--- a/src/virtManager/manager.py	Thu Oct 30 15:56:47 2008 -0400
+++ b/src/virtManager/manager.py	Thu Oct 30 16:37:20 2008 -0400
@@ -159,7 +159,6 @@
         self.vmmenu_items = {}
         self.vmmenushutdown_items = {}
         self.vmmenumigrate = gtk.Menu()
-        self.vmmenumigrate_items = {}
 
         self.vmmenu_items["run"] = gtk.ImageMenuItem("_Run")
         self.vmmenu_items["run"].set_image(self.vmmenu_icons["run"])
@@ -211,12 +210,9 @@
         self.vmmenu_items["migrate"] = gtk.ImageMenuItem("_Migrate")
         self.vmmenu_items["migrate"].set_submenu(self.vmmenumigrate)
         self.vmmenu_items["migrate"].show()
+        self.vmmenu_items["migrate"].connect("activate",
+                                             self.set_migrate_submenu)
         self.vmmenu.add(self.vmmenu_items["migrate"])
-
-        self.vmmenumigrate_items["(None)"] = gtk.ImageMenuItem(_("(None)"))
-        self.vmmenumigrate_items["(None)"].show()
-        self.vmmenumigrate_items["(None)"].set_sensitive(False)
-        self.vmmenumigrate.add(self.vmmenumigrate_items["(None)"])
 
         self.vmmenu_items["hsep2"] = gtk.SeparatorMenuItem()
         self.vmmenu_items["hsep2"].show();
@@ -746,7 +742,6 @@
                         self.vmmenu_items["resume"].set_sensitive(False)
                         self.vmmenu_items["shutdown"].set_sensitive(False)
                         self.vmmenu_items["migrate"].set_sensitive(True)
-                        self.set_migrate_submenu()
                     elif vm.status() == libvirt.VIR_DOMAIN_RUNNING:
                         self.vmmenu_items["run"].set_sensitive(False)
                         self.vmmenu_items["pause"].set_sensitive(True)
@@ -755,7 +750,6 @@
                         self.vmmenu_items["resume"].set_sensitive(False)
                         self.vmmenu_items["shutdown"].set_sensitive(True)
                         self.vmmenu_items["migrate"].set_sensitive(True)
-                        self.set_migrate_submenu()
                     elif vm.status() == libvirt.VIR_DOMAIN_PAUSED:
                         self.vmmenu_items["run"].set_sensitive(False)
                         self.vmmenu_items["pause"].hide()
@@ -764,7 +758,6 @@
                         self.vmmenu_items["resume"].set_sensitive(True)
                         self.vmmenu_items["shutdown"].set_sensitive(True)
                         self.vmmenu_items["migrate"].set_sensitive(True)
-                        self.set_migrate_submenu()
                 self.vmmenu.popup(None, None, None, 0, event.time)
             return False
         else:
@@ -1088,21 +1081,8 @@
         if vm is not None:
             self.emit("action-migrate-domain", vm.get_connection().get_uri(), vm.get_uuid(), host_uri)
 
-    def set_migrate_submenu(self):
-        # clear migrate-submenu
-        for submenu_item in self.vmmenumigrate.get_children():
-            submenu_item_name = submenu_item.get_image().get_stock()[0]
-            self.vmmenumigrate.remove(self.vmmenumigrate_items[submenu_item_name])
-
-        available_migrate_hostnames = self.engine.get_available_migrate_hostnames()
-        if len(available_migrate_hostnames) == 0:
-            self.vmmenumigrate.add(self.vmmenumigrate_items["(None)"])
-        else:
-            for hostname in available_migrate_hostnames.values():
-                self.vmmenumigrate_items[hostname] = gtk.ImageMenuItem(hostname)
-                self.vmmenumigrate_items[hostname].show()
-                self.vmmenumigrate_items[hostname].connect("activate", self.migrate)
-                self.vmmenumigrate.add(self.vmmenumigrate_items[hostname])
+    def set_migrate_submenu(self, src):
+        self.engine.populate_migrate_menu(self.vmmenumigrate, self.migrate)
 
     def _add_connection(self, engine, conn):
         conn.connect("vm-added", self.vm_added)

_______________________________________________
et-mgmt-tools mailing list
et-mgmt-tools@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/et-mgmt-tools

[Index of Archives]     [Fedora Users]     [Fedora Legacy List]     [Fedora Maintainers]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux