generatename: Remove collidelist

Fold it in to the callback of the single remaining user
This commit is contained in:
Cole Robinson 2019-06-11 08:56:50 -04:00
parent 47a6f3a6d5
commit 4cdf2e4a78
2 changed files with 9 additions and 11 deletions

View File

@ -25,7 +25,7 @@ def libvirt_collision(collision_cb, val):
def generate_name(base, collision_cb, suffix="", lib_collision=True,
start_num=1, sep="-", force_num=False, collidelist=None):
start_num=1, sep="-", force_num=False):
"""
Generate a new name from the passed base string, verifying it doesn't
collide with the collision callback.
@ -48,18 +48,14 @@ def generate_name(base, collision_cb, suffix="", lib_collision=True,
:param sep: The separator to use between the basename and the
generated number (default is "-")
:param force_num: Force the generated name to always end with a number
:param collidelist: An extra list of names to check for collision
"""
collidelist = collidelist or []
base = str(base)
def collide(n):
if n in collidelist:
return True
if lib_collision:
return libvirt_collision(collision_cb, tryname)
return libvirt_collision(collision_cb, n)
else:
return collision_cb(tryname)
return collision_cb(n)
numrange = list(range(start_num, start_num + 100000))
if not force_num:

View File

@ -557,11 +557,13 @@ class StorageVolume(_StorageObject):
os.path.dirname(disk.path) == pooltarget):
collidelist.append(os.path.basename(disk.path))
kwargs["collidelist"] = collidelist
def cb(tryname):
if tryname in collidelist:
return True
return pool_object.storageVolLookupByName(tryname)
StoragePool.ensure_pool_is_running(pool_object, refresh=True)
return generatename.generate_name(basename,
pool_object.storageVolLookupByName,
**kwargs)
return generatename.generate_name(basename, cb, **kwargs)
TYPE_FILE = getattr(libvirt, "VIR_STORAGE_VOL_FILE", 0)
TYPE_BLOCK = getattr(libvirt, "VIR_STORAGE_VOL_BLOCK", 1)