mirror of
https://github.com/virt-manager/virt-manager.git
synced 2025-02-25 18:55:27 -06:00
create: Make sure 'customize' respects already allocated disk paths
Going create->customize->addhw->storage->default storage would reuse the storage path allocated in the create wizard. Coordinate with virtinst's dup functions to avoid this problem.
This commit is contained in:
parent
12528d5028
commit
d692ea652d
@ -571,8 +571,10 @@ class vmmAddHardware(vmmGObjectUI):
|
|||||||
sparse = not self.widget("config-storage-nosparse").get_active()
|
sparse = not self.widget("config-storage-nosparse").get_active()
|
||||||
|
|
||||||
if self.is_default_storage():
|
if self.is_default_storage():
|
||||||
|
pathlist = map(lambda d: d.path, self.vm.get_disk_devices())
|
||||||
path = util.get_default_path(self.conn,
|
path = util.get_default_path(self.conn,
|
||||||
self.vm.get_name())
|
self.vm.get_name(),
|
||||||
|
collidelist=pathlist)
|
||||||
logging.debug("Default storage path is: %s" % path)
|
logging.debug("Default storage path is: %s" % path)
|
||||||
else:
|
else:
|
||||||
path = self.widget("config-storage-entry").get_text()
|
path = self.widget("config-storage-entry").get_text()
|
||||||
|
@ -96,31 +96,42 @@ def get_default_dir(conn):
|
|||||||
else:
|
else:
|
||||||
return running_config.get_default_image_dir(conn)
|
return running_config.get_default_image_dir(conn)
|
||||||
|
|
||||||
def get_default_path(conn, name):
|
def get_default_path(conn, name, collidelist=None):
|
||||||
|
collidelist = collidelist or []
|
||||||
pool = get_default_pool(conn)
|
pool = get_default_pool(conn)
|
||||||
|
|
||||||
default_dir = get_default_dir(conn)
|
default_dir = get_default_dir(conn)
|
||||||
|
|
||||||
|
def path_exists(p):
|
||||||
|
return os.path.exists(p) or p in collidelist
|
||||||
|
|
||||||
if not pool:
|
if not pool:
|
||||||
# Use old generating method
|
# Use old generating method
|
||||||
origf = os.path.join(default_dir, name + ".img")
|
origf = os.path.join(default_dir, name + ".img")
|
||||||
f = origf
|
f = origf
|
||||||
|
|
||||||
n = 1
|
n = 1
|
||||||
while os.path.exists(f) and n < 100:
|
while path_exists(f) and n < 100:
|
||||||
f = os.path.join(default_dir, name +
|
f = os.path.join(default_dir, name +
|
||||||
"-" + str(n) + ".img")
|
"-" + str(n) + ".img")
|
||||||
n += 1
|
n += 1
|
||||||
|
|
||||||
if os.path.exists(f):
|
if path_exists(f):
|
||||||
f = origf
|
f = origf
|
||||||
|
|
||||||
path = f
|
path = f
|
||||||
else:
|
else:
|
||||||
target, ignore, suffix = get_ideal_path_info(conn, name)
|
target, ignore, suffix = get_ideal_path_info(conn, name)
|
||||||
|
|
||||||
|
# Sanitize collidelist to work with the collision checker
|
||||||
|
for c in collidelist[:]:
|
||||||
|
collidelist.remove(c)
|
||||||
|
if os.path.dirname(c) == pool.get_target_path():
|
||||||
|
collidelist.append(os.path.basename(c))
|
||||||
|
|
||||||
path = virtinst.Storage.StorageVolume.find_free_name(name,
|
path = virtinst.Storage.StorageVolume.find_free_name(name,
|
||||||
pool_object=pool.pool, suffix=suffix)
|
pool_object=pool.pool, suffix=suffix,
|
||||||
|
collidelist=collidelist)
|
||||||
|
|
||||||
path = os.path.join(target, path)
|
path = os.path.join(target, path)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user