Skip to content
This repository was archived by the owner on Jan 22, 2026. It is now read-only.

Commit edd4a48

Browse files
committed
Added checks for duplicate disks (Shigeki Sakamoto.)
1 parent d944623 commit edd4a48

1 file changed

Lines changed: 47 additions & 0 deletions

File tree

virtinst/CloneManager.py

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import commands
3030
import libvirt
3131
import Guest
32+
import cli
3233
from virtinst import _virtinst as _
3334

3435
#
@@ -106,6 +107,13 @@ def get_clone_uuid(self):
106107
def set_clone_devices(self, devices):
107108
if len(devices) == 0:
108109
raise ValueError, _("New file to use for disk image is required")
110+
cdev = []
111+
cdev_size = []
112+
cdev_type = []
113+
cdev.append(devices)
114+
cdev_size,\
115+
cdev_type = self._get_clone_devices_info(cdev)
116+
devices = self._check_file(self._hyper_conn, devices, cdev_size)
109117
self._clone_devices.append(devices)
110118
def get_clone_devices(self):
111119
return self._clone_devices
@@ -321,6 +329,45 @@ def _check_uuid(self, uuid):
321329
pass
322330
return check
323331

332+
#
333+
# check used file func
334+
# ret : Use File Path
335+
#
336+
def _check_file(self, conn, disk, size):
337+
retryFlg = False
338+
while 1:
339+
if disk == None:
340+
msg = _("What would you like to use as the disk (path)?")
341+
disk = cli.prompt_for_input(msg, disk)
342+
343+
try:
344+
d = Guest.VirtualDisk(disk, size)
345+
if d.is_conflict_disk(conn) is True:
346+
while 1:
347+
retryFlg = False
348+
warnmsg = _("Disk %s is already in use by another guest!\n") % disk
349+
res = cli.prompt_for_input(warnmsg + _("Do you really want to use the disk (yes or no)? "))
350+
try:
351+
if cli.yes_or_no(res) is True:
352+
break
353+
else:
354+
retryFlg = True
355+
break
356+
except ValueError, e:
357+
print _("ERROR: "), e
358+
continue
359+
if retryFlg is True:
360+
disk = None
361+
continue
362+
except ValueError, e:
363+
print _("ERROR: "), e
364+
disk = None
365+
continue
366+
367+
break
368+
369+
return disk
370+
324371
#
325372
# check used mac func
326373
# 0 : OK

0 commit comments

Comments
 (0)