mirror of
https://github.com/virt-manager/virt-manager.git
synced 2025-02-25 18:55:27 -06:00
pollhelpers: Kill old style polling
All the major hypervisor drivers have supported listAllDomains since rhel6 vintage libvirt. Most other driver types have had the APIs since their introduction, or for just as long. I will be surprised if this affects anyone in any material way Signed-off-by: Cole Robinson <crobinso@redhat.com>
This commit is contained in:
@@ -144,9 +144,6 @@ def parse_commandline():
|
||||
# PackageKit integration
|
||||
parser.add_argument("--test-first-run",
|
||||
help=argparse.SUPPRESS, action="store_true")
|
||||
# Force use of old style libvirt polling APIs
|
||||
parser.add_argument("--test-old-poll",
|
||||
help=argparse.SUPPRESS, action="store_true")
|
||||
# Force disable use of libvirt object events
|
||||
parser.add_argument("--test-no-events",
|
||||
help=argparse.SUPPRESS, action="store_true")
|
||||
@@ -205,7 +202,6 @@ class CLITestOptionsClass:
|
||||
|
||||
self.first_run = _get("first-run")
|
||||
self.leak_debug = _get("leak-debug")
|
||||
self.old_poll = _get("old-poll")
|
||||
self.no_events = _get("no-events")
|
||||
self.xmleditor_enabled = _get("xmleditor-enabled")
|
||||
|
||||
@@ -241,8 +237,6 @@ def main():
|
||||
CLITestOptions.leak_debug = True
|
||||
if options.test_no_events:
|
||||
CLITestOptions.no_events = True
|
||||
if options.test_old_poll:
|
||||
CLITestOptions.old_poll = True
|
||||
|
||||
# With F27 gnome+wayland we need to set these before GTK import
|
||||
os.environ["GSETTINGS_SCHEMA_DIR"] = BuildConfig.gsettings_dir
|
||||
@@ -294,9 +288,6 @@ def main():
|
||||
|
||||
Gtk.Window.set_default_icon_name("virt-manager")
|
||||
|
||||
import virtinst.pollhelpers
|
||||
virtinst.pollhelpers.FORCE_OLD_POLL = CLITestOptions.old_poll
|
||||
|
||||
show_window = None
|
||||
domain = None
|
||||
if options.show_domain_creator:
|
||||
|
||||
@@ -8,11 +8,6 @@
|
||||
from .logger import log
|
||||
|
||||
|
||||
# Debugging helper to force old style polling
|
||||
# Can be enabled with virt-manager --test-old-poll
|
||||
FORCE_OLD_POLL = False
|
||||
|
||||
|
||||
def _new_poll_helper(origmap, typename, listfunc, buildfunc):
|
||||
"""
|
||||
Helper for new style listAll* APIs
|
||||
@@ -41,227 +36,37 @@ def _new_poll_helper(origmap, typename, listfunc, buildfunc):
|
||||
return (list(origmap.values()), list(new.values()), list(current.values()))
|
||||
|
||||
|
||||
def _old_poll_helper(origmap, typename,
|
||||
active_list, inactive_list,
|
||||
lookup_func, build_func):
|
||||
"""
|
||||
Helper routine for old style split API libvirt polling.
|
||||
@origmap: Pre-existing mapping of objects, with connkey->obj mapping.
|
||||
objects must have an is_active and set_active API
|
||||
@typename: string describing type of objects we are polling for use
|
||||
in debug messages.
|
||||
@active_list: Function that returns the list of active objects
|
||||
@inactive_list: Function that returns the list of inactive objects
|
||||
@lookup_func: Function to get an object handle for the passed name
|
||||
@build_func: Function that builds a new object class. It is passed
|
||||
args of (raw libvirt object, connkey)
|
||||
"""
|
||||
current = {}
|
||||
new = {}
|
||||
newActiveNames = []
|
||||
newInactiveNames = []
|
||||
|
||||
try:
|
||||
newActiveNames = active_list()
|
||||
except Exception as e:
|
||||
log.debug("Unable to list active %ss: %s", typename, e)
|
||||
try:
|
||||
newInactiveNames = inactive_list()
|
||||
except Exception as e:
|
||||
log.debug("Unable to list inactive %ss: %s", typename, e)
|
||||
|
||||
def check_obj(name):
|
||||
obj = None
|
||||
connkey = name
|
||||
|
||||
if connkey not in origmap:
|
||||
try:
|
||||
obj = lookup_func(name)
|
||||
except Exception as e:
|
||||
log.debug("Could not fetch %s '%s': %s",
|
||||
typename, connkey, e)
|
||||
return
|
||||
|
||||
# Object is brand new this period
|
||||
current[connkey] = build_func(obj, connkey)
|
||||
new[connkey] = current[connkey]
|
||||
else:
|
||||
# Previously known object
|
||||
current[connkey] = origmap[connkey]
|
||||
del(origmap[connkey])
|
||||
|
||||
for name in newActiveNames + newInactiveNames:
|
||||
try:
|
||||
check_obj(name)
|
||||
except Exception:
|
||||
log.exception("Couldn't fetch %s '%s'", typename, name)
|
||||
|
||||
return (list(origmap.values()), list(new.values()), list(current.values()))
|
||||
|
||||
|
||||
def fetch_nets(backend, origmap, build_func):
|
||||
name = "network"
|
||||
|
||||
if backend.support.conn_listallnetworks() and not FORCE_OLD_POLL:
|
||||
return _new_poll_helper(origmap, name,
|
||||
backend.listAllNetworks, build_func)
|
||||
else:
|
||||
active_list = backend.listNetworks
|
||||
inactive_list = backend.listDefinedNetworks
|
||||
lookup_func = backend.networkLookupByName
|
||||
|
||||
return _old_poll_helper(origmap, name,
|
||||
active_list, inactive_list,
|
||||
lookup_func, build_func)
|
||||
return _new_poll_helper(origmap, name,
|
||||
backend.listAllNetworks, build_func)
|
||||
|
||||
|
||||
def fetch_pools(backend, origmap, build_func):
|
||||
name = "pool"
|
||||
|
||||
if backend.support.conn_listallstoragepools() and not FORCE_OLD_POLL:
|
||||
return _new_poll_helper(origmap, name,
|
||||
backend.listAllStoragePools, build_func)
|
||||
else:
|
||||
active_list = backend.listStoragePools
|
||||
inactive_list = backend.listDefinedStoragePools
|
||||
lookup_func = backend.storagePoolLookupByName
|
||||
|
||||
return _old_poll_helper(origmap, name,
|
||||
active_list, inactive_list,
|
||||
lookup_func, build_func)
|
||||
return _new_poll_helper(origmap, name,
|
||||
backend.listAllStoragePools, build_func)
|
||||
|
||||
|
||||
def fetch_volumes(backend, pool, origmap, build_func):
|
||||
name = "volume"
|
||||
|
||||
if backend.support.pool_listallvolumes(pool) and not FORCE_OLD_POLL:
|
||||
return _new_poll_helper(origmap, name,
|
||||
pool.listAllVolumes, build_func)
|
||||
else:
|
||||
active_list = pool.listVolumes
|
||||
def inactive_list():
|
||||
return []
|
||||
lookup_func = pool.storageVolLookupByName
|
||||
return _old_poll_helper(origmap, name,
|
||||
active_list, inactive_list,
|
||||
lookup_func, build_func)
|
||||
return _new_poll_helper(origmap, name,
|
||||
pool.listAllVolumes, build_func)
|
||||
|
||||
|
||||
def fetch_interfaces(backend, origmap, build_func):
|
||||
name = "interface"
|
||||
|
||||
if backend.support.conn_listallinterfaces() and not FORCE_OLD_POLL:
|
||||
return _new_poll_helper(origmap, name,
|
||||
backend.listAllInterfaces, build_func)
|
||||
else:
|
||||
active_list = backend.listInterfaces
|
||||
inactive_list = backend.listDefinedInterfaces
|
||||
lookup_func = backend.interfaceLookupByName
|
||||
|
||||
return _old_poll_helper(origmap, name,
|
||||
active_list, inactive_list,
|
||||
lookup_func, build_func)
|
||||
return _new_poll_helper(origmap, name,
|
||||
backend.listAllInterfaces, build_func)
|
||||
|
||||
|
||||
def fetch_nodedevs(backend, origmap, build_func):
|
||||
name = "nodedev"
|
||||
if backend.support.conn_listalldevices() and not FORCE_OLD_POLL:
|
||||
return _new_poll_helper(origmap, name,
|
||||
backend.listAllDevices, build_func)
|
||||
else:
|
||||
def active_list():
|
||||
return backend.listDevices(None, 0)
|
||||
def inactive_list():
|
||||
return []
|
||||
lookup_func = backend.nodeDeviceLookupByName
|
||||
return _old_poll_helper(origmap, name,
|
||||
active_list, inactive_list,
|
||||
lookup_func, build_func)
|
||||
|
||||
|
||||
def _old_fetch_vms(backend, origmap, build_func):
|
||||
# We can't easily use _old_poll_helper here because the domain API
|
||||
# doesn't always return names like other objects, it returns
|
||||
# IDs for active VMs
|
||||
|
||||
newActiveIDs = []
|
||||
newInactiveNames = []
|
||||
oldActiveIDs = {}
|
||||
oldInactiveNames = {}
|
||||
current = {}
|
||||
new = {}
|
||||
|
||||
# Build list of previous vms with proper id/name mappings
|
||||
for vm in list(origmap.values()):
|
||||
if vm.is_active():
|
||||
oldActiveIDs[vm.get_id()] = vm
|
||||
else:
|
||||
oldInactiveNames[vm.get_name()] = vm
|
||||
|
||||
try:
|
||||
newActiveIDs = backend.listDomainsID()
|
||||
except Exception as e:
|
||||
log.debug("Unable to list active domains: %s", e)
|
||||
|
||||
try:
|
||||
newInactiveNames = backend.listDefinedDomains()
|
||||
except Exception as e:
|
||||
log.exception("Unable to list inactive domains: %s", e)
|
||||
|
||||
def add_vm(vm):
|
||||
connkey = vm.get_name()
|
||||
|
||||
current[connkey] = vm
|
||||
del(origmap[connkey])
|
||||
|
||||
def check_new(rawvm, connkey):
|
||||
if connkey in origmap:
|
||||
vm = origmap[connkey]
|
||||
del(origmap[connkey])
|
||||
else:
|
||||
vm = build_func(rawvm, connkey)
|
||||
new[connkey] = vm
|
||||
|
||||
current[connkey] = vm
|
||||
|
||||
for _id in newActiveIDs:
|
||||
if _id in oldActiveIDs:
|
||||
# No change, copy across existing VM object
|
||||
vm = oldActiveIDs[_id]
|
||||
add_vm(vm)
|
||||
else:
|
||||
# Check if domain is brand new, or old one that changed state
|
||||
try:
|
||||
vm = backend.lookupByID(_id)
|
||||
connkey = vm.name()
|
||||
|
||||
check_new(vm, connkey)
|
||||
except Exception:
|
||||
log.exception("Couldn't fetch domain id '%s'", _id)
|
||||
|
||||
|
||||
for name in newInactiveNames:
|
||||
if name in oldInactiveNames:
|
||||
# No change, copy across existing VM object
|
||||
vm = oldInactiveNames[name]
|
||||
add_vm(vm)
|
||||
else:
|
||||
# Check if domain is brand new, or old one that changed state
|
||||
try:
|
||||
vm = backend.lookupByName(name)
|
||||
connkey = name
|
||||
|
||||
check_new(vm, connkey)
|
||||
except Exception:
|
||||
log.exception("Couldn't fetch domain '%s'", name)
|
||||
|
||||
return (list(origmap.values()), list(new.values()), list(current.values()))
|
||||
return _new_poll_helper(origmap, name,
|
||||
backend.listAllDevices, build_func)
|
||||
|
||||
|
||||
def fetch_vms(backend, origmap, build_func):
|
||||
name = "domain"
|
||||
if backend.support.conn_listalldomains():
|
||||
return _new_poll_helper(origmap, name,
|
||||
backend.listAllDomains, build_func)
|
||||
else:
|
||||
return _old_fetch_vms(backend, origmap, build_func)
|
||||
return _new_poll_helper(origmap, name,
|
||||
backend.listAllDomains, build_func)
|
||||
|
||||
@@ -228,9 +228,9 @@ class SupportCache:
|
||||
self._virtconn = virtconn
|
||||
|
||||
conn_domain = _make(
|
||||
function="virConnect.listDomainsID", run_args=())
|
||||
function="virConnect.listAllDomains", run_args=())
|
||||
conn_storage = _make(
|
||||
function="virConnect.listStoragePools", run_args=())
|
||||
function="virConnect.listAllStoragePools", run_args=())
|
||||
conn_nodedev = _make(
|
||||
function="virConnect.listDevices", run_args=(None, 0))
|
||||
conn_network = _make(
|
||||
@@ -239,16 +239,6 @@ class SupportCache:
|
||||
function="virConnect.listInterfaces", run_args=())
|
||||
|
||||
conn_stream = _make(function="virConnect.newStream", run_args=(0,))
|
||||
conn_listalldomains = _make(
|
||||
function="virConnect.listAllDomains", run_args=())
|
||||
conn_listallnetworks = _make(
|
||||
function="virConnect.listAllNetworks", run_args=())
|
||||
conn_listallstoragepools = _make(
|
||||
function="virConnect.listAllStoragePools", run_args=())
|
||||
conn_listallinterfaces = _make(
|
||||
function="virConnect.listAllInterfaces", run_args=())
|
||||
conn_listalldevices = _make(
|
||||
function="virConnect.listAllDevices", run_args=())
|
||||
conn_working_xen_events = _make(hv_version={"xen": "4.0.0", "all": 0})
|
||||
# This is an arbitrary check to say whether it's a good idea to
|
||||
# default to qcow2. It might be fine for xen or qemu older than the versions
|
||||
@@ -319,8 +309,6 @@ class SupportCache:
|
||||
|
||||
# Pool checks
|
||||
pool_isactive = _make(function="virStoragePool.isActive", run_args=())
|
||||
pool_listallvolumes = _make(
|
||||
function="virStoragePool.listAllVolumes", run_args=())
|
||||
pool_metadata_prealloc = _make(
|
||||
flag="VIR_STORAGE_VOL_CREATE_PREALLOC_METADATA",
|
||||
version="1.0.1")
|
||||
|
||||
Reference in New Issue
Block a user