[virt-tools-list] [PATCH] virt-install: avoid disk name collisions
Guido Günther
agx at sigxcpu.org
Thu Oct 4 09:43:51 UTC 2012
When specifying multiple disks in pool without giving a name:
virt-install \
--disk=pool=test,bus=virtio,size=3.0,sparse=false
--disk=pool=test,bus=virtio,size=3.0,sparse=false
...
virt-install creates the names before hand which leads to name
collisions later on. Avoid this by filling in a collision list
with the image basenames.
This is overly cautions but better than running into a name collision
during the vm install.
---
virt-install | 4 +++-
virtinst/cli.py | 10 ++++++----
2 files changed, 9 insertions(+), 5 deletions(-)
diff --git a/virt-install b/virt-install
index cb42d56..12e65db 100755
--- a/virt-install
+++ b/virt-install
@@ -134,7 +134,9 @@ def get_disk(diskopts, size, sparse, guest, is_file_path):
if is_file_path:
path = diskopts
else:
- dev, size = cli.parse_disk(guest, diskopts)
+ collidelist = [os.path.basename(disk.path) for disk in guest.disks]
+ dev, size = cli.parse_disk(guest, diskopts,
+ collidelist=collidelist)
path = dev.path
sparse = dev.sparse
diff --git a/virtinst/cli.py b/virtinst/cli.py
index c5b9b17..feb01ec 100644
--- a/virtinst/cli.py
+++ b/virtinst/cli.py
@@ -1476,7 +1476,7 @@ def parse_security(guest, security):
# --disk parsing #
##################
-def _parse_disk_source(guest, path, pool, vol, size, fmt, sparse):
+def _parse_disk_source(guest, path, pool, vol, size, fmt, sparse, collidelist=None):
abspath = None
volinst = None
volobj = None
@@ -1500,7 +1500,8 @@ def _parse_disk_source(guest, path, pool, vol, size, fmt, sparse):
vname = virtinst.Storage.StorageVolume.find_free_name(conn=guest.conn,
pool_name=pool,
name=guest.name,
- suffix=".img")
+ suffix=".img",
+ collidelist=collidelist)
volinst = vc(pool_name=pool, name=vname, conn=guest.conn,
allocation=0, capacity=(size and
size * 1024 * 1024 * 1024))
@@ -1528,7 +1529,7 @@ def _parse_disk_source(guest, path, pool, vol, size, fmt, sparse):
return abspath, volinst, volobj
-def parse_disk(guest, optstr, dev=None):
+def parse_disk(guest, optstr, dev=None, collidelist=None):
"""
helper to properly parse --disk options
"""
@@ -1594,7 +1595,8 @@ def parse_disk(guest, optstr, dev=None):
device = opt_get("device")
abspath, volinst, volobj = _parse_disk_source(guest, path, pool, vol,
- size, fmt, sparse)
+ size, fmt, sparse,
+ collidelist)
if not dev:
# Build a stub device that should always validate cleanly
--
1.7.10.4
More information about the virt-tools-list
mailing list