mirror of
https://github.com/virt-manager/virt-manager.git
synced 2025-02-25 18:55:27 -06:00
inspection: Cache data between connection reconnects
This commit is contained in:
parent
5efe079158
commit
2e297ab70c
@ -30,8 +30,6 @@ import virtinst.support as support
|
||||
from virtManager import util
|
||||
from virtManager.libvirtobject import vmmLibvirtObject
|
||||
|
||||
from inspectiondata import vmmInspectionData
|
||||
|
||||
def compare_device(origdev, newdev, idx):
|
||||
devprops = {
|
||||
"disk" : ["target", "bus"],
|
||||
@ -120,6 +118,18 @@ def start_job_progress_thread(vm, meter, progtext):
|
||||
t.daemon = True
|
||||
t.start()
|
||||
|
||||
class vmmInspectionData(object):
|
||||
def __init__(self):
|
||||
self.type = None
|
||||
self.distro = None
|
||||
self.major_version = None
|
||||
self.minor_version = None
|
||||
self.hostname = None
|
||||
self.product_name = None
|
||||
self.product_variant = None
|
||||
self.icon = None
|
||||
self.applications = None
|
||||
|
||||
class vmmDomain(vmmLibvirtObject):
|
||||
"""
|
||||
Class wrapping virDomain libvirt objects. Is also extended to be
|
||||
|
@ -27,6 +27,7 @@ import gobject
|
||||
from guestfs import GuestFS
|
||||
|
||||
from virtManager.baseclass import vmmGObject
|
||||
from virtManager.domain import vmmInspectionData
|
||||
|
||||
class vmmInspection(vmmGObject):
|
||||
# Can't find a way to make Thread release our reference
|
||||
@ -40,14 +41,16 @@ class vmmInspection(vmmGObject):
|
||||
self._wait = 15 * 1000 # 15 seconds
|
||||
|
||||
self._q = Queue()
|
||||
self._conns = dict()
|
||||
self._vmseen = dict()
|
||||
self._conns = {}
|
||||
self._vmseen = {}
|
||||
self._cached_data = {}
|
||||
|
||||
def _cleanup(self):
|
||||
self._thread = None
|
||||
self._q = Queue()
|
||||
self._conns = {}
|
||||
self._vmseen = {}
|
||||
self._cached_data = {}
|
||||
|
||||
# Called by the main thread whenever a connection is added or
|
||||
# removed. We tell the inspection thread, so it can track
|
||||
@ -81,7 +84,6 @@ class vmmInspection(vmmGObject):
|
||||
|
||||
def _run(self):
|
||||
while True:
|
||||
logging.debug("ready")
|
||||
self._process_queue()
|
||||
self._process_vms()
|
||||
|
||||
@ -117,20 +119,26 @@ class vmmInspection(vmmGObject):
|
||||
def _process_vms(self):
|
||||
for conn in self._conns.itervalues():
|
||||
for vmuuid in conn.list_vm_uuids():
|
||||
if not (vmuuid in self._vmseen):
|
||||
prettyvm = vmuuid
|
||||
try:
|
||||
vm = conn.get_vm(vmuuid)
|
||||
prettyvm = conn.get_uri() + ":" + vm.get_name()
|
||||
prettyvm = vmuuid
|
||||
try:
|
||||
vm = conn.get_vm(vmuuid)
|
||||
prettyvm = conn.get_uri() + ":" + vm.get_name()
|
||||
|
||||
logging.debug("%s: processing started", prettyvm)
|
||||
# Whether success or failure, we've "seen" this VM now.
|
||||
self._vmseen[vmuuid] = True
|
||||
self._process(conn, vm, vmuuid)
|
||||
except:
|
||||
logging.exception("%s: exception while processing",
|
||||
prettyvm)
|
||||
logging.debug("%s: processing done", prettyvm)
|
||||
if vmuuid in self._vmseen:
|
||||
data = self._cached_data.get(vmuuid)
|
||||
if not data:
|
||||
continue
|
||||
|
||||
logging.debug("Found cached data for %s", prettyvm)
|
||||
self._set_vm_inspection_data(vm, data)
|
||||
continue
|
||||
|
||||
# Whether success or failure, we've "seen" this VM now.
|
||||
self._vmseen[vmuuid] = True
|
||||
self._process(conn, vm, vmuuid)
|
||||
except:
|
||||
logging.exception("%s: exception while processing",
|
||||
prettyvm)
|
||||
|
||||
def _process(self, conn, vm, vmuuid):
|
||||
g = GuestFS()
|
||||
@ -145,7 +153,7 @@ class vmmInspection(vmmGObject):
|
||||
disks.append(disk)
|
||||
|
||||
if not disks:
|
||||
# Nothing to inspect!
|
||||
logging.debug("%s: nothing to inspect", prettyvm)
|
||||
return
|
||||
|
||||
# Add the disks. Note they *must* be added with readonly flag set.
|
||||
@ -208,12 +216,14 @@ class vmmInspection(vmmGObject):
|
||||
try:
|
||||
g.mount_ro(mp_dev[1], mp_dev[0])
|
||||
except:
|
||||
logging.exception("exception mounting %s on %s "
|
||||
"(ignored)", mp_dev[1], mp_dev[0])
|
||||
logging.exception("%s: exception mounting %s on %s "
|
||||
"(ignored)",
|
||||
prettyvm, mp_dev[1], mp_dev[0])
|
||||
|
||||
filesystems_mounted = True
|
||||
except:
|
||||
logging.exception("exception while mounting disks (ignored)")
|
||||
logging.exception("%s: exception while mounting disks (ignored)",
|
||||
prettyvm)
|
||||
|
||||
icon = None
|
||||
apps = None
|
||||
@ -231,25 +241,33 @@ class vmmInspection(vmmGObject):
|
||||
# Force the libguestfs handle to close right now.
|
||||
del g
|
||||
|
||||
vm.inspection.type = typ
|
||||
vm.inspection.distro = distro
|
||||
vm.inspection.major_version = major_version
|
||||
vm.inspection.minor_version = minor_version
|
||||
vm.inspection.hostname = hostname
|
||||
vm.inspection.product_name = product_name
|
||||
vm.inspection.product_variant = product_variant
|
||||
vm.inspection.icon = icon
|
||||
vm.inspection.applications = apps
|
||||
|
||||
vm.inspection_data_updated()
|
||||
|
||||
# Log what we found.
|
||||
logging.debug("detected operating system: %s %s %d.%d (%s)",
|
||||
typ, distro, major_version, minor_version, product_name)
|
||||
logging.debug("%s: detected operating system: %s %s %d.%d (%s)",
|
||||
prettyvm, typ, distro, major_version, minor_version,
|
||||
product_name)
|
||||
logging.debug("hostname: %s", hostname)
|
||||
if icon:
|
||||
logging.debug("icon: %d bytes", len(icon))
|
||||
if apps:
|
||||
logging.debug("# apps: %d", len(apps))
|
||||
|
||||
data = vmmInspectionData()
|
||||
data.type = str(type)
|
||||
data.distro = str(distro)
|
||||
data.major_version = int(major_version)
|
||||
data.minor_version = int(minor_version)
|
||||
data.hostname = str(hostname)
|
||||
data.product_name = str(product_name)
|
||||
data.product_variant = str(product_variant)
|
||||
data.icon = str(icon)
|
||||
data.applications = list(apps)
|
||||
|
||||
self._set_vm_inspection_data(vm, data)
|
||||
|
||||
def _set_vm_inspection_data(self, vm, data):
|
||||
vm.inspection = data
|
||||
vm.inspection_data_updated()
|
||||
self._cached_data[vm.get_uuid()] = data
|
||||
|
||||
|
||||
vmmGObject.type_register(vmmInspection)
|
||||
|
@ -1,76 +0,0 @@
|
||||
#
|
||||
# Copyright (C) 2011 Red Hat, Inc.
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation; either version 2 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||
# MA 02110-1301 USA.
|
||||
#
|
||||
|
||||
class vmmInspectionData(object):
|
||||
def __init__(self):
|
||||
self._type = None
|
||||
self._distro = None
|
||||
self._major_version = None
|
||||
self._minor_version = None
|
||||
self._hostname = None
|
||||
self._product_name = None
|
||||
self._product_variant = None
|
||||
self._icon = None
|
||||
self._applications = None
|
||||
|
||||
def _set_type(self, new):
|
||||
self._type = str(new)
|
||||
def _get_type(self):
|
||||
return self._type
|
||||
type = property(_get_type, _set_type)
|
||||
def _set_distro(self, new):
|
||||
self._distro = str(new)
|
||||
def _get_distro(self):
|
||||
return self._distro
|
||||
distro = property(_get_distro, _set_distro)
|
||||
def _set_major_version(self, new):
|
||||
self._major_version = int(new)
|
||||
def _get_major_version(self):
|
||||
return self._major_version
|
||||
major_version = property(_get_major_version, _set_major_version)
|
||||
def _set_minor_version(self, new):
|
||||
self._minor_version = int(new)
|
||||
def _get_minor_version(self):
|
||||
return self._minor_version
|
||||
minor_version = property(_get_minor_version, _set_minor_version)
|
||||
def _set_hostname(self, new):
|
||||
self._hostname = str(new)
|
||||
def _get_hostname(self):
|
||||
return self._hostname
|
||||
hostname = property(_get_hostname, _set_hostname)
|
||||
def _set_product_name(self, new):
|
||||
self._product_name = str(new)
|
||||
def _get_product_name(self):
|
||||
return self._product_name
|
||||
product_name = property(_get_product_name, _set_product_name)
|
||||
def _set_product_variant(self, new):
|
||||
self._product_variant = str(new)
|
||||
def _get_product_variant(self):
|
||||
return self._product_variant
|
||||
product_variant = property(_get_product_variant, _set_product_variant)
|
||||
def _set_icon(self, new):
|
||||
self._icon = str(new)
|
||||
def _get_icon(self):
|
||||
return self._icon
|
||||
icon = property(_get_icon, _set_icon)
|
||||
def _set_applications(self, new):
|
||||
self._applications = list(new)
|
||||
def _get_applications(self):
|
||||
return self._applications
|
||||
applications = property(_get_applications, _set_applications)
|
Loading…
Reference in New Issue
Block a user