mirror of
https://github.com/virt-manager/virt-manager.git
synced 2025-02-25 18:55:27 -06:00
generatename: Remove collidelist
Fold it in to the callback of the single remaining user
This commit is contained in:
parent
47a6f3a6d5
commit
4cdf2e4a78
@ -25,7 +25,7 @@ def libvirt_collision(collision_cb, val):
|
|||||||
|
|
||||||
|
|
||||||
def generate_name(base, collision_cb, suffix="", lib_collision=True,
|
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
|
Generate a new name from the passed base string, verifying it doesn't
|
||||||
collide with the collision callback.
|
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
|
:param sep: The separator to use between the basename and the
|
||||||
generated number (default is "-")
|
generated number (default is "-")
|
||||||
:param force_num: Force the generated name to always end with a number
|
: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)
|
base = str(base)
|
||||||
|
|
||||||
def collide(n):
|
def collide(n):
|
||||||
if n in collidelist:
|
|
||||||
return True
|
|
||||||
if lib_collision:
|
if lib_collision:
|
||||||
return libvirt_collision(collision_cb, tryname)
|
return libvirt_collision(collision_cb, n)
|
||||||
else:
|
else:
|
||||||
return collision_cb(tryname)
|
return collision_cb(n)
|
||||||
|
|
||||||
numrange = list(range(start_num, start_num + 100000))
|
numrange = list(range(start_num, start_num + 100000))
|
||||||
if not force_num:
|
if not force_num:
|
||||||
|
@ -557,11 +557,13 @@ class StorageVolume(_StorageObject):
|
|||||||
os.path.dirname(disk.path) == pooltarget):
|
os.path.dirname(disk.path) == pooltarget):
|
||||||
collidelist.append(os.path.basename(disk.path))
|
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)
|
StoragePool.ensure_pool_is_running(pool_object, refresh=True)
|
||||||
return generatename.generate_name(basename,
|
return generatename.generate_name(basename, cb, **kwargs)
|
||||||
pool_object.storageVolLookupByName,
|
|
||||||
**kwargs)
|
|
||||||
|
|
||||||
TYPE_FILE = getattr(libvirt, "VIR_STORAGE_VOL_FILE", 0)
|
TYPE_FILE = getattr(libvirt, "VIR_STORAGE_VOL_FILE", 0)
|
||||||
TYPE_BLOCK = getattr(libvirt, "VIR_STORAGE_VOL_BLOCK", 1)
|
TYPE_BLOCK = getattr(libvirt, "VIR_STORAGE_VOL_BLOCK", 1)
|
||||||
|
Loading…
Reference in New Issue
Block a user