mirror of
https://github.com/virt-manager/virt-manager.git
synced 2025-01-27 14:03:57 +03:00
First crack at multiple connections UI. Basic idea is there but popup menus, buttons, create wizard still not right.
This commit is contained in:
parent
c4e0602f36
commit
82bc8086de
@ -129,7 +129,7 @@ def show_engine(engine, show, uri, uuid):
|
|||||||
elif show=='console':
|
elif show=='console':
|
||||||
engine.show_console(uri, uuid)
|
engine.show_console(uri, uuid)
|
||||||
elif show=='summary' or uri:
|
elif show=='summary' or uri:
|
||||||
engine.show_manager(uri)
|
engine.connect_to_uri(uri)
|
||||||
else:
|
else:
|
||||||
tryuri = None
|
tryuri = None
|
||||||
if os.path.exists("/var/lib/xend") and os.path.exists("/proc/xen"):
|
if os.path.exists("/var/lib/xend") and os.path.exists("/proc/xen"):
|
||||||
@ -141,8 +141,7 @@ def show_engine(engine, show, uri, uuid):
|
|||||||
tryuri = "qemu:///session"
|
tryuri = "qemu:///session"
|
||||||
if tryuri is not None:
|
if tryuri is not None:
|
||||||
try:
|
try:
|
||||||
conn = engine.get_connection(tryuri)
|
engine.connect_to_uri(tryuri)
|
||||||
engine.show_manager(tryuri)
|
|
||||||
except:
|
except:
|
||||||
(type, value, stacktrace) = sys.exc_info ()
|
(type, value, stacktrace) = sys.exc_info ()
|
||||||
|
|
||||||
@ -236,7 +235,7 @@ def main():
|
|||||||
remote = vmmRemote(engine, name)
|
remote = vmmRemote(engine, name)
|
||||||
except:
|
except:
|
||||||
# Something went wrong doing dbus setup, just ignor & carry on
|
# Something went wrong doing dbus setup, just ignor & carry on
|
||||||
logging.warning("Could not connection to session bus, disabling DBus service " + \
|
logging.warning("Could not get connection to session bus, disabling DBus service " + \
|
||||||
str(sys.exc_info()[0]) + " " + str(sys.exc_info()[1]))
|
str(sys.exc_info()[0]) + " " + str(sys.exc_info()[1]))
|
||||||
|
|
||||||
# Finally start the app for real
|
# Finally start the app for real
|
||||||
|
@ -56,11 +56,12 @@ class vmmConnection(gobject.GObject):
|
|||||||
"disconnected": (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, [str])
|
"disconnected": (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, [str])
|
||||||
}
|
}
|
||||||
|
|
||||||
def __init__(self, config, uri, readOnly):
|
def __init__(self, config, uri, readOnly, active=True):
|
||||||
self.__gobject_init__()
|
self.__gobject_init__()
|
||||||
self.config = config
|
self.config = config
|
||||||
self.uri = uri
|
self.uri = uri
|
||||||
self.readOnly = readOnly
|
self.readOnly = readOnly
|
||||||
|
self._active = active
|
||||||
|
|
||||||
openURI = uri
|
openURI = uri
|
||||||
if openURI == "Xen":
|
if openURI == "Xen":
|
||||||
@ -310,6 +311,9 @@ class vmmConnection(gobject.GObject):
|
|||||||
if self.vmm == None:
|
if self.vmm == None:
|
||||||
return
|
return
|
||||||
|
|
||||||
|
if not self.is_active:
|
||||||
|
return
|
||||||
|
|
||||||
oldNets = self.nets
|
oldNets = self.nets
|
||||||
startNets = {}
|
startNets = {}
|
||||||
stopNets = {}
|
stopNets = {}
|
||||||
@ -641,5 +645,13 @@ class vmmConnection(gobject.GObject):
|
|||||||
delim = len(url)
|
delim = len(url)
|
||||||
return url[start:delim], url[delim:]
|
return url[start:delim], url[delim:]
|
||||||
|
|
||||||
|
|
||||||
|
def is_active(self):
|
||||||
|
return self._active
|
||||||
|
def set_active(self, val):
|
||||||
|
self._active = val
|
||||||
|
active = property(is_active, set_active)
|
||||||
|
|
||||||
|
|
||||||
gobject.type_register(vmmConnection)
|
gobject.type_register(vmmConnection)
|
||||||
|
|
||||||
|
@ -151,6 +151,8 @@ class vmmDomain(gobject.GObject):
|
|||||||
self.emit("status-changed", status)
|
self.emit("status-changed", status)
|
||||||
|
|
||||||
def tick(self, now):
|
def tick(self, now):
|
||||||
|
if not self.connection.active:
|
||||||
|
return
|
||||||
# Clear cached XML
|
# Clear cached XML
|
||||||
self.xml = None
|
self.xml = None
|
||||||
hostInfo = self.connection.get_host_info()
|
hostInfo = self.connection.get_host_info()
|
||||||
|
@ -43,6 +43,7 @@ class vmmEngine:
|
|||||||
self.windowPreferences = None
|
self.windowPreferences = None
|
||||||
self.windowAbout = None
|
self.windowAbout = None
|
||||||
self.windowCreate = None
|
self.windowCreate = None
|
||||||
|
self.windowManager = None
|
||||||
self.connections = {}
|
self.connections = {}
|
||||||
|
|
||||||
self.timer = None
|
self.timer = None
|
||||||
@ -57,16 +58,20 @@ class vmmEngine:
|
|||||||
|
|
||||||
def _do_connection_disconnected(self, connection, hvuri):
|
def _do_connection_disconnected(self, connection, hvuri):
|
||||||
del self.connections[hvuri]
|
del self.connections[hvuri]
|
||||||
|
|
||||||
if len(self.connections.keys()) == 0 and self.windowConnect == None:
|
if len(self.connections.keys()) == 0 and self.windowConnect == None:
|
||||||
gtk.main_quit()
|
gtk.main_quit()
|
||||||
|
if self.windowManager is not None:
|
||||||
|
self.windowManager.remove_connection(hvuri)
|
||||||
|
|
||||||
|
def connect_to_uri(self, uri, readOnly=None):
|
||||||
|
self._connect_to_uri(None, uri, readOnly)
|
||||||
|
|
||||||
def _connect_to_uri(self, connect, uri, readOnly):
|
def _connect_to_uri(self, connect, uri, readOnly):
|
||||||
self.windowConnect = None
|
self.windowConnect = None
|
||||||
|
|
||||||
try:
|
try:
|
||||||
conn = self.get_connection(uri, readOnly)
|
conn = self.get_connection(uri, readOnly)
|
||||||
self.show_manager(uri)
|
self.show_manager()
|
||||||
except:
|
except:
|
||||||
(type, value, stacktrace) = sys.exc_info ()
|
(type, value, stacktrace) = sys.exc_info ()
|
||||||
|
|
||||||
@ -166,11 +171,12 @@ class vmmEngine:
|
|||||||
for name in [ "windowDetails", "windowConsole", "windowSerialConsole" ]:
|
for name in [ "windowDetails", "windowConsole", "windowSerialConsole" ]:
|
||||||
for window in conn[name].values():
|
for window in conn[name].values():
|
||||||
ct += window.is_visible()
|
ct += window.is_visible()
|
||||||
for name in [ "windowManager", "windowHost"]:
|
if conn["windowHost"] != None and conn[name].is_visible():
|
||||||
if conn[name] != None and conn[name].is_visible():
|
ct += 1
|
||||||
ct += 1
|
|
||||||
if self.windowCreate:
|
if self.windowCreate:
|
||||||
ct += self.windowCreate.is_visible()
|
ct += self.windowCreate.is_visible()
|
||||||
|
if self.windowManager:
|
||||||
|
ct += self.windowManager.is_visible()
|
||||||
return ct
|
return ct
|
||||||
|
|
||||||
def change_timer_interval(self,ignore1,ignore2,ignore3,ignore4):
|
def change_timer_interval(self,ignore1,ignore2,ignore3,ignore4):
|
||||||
@ -188,12 +194,10 @@ class vmmEngine:
|
|||||||
self.show_host(uri)
|
self.show_host(uri)
|
||||||
def _do_show_connect(self, src):
|
def _do_show_connect(self, src):
|
||||||
self.show_connect()
|
self.show_connect()
|
||||||
def _do_show_manager(self, src, uri):
|
|
||||||
self.show_manager(uri)
|
|
||||||
def _do_show_details(self, src, uri, uuid):
|
def _do_show_details(self, src, uri, uuid):
|
||||||
self.show_details(uri, uuid)
|
self.show_details(uri, uuid)
|
||||||
def _do_show_create(self, src, uri):
|
def _do_show_create(self, src):
|
||||||
self.show_create(uri)
|
self.show_create()
|
||||||
def _do_show_help(self, src, index):
|
def _do_show_help(self, src, index):
|
||||||
self.show_help(index)
|
self.show_help(index)
|
||||||
def _do_show_console(self, src, uri, uuid):
|
def _do_show_console(self, src, uri, uuid):
|
||||||
@ -284,27 +288,26 @@ class vmmEngine:
|
|||||||
self.connections[uri]["windowDetails"][uuid].show()
|
self.connections[uri]["windowDetails"][uuid].show()
|
||||||
return self.connections[uri]["windowDetails"][uuid]
|
return self.connections[uri]["windowDetails"][uuid]
|
||||||
|
|
||||||
def show_manager(self, uri):
|
def get_manager(self):
|
||||||
con = self.get_connection(uri)
|
if self.windowManager == None:
|
||||||
|
self.windowManager = vmmManager(self.get_config())
|
||||||
|
self.windowManager.connect("action-show-console", self._do_show_console)
|
||||||
|
self.windowManager.connect("action-show-terminal", self._do_show_terminal)
|
||||||
|
self.windowManager.connect("action-show-details", self._do_show_details)
|
||||||
|
self.windowManager.connect("action-show-preferences", self._do_show_preferences)
|
||||||
|
self.windowManager.connect("action-show-create", self._do_show_create)
|
||||||
|
self.windowManager.connect("action-show-help", self._do_show_help)
|
||||||
|
self.windowManager.connect("action-show-about", self._do_show_about)
|
||||||
|
self.windowManager.connect("action-show-host", self._do_show_host)
|
||||||
|
self.windowManager.connect("action-show-connect", self._do_show_connect)
|
||||||
|
return self.windowManager
|
||||||
|
|
||||||
if self.connections[uri]["windowManager"] == None:
|
def show_manager(self):
|
||||||
manager = vmmManager(self.get_config(),
|
self.get_manager().show()
|
||||||
con)
|
|
||||||
manager.connect("action-show-console", self._do_show_console)
|
|
||||||
manager.connect("action-show-terminal", self._do_show_terminal)
|
|
||||||
manager.connect("action-show-details", self._do_show_details)
|
|
||||||
manager.connect("action-show-preferences", self._do_show_preferences)
|
|
||||||
manager.connect("action-show-create", self._do_show_create)
|
|
||||||
manager.connect("action-show-help", self._do_show_help)
|
|
||||||
manager.connect("action-show-about", self._do_show_about)
|
|
||||||
manager.connect("action-show-host", self._do_show_host)
|
|
||||||
manager.connect("action-show-connect", self._do_show_connect)
|
|
||||||
self.connections[uri]["windowManager"] = manager
|
|
||||||
self.connections[uri]["windowManager"].show()
|
|
||||||
|
|
||||||
def show_create(self, uri):
|
def show_create(self):
|
||||||
if self.windowCreate == None:
|
if self.windowCreate == None:
|
||||||
self.windowCreate = vmmCreate(self.get_config(), self.get_connection(uri, False))
|
self.windowCreate = vmmCreate(self.get_config(), self.connections)
|
||||||
self.windowCreate.connect("action-show-console", self._do_show_console)
|
self.windowCreate.connect("action-show-console", self._do_show_console)
|
||||||
self.windowCreate.connect("action-show-terminal", self._do_show_terminal)
|
self.windowCreate.connect("action-show-terminal", self._do_show_terminal)
|
||||||
self.windowCreate.connect("action-show-help", self._do_show_help)
|
self.windowCreate.connect("action-show-help", self._do_show_help)
|
||||||
@ -316,7 +319,6 @@ class vmmEngine:
|
|||||||
conn = vmmConnection(self.get_config(), uri, readOnly)
|
conn = vmmConnection(self.get_config(), uri, readOnly)
|
||||||
self.connections[uri] = {
|
self.connections[uri] = {
|
||||||
"connection": conn,
|
"connection": conn,
|
||||||
"windowManager": None,
|
|
||||||
"windowHost": None,
|
"windowHost": None,
|
||||||
"windowDetails": {},
|
"windowDetails": {},
|
||||||
"windowConsole": {},
|
"windowConsole": {},
|
||||||
@ -324,6 +326,7 @@ class vmmEngine:
|
|||||||
}
|
}
|
||||||
self.connections[uri]["connection"].connect("disconnected", self._do_connection_disconnected)
|
self.connections[uri]["connection"].connect("disconnected", self._do_connection_disconnected)
|
||||||
self.connections[uri]["connection"].connect("vm-removed", self._do_vm_removed)
|
self.connections[uri]["connection"].connect("vm-removed", self._do_vm_removed)
|
||||||
|
self.get_manager().add_connection(self.connections[uri]["connection"])
|
||||||
self.connections[uri]["connection"].tick()
|
self.connections[uri]["connection"].tick()
|
||||||
|
|
||||||
return self.connections[uri]["connection"]
|
return self.connections[uri]["connection"]
|
||||||
|
@ -56,11 +56,11 @@ class vmmManager(gobject.GObject):
|
|||||||
"action-show-help": (gobject.SIGNAL_RUN_FIRST,
|
"action-show-help": (gobject.SIGNAL_RUN_FIRST,
|
||||||
gobject.TYPE_NONE, [str]),}
|
gobject.TYPE_NONE, [str]),}
|
||||||
|
|
||||||
def __init__(self, config, connection):
|
def __init__(self, config):
|
||||||
self.__gobject_init__()
|
self.__gobject_init__()
|
||||||
self.window = gtk.glade.XML(config.get_glade_dir() + "/vmm-manager.glade", "vmm-manager", domain="virt-manager")
|
self.window = gtk.glade.XML(config.get_glade_dir() + "/vmm-manager.glade", "vmm-manager", domain="virt-manager")
|
||||||
self.config = config
|
self.config = config
|
||||||
self.connection = connection
|
self.connections = {}
|
||||||
self.prepare_vmlist()
|
self.prepare_vmlist()
|
||||||
|
|
||||||
self.config.on_vmlist_domain_id_visible_changed(self.toggle_domain_id_visible_widget)
|
self.config.on_vmlist_domain_id_visible_changed(self.toggle_domain_id_visible_widget)
|
||||||
@ -81,15 +81,7 @@ class vmmManager(gobject.GObject):
|
|||||||
self.window.get_widget("menu_view_disk_usage").set_sensitive(False)
|
self.window.get_widget("menu_view_disk_usage").set_sensitive(False)
|
||||||
self.window.get_widget("menu_view_network_traffic").set_sensitive(False)
|
self.window.get_widget("menu_view_network_traffic").set_sensitive(False)
|
||||||
|
|
||||||
|
self.set_menu_visibility(None)
|
||||||
if self.connection.is_read_only():
|
|
||||||
self.window.get_widget("menu_file_new").set_sensitive(False)
|
|
||||||
self.window.get_widget("menu_file_restore_saved").set_sensitive(False)
|
|
||||||
self.window.get_widget("vm-new").set_sensitive(False)
|
|
||||||
else:
|
|
||||||
self.window.get_widget("menu_file_new").set_sensitive(True)
|
|
||||||
self.window.get_widget("vm-new").set_sensitive(True)
|
|
||||||
self.window.get_widget("menu_file_restore_saved").set_sensitive(True)
|
|
||||||
|
|
||||||
self.window.get_widget("vm-view").set_active(0)
|
self.window.get_widget("vm-view").set_active(0)
|
||||||
|
|
||||||
@ -187,19 +179,10 @@ class vmmManager(gobject.GObject):
|
|||||||
|
|
||||||
self.vm_selected(None)
|
self.vm_selected(None)
|
||||||
self.window.get_widget("vm-list").get_selection().connect("changed", self.vm_selected)
|
self.window.get_widget("vm-list").get_selection().connect("changed", self.vm_selected)
|
||||||
self.connection.connect("disconnected", self.close)
|
|
||||||
|
|
||||||
self.connection.connect("vm-added", self.vm_added)
|
|
||||||
self.connection.connect("vm-removed", self.vm_removed)
|
|
||||||
|
|
||||||
win = self.window.get_widget("vmm-manager")
|
|
||||||
win.set_title(win.get_title() + " (" + self.connection.get_name() + ")")
|
|
||||||
|
|
||||||
# store any error message from the restore-domain callback
|
# store any error message from the restore-domain callback
|
||||||
self.domain_restore_error = ""
|
self.domain_restore_error = ""
|
||||||
|
|
||||||
# Do useful things when a vm starts
|
|
||||||
self.connection.connect("vm-started", self.vm_started)
|
|
||||||
|
|
||||||
def show(self):
|
def show(self):
|
||||||
win = self.window.get_widget("vmm-manager")
|
win = self.window.get_widget("vmm-manager")
|
||||||
@ -207,7 +190,8 @@ class vmmManager(gobject.GObject):
|
|||||||
win.present()
|
win.present()
|
||||||
|
|
||||||
def close(self, src=None, src2=None):
|
def close(self, src=None, src2=None):
|
||||||
self.connection.close()
|
for uri in self.connections:
|
||||||
|
self.connections[uri].close()
|
||||||
win = self.window.get_widget("vmm-manager")
|
win = self.window.get_widget("vmm-manager")
|
||||||
win.hide()
|
win.hide()
|
||||||
return 1
|
return 1
|
||||||
@ -237,6 +221,9 @@ class vmmManager(gobject.GObject):
|
|||||||
|
|
||||||
|
|
||||||
def restore_saved(self, src=None):
|
def restore_saved(self, src=None):
|
||||||
|
# XXX save/restore with multiple connection UI not yet supported
|
||||||
|
return
|
||||||
|
|
||||||
# get filename
|
# get filename
|
||||||
self.fcdialog = gtk.FileChooserDialog(_("Restore Virtual Machine"),
|
self.fcdialog = gtk.FileChooserDialog(_("Restore Virtual Machine"),
|
||||||
self.window.get_widget("vmm-manager"),
|
self.window.get_widget("vmm-manager"),
|
||||||
@ -296,21 +283,23 @@ class vmmManager(gobject.GObject):
|
|||||||
model = vmlist.get_model()
|
model = vmlist.get_model()
|
||||||
model.clear()
|
model.clear()
|
||||||
self.rows = {}
|
self.rows = {}
|
||||||
|
|
||||||
uuids = self.connection.list_vm_uuids()
|
for uri in self.connections:
|
||||||
for vmuuid in uuids:
|
conn = self.connections[uri]
|
||||||
vm = self.connection.get_vm(vmuuid)
|
self._append_connection(model, conn)
|
||||||
if vm.is_active():
|
uuids = conn.list_vm_uuids()
|
||||||
if not(self.is_showing_active()):
|
for vmuuid in uuids:
|
||||||
continue
|
vm = conn.get_vm(vmuuid)
|
||||||
else:
|
if vm.is_active():
|
||||||
if not(self.is_showing_inactive()):
|
if not(self.is_showing_active()):
|
||||||
continue
|
continue
|
||||||
|
else:
|
||||||
self._append_vm(model, vm)
|
if not(self.is_showing_inactive()):
|
||||||
|
continue
|
||||||
|
self._append_vm(model, vm, conn)
|
||||||
|
|
||||||
def vm_added(self, connection, uri, vmuuid):
|
def vm_added(self, connection, uri, vmuuid):
|
||||||
vm = self.connection.get_vm(vmuuid)
|
vm = connection.get_vm(vmuuid)
|
||||||
vm.connect("status-changed", self.vm_status_changed)
|
vm.connect("status-changed", self.vm_status_changed)
|
||||||
vm.connect("resources-sampled", self.vm_resources_sampled)
|
vm.connect("resources-sampled", self.vm_resources_sampled)
|
||||||
|
|
||||||
@ -324,10 +313,10 @@ class vmmManager(gobject.GObject):
|
|||||||
if not(self.is_showing_inactive()):
|
if not(self.is_showing_inactive()):
|
||||||
return
|
return
|
||||||
|
|
||||||
self._append_vm(model, vm)
|
self._append_vm(model, vm, connection)
|
||||||
|
|
||||||
def vm_started(self, connection, uri, vmuuid):
|
def vm_started(self, connection, uri, vmuuid):
|
||||||
vm = self.connection.get_vm(vmuuid)
|
vm = connection.get_vm(vmuuid)
|
||||||
logging.debug("VM %s started" % vm.get_name())
|
logging.debug("VM %s started" % vm.get_name())
|
||||||
if self.config.get_console_popup() == 2 and not vm.is_management_domain():
|
if self.config.get_console_popup() == 2 and not vm.is_management_domain():
|
||||||
# user has requested consoles on all vms
|
# user has requested consoles on all vms
|
||||||
@ -337,26 +326,40 @@ class vmmManager(gobject.GObject):
|
|||||||
else:
|
else:
|
||||||
self.emit("action-show-terminal", uri, vmuuid)
|
self.emit("action-show-terminal", uri, vmuuid)
|
||||||
|
|
||||||
def _append_vm(self, model, vm):
|
def _append_vm(self, model, vm, conn):
|
||||||
# Handle, name, ID, status, status icon, cpu, [cpu graph], vcpus, mem, mem bar
|
logging.debug("About to append vm: %s" % vm.get_name())
|
||||||
iter = model.append([vm, vm.get_name(), vm.get_id_pretty(), vm.run_status(), \
|
parent = self.rows[conn.get_uri()].iter
|
||||||
|
# Handle, name, ID, status, status icon, cpu, [cpu graph], vcpus, mem, mem bar, uuid
|
||||||
|
iter = model.append(parent, [vm, vm.get_name(), vm.get_id_pretty(), vm.run_status(), \
|
||||||
vm.run_status_icon(), vm.cpu_time_pretty(), vm.vcpu_count(), \
|
vm.run_status_icon(), vm.cpu_time_pretty(), vm.vcpu_count(), \
|
||||||
vm.get_memory_pretty(), vm.current_memory_percentage()])
|
vm.get_memory_pretty(), vm.current_memory_percentage(), vm.get_uuid()])
|
||||||
path = model.get_path(iter)
|
path = model.get_path(iter)
|
||||||
self.rows[vm.get_uuid()] = model[path]
|
self.rows[vm.get_uuid()] = model[path]
|
||||||
|
|
||||||
|
def _append_connection(self, model, conn):
|
||||||
|
# Handle, name, ID, status, status icon, cpu, [cpu graph], vcpus, mem, mem bar, uuid
|
||||||
|
# Connections are top-level rows, so append with parent None
|
||||||
|
logging.debug("About to append connection: %s" % conn.get_name())
|
||||||
|
iter = model.append(None, [conn, conn.get_name(), conn.get_uri(), "connected", \
|
||||||
|
self.config.get_vm_status_icon(libvirt.VIR_DOMAIN_RUNNING), "0", 0, \
|
||||||
|
"0", 0, "0"])
|
||||||
|
path = model.get_path(iter)
|
||||||
|
self.rows[conn.get_uri()] = model[path]
|
||||||
|
|
||||||
def vm_removed(self, connection, uri, vmuuid):
|
def vm_removed(self, connection, uri, vmuuid):
|
||||||
vmlist = self.window.get_widget("vm-list")
|
vmlist = self.window.get_widget("vm-list")
|
||||||
model = vmlist.get_model()
|
model = vmlist.get_model()
|
||||||
|
|
||||||
for row in range(model.iter_n_children(None)):
|
parent = self.rows[connection.get_uri()].iter
|
||||||
vm = model.get_value(model.iter_nth_child(None, row), 0)
|
for row in range(model.iter_n_children(parent)):
|
||||||
|
vm = model.get_value(model.iter_nth_child(parent, row), 0)
|
||||||
if vm.get_uuid() == vmuuid:
|
if vm.get_uuid() == vmuuid:
|
||||||
model.remove(model.iter_nth_child(None, row))
|
model.remove(model.iter_nth_child(parent, row))
|
||||||
del self.rows[vmuuid]
|
del self.rows[vmuuid]
|
||||||
break
|
break
|
||||||
|
|
||||||
def vm_status_changed(self, vm, status):
|
def vm_status_changed(self, vm, status):
|
||||||
|
parent = self.rows[vm.get_connection().get_uri()].iter
|
||||||
wanted = False
|
wanted = False
|
||||||
if vm.is_active():
|
if vm.is_active():
|
||||||
if self.is_showing_active():
|
if self.is_showing_active():
|
||||||
@ -369,18 +372,18 @@ class vmmManager(gobject.GObject):
|
|||||||
model = vmlist.get_model()
|
model = vmlist.get_model()
|
||||||
|
|
||||||
missing = True
|
missing = True
|
||||||
for row in range(model.iter_n_children(None)):
|
for row in range(model.iter_n_children(parent)):
|
||||||
iter = model.iter_nth_child(None, row)
|
iter = model.iter_nth_child(parent, row)
|
||||||
if model.get_value(iter, 0).get_uuid() == vm.get_uuid():
|
if model.get_value(iter, 0).get_uuid() == vm.get_uuid():
|
||||||
if wanted:
|
if wanted:
|
||||||
missing = False
|
missing = False
|
||||||
else:
|
else:
|
||||||
model.remove(model.iter_nth_child(None, row))
|
model.remove(model.iter_nth_child(parent, row))
|
||||||
del self.rows[vm.get_uuid()]
|
del self.rows[vm.get_uuid()]
|
||||||
break
|
break
|
||||||
|
|
||||||
if missing and wanted:
|
if missing and wanted:
|
||||||
self._append_vm(model, vm)
|
self._append_vm(model, vm, vm.get_connection())
|
||||||
|
|
||||||
|
|
||||||
def vm_resources_sampled(self, vm):
|
def vm_resources_sampled(self, vm):
|
||||||
@ -417,10 +420,25 @@ class vmmManager(gobject.GObject):
|
|||||||
vmlist = self.window.get_widget("vm-list")
|
vmlist = self.window.get_widget("vm-list")
|
||||||
selection = vmlist.get_selection()
|
selection = vmlist.get_selection()
|
||||||
active = selection.get_selected()
|
active = selection.get_selected()
|
||||||
if active[1] != None:
|
# check that something is selected and that it is a vm, not a connection
|
||||||
|
if active[1] != None and active[0].iter_parent(active[1]) != None:
|
||||||
return active[0].get_value(active[1], 0)
|
return active[0].get_value(active[1], 0)
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
def current_connection(self):
|
||||||
|
vmlist = self.window.get_widget("vm-list")
|
||||||
|
selection = vmlist.get_selection()
|
||||||
|
active = selection.get_selected()
|
||||||
|
if active[1] != None:
|
||||||
|
parent = active[0].iter_parent(active[1])
|
||||||
|
# return the connection of the currently selected vm, or the
|
||||||
|
# currently selected connection
|
||||||
|
if parent is not None:
|
||||||
|
return active[0].get_value(parent, 0)
|
||||||
|
else:
|
||||||
|
return active[0].get_value(active[1], 0)
|
||||||
|
return None
|
||||||
|
|
||||||
def current_vmuuid(self):
|
def current_vmuuid(self):
|
||||||
vm = self.current_vm()
|
vm = self.current_vm()
|
||||||
if vm is None:
|
if vm is None:
|
||||||
@ -431,29 +449,33 @@ class vmmManager(gobject.GObject):
|
|||||||
vm = self.current_vm()
|
vm = self.current_vm()
|
||||||
if vm is None or vm.is_active():
|
if vm is None or vm.is_active():
|
||||||
return
|
return
|
||||||
|
conn = vm.get_connection()
|
||||||
vm.delete()
|
vm.delete()
|
||||||
self.connection.tick(noStatsUpdate=True)
|
conn.tick(noStatsUpdate=True)
|
||||||
|
|
||||||
def show_vm_details(self,ignore):
|
def show_vm_details(self,ignore):
|
||||||
self.emit("action-show-details", self.connection.get_uri(), self.current_vmuuid())
|
vm = self.current_vm()
|
||||||
|
if vm is None:
|
||||||
|
return
|
||||||
|
conn = vm.get_connection()
|
||||||
|
self.emit("action-show-details", conn.get_uri(), self.current_vmuuid())
|
||||||
|
|
||||||
def show_vm_create(self,ignore):
|
def show_vm_create(self,ignore):
|
||||||
self.emit("action-show-create", self.connection.get_uri())
|
self.emit("action-show-create", self.connections)
|
||||||
|
|
||||||
def open_vm_console(self,ignore,ignore2=None,ignore3=None):
|
def open_vm_console(self,ignore,ignore2=None,ignore3=None):
|
||||||
self.emit("action-show-console", self.connection.get_uri(), self.current_vmuuid())
|
self.emit("action-show-console", self.connection.get_uri(), self.current_vmuuid())
|
||||||
|
|
||||||
|
|
||||||
def vm_selected(self, selection):
|
def vm_selected(self, selection):
|
||||||
|
vm = self.current_vm()
|
||||||
if selection == None or selection.count_selected_rows() == 0:
|
if selection == None or selection.count_selected_rows() == 0:
|
||||||
self.window.get_widget("vm-delete").set_sensitive(False)
|
self.window.get_widget("vm-delete").set_sensitive(False)
|
||||||
self.window.get_widget("vm-details").set_sensitive(False)
|
self.window.get_widget("vm-details").set_sensitive(False)
|
||||||
self.window.get_widget("vm-open").set_sensitive(False)
|
self.window.get_widget("vm-open").set_sensitive(False)
|
||||||
self.window.get_widget("menu_edit_delete").set_sensitive(False)
|
self.window.get_widget("menu_edit_delete").set_sensitive(False)
|
||||||
self.window.get_widget("menu_edit_details").set_sensitive(False)
|
self.window.get_widget("menu_edit_details").set_sensitive(False)
|
||||||
else:
|
elif vm is not None:
|
||||||
vm = self.current_vm()
|
|
||||||
if vm.is_active():
|
if vm.is_active():
|
||||||
self.window.get_widget("vm-delete").set_sensitive(False)
|
self.window.get_widget("vm-delete").set_sensitive(False)
|
||||||
self.window.get_widget("menu_edit_delete").set_sensitive(False)
|
self.window.get_widget("menu_edit_delete").set_sensitive(False)
|
||||||
@ -463,9 +485,19 @@ class vmmManager(gobject.GObject):
|
|||||||
self.window.get_widget("vm-details").set_sensitive(True)
|
self.window.get_widget("vm-details").set_sensitive(True)
|
||||||
self.window.get_widget("vm-open").set_sensitive(True)
|
self.window.get_widget("vm-open").set_sensitive(True)
|
||||||
self.window.get_widget("menu_edit_details").set_sensitive(True)
|
self.window.get_widget("menu_edit_details").set_sensitive(True)
|
||||||
|
else:
|
||||||
|
connection = self.current_connection()
|
||||||
|
self.set_menu_visibility(connection)
|
||||||
|
self.window.get_widget("vm-delete").set_sensitive(False)
|
||||||
|
self.window.get_widget("vm-details").set_sensitive(False)
|
||||||
|
self.window.get_widget("vm-open").set_sensitive(False)
|
||||||
|
self.window.get_widget("menu_edit_delete").set_sensitive(False)
|
||||||
|
self.window.get_widget("menu_edit_details").set_sensitive(False)
|
||||||
|
self.window.get_widget("vm-delete").set_sensitive(False)
|
||||||
|
self.window.get_widget("menu_edit_delete").set_sensitive(False)
|
||||||
def popup_vm_menu(self, widget, event):
|
def popup_vm_menu(self, widget, event):
|
||||||
vm = self.current_vm()
|
vm = self.current_vm()
|
||||||
|
connection = self.current_connection()
|
||||||
if vm != None:
|
if vm != None:
|
||||||
|
|
||||||
# Update popup menu based upon vm status
|
# Update popup menu based upon vm status
|
||||||
@ -498,9 +530,13 @@ class vmmManager(gobject.GObject):
|
|||||||
self.vmmenu_items["resume"].show()
|
self.vmmenu_items["resume"].show()
|
||||||
self.vmmenu_items["resume"].set_sensitive(True)
|
self.vmmenu_items["resume"].set_sensitive(True)
|
||||||
self.vmmenu_items["shutdown"].set_sensitive(True)
|
self.vmmenu_items["shutdown"].set_sensitive(True)
|
||||||
|
|
||||||
if event.button == 3:
|
if event.button == 3:
|
||||||
self.vmmenu.popup(None, None, None, 0, event.time)
|
self.vmmenu.popup(None, None, None, 0, event.time)
|
||||||
|
elif connection is not None:
|
||||||
|
# later, add "disconnect" item
|
||||||
|
if event.button == 3:
|
||||||
|
self.vmmenu.popup(None, None, None, 0, event.time)
|
||||||
|
|
||||||
|
|
||||||
def show_about(self, src):
|
def show_about(self, src):
|
||||||
self.emit("action-show-about")
|
self.emit("action-show-about")
|
||||||
@ -519,7 +555,7 @@ class vmmManager(gobject.GObject):
|
|||||||
vmlist = self.window.get_widget("vm-list")
|
vmlist = self.window.get_widget("vm-list")
|
||||||
|
|
||||||
# Handle, name, ID, status, status icon, cpu, [cpu graph], vcpus, mem, mem bar
|
# Handle, name, ID, status, status icon, cpu, [cpu graph], vcpus, mem, mem bar
|
||||||
model = gtk.ListStore(object, str, str, str, gtk.gdk.Pixbuf, str, int, str, int)
|
model = gtk.TreeStore(object, str, str, str, gtk.gdk.Pixbuf, str, int, str, int, str)
|
||||||
vmlist.set_model(model)
|
vmlist.set_model(model)
|
||||||
|
|
||||||
idCol = gtk.TreeViewColumn(_("ID"))
|
idCol = gtk.TreeViewColumn(_("ID"))
|
||||||
@ -703,19 +739,55 @@ class vmmManager(gobject.GObject):
|
|||||||
|
|
||||||
def start_vm(self, ignore):
|
def start_vm(self, ignore):
|
||||||
vm = self.current_vm()
|
vm = self.current_vm()
|
||||||
vm.startup()
|
if vm is not None:
|
||||||
|
vm.startup()
|
||||||
|
|
||||||
def stop_vm(self, ignore):
|
def stop_vm(self, ignore):
|
||||||
vm = self.current_vm()
|
vm = self.current_vm()
|
||||||
vm.shutdown()
|
if vm is not None:
|
||||||
|
vm.shutdown()
|
||||||
|
|
||||||
def pause_vm(self, ignore):
|
def pause_vm(self, ignore):
|
||||||
vm = self.current_vm()
|
vm = self.current_vm()
|
||||||
vm.suspend()
|
if vm is not None:
|
||||||
|
vm.suspend()
|
||||||
|
|
||||||
def resume_vm(self, ignore):
|
def resume_vm(self, ignore):
|
||||||
vm = self.current_vm()
|
vm = self.current_vm()
|
||||||
vm.resume()
|
if vm is not None:
|
||||||
|
vm.resume()
|
||||||
|
|
||||||
|
def add_connection(self, connection):
|
||||||
|
# connection.connect("disconnected", self.close)
|
||||||
|
connection.connect("vm-added", self.vm_added)
|
||||||
|
connection.connect("vm-removed", self.vm_removed)
|
||||||
|
# Do useful things when a vm starts
|
||||||
|
connection.connect("vm-started", self.vm_started)
|
||||||
|
# add the connection to the treeModel
|
||||||
|
vmlist = self.window.get_widget("vm-list")
|
||||||
|
self.connections[connection.uri] = connection
|
||||||
|
self._append_connection(vmlist.get_model(), connection)
|
||||||
|
|
||||||
|
def remove_connection(self, uri):
|
||||||
|
model = self.window.get_widget("vm-list").get_model()
|
||||||
|
parent = self.rows[uri].iter
|
||||||
|
if parent is not None:
|
||||||
|
child = model.iter_children(parent)
|
||||||
|
while child is not None:
|
||||||
|
del self.rows[model.get_value(child, 9)]
|
||||||
|
model.remove(child)
|
||||||
|
child = model.iter_children(parent)
|
||||||
|
model.remove(parent)
|
||||||
|
del self.rows[uri]
|
||||||
|
|
||||||
|
def set_menu_visibility(self, connection):
|
||||||
|
if connection is None or connection.is_read_only():
|
||||||
|
self.window.get_widget("menu_file_new").set_sensitive(False)
|
||||||
|
self.window.get_widget("menu_file_restore_saved").set_sensitive(False)
|
||||||
|
self.window.get_widget("vm-new").set_sensitive(False)
|
||||||
|
else:
|
||||||
|
self.window.get_widget("menu_file_new").set_sensitive(True)
|
||||||
|
self.window.get_widget("vm-new").set_sensitive(True)
|
||||||
|
self.window.get_widget("menu_file_restore_saved").set_sensitive(True)
|
||||||
|
|
||||||
gobject.type_register(vmmManager)
|
gobject.type_register(vmmManager)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user