mirror of
https://github.com/virt-manager/virt-manager.git
synced 2025-02-25 18:55:27 -06:00
Make vmmConnection subclass GObject & use its signal infrastructure
This commit is contained in:
parent
2f838a74be
commit
7547140130
@ -1,4 +1,5 @@
|
|||||||
|
|
||||||
|
import gobject
|
||||||
import libvirt
|
import libvirt
|
||||||
|
|
||||||
from virtManager.stats import vmmStats
|
from virtManager.stats import vmmStats
|
||||||
@ -6,8 +7,19 @@ from virtManager.manager import vmmManager
|
|||||||
from virtManager.details import vmmDetails
|
from virtManager.details import vmmDetails
|
||||||
from virtManager.console import vmmConsole
|
from virtManager.console import vmmConsole
|
||||||
|
|
||||||
class vmmConnection:
|
class vmmConnection(gobject.GObject):
|
||||||
|
__gsignals__ = {
|
||||||
|
"vm-added": (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE,
|
||||||
|
(str, str,)),
|
||||||
|
"vm-removed": (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE,
|
||||||
|
(str,)),
|
||||||
|
"vm-updated": (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE,
|
||||||
|
(str,)),
|
||||||
|
"disconnected": (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, (str,))
|
||||||
|
}
|
||||||
|
|
||||||
def __init__(self, engine, config, uri, readOnly):
|
def __init__(self, engine, config, uri, readOnly):
|
||||||
|
self.__gobject_init__()
|
||||||
self.engine = engine
|
self.engine = engine
|
||||||
self.config = config
|
self.config = config
|
||||||
|
|
||||||
@ -21,7 +33,6 @@ class vmmConnection:
|
|||||||
self.windowConsole = {}
|
self.windowConsole = {}
|
||||||
self.vms = {}
|
self.vms = {}
|
||||||
|
|
||||||
self.callbacks = { "vm_added": [], "vm_removed": [], "vm_updated": [] }
|
|
||||||
self.stats = vmmStats(config, self)
|
self.stats = vmmStats(config, self)
|
||||||
|
|
||||||
def get_stats(self):
|
def get_stats(self):
|
||||||
@ -38,6 +49,11 @@ class vmmConnection:
|
|||||||
self.windowManager = vmmManager(self.config, self)
|
self.windowManager = vmmManager(self.config, self)
|
||||||
self.windowManager.show()
|
self.windowManager.show()
|
||||||
|
|
||||||
|
def disconnect(self):
|
||||||
|
self.vmm.disconnect()
|
||||||
|
self.vmm = None
|
||||||
|
self.emit("disconnected")
|
||||||
|
|
||||||
def get_host_info(self):
|
def get_host_info(self):
|
||||||
return self.vmm.getInfo()
|
return self.vmm.getInfo()
|
||||||
|
|
||||||
@ -56,35 +72,17 @@ class vmmConnection:
|
|||||||
def show_open_connection(self):
|
def show_open_connection(self):
|
||||||
self.engine.show_open_connection()
|
self.engine.show_open_connection()
|
||||||
|
|
||||||
def connect_to_signal(self, name, callback):
|
def connect(self, name, callback):
|
||||||
if not(self.callbacks.has_key(name)):
|
gobject.GObject.connect(self, name, callback)
|
||||||
raise "unknown signal " + name + "requested"
|
print "Cnnect " + name + " to " + str(callback)
|
||||||
|
if name == "vm-added":
|
||||||
self.callbacks[name].append(callback)
|
|
||||||
|
|
||||||
if name == "vm_removed":
|
|
||||||
for uuid in self.vms.keys():
|
for uuid in self.vms.keys():
|
||||||
self.notify_vm_added(uuid, self.vms[uuid].name())
|
self.emit("vm-added", uuid, self.vms[uuid].name())
|
||||||
|
|
||||||
def disconnect_from_signal(self, name, callback):
|
|
||||||
for i in len(self.callbacks[name]):
|
|
||||||
if self.callbacks[i] == callback:
|
|
||||||
del self.callbacks[i:i]
|
|
||||||
|
|
||||||
|
|
||||||
def notify_vm_added(self, uuid, name):
|
|
||||||
for cb in self.callbacks["vm_added"]:
|
|
||||||
cb(uuid, name)
|
|
||||||
|
|
||||||
def notify_vm_removed(self, uuid):
|
|
||||||
for cb in self.callbacks["vm_removed"]:
|
|
||||||
cb(uuid)
|
|
||||||
|
|
||||||
def notify_vm_updated(self, uuid):
|
|
||||||
for cb in self.callbacks["vm_updated"]:
|
|
||||||
cb(uuid)
|
|
||||||
|
|
||||||
def tick(self):
|
def tick(self):
|
||||||
|
if self.vmm == None:
|
||||||
|
return
|
||||||
|
|
||||||
doms = self.vmm.listDomainsID()
|
doms = self.vmm.listDomainsID()
|
||||||
newVms = {}
|
newVms = {}
|
||||||
if doms != None:
|
if doms != None:
|
||||||
@ -95,16 +93,17 @@ class vmmConnection:
|
|||||||
for uuid in self.vms.keys():
|
for uuid in self.vms.keys():
|
||||||
if not(newVms.has_key(uuid)):
|
if not(newVms.has_key(uuid)):
|
||||||
del self.vms[uuid]
|
del self.vms[uuid]
|
||||||
self.notify_vm_removed(uuid)
|
self.emit("vm-removed", uuid)
|
||||||
|
|
||||||
for uuid in newVms.keys():
|
for uuid in newVms.keys():
|
||||||
if not(self.vms.has_key(uuid)):
|
if not(self.vms.has_key(uuid)):
|
||||||
self.vms[uuid] = newVms[uuid]
|
self.vms[uuid] = newVms[uuid]
|
||||||
self.notify_vm_added(uuid, newVms[uuid].name())
|
print "Trying to emit"
|
||||||
|
self.emit("vm-added",uuid, newVms[uuid].name())
|
||||||
|
|
||||||
for uuid in self.vms.keys():
|
for uuid in self.vms.keys():
|
||||||
self.stats.update(uuid, self.vms[uuid])
|
self.stats.update(uuid, self.vms[uuid])
|
||||||
self.notify_vm_updated(uuid)
|
self.emit("vm-updated", uuid)
|
||||||
|
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
@ -118,4 +117,5 @@ class vmmConnection:
|
|||||||
uuid.append('-')
|
uuid.append('-')
|
||||||
return "".join(uuid)
|
return "".join(uuid)
|
||||||
|
|
||||||
|
gobject.type_register(vmmConnection)
|
||||||
|
|
||||||
|
@ -43,7 +43,7 @@ class vmmConsole:
|
|||||||
"on_control_details_clicked": self.control_vm_details,
|
"on_control_details_clicked": self.control_vm_details,
|
||||||
})
|
})
|
||||||
|
|
||||||
self.connection.connect_to_signal("vm_updated", self.vm_updated)
|
self.connection.connect("vm-updated", self.vm_updated)
|
||||||
self.refresh_status()
|
self.refresh_status()
|
||||||
|
|
||||||
def show(self):
|
def show(self):
|
||||||
@ -91,7 +91,7 @@ class vmmConsole:
|
|||||||
def control_vm_details(self, src):
|
def control_vm_details(self, src):
|
||||||
self.connection.show_details(self.vmuuid)
|
self.connection.show_details(self.vmuuid)
|
||||||
|
|
||||||
def vm_updated(self, uuid):
|
def vm_updated(self, connection, uuid):
|
||||||
if uuid == self.vmuuid:
|
if uuid == self.vmuuid:
|
||||||
self.refresh_status()
|
self.refresh_status()
|
||||||
|
|
||||||
|
@ -107,9 +107,9 @@ class vmmDetails:
|
|||||||
"on_control_snapshot_clicked": self.control_vm_snapshot,
|
"on_control_snapshot_clicked": self.control_vm_snapshot,
|
||||||
})
|
})
|
||||||
|
|
||||||
self.connection.connect_to_signal("vm_updated", self.refresh_overview)
|
self.connection.connect("vm-updated", self.refresh_overview)
|
||||||
self.change_graph_ranges()
|
self.change_graph_ranges()
|
||||||
self.refresh_overview(vmuuid)
|
self.refresh_overview(self.connection, vmuuid)
|
||||||
self.hw_selected()
|
self.hw_selected()
|
||||||
|
|
||||||
def show(self):
|
def show(self):
|
||||||
@ -207,7 +207,7 @@ class vmmDetails:
|
|||||||
|
|
||||||
self.lastStatus = status
|
self.lastStatus = status
|
||||||
|
|
||||||
def refresh_overview(self, vmuuid):
|
def refresh_overview(self, connection, vmuuid):
|
||||||
if not(vmuuid == self.vmuuid):
|
if not(vmuuid == self.vmuuid):
|
||||||
return
|
return
|
||||||
|
|
||||||
|
@ -15,9 +15,9 @@ class vmmManager:
|
|||||||
self.connection = connection
|
self.connection = connection
|
||||||
self.prepare_vmlist()
|
self.prepare_vmlist()
|
||||||
|
|
||||||
self.connection.connect_to_signal("vm_added", self.vm_added)
|
self.connection.connect("vm-added", self.vm_added)
|
||||||
self.connection.connect_to_signal("vm_removed", self.vm_removed)
|
self.connection.connect("vm-removed", self.vm_removed)
|
||||||
self.connection.connect_to_signal("vm_updated", self.vm_updated)
|
self.connection.connect("vm-updated", self.vm_updated)
|
||||||
|
|
||||||
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)
|
||||||
@ -91,10 +91,10 @@ class vmmManager:
|
|||||||
def open_connection(self, src=None):
|
def open_connection(self, src=None):
|
||||||
self.connection.show_open_connection()
|
self.connection.show_open_connection()
|
||||||
|
|
||||||
def vm_added(self, vmuuid, name):
|
def vm_added(self, connection, vmuuid, name):
|
||||||
vmlist = self.window.get_widget("vm-list")
|
vmlist = self.window.get_widget("vm-list")
|
||||||
model = vmlist.get_model()
|
model = vmlist.get_model()
|
||||||
|
print "Added\n"
|
||||||
dup = 0
|
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)
|
||||||
@ -105,7 +105,7 @@ class vmmManager:
|
|||||||
model.append([vmuuid, name])
|
model.append([vmuuid, name])
|
||||||
|
|
||||||
|
|
||||||
def vm_removed(self, vmuuid):
|
def vm_removed(self, connection, vmuuid):
|
||||||
vmlist = self.window.get_widget("vm-list")
|
vmlist = self.window.get_widget("vm-list")
|
||||||
model = vmlist.get_model()
|
model = vmlist.get_model()
|
||||||
|
|
||||||
@ -116,7 +116,7 @@ class vmmManager:
|
|||||||
model.remove(model.iter_nth_child(None, row))
|
model.remove(model.iter_nth_child(None, row))
|
||||||
break
|
break
|
||||||
|
|
||||||
def vm_updated(self, vmuuid):
|
def vm_updated(self, connection, vmuuid):
|
||||||
vmlist = self.window.get_widget("vm-list")
|
vmlist = self.window.get_widget("vm-list")
|
||||||
model = vmlist.get_model()
|
model = vmlist.get_model()
|
||||||
|
|
||||||
|
@ -20,14 +20,14 @@ class vmmStats:
|
|||||||
}
|
}
|
||||||
|
|
||||||
self.hostinfo = self.connection.get_host_info()
|
self.hostinfo = self.connection.get_host_info()
|
||||||
self.connection.connect_to_signal("vm_added", self._vm_added)
|
self.connection.connect("vm-added", self._vm_added)
|
||||||
self.connection.connect_to_signal("vm_removed", self._vm_removed)
|
self.connection.connect("vm-removed", self._vm_removed)
|
||||||
|
|
||||||
|
|
||||||
def _vm_added(self, vmuuid, name):
|
def _vm_added(self, connection, vmuuid, name):
|
||||||
self.record[vmuuid] = []
|
self.record[vmuuid] = []
|
||||||
|
|
||||||
def _vm_removed(self, vmuuid):
|
def _vm_removed(self, connection, vmuuid):
|
||||||
del self.record[vmuuid]
|
del self.record[vmuuid]
|
||||||
|
|
||||||
def update(self, vmuuid, vm):
|
def update(self, vmuuid, vm):
|
||||||
|
Loading…
Reference in New Issue
Block a user