Show inactive conn entries in the migrate list.

This commit is contained in:
Cole Robinson 2008-10-31 09:48:21 -04:00
parent d2c6bb5996
commit 6d1794beb5
3 changed files with 57 additions and 56 deletions

View File

@ -132,13 +132,8 @@ class vmmDetails(gobject.GObject):
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)"])
self.migrate_menu_items = {}
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 @@ class vmmDetails(gobject.GObject):
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:

View File

@ -569,26 +569,65 @@ class vmmEngine(gobject.GObject):
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

View File

@ -159,7 +159,6 @@ class vmmManager(gobject.GObject):
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,13 +210,10 @@ class vmmManager(gobject.GObject):
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();
self.vmmenu.add(self.vmmenu_items["hsep2"])
@ -746,7 +742,6 @@ class vmmManager(gobject.GObject):
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 @@ class vmmManager(gobject.GObject):
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 @@ class vmmManager(gobject.GObject):
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 @@ class vmmManager(gobject.GObject):
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)