pollhelpers: Clarify some variable names and docs

This commit is contained in:
Cole Robinson 2013-09-29 09:28:42 -04:00
parent 07ea05365d
commit ce9f8ee24e

View File

@ -22,7 +22,7 @@ import logging
from virtinst import util from virtinst import util
def _new_poll_helper(origlist, typename, listfunc, keyfunc, buildfunc): def _new_poll_helper(origmap, typename, listfunc, keyfunc, buildfunc):
""" """
Helper for new style listAll* APIs Helper for new style listAll* APIs
""" """
@ -38,24 +38,24 @@ def _new_poll_helper(origlist, typename, listfunc, keyfunc, buildfunc):
for obj in objs: for obj in objs:
key = getattr(obj, keyfunc)() key = getattr(obj, keyfunc)()
if key not in origlist: if key not in origmap:
# Object is brand new this period # Object is brand new this period
current[key] = buildfunc(obj, key) current[key] = buildfunc(obj, key)
new[key] = current[key] new[key] = current[key]
else: else:
# Previously known object # Previously known object
current[key] = origlist[key] current[key] = origmap[key]
del origlist[key] del origmap[key]
return (origlist, new, current) return (origmap, new, current)
def _old_poll_helper(origlist, typename, def _old_poll_helper(origmap, typename,
active_list, inactive_list, active_list, inactive_list,
lookup_func, build_func): lookup_func, build_func):
""" """
Helper routine for old style split API libvirt polling. Helper routine for old style split API libvirt polling.
@origlist: Pre-existing mapping of objects, with key->obj mapping @origmap: Pre-existing mapping of objects, with key->obj mapping.
objects must have an is_active and set_active API objects must have an is_active and set_active API
@typename: string describing type of objects we are polling for use @typename: string describing type of objects we are polling for use
in debug messages. in debug messages.
@ -63,7 +63,7 @@ def _old_poll_helper(origlist, typename,
@inactive_list: Function that returns the list of inactive objects @inactive_list: Function that returns the list of inactive objects
@lookup_func: Function to get an object handle for the passed name @lookup_func: Function to get an object handle for the passed name
@build_func: Function that builds a new object class. It is passed @build_func: Function that builds a new object class. It is passed
args of (raw libvirt object, key (usually UUID), bool is_active) args of (raw libvirt object, key (usually UUID))
""" """
current = {} current = {}
new = {} new = {}
@ -80,7 +80,7 @@ def _old_poll_helper(origlist, typename,
logging.debug("Unable to list inactive %ss: %s", typename, e) logging.debug("Unable to list inactive %ss: %s", typename, e)
def check_obj(key): def check_obj(key):
if key not in origlist: if key not in origmap:
try: try:
obj = lookup_func(key) obj = lookup_func(key)
except Exception, e: except Exception, e:
@ -93,8 +93,8 @@ def _old_poll_helper(origlist, typename,
new[key] = current[key] new[key] = current[key]
else: else:
# Previously known object # Previously known object
current[key] = origlist[key] current[key] = origmap[key]
del origlist[key] del origmap[key]
for name in newActiveNames + newInactiveNames: for name in newActiveNames + newInactiveNames:
try: try:
@ -102,15 +102,15 @@ def _old_poll_helper(origlist, typename,
except: except:
logging.exception("Couldn't fetch %s '%s'", typename, name) logging.exception("Couldn't fetch %s '%s'", typename, name)
return (origlist, new, current) return (origmap, new, current)
def fetch_nets(backend, orig, build_func): def fetch_nets(backend, origmap, build_func):
name = "network" name = "network"
if backend.check_conn_support( if backend.check_conn_support(
backend.SUPPORT_CONN_LISTALLNETWORKS): backend.SUPPORT_CONN_LISTALLNETWORKS):
return _new_poll_helper(orig, name, return _new_poll_helper(origmap, name,
backend.listAllNetworks, backend.listAllNetworks,
"UUIDString", build_func) "UUIDString", build_func)
else: else:
@ -118,17 +118,17 @@ def fetch_nets(backend, orig, build_func):
inactive_list = backend.listDefinedNetworks inactive_list = backend.listDefinedNetworks
lookup_func = backend.networkLookupByName lookup_func = backend.networkLookupByName
return _old_poll_helper(orig, name, return _old_poll_helper(origmap, name,
active_list, inactive_list, active_list, inactive_list,
lookup_func, build_func) lookup_func, build_func)
def fetch_pools(backend, orig, build_func): def fetch_pools(backend, origmap, build_func):
name = "pool" name = "pool"
if backend.check_conn_support( if backend.check_conn_support(
backend.SUPPORT_CONN_LISTALLSTORAGEPOOLS): backend.SUPPORT_CONN_LISTALLSTORAGEPOOLS):
return _new_poll_helper(orig, name, return _new_poll_helper(origmap, name,
backend.listAllStoragePools, backend.listAllStoragePools,
"UUIDString", build_func) "UUIDString", build_func)
else: else:
@ -136,17 +136,17 @@ def fetch_pools(backend, orig, build_func):
inactive_list = backend.listDefinedStoragePools inactive_list = backend.listDefinedStoragePools
lookup_func = backend.storagePoolLookupByName lookup_func = backend.storagePoolLookupByName
return _old_poll_helper(orig, name, return _old_poll_helper(origmap, name,
active_list, inactive_list, active_list, inactive_list,
lookup_func, build_func) lookup_func, build_func)
def fetch_interfaces(backend, orig, build_func): def fetch_interfaces(backend, origmap, build_func):
name = "interface" name = "interface"
if backend.check_conn_support( if backend.check_conn_support(
backend.SUPPORT_CONN_LISTALLINTERFACES): backend.SUPPORT_CONN_LISTALLINTERFACES):
return _new_poll_helper(orig, name, return _new_poll_helper(origmap, name,
backend.listAllInterfaces, backend.listAllInterfaces,
"name", build_func) "name", build_func)
else: else:
@ -154,23 +154,23 @@ def fetch_interfaces(backend, orig, build_func):
inactive_list = backend.listDefinedInterfaces inactive_list = backend.listDefinedInterfaces
lookup_func = backend.interfaceLookupByName lookup_func = backend.interfaceLookupByName
return _old_poll_helper(orig, name, return _old_poll_helper(origmap, name,
active_list, inactive_list, active_list, inactive_list,
lookup_func, build_func) lookup_func, build_func)
def fetch_nodedevs(backend, orig, build_func): def fetch_nodedevs(backend, origmap, build_func):
name = "nodedev" name = "nodedev"
active_list = lambda: backend.listDevices(None, 0) active_list = lambda: backend.listDevices(None, 0)
inactive_list = lambda: [] inactive_list = lambda: []
lookup_func = backend.nodeDeviceLookupByName lookup_func = backend.nodeDeviceLookupByName
return _old_poll_helper(orig, name, return _old_poll_helper(origmap, name,
active_list, inactive_list, active_list, inactive_list,
lookup_func, build_func) lookup_func, build_func)
def _old_fetch_vms(backend, origlist, build_func): def _old_fetch_vms(backend, origmap, build_func):
# We can't easily use _old_poll_helper here because the domain API # We can't easily use _old_poll_helper here because the domain API
# doesn't always return names like other objects, it returns # doesn't always return names like other objects, it returns
# IDs for active VMs # IDs for active VMs
@ -183,8 +183,8 @@ def _old_fetch_vms(backend, origlist, build_func):
new = {} new = {}
# Build list of previous vms with proper id/name mappings # Build list of previous vms with proper id/name mappings
for uuid in origlist: for uuid in origmap:
vm = origlist[uuid] vm = origmap[uuid]
if vm.is_active(): if vm.is_active():
oldActiveIDs[vm.get_id()] = vm oldActiveIDs[vm.get_id()] = vm
else: else:
@ -204,12 +204,12 @@ def _old_fetch_vms(backend, origlist, build_func):
uuid = vm.get_uuid() uuid = vm.get_uuid()
current[uuid] = vm current[uuid] = vm
del(origlist[uuid]) del(origmap[uuid])
def check_new(rawvm, uuid): def check_new(rawvm, uuid):
if uuid in origlist: if uuid in origmap:
vm = origlist[uuid] vm = origmap[uuid]
del(origlist[uuid]) del(origmap[uuid])
else: else:
vm = build_func(rawvm, uuid) vm = build_func(rawvm, uuid)
new[uuid] = vm new[uuid] = vm
@ -247,15 +247,15 @@ def _old_fetch_vms(backend, origlist, build_func):
except: except:
logging.exception("Couldn't fetch domain '%s'", name) logging.exception("Couldn't fetch domain '%s'", name)
return (origlist, new, current) return (origmap, new, current)
def fetch_vms(backend, origlist, build_func): def fetch_vms(backend, origmap, build_func):
name = "domain" name = "domain"
if backend.check_conn_support( if backend.check_conn_support(
backend.SUPPORT_CONN_LISTALLDOMAINS): backend.SUPPORT_CONN_LISTALLDOMAINS):
return _new_poll_helper(origlist, name, return _new_poll_helper(origmap, name,
backend.listAllDomains, backend.listAllDomains,
"UUIDString", build_func) "UUIDString", build_func)
else: else:
return _old_fetch_vms(backend, origlist, build_func) return _old_fetch_vms(backend, origmap, build_func)