cli: Combine registering a bunch of common options

This commit is contained in:
Cole Robinson
2013-09-28 11:27:26 -04:00
parent b1fb6c2567
commit 4c15da439b
6 changed files with 57 additions and 74 deletions
+1 -1
View File
@@ -159,7 +159,7 @@ This option is deprecated in favor of C<--graphics none>
=over 2
=item -p, --print
=item --print-xml
Print the libvirt XML, but do not start the guest.
+4 -18
View File
@@ -174,27 +174,13 @@ def parse_args():
parser.add_option_group(netg)
misc = optparse.OptionGroup(parser, _("Miscellaneous Options"))
misc.add_option("--print-xml", action="store_true", dest="xmlonly",
help=_("Print the generated domain XML rather than define "
"and clone the guest."))
misc.add_option("--replace", action="store_true", dest="replace",
help=_("Don't check for name collision. Allows replacing "
"an existing guest with the new clone"))
misc.add_option("-d", "--debug", action="store_true", dest="debug",
help=_("Print debugging information"))
misc.add_option("--prompt", action="store_true", dest="prompt",
default=False,
help=_("Request user input for ambiguous situations or "
"required options."))
misc.add_option("--force", action="store_true", dest="force",
default=False,
help=_("Do not prompt for input. Answers yes where "
"applicable, terminates for all other prompts"))
misc.add_option("-q", "--quiet", action="store_true", dest="quiet",
help=_("Suppress non-error output"))
# Just used for clone tests
misc.add_option("--clone-running", action="store_true",
dest="clone_running", default=False,
help=optparse.SUPPRESS_HELP)
cli.add_misc_options(misc, prompt=True, replace=True, printxml=True)
parser.add_option_group(misc)
(options, parseargs) = parser.parse_args()
+5 -11
View File
@@ -74,13 +74,7 @@ def parse_args():
opts.add_option_group(cfgg)
misc = OptionGroup(opts, "Miscellaneous Options")
misc.add_option("-q", "--quiet", action="store_true", dest="quiet",
help=_("Suppress non-error output"))
misc.add_option("-d", "--debug", action="store_true", dest="debug",
help=_("Print debugging information"))
misc.add_option("--dry-run", action="store_false", dest="nodry",
default=True,
help=_("Dry run, don't make any changes"))
cli.add_misc_options(misc, dryrun=True)
opts.add_option_group(misc)
@@ -149,7 +143,7 @@ def cleanup(msg, options, vmdef, paths):
After failure, clean up anything we created.
"""
logging.error(msg)
if not options.nodry:
if options.dry:
return
try:
@@ -204,7 +198,7 @@ def main():
options.output_dir = unixname
try:
logging.debug("Creating directory %s", options.output_dir)
if options.nodry:
if not options.dry:
os.mkdir(options.output_dir)
clean += [options.output_dir]
except OSError, e:
@@ -239,7 +233,7 @@ def main():
"%(format)s...") % {"path": d.path,
"format": dformat})
if options.nodry:
if not options.dry:
d.convert(options.input_dir, options.output_dir, dformat)
except OSError, e:
@@ -252,7 +246,7 @@ def main():
output = outp.export(vmdef)
logging.debug("Output VM config:\n%s", output)
if options.nodry:
if not options.dry:
outfile = open(options.output_file, "w")
outfile.writelines(output)
outfile.close()
+5 -21
View File
@@ -58,30 +58,14 @@ def parse_args():
parser.add_option_group(vncg)
misc = optparse.OptionGroup(parser, _("Miscellaneous Options"))
misc.add_option("-p", "--print", action="store_true", dest="print_only",
help=_("Print the libvirt XML, but do not start the "
"domain"))
misc.add_option("--boot", type="int", dest="boot",
help=_("The zero-based index of the boot record to use"))
misc.add_option("--replace", action="store_true", dest="replace",
default=False,
help=_("Overwrite, or destroy, an existing image with "
"the same name"))
misc.add_option("--noreboot", action="store_true", dest="noreboot",
help=_("Don't boot guest after completing install."))
misc.add_option("--skip-checksum", action="store_true",
dest="skipchecksum",
help=_("Skip disk checksum verification process"))
misc.add_option("-d", "--debug", action="store_true", dest="debug",
help=_("Print debugging information"))
misc.add_option("--prompt", action="store_true", dest="prompt",
default=False,
help=optparse.SUPPRESS_HELP)
misc.add_option("--force", action="store_true", dest="force",
default=False,
help=optparse.SUPPRESS_HELP)
misc.add_option("-q", "--quiet", action="store_true", dest="quiet",
help=_("Suppress non-error output"))
cli.add_misc_options(misc, prompt=True, replace=True, printxml=True,
noreboot=True)
parser.add_option_group(misc)
(options, args) = parser.parse_args()
@@ -97,7 +81,7 @@ def main(conn=None):
cli.earlyLogging()
options = parse_args()
options.quiet = options.print_only or options.quiet
options.quiet = options.xmlonly or options.quiet
cli.setupLogging("virt-image", options.debug, options.quiet)
cli.set_prompt(False)
@@ -148,7 +132,7 @@ def main(conn=None):
guest.add_device(virtinst.VirtualVideoDevice(guest.conn))
# we've got everything -- try to start the install
if options.print_only:
if options.xmlonly:
start_xml, final_xml = guest.start_install(return_xml=True)
print_stdout(start_xml or final_xml, do_force=True)
return 0
+4 -23
View File
@@ -1007,30 +1007,11 @@ def parse_args():
misc.add_option("--autostart", action="store_true", dest="autostart",
default=False,
help=_("Have domain autostart on host boot up."))
misc.add_option("--print-xml", action="store_true", dest="xmlonly",
help=_("Print the generated domain XML rather than define "
"the guest."))
misc.add_option("--print-step", type="str", dest="xmlstep",
help=_("Print XML of a specific install step "
"(1, 2, 3, all) rather than define the guest."))
misc.add_option("--noreboot", action="store_true", dest="noreboot",
help=_("Don't boot guest after completing install."))
misc.add_option("--wait", type="int", dest="wait",
help=_("Time to wait (in minutes)"))
misc.add_option("--dry-run", action="store_true", dest="dry",
help=_("Run through install process, but do not "
"create devices or define the guest."))
misc.add_option("--force", action="store_true", dest="force",
help=_("Forces 'yes' for any applicable prompts, "
"terminates for all others"))
misc.add_option("-q", "--quiet", action="store_true", dest="quiet",
help=_("Suppress non-error output"))
misc.add_option("--prompt", action="store_true", dest="prompt",
default=False,
help=_("Request user input for ambiguous situations or "
"required options."))
misc.add_option("-d", "--debug", action="store_true", dest="debug",
help=_("Print debugging information"))
help=_("Minutes to wait for install to complete."))
cli.add_misc_options(misc, prompt=True, printxml=True, printstep=True,
noreboot=True, dryrun=True)
parser.add_option_group(misc)
(options, cliargs) = parser.parse_args()
+38
View File
@@ -793,6 +793,44 @@ def add_connect_option(parser):
help=_("Connect to hypervisor with libvirt URI"))
def add_misc_options(grp, prompt=False, replace=False,
printxml=False, printstep=False,
noreboot=False, dryrun=False):
if prompt:
grp.add_option("--prompt", action="store_true", dest="prompt",
default=False, help=optparse.SUPPRESS_HELP)
grp.add_option("--force", action="store_true", dest="force",
default=False, help=optparse.SUPPRESS_HELP)
if noreboot:
grp.add_option("--noreboot", action="store_true", dest="noreboot",
help=_("Don't boot guest after completing install."))
if replace:
grp.add_option("--replace", action="store_true", dest="replace",
help=_("Don't check name collision, overwrite any guest "
"with the same name."))
if printxml:
grp.add_option("--print-xml", action="store_true", dest="xmlonly",
help=_("Print the generated domain XML rather than define "
"and clone the guest."))
if printstep:
grp.add_option("--print-step", type="str", dest="xmlstep",
help=_("Print XML of a specific install step "
"(1, 2, 3, all) rather than define the guest."))
if dryrun:
grp.add_option("--dry-run", action="store_true", dest="dry",
help=_("Run through install process, but do not "
"create devices or define the guest."))
grp.add_option("-q", "--quiet", action="store_true", dest="quiet",
help=_("Suppress non-error output"))
grp.add_option("-d", "--debug", action="store_true", dest="debug",
help=_("Print debugging information"))
def vcpu_cli_options(grp, backcompat=True):
grp.add_option("--vcpus", dest="vcpus",
help=_("Number of vcpus to configure for your guest. Ex:\n"