From 01bf07ba117a63e81331047bca123c597df6abde Mon Sep 17 00:00:00 2001 From: Cole Robinson Date: Thu, 9 Apr 2015 16:07:09 -0400 Subject: [PATCH] libvirtobject: Unify status signals Dispatch them all from the actual object and not proxied through the connection. Use the same signal name for all objects with the same signature. --- virtManager/connection.py | 20 -------------------- virtManager/create.py | 2 +- virtManager/details.py | 2 +- virtManager/domain.py | 8 +++----- virtManager/host.py | 25 ++++++++++++++----------- virtManager/interface.py | 8 ++++---- virtManager/libvirtobject.py | 1 + virtManager/manager.py | 4 +--- virtManager/network.py | 5 +++-- virtManager/serialcon.py | 4 ++-- virtManager/storagelist.py | 26 ++++++++++---------------- virtManager/storagepool.py | 5 +++-- virtManager/systray.py | 2 +- 13 files changed, 44 insertions(+), 68 deletions(-) diff --git a/virtManager/connection.py b/virtManager/connection.py index 583c8fb11..4368089d1 100644 --- a/virtManager/connection.py +++ b/virtManager/connection.py @@ -52,17 +52,10 @@ class vmmConnection(vmmGObject): "vm-removed": (GObject.SignalFlags.RUN_FIRST, None, [str]), "net-added": (GObject.SignalFlags.RUN_FIRST, None, [str]), "net-removed": (GObject.SignalFlags.RUN_FIRST, None, [str]), - "net-started": (GObject.SignalFlags.RUN_FIRST, None, [str]), - "net-stopped": (GObject.SignalFlags.RUN_FIRST, None, [str]), "pool-added": (GObject.SignalFlags.RUN_FIRST, None, [str]), "pool-removed": (GObject.SignalFlags.RUN_FIRST, None, [str]), - "pool-started": (GObject.SignalFlags.RUN_FIRST, None, [str]), - "pool-stopped": (GObject.SignalFlags.RUN_FIRST, None, [str]), - "pool-refreshed": (GObject.SignalFlags.RUN_FIRST, None, [str]), "interface-added": (GObject.SignalFlags.RUN_FIRST, None, [str]), "interface-removed": (GObject.SignalFlags.RUN_FIRST, None, [str]), - "interface-started": (GObject.SignalFlags.RUN_FIRST, None, [str]), - "interface-stopped": (GObject.SignalFlags.RUN_FIRST, None, [str]), "nodedev-added": (GObject.SignalFlags.RUN_FIRST, None, [str]), "nodedev-removed": (GObject.SignalFlags.RUN_FIRST, None, [str]), "resources-sampled": (GObject.SignalFlags.RUN_FIRST, None, []), @@ -973,9 +966,6 @@ class vmmConnection(vmmGObject): return pollhelpers.fetch_vms(self._backend, self._vms.copy(), (lambda obj, key: vmmDomain(self, obj, key))) - def _obj_signal_proxy(self, obj, signal): - self.emit(signal, obj.get_connkey()) - def schedule_priority_tick(self, **kwargs): # args/kwargs are what is passed to def tick() if "stats_update" not in kwargs: @@ -1140,8 +1130,6 @@ class vmmConnection(vmmGObject): obj.cleanup() for connkey, obj in newNets.items(): logging.debug("network=%s added", obj.get_name()) - obj.connect("started", self._obj_signal_proxy, "net-started") - obj.connect("stopped", self._obj_signal_proxy, "net-stopped") self.emit("net-added", connkey) # Update storage pool states @@ -1151,10 +1139,6 @@ class vmmConnection(vmmGObject): obj.cleanup() for connkey, obj in newPools.items(): logging.debug("pool=%s added", obj.get_name()) - obj.connect("started", self._obj_signal_proxy, "pool-started") - obj.connect("stopped", self._obj_signal_proxy, "pool-stopped") - obj.connect("refreshed", self._obj_signal_proxy, - "pool-refreshed") self.emit("pool-added", connkey) # Update interface states @@ -1164,10 +1148,6 @@ class vmmConnection(vmmGObject): obj.cleanup() for name, obj in newInterfaces.items(): logging.debug("interface=%s added", obj.get_name()) - obj.connect("started", self._obj_signal_proxy, - "interface-started") - obj.connect("stopped", self._obj_signal_proxy, - "interface-stopped") self.emit("interface-added", name) # Update nodedev list diff --git a/virtManager/create.py b/virtManager/create.py index 5bbe50447..ad3fb4f26 100644 --- a/virtManager/create.py +++ b/virtManager/create.py @@ -1906,7 +1906,7 @@ class vmmCreate(vmmGObjectUI): "VM creation.", poolname, exc_info=True) - def check_install_status(self, vm, ignore1, ignore2, virtinst_guest=None): + def check_install_status(self, vm, virtinst_guest): if vm.is_crashed(): logging.debug("VM crashed, cancelling install plans.") return True diff --git a/virtManager/details.py b/virtManager/details.py index b6c26d722..0b6e2349d 100644 --- a/virtManager/details.py +++ b/virtManager/details.py @@ -1300,7 +1300,7 @@ class vmmDetails(vmmGObjectUI): self.widget("details-vm-menu").get_submenu().change_run_text(text) self.widget("control-run").set_label(strip_text) - def refresh_vm_state(self, ignore1=None, ignore2=None, ignore3=None): + def refresh_vm_state(self, ignore=None): vm = self.vm status = self.vm.status() diff --git a/virtManager/domain.py b/virtManager/domain.py index 40aff76a2..53cd79fc2 100644 --- a/virtManager/domain.py +++ b/virtManager/domain.py @@ -209,7 +209,6 @@ class vmmDomain(vmmLibvirtObject): backed by a virtinst.Guest object for new VM 'customize before install' """ __gsignals__ = { - "status-changed": (GObject.SignalFlags.RUN_FIRST, None, [int, int]), "resources-sampled": (GObject.SignalFlags.RUN_FIRST, None, []), "inspection-changed": (GObject.SignalFlags.RUN_FIRST, None, []), "pre-startup": (GObject.SignalFlags.RUN_FIRST, None, [object]), @@ -1321,7 +1320,7 @@ class vmmDomain(vmmLibvirtObject): Attempt a manual reboot by invoking 'shutdown', then listen for a state change and restart the VM """ - def reboot_listener(vm, ignore1, ignore2, self): + def reboot_listener(vm, self): if vm.is_crashed(): # Abandon reboot plans self.reboot_listener = None @@ -1347,7 +1346,7 @@ class vmmDomain(vmmLibvirtObject): def add_reboot(): self.reboot_listener = self.connect_opt_out("status-changed", - reboot_listener, self) + reboot_listener, self) self.idle_add(add_reboot) def shutdown(self): @@ -1748,7 +1747,6 @@ class vmmDomain(vmmLibvirtObject): if status == self.lastStatus: return - oldstatus = self.lastStatus self.lastStatus = status if self.domain_state_supported: self._lastStatusReason = self._backend.state()[1] @@ -1758,7 +1756,7 @@ class vmmDomain(vmmLibvirtObject): # are operating with fresh XML self.refresh_xml() - self.idle_emit("status-changed", oldstatus, status) + self.idle_emit("status-changed") def inspection_data_updated(self): self.idle_emit("inspection-changed") diff --git a/virtManager/host.py b/virtManager/host.py index 4c97deff3..45225d1f9 100644 --- a/virtManager/host.py +++ b/virtManager/host.py @@ -131,13 +131,9 @@ class vmmHost(vmmGObjectUI): self.conn.connect("net-added", self.repopulate_networks) self.conn.connect("net-removed", self.repopulate_networks) - self.conn.connect("net-started", self.refresh_network) - self.conn.connect("net-stopped", self.refresh_network) self.conn.connect("interface-added", self.repopulate_interfaces) self.conn.connect("interface-removed", self.repopulate_interfaces) - self.conn.connect("interface-started", self.refresh_interface) - self.conn.connect("interface-stopped", self.refresh_interface) self.conn.connect("state-changed", self.conn_state_changed) self.conn.connect("resources-sampled", self.refresh_resources) @@ -498,11 +494,11 @@ class vmmHost(vmmGObjectUI): except KeyError: return None - def refresh_network(self, src_ignore, connkey): + def refresh_network(self, net): + connkey = net.get_connkey() uilist = self.widget("net-list") sel = uilist.get_selection() model, treeiter = sel.get_selected() - net = self.conn.get_net(connkey) net.tick() for row in uilist.get_model(): @@ -703,6 +699,11 @@ class vmmHost(vmmGObjectUI): net_list.get_selection().unselect_all() model.clear() for net in self.conn.list_nets(): + try: + net.disconnect_by_func(self.refresh_network) + except: + pass + net.connect("status-changed", self.refresh_network) model.append([net.get_connkey(), net.get_name(), "network-idle", Gtk.IconSize.LARGE_TOOLBAR, bool(net.is_active())]) @@ -775,7 +776,7 @@ class vmmHost(vmmGObjectUI): if cp is None: return - self.refresh_interface(None, cp.get_name()) + self.refresh_interface(cp) def current_interface(self): connkey = uiutil.get_list_selection(self.widget("interface-list"), 0) @@ -915,13 +916,10 @@ class vmmHost(vmmGObjectUI): self.widget("interface-child-box").set_visible(show_child) self.populate_interface_children() - def refresh_interface(self, src, connkey): - ignore = src - + def refresh_interface(self, iface): iface_list = self.widget("interface-list") sel = iface_list.get_selection() model, treeiter = sel.get_selected() - iface = self.conn.get_interface(connkey) name = iface.get_name() iface.tick() @@ -953,6 +951,11 @@ class vmmHost(vmmGObjectUI): iface_list.get_selection().unselect_all() model.clear() for iface in self.conn.list_interfaces(): + try: + iface.disconnect_by_func(self.refresh_interface) + except: + pass + iface.connect("status-changed", self.refresh_interface) model.append([iface.get_connkey(), iface.get_name(), "network-idle", Gtk.IconSize.LARGE_TOOLBAR, bool(iface.is_active())]) diff --git a/virtManager/interface.py b/virtManager/interface.py index 85622be8a..55b8b0ced 100644 --- a/virtManager/interface.py +++ b/virtManager/interface.py @@ -42,13 +42,13 @@ class vmmInterface(vmmLibvirtObject): def _define(self, xml): return self.conn.define_interface(xml) - def set_active(self, state): + def _set_active(self, state): if state == self._active: return - self.idle_emit(state and "started" or "stopped") self._active = state - self.refresh_xml() + self._invalidate_xml() + self.idle_emit("status-changed") def _backend_get_active(self): ret = True @@ -61,7 +61,7 @@ class vmmInterface(vmmLibvirtObject): return bool(self._backend.isActive()) def tick(self): - self.set_active(self._backend_get_active()) + self._set_active(self._backend_get_active()) def is_active(self): return self._active diff --git a/virtManager/libvirtobject.py b/virtManager/libvirtobject.py index 963ed18e8..24781caa5 100644 --- a/virtManager/libvirtobject.py +++ b/virtManager/libvirtobject.py @@ -27,6 +27,7 @@ from .baseclass import vmmGObject class vmmLibvirtObject(vmmGObject): __gsignals__ = { + "status-changed": (GObject.SignalFlags.RUN_FIRST, None, []), "config-changed": (GObject.SignalFlags.RUN_FIRST, None, []), "started": (GObject.SignalFlags.RUN_FIRST, None, []), "stopped": (GObject.SignalFlags.RUN_FIRST, None, []), diff --git a/virtManager/manager.py b/virtManager/manager.py index 248fd6c21..619b2b0ae 100644 --- a/virtManager/manager.py +++ b/virtManager/manager.py @@ -803,9 +803,7 @@ class vmmManager(vmmGObjectUI): self.vm_row_updated(vm) - def vm_status_changed(self, vm, oldstatus, newstatus): - ignore = newstatus - ignore = oldstatus + def vm_status_changed(self, vm): parent = self.rows[vm.conn.get_uri()].iter vmlist = self.widget("vm-list") model = vmlist.get_model() diff --git a/virtManager/network.py b/virtManager/network.py index 2576003cd..233e4e8fb 100644 --- a/virtManager/network.py +++ b/virtManager/network.py @@ -78,9 +78,10 @@ class vmmNetwork(vmmLibvirtObject): def _set_active(self, state): if state == self._active: return - self.refresh_xml() - self.idle_emit(state and "started" or "stopped") + self._active = state + self._invalidate_xml() + self.idle_emit("status-changed") def force_update_status(self, from_event=False, log=True): ignore = log diff --git a/virtManager/serialcon.py b/virtManager/serialcon.py index 73e76a697..c982100e4 100644 --- a/virtManager/serialcon.py +++ b/virtManager/serialcon.py @@ -411,8 +411,8 @@ class vmmSerialConsole(vmmGObject): return False - def vm_status_changed(self, src_ignore, oldstatus_ignore, status): - if status in [libvirt.VIR_DOMAIN_RUNNING]: + def vm_status_changed(self, vm): + if vm.status() in [libvirt.VIR_DOMAIN_RUNNING]: self.open_console() else: self.console.close() diff --git a/virtManager/storagelist.py b/virtManager/storagelist.py index e7398c900..04e0791ff 100644 --- a/virtManager/storagelist.py +++ b/virtManager/storagelist.py @@ -118,16 +118,6 @@ class vmmStorageList(vmmGObjectUI): def _cleanup(self): - try: - self.conn.disconnect_by_func(self._conn_pool_count_changed) - self.conn.disconnect_by_func(self._conn_pool_count_changed) - self.conn.disconnect_by_func(self._conn_pool_changed) - self.conn.disconnect_by_func(self._conn_pool_changed) - self.conn.disconnect_by_func(self._conn_pool_changed) - self.conn.disconnect_by_func(self._conn_state_changed) - except: - pass - self.conn = None if self._addpool: @@ -238,9 +228,6 @@ class vmmStorageList(vmmGObjectUI): self._populate_pools() self.conn.connect("pool-added", self._conn_pool_count_changed) self.conn.connect("pool-removed", self._conn_pool_count_changed) - self.conn.connect("pool-started", self._conn_pool_changed) - self.conn.connect("pool-stopped", self._conn_pool_changed) - self.conn.connect("pool-refreshed", self._conn_pool_changed) self.conn.connect("state-changed", self._conn_state_changed) self._conn_state_changed() @@ -392,6 +379,14 @@ class vmmStorageList(vmmGObjectUI): model.clear() for pool in self.conn.list_pools(): + try: + pool.disconnect_by_func(self._pool_changed) + pool.disconnect_by_func(self._pool_changed) + except: + pass + pool.connect("status-changed", self._pool_changed) + pool.connect("refreshed", self._pool_changed) + name = pool.get_name() typ = StoragePool.get_pool_type_desc(pool.get_type()) label = "%s\n%s" % (name, typ) @@ -576,9 +571,8 @@ class vmmStorageList(vmmGObjectUI): self._set_storage_error_page( _("Libvirt connection does not support storage management.")) - def _conn_pool_changed(self, src, connkey): - ignore = src - self._update_pool_row(connkey) + def _pool_changed(self, pool): + self._update_pool_row(pool.get_connkey()) def _conn_pool_count_changed(self, src, connkey): ignore = src diff --git a/virtManager/storagepool.py b/virtManager/storagepool.py index 9f0b0ea0b..1a32a8898 100644 --- a/virtManager/storagepool.py +++ b/virtManager/storagepool.py @@ -140,9 +140,10 @@ class vmmStoragePool(vmmLibvirtObject): def _set_active(self, state): if state == self._active: return - self.idle_emit(state and "started" or "stopped") + self._active = state - self.refresh_xml() + self._invalidate_xml() + self.idle_emit("status-changed") def _kick_conn(self): self.conn.schedule_priority_tick(pollpool=True) diff --git a/virtManager/systray.py b/virtManager/systray.py index 52b66bf1f..a7fdcdd60 100644 --- a/virtManager/systray.py +++ b/virtManager/systray.py @@ -325,7 +325,7 @@ class vmmSystray(vmmGObject): placeholder.set_sensitive(False) vm_menu.add(placeholder) - def vm_state_changed(self, vm, ignore=None, ignore2=None): + def vm_state_changed(self, vm): menu_item = self._get_vm_menu_item(vm) if not menu_item: return