Hooked up domain filter in manager list. Ensure we don't recreate vmmDomain object on state changes

This commit is contained in:
Daniel P. Berrange 2006-10-10 17:24:59 -04:00
parent 9b9cadea98
commit f345ddbf5d
4 changed files with 92 additions and 33 deletions

View File

@ -360,12 +360,12 @@
<child> <child>
<widget class="GtkComboBox" id="vm-view"> <widget class="GtkComboBox" id="vm-view">
<property name="visible">True</property> <property name="visible">True</property>
<property name="sensitive">False</property>
<property name="items" translatable="yes">All virtual machines <property name="items" translatable="yes">All virtual machines
Active virtual machines Active virtual machines
Inactive virtual machines</property> Inactive virtual machines</property>
<property name="add_tearoffs">False</property> <property name="add_tearoffs">False</property>
<property name="focus_on_click">True</property> <property name="focus_on_click">True</property>
<signal name="changed" handler="on_vm_view_changed" last_modification_time="Tue, 10 Oct 2006 20:44:44 GMT"/>
</widget> </widget>
<packing> <packing>
<property name="padding">0</property> <property name="padding">0</property>

View File

@ -66,6 +66,9 @@ class vmmConnection(gobject.GObject):
self.vmm = None self.vmm = None
self.emit("disconnected", self.uri) self.emit("disconnected", self.uri)
def list_vm_uuids(self):
return self.vms.keys()
def get_host_info(self): def get_host_info(self):
return self.hostinfo return self.hostinfo
@ -133,8 +136,7 @@ class vmmConnection(gobject.GObject):
# if its a previously inactive domain. # if its a previously inactive domain.
vm = self.vmm.lookupByID(id) vm = self.vmm.lookupByID(id)
uuid = self.uuidstr(vm.UUID()) uuid = self.uuidstr(vm.UUID())
maybeNewUUIDs[uuid] = vmmDomain(self.config, self, vm, uuid) maybeNewUUIDs[uuid] = vm
curUUIDs[uuid] = maybeNewUUIDs[uuid]
#print "Maybe new active " + str(maybeNewUUIDs[uuid].get_name()) + " " + uuid #print "Maybe new active " + str(maybeNewUUIDs[uuid].get_name()) + " " + uuid
# Filter out inactive domains which haven't changed # Filter out inactive domains which haven't changed
@ -151,8 +153,7 @@ class vmmConnection(gobject.GObject):
# if its a previously inactive domain. # if its a previously inactive domain.
vm = self.vmm.lookupByName(name) vm = self.vmm.lookupByName(name)
uuid = self.uuidstr(vm.UUID()) uuid = self.uuidstr(vm.UUID())
maybeNewUUIDs[uuid] = vmmDomain(self.config, self, vm, uuid) maybeNewUUIDs[uuid] = vm
curUUIDs[uuid] = maybeNewUUIDs[uuid]
#print "Maybe new inactive " + str(maybeNewUUIDs[uuid].get_name()) + " " + uuid #print "Maybe new inactive " + str(maybeNewUUIDs[uuid].get_name()) + " " + uuid
# At this point, maybeNewUUIDs has domains which are # At this point, maybeNewUUIDs has domains which are
@ -161,13 +162,17 @@ class vmmConnection(gobject.GObject):
# Filter out VMs which merely changed state, leaving # Filter out VMs which merely changed state, leaving
# only new domains # only new domains
for uuid in maybeNewUUIDs.keys(): for uuid in maybeNewUUIDs.keys():
vm = maybeNewUUIDs[uuid] rawvm = maybeNewUUIDs[uuid]
if not(self.vms.has_key(vm.get_uuid())): if not(self.vms.has_key(uuid)):
#print "Completely new VM " + str(vm) #print "Completely new VM " + str(vm)
vm = vmmDomain(self.config, self, rawvm, uuid)
newUUIDs[vm.get_uuid()] = vm newUUIDs[vm.get_uuid()] = vm
curUUIDs[uuid] = vm
else: else:
vm = self.vms[uuid]
vm.set_handle(rawvm)
curUUIDs[uuid] = vm
#print "Mere state change " + str(vm) #print "Mere state change " + str(vm)
pass
# Finalize list of domains which went away altogether # Finalize list of domains which went away altogether
for uuid in self.vms.keys(): for uuid in self.vms.keys():
@ -185,10 +190,12 @@ class vmmConnection(gobject.GObject):
# Inform everyone what changed # Inform everyone what changed
for uuid in oldUUIDs: for uuid in oldUUIDs:
vm = oldUUIDs[uuid] vm = oldUUIDs[uuid]
#print "Remove " + vm.get_name() + " " + uuid
self.emit("vm-removed", self.uri, uuid) self.emit("vm-removed", self.uri, uuid)
for uuid in newUUIDs: for uuid in newUUIDs:
vm = newUUIDs[uuid] vm = newUUIDs[uuid]
#print "Add " + vm.get_name() + " " + uuid
self.emit("vm-added", self.uri, uuid) self.emit("vm-added", self.uri, uuid)
# Finally, we sample each domain # Finally, we sample each domain

