connection: Pass object in -added/-removed signals

And not connkey. connkey == name, and name can change with object
rename, so it's a bad pattern to propagate that connkey can be used
as a static lookup key for objects. This begins unwinding it

Signed-off-by: Cole Robinson <crobinso@redhat.com>
This commit is contained in:
Cole Robinson 2020-09-01 11:54:10 -04:00
parent e4c0191f83
commit 8ff0da7664
10 changed files with 40 additions and 46 deletions

View File

@ -197,8 +197,8 @@ class vmmCloneVM(vmmGObjectUI):
return 1
def _vm_removed(self, _conn, connkey):
if self.vm.get_connkey() == connkey:
def _vm_removed_cb(self, _conn, vm):
if self.vm == vm:
self.close()
def _set_vm(self, newvm):
@ -206,7 +206,7 @@ class vmmCloneVM(vmmGObjectUI):
if oldvm:
oldvm.conn.disconnect_by_obj(self)
if newvm:
newvm.conn.connect("vm-removed", self._vm_removed)
newvm.conn.connect("vm-removed", self._vm_removed_cb)
self.vm = newvm
def _cleanup(self):

View File

@ -140,14 +140,14 @@ class _ObjectList(vmmGObject):
class vmmConnection(vmmGObject):
__gsignals__ = {
"vm-added": (vmmGObject.RUN_FIRST, None, [str]),
"vm-removed": (vmmGObject.RUN_FIRST, None, [str]),
"net-added": (vmmGObject.RUN_FIRST, None, [str]),
"net-removed": (vmmGObject.RUN_FIRST, None, [str]),
"pool-added": (vmmGObject.RUN_FIRST, None, [str]),
"pool-removed": (vmmGObject.RUN_FIRST, None, [str]),
"nodedev-added": (vmmGObject.RUN_FIRST, None, [str]),
"nodedev-removed": (vmmGObject.RUN_FIRST, None, [str]),
"vm-added": (vmmGObject.RUN_FIRST, None, [object]),
"vm-removed": (vmmGObject.RUN_FIRST, None, [object]),
"net-added": (vmmGObject.RUN_FIRST, None, [object]),
"net-removed": (vmmGObject.RUN_FIRST, None, [object]),
"pool-added": (vmmGObject.RUN_FIRST, None, [object]),
"pool-removed": (vmmGObject.RUN_FIRST, None, [object]),
"nodedev-added": (vmmGObject.RUN_FIRST, None, [object]),
"nodedev-removed": (vmmGObject.RUN_FIRST, None, [object]),
"resources-sampled": (vmmGObject.RUN_FIRST, None, []),
"state-changed": (vmmGObject.RUN_FIRST, None, []),
"open-completed": (vmmGObject.RUN_FIRST, None, [object]),
@ -1000,13 +1000,13 @@ class vmmConnection(vmmGObject):
def _remove_object_signal(self, obj):
if obj.is_domain():
self.emit("vm-removed", obj.get_connkey())
self.emit("vm-removed", obj)
elif obj.is_network():
self.emit("net-removed", obj.get_connkey())
self.emit("net-removed", obj)
elif obj.is_pool():
self.emit("pool-removed", obj.get_connkey())
self.emit("pool-removed", obj)
elif obj.is_nodedev():
self.emit("nodedev-removed", obj.get_connkey())
self.emit("nodedev-removed", obj)
def _gone_object_signals(self, gone_objects):
"""
@ -1061,13 +1061,13 @@ class vmmConnection(vmmGObject):
log.debug("%s=%s status=%s added", class_name,
obj.get_name(), obj.run_status())
if obj.is_domain():
self.emit("vm-added", obj.get_connkey())
self.emit("vm-added", obj)
elif obj.is_network():
self.emit("net-added", obj.get_connkey())
self.emit("net-added", obj)
elif obj.is_pool():
self.emit("pool-added", obj.get_connkey())
self.emit("pool-added", obj)
elif obj.is_nodedev():
self.emit("nodedev-added", obj.get_connkey())
self.emit("nodedev-added", obj)
finally:
if self._init_object_event:
self._init_object_count -= 1

View File

@ -90,7 +90,7 @@ class _vmmDeleteBase(vmmGObjectUI):
if oldvm:
oldvm.conn.disconnect_by_obj(self)
if newvm:
newvm.conn.connect("vm-removed", self._vm_removed)
newvm.conn.connect("vm-removed", self._vm_removed_cb)
self.vm = newvm
def _reset_state(self):
@ -125,8 +125,8 @@ class _vmmDeleteBase(vmmGObjectUI):
def _finish_clicked_cb(self, src):
self._finish()
def _vm_removed(self, _conn, connkey):
if self.vm.get_connkey() == connkey:
def _vm_removed_cb(self, _conn, vm):
if self.vm == vm:
self.close()
def _toggle_remove_storage(self, src):

View File

@ -367,7 +367,7 @@ class vmmHostNets(vmmGObjectUI):
def _conn_state_changed_cb(self, conn):
self._refresh_conn_state()
def _conn_nets_changed_cb(self, src, connkey):
def _conn_nets_changed_cb(self, src, net):
self._populate_networks()
def _net_state_changed_cb(self, net):

View File

@ -671,7 +671,7 @@ class vmmHostStorage(vmmGObjectUI):
def _conn_state_changed_cb(self, conn):
self._refresh_conn_state()
def _conn_pools_changed_cb(self, src, connkey):
def _conn_pools_changed_cb(self, src, pool):
self._populate_pools()
def _pool_selected_cb(self, selection):

View File

@ -252,14 +252,14 @@ class vmmInspection(vmmGObject):
def _conn_removed_cb(self, connmanager, uri):
self._uris.remove(uri)
def _vm_added_cb(self, conn, connkey):
def _vm_added_cb(self, conn, vm):
# Called by the main thread whenever a VM is added to vmlist.
if connkey.startswith("guestfs-"):
log.debug("ignore libvirt/guestfs temporary VM %s",
connkey)
name = vm.get_name()
if name.startswith("guestfs-"):
log.debug("ignore libvirt/guestfs temporary VM %s", name)
return
self._q.put((conn.get_uri(), connkey))
self._q.put((conn.get_uri(), vm.get_connkey()))
def _start(self):
self._thread = threading.Thread(

View File

@ -548,11 +548,7 @@ class vmmManager(vmmGObjectUI):
# VM add/remove management methods #
####################################
def vm_added(self, conn, connkey):
vm = conn.get_vm(connkey)
if not vm:
return # pragma: no cover
def vm_added(self, conn, vm):
vm_row = self._build_row(None, vm)
conn_row = self.get_row(conn)
self.model.append(conn_row.iter, vm_row)
@ -564,12 +560,11 @@ class vmmManager(vmmGObjectUI):
# Expand a connection when adding a vm to it
self.widget("vm-list").expand_row(conn_row.path, False)
def vm_removed(self, conn, connkey):
def vm_removed(self, conn, vm):
parent = self.get_row(conn).iter
for rowidx in range(self.model.iter_n_children(parent)):
rowiter = self.model.iter_nth_child(parent, rowidx)
vm = self.model[rowiter][ROW_HANDLE]
if vm.get_connkey() == connkey:
if self.model[rowiter][ROW_HANDLE] == vm:
self.model.remove(rowiter)
break
@ -652,7 +647,7 @@ class vmmManager(vmmGObjectUI):
conn.connect("state-changed", self.conn_state_changed)
for vm in conn.list_vms():
self.vm_added(conn, vm.get_connkey())
self.vm_added(conn, vm)
def _remove_child_rows(self, row):
child = self.model.iter_children(row.iter)

View File

@ -85,8 +85,8 @@ class vmmMigrateDialog(vmmGObjectUI):
self._set_vm(None)
return 1
def _vm_removed(self, _conn, connkey):
if self.vm.get_connkey() == connkey:
def _vm_removed_cb(self, _conn, vm):
if self.vm == vm:
self.close()
def _set_vm(self, newvm):
@ -94,7 +94,7 @@ class vmmMigrateDialog(vmmGObjectUI):
if oldvm:
oldvm.conn.disconnect_by_obj(self)
if newvm:
newvm.conn.connect("vm-removed", self._vm_removed)
newvm.conn.connect("vm-removed", self._vm_removed_cb)
self.vm = newvm

View File

@ -310,8 +310,7 @@ class vmmSystray(vmmGObject):
conn.connect("state-changed", self._rebuild_menu)
self._rebuild_menu()
def _vm_added_cb(self, conn, connkey):
vm = conn.get_vm(connkey)
def _vm_added_cb(self, conn, vm):
vm.connect("state-changed", self._rebuild_menu)
self._rebuild_menu()

View File

@ -63,7 +63,7 @@ class vmmVMWindow(vmmGObjectUI):
pages = self.widget("details-pages")
pages.set_current_page(DETAILS_PAGE_DETAILS)
else:
self.conn.connect("vm-removed", self._vm_removed)
self.conn.connect("vm-removed", self._vm_removed_cb)
self._mediacombo = None
@ -187,8 +187,8 @@ class vmmVMWindow(vmmGObjectUI):
return
self.emit("customize-finished", self.vm)
def _vm_removed(self, _conn, connkey):
if self.vm.get_connkey() == connkey:
def _vm_removed_cb(self, _conn, vm):
if self.vm == vm:
self.cleanup()
def _customize_cancel(self):