# HG changeset patch
# User "Cole Robinson <crobinso@redhat.com>"
# Date 1203011013 18000
# Node ID d5c41f1ff597cb74b9f4da8521972ca35f9aed7d
# Parent 71ebde48210c8dd642afddac6cf5629cd93f7955
Add simpler prompt for yes or no
diff -r 71ebde48210c -r d5c41f1ff597 virtinst/cli.py
--- a/virtinst/cli.py Wed Feb 06 09:41:07 2008 -0500
+++ b/virtinst/cli.py Thu Feb 14 12:43:33 2008 -0500
@@ -91,6 +91,18 @@ def yes_or_no(s):
elif s in ("n", "no", "0", "false", "f"):
return False
raise ValueError, "A yes or no response is required"
+
+def prompt_for_yes_or_no(prompt):
+ """catches yes_or_no errors and ensures a valid bool return"""
+ while 1:
+ input = prompt_for_input(prompt, None)
+ try:
+ res = yes_or_no(input)
+ break
+ except ValueError, e:
+ print _("ERROR: "), e
+ continue
+ return res
#
# Ask for attributes
# HG changeset patch
# User "Cole Robinson <crobinso@redhat.com>"
# Date 1203011236 18000
# Node ID 07091304b75962460fd01c419a358e1a30fecb65
# Parent d5c41f1ff597cb74b9f4da8521972ca35f9aed7d
Use new cli yes or no function for install tools. Remove prompting from
CloneManager. Fix virt-clone bug where full qualified paths weren't being
written to the config. Fix lack of prompt issue when just running 'virt-clone'
diff -r d5c41f1ff597 -r 07091304b759 virt-clone
--- a/virt-clone Thu Feb 14 12:43:33 2008 -0500
+++ b/virt-clone Thu Feb 14 12:47:16 2008 -0500
@@ -71,11 +71,40 @@ def get_clone_uuid(new_uuid, design):
if new_uuid is not None:
design.set_clone_uuid(new_uuid)
-def get_clone_diskfile(new_diskfile, design):
- if new_diskfile is None:
- raise ValueError, _("A new disk image file for the cloned guest is required")
- for i in new_diskfile:
- design.set_clone_devices(i)
+def get_clone_diskfile(new_diskfiles, design, conn):
+ if new_diskfiles is None:
+ new_diskfiles = [None]
+
+ for i in range(0, len(new_diskfiles)):
+ disk = new_diskfiles[i]
+ while 1:
+ disk = cli.prompt_for_input(_("What would you like to use as the cloned disk (file path)?"), disk)
+
+ # Build disk object for validation
+ try:
+ d = virtinst.VirtualDisk(path=disk, size=0)
+ except ValueError, e:
+ print _("ERROR: "), e
+ disk = None
+ continue
+
+ # Check disk conflicts
+ if d.is_conflict_disk(conn) is True:
+ warnmsg = _("Disk %s is already in use by another guest!\n") % d.path
+ if not cli.prompt_for_yes_or_no(warnmsg + _("Do you really want to use the disk (yes or no)? ")):
+ disk = None
+ continue
+ # Overwrite disk?
+ elif os.path.exists(d.path) and os.path.isfile(d.path):
+ warnmsg = _("You are going to overwrite file '%s'!\n") % d.path
+ if not cli.prompt_for_yes_or_no(warnmsg + _("Do you really want to use the file (yes or no)? ")):
+ disk = None
+ continue
+ new_diskfiles[i] = d.path
+ break
+
+ for i in new_diskfiles:
+ design.set_clone_devices(i)
def get_clone_sparse(sparse, design):
design.set_clone_sparse(sparse)
@@ -161,8 +190,8 @@ def main():
conn = cli.getConnection(options.connect)
design = clmgr.CloneDesign(connection=conn)
- try:
- get_clone_diskfile(options.new_diskfile, design)
+ try:
+ get_clone_diskfile(options.new_diskfile, design, conn)
get_clone_macaddr(options.new_mac, design)
get_original_guest(options.original_guest, design)
get_clone_name(options.new_name, design)
diff -r d5c41f1ff597 -r 07091304b759 virt-install
--- a/virt-install Thu Feb 14 12:43:33 2008 -0500
+++ b/virt-install Thu Feb 14 12:47:16 2008 -0500
@@ -43,11 +43,7 @@ gettext.install(virtinst.gettext_app, vi
### General input gathering functions
def get_full_virt():
while 1:
- res = cli.prompt_for_input(_("Would you like a fully virtualized guest (yes or no)? This will allow you to run unmodified operating systems."))
- try:
- return cli.yes_or_no(res)
- except ValueError, e:
- print _("ERROR: "), e
+ return cli.prompt_for_yes_or_no(_("Would you like a fully virtualized guest (yes or no)? This will allow you to run unmodified operating systems."))
def get_disk(disk, size, sparse, guest, hvm, conn):
@@ -56,23 +52,8 @@ def get_disk(disk, size, sparse, guest,
if not size is None:
msg = _("Please enter the path to the file you would like to use for storage. It will have size %sGB.") %(size,)
disk = cli.prompt_for_input(msg, disk)
- if os.path.exists(disk) and os.path.isfile(disk):
- while 1:
- retryFlg = False
- warnmsg = _("You are going to overwrite file '%s'!\n") % disk
- res = cli.prompt_for_input(warnmsg + _("Do you really want to use the file (yes or no)? "))
- try:
- if cli.yes_or_no(res) is True:
- break
- else:
- retryFlg = True
- break
- except ValueError, e:
- print _("ERROR: "), e
- continue
- if retryFlg is True:
- disk = None
- continue
+
+ # Getting disk size
while 1:
if os.path.exists(disk):
break
@@ -84,33 +65,33 @@ def get_disk(disk, size, sparse, guest,
print _("ERROR: "), e
size = None
+ # Build disk object
try:
d = virtinst.VirtualDisk(disk, size, sparse = sparse)
- if d.is_conflict_disk(conn) is True:
- while 1:
- retryFlg = False
- warnmsg = _("Disk %s is already in use by another guest!\n") % disk
- res = cli.prompt_for_input(warnmsg + _("Do you really want to use the disk (yes or no)? "))
- try:
- if cli.yes_or_no(res) is True:
- break
- else:
- retryFlg = True
- break
- except ValueError, e:
- print _("ERROR: "), e
- continue
- if retryFlg is True:
- disk = size = None
- continue
- if d.type == virtinst.VirtualDisk.TYPE_FILE and not(hvm) and virtinst.util.is_blktap_capable():
+ # Default file backed PV guests to tap driver
+ if d.type == virtinst.VirtualDisk.TYPE_FILE \
+ and not(hvm) and virtinst.util.is_blktap_capable():
d.driver_name = virtinst.VirtualDisk.DRIVER_TAP
except ValueError, e:
print _("ERROR: "), e
disk = size = None
continue
- guest.disks.append(d)
+ # Check disk conflicts
+ if d.is_conflict_disk(conn) is True:
+ warnmsg = _("Disk %s is already in use by another guest!\n") \
+ % d.path
+ if not cli.prompt_for_yes_or_no(warnmsg + _("Do you really want to use the disk (yes or no)? ")):
+ disk = size = None
+ continue
+ # Overwrite disk?
+ elif os.path.exists(d.path) and os.path.isfile(d.path):
+ warnmsg = _("You are going to overwrite file '%s'!\n") % d.path
+ if not cli.prompt_for_yes_or_no(warnmsg + _("Do you really want to use the file (yes or no)? ")):
+ disk = None
+ continue
+
+ guest.disks.append(disk)
break
def get_disks(disk, size, sparse, nodisks, guest, hvm, conn):
diff -r d5c41f1ff597 -r 07091304b759 virtinst/CloneManager.py
--- a/virtinst/CloneManager.py Thu Feb 14 12:43:33 2008 -0500
+++ b/virtinst/CloneManager.py Thu Feb 14 12:47:16 2008 -0500
@@ -29,7 +29,6 @@ import commands
import commands
import libvirt
import Guest
-import cli
from virtinst import _virtinst as _
#
@@ -334,39 +333,8 @@ class CloneDesign(object):
# ret : Use File Path
#
def _check_file(self, conn, disk, size):
- retryFlg = False
- while 1:
- if disk == None:
- msg = _("What would you like to use as the disk (path)?")
- disk = cli.prompt_for_input(msg, disk)
-
- try:
- d = Guest.VirtualDisk(disk, size)
- if d.is_conflict_disk(conn) is True:
- while 1:
- retryFlg = False
- warnmsg = _("Disk %s is already in use by another guest!\n") % disk
- res = cli.prompt_for_input(warnmsg + _("Do you really want to use the disk (yes or no)? "))
- try:
- if cli.yes_or_no(res) is True:
- break
- else:
- retryFlg = True
- break
- except ValueError, e:
- print _("ERROR: "), e
- continue
- if retryFlg is True:
- disk = None
- continue
- except ValueError, e:
- print _("ERROR: "), e
- disk = None
- continue
-
- break
-
- return disk
+ d = Guest.VirtualDisk(disk, size)
+ return d.path
#
# check used mac func
# HG changeset patch
# User Mark McLoughlin <markmc@redhat.com>
# Date 1203068244 0
# Node ID fd6a7fa855d11ca890f3c60f669c1830b9874f25
# Parent 07091304b75962460fd01c419a358e1a30fecb65
Fix virt-install disks typo
Fixes this traceback:
Traceback (most recent call last):
File "./virt-install", line 498, in <module>
main()
File "./virt-install", line 462, in main
dom = guest.start_install(conscb,progresscb)
File "/home/markmc/projects/virt/virtinst--devel/virtinst/Guest.py", line 813, in start_install
return self._do_install(consolecb, meter)
File "/home/markmc/projects/virt/virtinst--devel/virtinst/Guest.py", line 829, in _do_install
self._create_devices(meter)
File "/home/markmc/projects/virt/virtinst--devel/virtinst/Guest.py", line 725, in _create_devices
disk.setup(progresscb)
AttributeError: 'str' object has no attribute 'setup'
Looks to have been introduced by cset 351:07091304b759
Signed-off-by: Mark McLoughlin <markmc@redhat.com>
diff -r 07091304b759 -r fd6a7fa855d1 virt-install
--- a/virt-install Thu Feb 14 12:47:16 2008 -0500
+++ b/virt-install Fri Feb 15 09:37:24 2008 +0000
@@ -91,7 +91,7 @@ def get_disk(disk, size, sparse, guest,
disk = None
continue
- guest.disks.append(disk)
+ guest.disks.append(d)
break
def get_disks(disk, size, sparse, nodisks, guest, hvm, conn):
# HG changeset patch
# User "Cole Robinson <crobinso@redhat.com>"
# Date 1204823953 18000
# Node ID 507a70e9ed103090ae773adecd11adb672fb65b5
# Parent f162e1a34ed1cb2ecf3487a01b624c61c06aa0f8
Add --force option to all cmdline utilities.
Option forces a yes answer where applicable, bails out on any prompt that requires non boolean input.
diff -r f162e1a34ed1 -r 507a70e9ed10 virt-clone
--- a/virt-clone Thu Mar 06 10:16:36 2008 -0500
+++ b/virt-clone Thu Mar 06 12:19:13 2008 -0500
@@ -164,6 +164,9 @@ def parse_args():
# Misc options
parser.add_option("-d", "--debug", action="store_true", dest="debug",
help=_("Print debugging information"))
+ parser.add_option("", "--force", action="store_true", dest="force",
+ help=_("Do not prompt for input. Answers yes where applicable, terminates for all other prompts"),
+ default=False)
(options,args) = parser.parse_args()
return options
@@ -173,6 +176,7 @@ def main():
options = parse_args()
cli.setupLogging("virt-clone", options.debug)
+ cli.set_force(options.force)
logging.debug("start clone with HV " + options.connect)
diff -r f162e1a34ed1 -r 507a70e9ed10 virt-image
--- a/virt-image Thu Mar 06 10:16:36 2008 -0500
+++ b/virt-image Thu Mar 06 12:19:13 2008 -0500
@@ -139,6 +139,9 @@ def parse_args():
help=_("Print the libvirt XML, but do not start the domain"))
parser.add_option("", "--boot", type="int", dest="boot",
help=_("The zero-based index of the boot record to use"))
+ parser.add_option("", "--force", action="store_true", dest="force",
+ help=_("Do not prompt for input. Answers yes where applicable, terminates for all other prompts"),
+ default=False)
(options,args) = parser.parse_args()
if len(args) < 1:
@@ -162,6 +165,7 @@ def main():
options = parse_args()
cli.setupLogging("virt-image", options.debug)
+ cli.set_force(options.force)
conn = cli.getConnection(options.connect)
type = None
diff -r f162e1a34ed1 -r 507a70e9ed10 virt-install
--- a/virt-install Thu Mar 06 10:16:36 2008 -0500
+++ b/virt-install Thu Mar 06 12:19:13 2008 -0500
@@ -273,6 +273,9 @@ def parse_args():
help=_("Print debugging information"))
parser.add_option("", "--noreboot", action="store_true", dest="noreboot",
help=_("Disables the automatic rebooting when the installation is complete."))
+ parser.add_option("", "--force", action="store_true", dest="force",
+ help=_("Do not prompt for input. Answers yes where applicable, terminates for all other prompts"),
+ default=False)
(options,args) = parser.parse_args()
@@ -338,6 +341,7 @@ def main():
options = parse_args()
cli.setupLogging("virt-install", options.debug)
+ cli.set_force(options.force)
conn = cli.getConnection(options.connect)
capabilities = virtinst.CapabilitiesParser.parse(conn.getCapabilities())
diff -r f162e1a34ed1 -r 507a70e9ed10 virtinst/cli.py
--- a/virtinst/cli.py Thu Mar 06 10:16:36 2008 -0500
+++ b/virtinst/cli.py Thu Mar 06 12:19:13 2008 -0500
@@ -29,6 +29,7 @@ import Guest
import Guest
MIN_RAM = 256
+force = False
#
# Setup helpers
@@ -94,9 +95,15 @@ def getConnection(connect):
# Prompting
#
+def set_force(val=True):
+ global force
+ force = val
+
def prompt_for_input(prompt = "", val = None):
if val is not None:
return val
+ if force:
+ raise RuntimeError(_("Force flag is set but input was required. Prompt was: %s" % prompt))
print prompt + " ",
return sys.stdin.readline().strip()
@@ -110,6 +117,10 @@ def yes_or_no(s):
def prompt_for_yes_or_no(prompt):
"""catches yes_or_no errors and ensures a valid bool return"""
+ if force:
+ logging.debug("Forcing return value of True to prompt '%s'")
+ return True
+
while 1:
input = prompt_for_input(prompt, None)
try: