VirtualDisk: Always return VM names from is_conflict_disk

This commit is contained in:
Cole Robinson 2013-07-07 16:34:46 -04:00
parent d5dc06148d
commit 9d560f7d9a
4 changed files with 24 additions and 32 deletions

View File

@ -1362,10 +1362,12 @@ class vmmAddHardware(vmmGObjectUI):
return False
# Disk collision
if disk.is_conflict_disk(conn):
res = self.err.yes_no(_('Disk "%s" is already in use by another '
'guest!' % disk.path),
_("Do you really want to use the disk?"))
names = disk.is_conflict_disk(conn)
if names:
res = self.err.yes_no(
_('Disk "%s" is already in use by other guests %s') %
(disk.path, names),
_("Do you really want to use the disk?"))
if not res:
return False

View File

@ -1717,12 +1717,15 @@ class vmmCreate(vmmGObjectUI):
return False
# Disk collision
if not oldguest and disk.is_conflict_disk(self.guest.conn):
res = self.err.yes_no(_('Disk "%s" is already in use by another '
'guest!' % disk.path),
_("Do you really want to use the disk?"))
if not res:
return False
if not oldguest:
names = disk.is_conflict_disk(self.guest.conn)
if names:
res = self.err.yes_no(
_('Disk "%s" is already in use by other guests %s') %
(disk.path, names),
_("Do you really want to use the disk?"))
if not res:
return False
if not oldguest:
uihelpers.check_path_search_for_qemu(self.topwin,

View File

@ -1554,20 +1554,13 @@ class VirtualDisk(VirtualDevice):
((need / (1024 * 1024)), (avail / (1024 * 1024))))
return (ret, msg)
def is_conflict_disk(self, conn, return_names=False):
def is_conflict_disk(self, conn):
"""
check if specified storage is in use by any other VMs on passed
connection.
@param conn: connection to check for collisions on
@type conn: libvirt.virConnect
@param return_names: Whether or not to return a list of VM names using
the same storage (default = False)
@type return_names: C{bool}
@return: True if a collision, False otherwise (list of names if
return_names passed)
@rtype: C{bool}
@return: list of colliding VM names
@rtype: C{list}
"""
if self.vol_object:
path = self.vol_object.path()
@ -1581,15 +1574,8 @@ class VirtualDisk(VirtualDevice):
conn = self.conn
check_conflict = self.shareable
names = self.path_in_use_by(conn, path,
check_conflict=check_conflict)
ret = False
if names:
ret = True
if return_names:
ret = names
ret = self.path_in_use_by(conn, path,
check_conflict=check_conflict)
return ret

View File

@ -534,11 +534,12 @@ def disk_prompt(conn, origpath, origsize, origsparse,
"""
Check if disk is inuse by another guest
"""
msg = (_("Disk %s is already in use by another guest" % dev.path))
if not dev.is_conflict_disk(conn):
names = dev.is_conflict_disk(conn)
if not names:
return False
msg = (_("Disk %s is already in use by other guests %s." %
(dev.path, names)))
return not prompt_for_yes_or_no(msg, askmsg)
def prompt_size_conflict(dev):