storage: Check for pool name collisions against the pool cache

Rather than using storagePoolLookupByName. This will save some API
calls, but the main benefit is that it can help shake out cache
issues.
This commit is contained in:
Cole Robinson 2017-07-18 19:09:58 -04:00
parent 55aa23b400
commit 5b51c98ae5
3 changed files with 10 additions and 17 deletions

View File

@ -44,22 +44,11 @@ def generate_uuid_from_string(msg):
numstr[20:32]])
def _findFreePoolName(conn, namebase):
i = 0
while True:
poolname = namebase + "-%d" % i
try:
conn.storagePoolLookupByName(poolname)
i += 1
except:
return poolname
def createPool(conn, ptype, poolname=None, fmt=None, target_path=None,
source_path=None, source_name=None, uuid=None, iqn=None):
if poolname is None:
poolname = _findFreePoolName(conn, str(ptype) + "-pool")
poolname = StoragePool.find_free_name(conn, "%s-pool" % ptype)
if uuid is None:
uuid = generate_uuid_from_string(poolname)

View File

@ -36,8 +36,7 @@ def _build_pool(conn, meter, path):
pool.refresh(0)
return pool
name = util.generate_name("boot-scratch",
conn.storagePoolLookupByName)
name = StoragePool.find_free_name(conn, "boot-scratch")
logging.debug("Building storage pool: path=%s name=%s", path, name)
poolbuild = StoragePool(conn)
poolbuild.type = poolbuild.TYPE_DIR

View File

@ -295,9 +295,14 @@ class StoragePool(_StorageObject):
Finds a name similar (or equal) to passed 'basename' that is not
in use by another pool. Extra params are passed to generate_name
"""
return util.generate_name(basename,
conn.storagePoolLookupByName,
**kwargs)
def cb(name):
for pool in conn.fetch_all_pools():
if pool.name == name:
return True
return False
kwargs["lib_collision"] = False
return util.generate_name(basename, cb, **kwargs)
def __init__(self, *args, **kwargs):