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:
Cole Robinson 2011-07-22 19:50:30 -04:00
parent 12528d5028
commit d692ea652d
2 changed files with 18 additions and 5 deletions

View File

@ -571,8 +571,10 @@ class vmmAddHardware(vmmGObjectUI):
sparse = not self.widget("config-storage-nosparse").get_active()
if self.is_default_storage():
pathlist = map(lambda d: d.path, self.vm.get_disk_devices())
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)
else:
path = self.widget("config-storage-entry").get_text()

View File

@ -96,31 +96,42 @@ def get_default_dir(conn):
else:
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)
default_dir = get_default_dir(conn)
def path_exists(p):
return os.path.exists(p) or p in collidelist
if not pool:
# Use old generating method
origf = os.path.join(default_dir, name + ".img")
f = origf
n = 1
while os.path.exists(f) and n < 100:
while path_exists(f) and n < 100:
f = os.path.join(default_dir, name +
"-" + str(n) + ".img")
n += 1
if os.path.exists(f):
if path_exists(f):
f = origf
path = f
else:
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,
pool_object=pool.pool, suffix=suffix)
pool_object=pool.pool, suffix=suffix,
collidelist=collidelist)
path = os.path.join(target, path)