mirror of
https://github.com/virt-manager/virt-manager.git
synced 2024-12-22 13:34:07 +03:00
cli: Break up parse_option_strings
Into run_parser and run_all_parsers. Opencode some of the special case handling in virtxml Signed-off-by: Cole Robinson <crobinso@redhat.com>
This commit is contained in:
parent
e2dfbf9bd9
commit
02e6abad48
@ -4812,38 +4812,30 @@ class ParserLaunchSecurity(VirtCLIParser):
|
||||
# Public virt parser APIs #
|
||||
###########################
|
||||
|
||||
def parse_option_strings(options, guest, instlist, editing=False):
|
||||
def run_parser(options, guest, parserclass, editinst=None):
|
||||
"""
|
||||
Iterate over VIRT_PARSERS, and launch the associated parser
|
||||
function for every value that was filled in on 'options', which
|
||||
came from argparse/the command line.
|
||||
|
||||
@editing: If we are updating an existing guest, like from virt-xml
|
||||
Lookup the cli options.* string associated with the passed in Parser*
|
||||
class, and parse its values into the passed guest instance, or editinst
|
||||
for some virt-xml usage.
|
||||
"""
|
||||
instlist = xmlutil.listify(instlist)
|
||||
if not instlist:
|
||||
instlist = [None]
|
||||
|
||||
ret = []
|
||||
for parserclass in VIRT_PARSERS:
|
||||
optlist = xmlutil.listify(getattr(options, parserclass.cli_arg_name))
|
||||
if not optlist:
|
||||
continue
|
||||
optstr_list = xmlutil.listify(getattr(options, parserclass.cli_arg_name))
|
||||
|
||||
for inst in instlist:
|
||||
if inst and optlist:
|
||||
# If an object is passed in, we are updating it in place, and
|
||||
# only use the last command line occurrence, eg. from virt-xml
|
||||
optlist = [optlist[-1]]
|
||||
|
||||
for optstr in optlist:
|
||||
parserobj = parserclass(optstr, guest=guest, editing=editing)
|
||||
parseret = parserobj.parse(inst)
|
||||
for optstr in optstr_list:
|
||||
parserobj = parserclass(optstr, guest=guest, editing=bool(editinst))
|
||||
parseret = parserobj.parse(editinst)
|
||||
ret += xmlutil.listify(parseret)
|
||||
|
||||
return ret
|
||||
|
||||
|
||||
def run_all_parsers(options, guest):
|
||||
ret = []
|
||||
for parserclass in VIRT_PARSERS:
|
||||
ret += run_parser(options, guest, parserclass)
|
||||
return ret
|
||||
|
||||
|
||||
def check_option_introspection(options):
|
||||
"""
|
||||
Check if the user requested option introspection with ex: '--disk=?'
|
||||
|
@ -618,12 +618,12 @@ def _build_options_guest(conn, options):
|
||||
|
||||
# Fill in guest from the command line content
|
||||
set_explicit_guest_options(options, guest)
|
||||
cli.parse_option_strings(options, guest, None)
|
||||
cli.run_all_parsers(options, guest)
|
||||
cli.parse_xmlcli(guest, options)
|
||||
|
||||
# Call set_capabilities_defaults explicitly here rather than depend
|
||||
# on set_defaults calling it. Installer setup needs filled in values.
|
||||
# However we want to do it after parse_option_strings to ensure
|
||||
# However we want to do it after run_all_parsers to ensure
|
||||
# we are operating on any arch/os/type values passed in with --boot
|
||||
guest.set_capabilities_defaults()
|
||||
|
||||
|
@ -156,7 +156,10 @@ def action_edit(guest, options, parserclass):
|
||||
if options.os_variant is not None:
|
||||
fail(_("--os-variant/--osinfo is not supported with --edit"))
|
||||
|
||||
return cli.parse_option_strings(options, guest, inst, editing=True)
|
||||
devs = []
|
||||
for editinst in xmlutil.listify(inst):
|
||||
devs += cli.run_parser(options, guest, parserclass, editinst=editinst)
|
||||
return devs
|
||||
|
||||
|
||||
def action_add_device(guest, options, parserclass, devs):
|
||||
@ -168,7 +171,7 @@ def action_add_device(guest, options, parserclass, devs):
|
||||
for dev in devs:
|
||||
guest.add_device(dev)
|
||||
else:
|
||||
devs = cli.parse_option_strings(options, guest, None)
|
||||
devs = cli.run_parser(options, guest, parserclass)
|
||||
for dev in devs:
|
||||
dev.set_defaults(guest)
|
||||
|
||||
@ -205,7 +208,7 @@ def action_build_xml(options, parserclass, guest):
|
||||
if options.os_variant is not None:
|
||||
fail(_("--os-variant/--osinfo is not supported with --build-xml"))
|
||||
|
||||
devs = cli.parse_option_strings(options, guest, None)
|
||||
devs = cli.run_parser(options, guest, parserclass)
|
||||
for dev in devs:
|
||||
dev.set_defaults(guest)
|
||||
return devs
|
||||
|
Loading…
Reference in New Issue
Block a user