virt-install: Better error when user accidentally passes -vcpus

Notice the missing - in -vcpus. It maps to

--hvm --cdrom pus

If the user also specifies --paravirt, they get an error that hvm and
paravirt conflict, which is very confusing.

There isn't a nice way to catch this issue which isn't back compatible,
so scrape the raw argv and try to figure it out.
This commit is contained in:
Cole Robinson 2013-04-04 12:04:07 -04:00
parent 9aa54dc1c4
commit 9fc356af43

View File

@ -93,6 +93,18 @@ def supports_pxe(guest):
return False
def check_vcpu_option_error(options):
# Catch a strangely common error of users passing -vcpus=2 instead of
# --vcpus=2. The single dash happens to map to enough shortened options
# that things can fail weirdly if --paravirt is also specified.
if not options.cdrom:
return
for vcpu in [o for o in sys.argv if o.startswith("-vcpu")]:
if options.cdrom == vcpu[3:]:
fail("You specified -vcpus, you want --vcpus")
##############################
# Device validation wrappers #
##############################
@ -980,6 +992,7 @@ def main(conn=None):
if cliargs:
fail(_("Unknown argument '%s'") % cliargs[0])
check_vcpu_option_error(options)
if options.distro_variant == "list":
logging.debug("OS list requested")