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 return False
# Disk collision # Disk collision
if disk.is_conflict_disk(conn): names = disk.is_conflict_disk(conn)
res = self.err.yes_no(_('Disk "%s" is already in use by another ' if names:
'guest!' % disk.path), res = self.err.yes_no(
_("Do you really want to use the disk?")) _('Disk "%s" is already in use by other guests %s') %
(disk.path, names),
_("Do you really want to use the disk?"))
if not res: if not res:
return False return False

View File

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

View File

@ -1554,20 +1554,13 @@ class VirtualDisk(VirtualDevice):
((need / (1024 * 1024)), (avail / (1024 * 1024)))) ((need / (1024 * 1024)), (avail / (1024 * 1024))))
return (ret, msg) 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 check if specified storage is in use by any other VMs on passed
connection. connection.
@param conn: connection to check for collisions on @return: list of colliding VM names
@type conn: libvirt.virConnect @rtype: C{list}
@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}
""" """
if self.vol_object: if self.vol_object:
path = self.vol_object.path() path = self.vol_object.path()
@ -1581,15 +1574,8 @@ class VirtualDisk(VirtualDevice):
conn = self.conn conn = self.conn
check_conflict = self.shareable check_conflict = self.shareable
names = self.path_in_use_by(conn, path, ret = self.path_in_use_by(conn, path,
check_conflict=check_conflict) check_conflict=check_conflict)
ret = False
if names:
ret = True
if return_names:
ret = names
return ret return ret

View File

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