View File

@ -43,6 +43,9 @@ class vmmDomain(gobject.GObject):
self.lastStatus = None self.lastStatus = None
self.record = [] self.record = []
def set_handle(self, vm):
self.vm = vm
def is_active(self): def is_active(self):
if self.vm.ID() == -1: if self.vm.ID() == -1:
return False return False

View File

@ -54,9 +54,6 @@ class vmmManager(gobject.GObject):
self.connection = connection self.connection = connection
self.prepare_vmlist() self.prepare_vmlist()
self.connection.connect("vm-added", self.vm_added)
self.connection.connect("vm-removed", self.vm_removed)
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)
self.config.on_vmlist_status_visible_changed(self.toggle_status_visible_widget) self.config.on_vmlist_status_visible_changed(self.toggle_status_visible_widget)
self.config.on_vmlist_cpu_usage_visible_changed(self.toggle_cpu_usage_visible_widget) self.config.on_vmlist_cpu_usage_visible_changed(self.toggle_cpu_usage_visible_widget)
@ -85,7 +82,6 @@ class vmmManager(gobject.GObject):
self.window.get_widget("vm-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("menu_file_restore_saved").set_sensitive(True)
self.window.get_widget("vm-view").set_sensitive(False)
self.window.get_widget("vm-view").set_active(0) self.window.get_widget("vm-view").set_active(0)
self.vmmenu = gtk.Menu() self.vmmenu = gtk.Menu()
@ -125,6 +121,7 @@ class vmmManager(gobject.GObject):
"on_vm_new_clicked": self.show_vm_create, "on_vm_new_clicked": self.show_vm_create,
"on_menu_edit_details_activate": self.show_vm_details, "on_menu_edit_details_activate": self.show_vm_details,
"on_vm_view_changed": self.vm_view_changed,
"on_vm_list_row_activated": self.open_vm_console, "on_vm_list_row_activated": self.open_vm_console,
"on_vm_list_button_press_event": self.popup_vm_menu, "on_vm_list_button_press_event": self.popup_vm_menu,
@ -137,6 +134,10 @@ class vmmManager(gobject.GObject):
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("disconnected", self.close)
self.connection.connect("vm-added", self.vm_added)
self.connection.connect("vm-removed", self.vm_removed)
# 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 = ""
@ -157,6 +158,19 @@ class vmmManager(gobject.GObject):
def open_connection(self, src=None): def open_connection(self, src=None):
self.emit("action-show-connect") self.emit("action-show-connect")
def is_showing_active(self):
active = self.window.get_widget("vm-view").get_active()
if active in [0,1]:
return True
return False
def is_showing_inactive(self):
active = self.window.get_widget("vm-view").get_active()
if active in [0,2]:
return True
return False
def restore_saved(self, src=None): def restore_saved(self, src=None):
# get filename # get filename
self.fcdialog = gtk.FileChooserDialog(_("Restore Virtual Machine"), self.fcdialog = gtk.FileChooserDialog(_("Restore Virtual Machine"),
@ -175,7 +189,7 @@ class vmmManager(gobject.GObject):
[file_to_load], [file_to_load],
_("Restoring Virtual Machine")) _("Restoring Virtual Machine"))
progWin.run() progWin.run()
self.fcdialog.destroy() self.fcdialog.destroy()
if(self.domain_restore_error != ""): if(self.domain_restore_error != ""):
self.error_msg = gtk.MessageDialog(self.window.get_widget("vmm-manager"), self.error_msg = gtk.MessageDialog(self.window.get_widget("vmm-manager"),
@ -186,56 +200,91 @@ class vmmManager(gobject.GObject):
self.error_msg.run() self.error_msg.run()
self.error_msg.destroy() self.error_msg.destroy()
self.domain_restore_error = "" self.domain_restore_error = ""
def restore_saved_callback(self, file_to_load): def restore_saved_callback(self, file_to_load):
status = self.connection.restore(file_to_load) status = self.connection.restore(file_to_load)
if(status != 0): if(status != 0):
self.domain_restore_error = _("Error restoring domain '%s'. Is the domain already running?") % file_to_load self.domain_restore_error = _("Error restoring domain '%s'. Is the domain already running?") % file_to_load
def vm_view_changed(self, src):
vmlist = self.window.get_widget("vm-list")
model = vmlist.get_model()
model.clear()
uuids = self.connection.list_vm_uuids()
for vmuuid in uuids:
vm = self.connection.get_vm(vmuuid)
if vm.is_active():
if not(self.is_showing_active()):
continue
else:
if not(self.is_showing_inactive()):
continue
model.append([vmuuid, vm.get_name()])
def vm_added(self, connection, uri, vmuuid): def vm_added(self, connection, uri, vmuuid):
vm = self.connection.get_vm(vmuuid)
vm.connect("status-changed", self.vm_status_changed)
vm.connect("resources-sampled", self.vm_resources_sampled)
vmlist = self.window.get_widget("vm-list") vmlist = self.window.get_widget("vm-list")
model = vmlist.get_model() model = vmlist.get_model()
dup = 0 if vm.is_active():
for row in range(model.iter_n_children(None)): if not(self.is_showing_active()):
vm = model.get_value(model.iter_nth_child(None, row), 0) return
if vm == vmuuid: else:
dup = 1 if not(self.is_showing_inactive()):
return
vm = self.connection.get_vm(vmuuid) model.append([vmuuid, vm.get_name()])
if dup != 1:
model.append([vmuuid, vm.get_name()])
vm.connect("status-changed", self.vm_status_changed)
vm.connect("resources-sampled", self.vm_resources_sampled)
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()
dup = 0
for row in range(model.iter_n_children(None)): for row in range(model.iter_n_children(None)):
vm = model.get_value(model.iter_nth_child(None, row), 0) vm = model.get_value(model.iter_nth_child(None, row), 0)
if vm == vmuuid: if vm == vmuuid:
model.remove(model.iter_nth_child(None, row)) model.remove(model.iter_nth_child(None, row))
break break
def vm_status_changed(self, domain, status): def vm_status_changed(self, vm, status):
self.vm_updated(domain.get_uuid()) wanted = False
if vm.is_active():
if self.is_showing_active():
wanted = True
else:
if self.is_showing_inactive():
wanted = True
def vm_resources_sampled(self, domain): vmlist = self.window.get_widget("vm-list")
self.vm_updated(domain.get_uuid()) model = vmlist.get_model()
def vm_updated(self, vmuuid): missing = True
for row in range(model.iter_n_children(None)):
iter = model.iter_nth_child(None, row)
if model.get_value(iter, 0) == vm.get_uuid():
if wanted:
missing = False
else:
model.remove(model.iter_nth_child(None, row))
break
if missing and wanted:
model.append([vm.get_uuid(), vm.get_name()])
def vm_resources_sampled(self, vm):
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)): for row in range(model.iter_n_children(None)):
iter = model.iter_nth_child(None, row) iter = model.iter_nth_child(None, row)
if model.get_value(iter, 0) == vmuuid: if model.get_value(iter, 0) == vm.get_uuid():
model.row_changed(str(row), iter) model.row_changed(str(row), iter)
def current_vm(self): def current_vm(self):