mirror of
https://github.com/virt-manager/virt-manager.git
synced 2025-02-25 18:55:27 -06:00
inspection: Some cleanups
* Simplify the queue data, just push in VM data to refresh * Do less work in threads * Slight rework of updating inspection data in the VM Signed-off-by: Cole Robinson <crobinso@redhat.com>
This commit is contained in:
parent
53aba9204d
commit
1ad470c021
@ -53,8 +53,8 @@ class vmmInspection(vmmGObject):
|
|||||||
self._thread = None
|
self._thread = None
|
||||||
|
|
||||||
self._q = queue.Queue()
|
self._q = queue.Queue()
|
||||||
self._conns = {}
|
|
||||||
self._cached_data = {}
|
self._cached_data = {}
|
||||||
|
self._uris = []
|
||||||
|
|
||||||
val = self.config.get_libguestfs_inspect_vms()
|
val = self.config.get_libguestfs_inspect_vms()
|
||||||
log.debug("libguestfs gsetting enabled=%s", str(val))
|
log.debug("libguestfs gsetting enabled=%s", str(val))
|
||||||
@ -62,41 +62,39 @@ class vmmInspection(vmmGObject):
|
|||||||
return
|
return
|
||||||
|
|
||||||
connmanager = vmmConnectionManager.get_instance()
|
connmanager = vmmConnectionManager.get_instance()
|
||||||
connmanager.connect("conn-added", self._conn_added)
|
connmanager.connect("conn-added", self._conn_added_cb)
|
||||||
connmanager.connect("conn-removed", self._conn_removed)
|
connmanager.connect("conn-removed", self._conn_removed_cb)
|
||||||
for conn in connmanager.conns.values():
|
for conn in connmanager.conns.values():
|
||||||
self._conn_added(connmanager, conn)
|
self._conn_added_cb(connmanager, conn)
|
||||||
|
|
||||||
self._start()
|
self._start()
|
||||||
|
|
||||||
def _cleanup(self):
|
def _cleanup(self):
|
||||||
self._stop()
|
self._stop()
|
||||||
self._q = queue.Queue()
|
self._q = queue.Queue()
|
||||||
self._conns = {}
|
|
||||||
self._cached_data = {}
|
self._cached_data = {}
|
||||||
|
|
||||||
def _conn_added(self, _src, conn):
|
def _conn_added_cb(self, connmanager, conn):
|
||||||
obj = ("conn_added", conn)
|
uri = conn.get_uri()
|
||||||
self._q.put(obj)
|
if uri in self._uris:
|
||||||
|
return
|
||||||
|
|
||||||
def _conn_removed(self, _src, uri):
|
self._uris.append(uri)
|
||||||
obj = ("conn_removed", uri)
|
conn.connect("vm-added", self._vm_added_cb)
|
||||||
self._q.put(obj)
|
for vm in conn.list_vms():
|
||||||
|
self._vm_added_cb(conn, vm.get_connkey())
|
||||||
|
|
||||||
# Called by the main thread whenever a VM is added to vmlist.
|
def _conn_removed_cb(self, connmanager, uri):
|
||||||
def _vm_added(self, conn, connkey):
|
self._uris.remove(uri)
|
||||||
|
|
||||||
|
def _vm_added_cb(self, conn, connkey):
|
||||||
|
# Called by the main thread whenever a VM is added to vmlist.
|
||||||
if connkey.startswith("guestfs-"):
|
if connkey.startswith("guestfs-"):
|
||||||
log.debug("ignore libvirt/guestfs temporary VM %s",
|
log.debug("ignore libvirt/guestfs temporary VM %s",
|
||||||
connkey)
|
connkey)
|
||||||
return
|
return
|
||||||
|
|
||||||
obj = ("vm_added", conn.get_uri(), connkey)
|
self._q.put((conn.get_uri(), connkey))
|
||||||
self._q.put(obj)
|
|
||||||
|
|
||||||
def vm_refresh(self, vm):
|
|
||||||
log.debug("Refresh requested for vm=%s", vm.get_name())
|
|
||||||
obj = ("vm_refresh", vm.conn.get_uri(), vm.get_name(), vm.get_uuid())
|
|
||||||
self._q.put(obj)
|
|
||||||
|
|
||||||
def _start(self):
|
def _start(self):
|
||||||
self._thread = threading.Thread(
|
self._thread = threading.Thread(
|
||||||
@ -115,58 +113,28 @@ class vmmInspection(vmmGObject):
|
|||||||
# Process everything on the queue. If the queue is empty when
|
# Process everything on the queue. If the queue is empty when
|
||||||
# called, block.
|
# called, block.
|
||||||
while True:
|
while True:
|
||||||
obj = self._q.get()
|
data = self._q.get()
|
||||||
if obj is None:
|
if data is None:
|
||||||
log.debug("libguestfs queue obj=None, exiting thread")
|
log.debug("libguestfs queue vm=None, exiting thread")
|
||||||
return
|
return
|
||||||
self._process_queue_item(obj)
|
uri, connkey = data
|
||||||
|
self._process_vm(uri, connkey)
|
||||||
self._q.task_done()
|
self._q.task_done()
|
||||||
|
|
||||||
def _process_queue_item(self, obj):
|
def _process_vm(self, uri, connkey):
|
||||||
cmd = obj[0]
|
connmanager = vmmConnectionManager.get_instance()
|
||||||
if cmd == "conn_added":
|
conn = connmanager.conns.get(uri)
|
||||||
conn = obj[1]
|
if not conn:
|
||||||
uri = conn.get_uri()
|
return
|
||||||
if uri in self._conns:
|
|
||||||
return
|
|
||||||
|
|
||||||
self._conns[uri] = conn
|
vm = conn.get_vm(connkey)
|
||||||
conn.connect("vm-added", self._vm_added)
|
if not vm:
|
||||||
for vm in conn.list_vms():
|
return
|
||||||
self._vm_added(conn, vm.get_connkey())
|
|
||||||
|
|
||||||
elif cmd == "conn_removed":
|
|
||||||
uri = obj[1]
|
|
||||||
self._conns.pop(uri)
|
|
||||||
|
|
||||||
elif cmd == "vm_added" or cmd == "vm_refresh":
|
|
||||||
uri = obj[1]
|
|
||||||
if uri not in self._conns:
|
|
||||||
# This connection disappeared in the meanwhile.
|
|
||||||
return
|
|
||||||
|
|
||||||
conn = self._conns[uri]
|
|
||||||
vm = conn.get_vm(obj[2])
|
|
||||||
if not vm:
|
|
||||||
# The VM was removed in the meanwhile.
|
|
||||||
return
|
|
||||||
|
|
||||||
if cmd == "vm_refresh":
|
|
||||||
vmuuid = obj[3]
|
|
||||||
# When refreshing the inspection data of a VM,
|
|
||||||
# all we need is to remove it from the "seen" cache,
|
|
||||||
# as the data itself will be replaced once the new
|
|
||||||
# results are available.
|
|
||||||
self._cached_data.pop(vmuuid, None)
|
|
||||||
|
|
||||||
self._process_vm(conn, vm)
|
|
||||||
|
|
||||||
def _process_vm(self, conn, vm):
|
|
||||||
# Try processing a single VM, keeping into account whether it was
|
# Try processing a single VM, keeping into account whether it was
|
||||||
# visited already, and whether there are cached data for it.
|
# visited already, and whether there are cached data for it.
|
||||||
def _set_vm_inspection_data(_data):
|
def _set_vm_inspection_data(_data):
|
||||||
vm.inspection = _data
|
vm.set_inspection_data(_data)
|
||||||
vm.inspection_data_updated()
|
|
||||||
self._cached_data[vm.get_uuid()] = _data
|
self._cached_data[vm.get_uuid()] = _data
|
||||||
|
|
||||||
prettyvm = conn.get_uri() + ":" + vm.get_name()
|
prettyvm = conn.get_uri() + ":" + vm.get_name()
|
||||||
@ -315,3 +283,18 @@ class vmmInspection(vmmGObject):
|
|||||||
data.package_format = str(package_format)
|
data.package_format = str(package_format)
|
||||||
|
|
||||||
return data
|
return data
|
||||||
|
|
||||||
|
|
||||||
|
##############
|
||||||
|
# Public API #
|
||||||
|
##############
|
||||||
|
|
||||||
|
def vm_refresh(self, vm):
|
||||||
|
log.debug("Refresh requested for vm=%s", vm.get_name())
|
||||||
|
|
||||||
|
# When refreshing the inspection data of a VM,
|
||||||
|
# all we need is to remove it from the "seen" cache,
|
||||||
|
# as the data itself will be replaced once the new
|
||||||
|
# results are available.
|
||||||
|
self._cached_data.pop(vm.get_uuid(), None)
|
||||||
|
self._q.put((vm.conn.get_uri(), vm.get_connkey()))
|
||||||
|
@ -1529,7 +1529,8 @@ class vmmDomain(vmmLibvirtObject):
|
|||||||
status = libvirt.VIR_DOMAIN_NOSTATE
|
status = libvirt.VIR_DOMAIN_NOSTATE
|
||||||
return LibvirtEnumMap.VM_STATUS_ICONS[status]
|
return LibvirtEnumMap.VM_STATUS_ICONS[status]
|
||||||
|
|
||||||
def inspection_data_updated(self):
|
def set_inspection_data(self, data):
|
||||||
|
self.inspection = data
|
||||||
self.idle_emit("inspection-changed")
|
self.idle_emit("inspection-changed")
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user