cli: Rename parse_option_strings update= to editing=

Makes it more clear what the distinction is. Set this in the parser
class so the cli infrastructure can access it
This commit is contained in:
Cole Robinson 2019-06-13 17:37:26 -04:00
parent f36e8b36bc
commit 8c8fec6cb1
2 changed files with 9 additions and 8 deletions

View File

@ -191,7 +191,7 @@ def action_edit(guest, options, parserclass):
if options.os_variant is not None: if options.os_variant is not None:
fail(_("--os-variant is not supported with --edit")) fail(_("--os-variant is not supported with --edit"))
return cli.parse_option_strings(options, guest, inst, update=True) return cli.parse_option_strings(options, guest, inst, editing=True)
def action_add_device(guest, options, parserclass): def action_add_device(guest, options, parserclass):

View File

@ -1321,9 +1321,10 @@ class VirtCLIParser(metaclass=_InitClass):
def _init_class(cls, **kwargs): def _init_class(cls, **kwargs):
"""This method also terminates the super() chain""" """This method also terminates the super() chain"""
def __init__(self, optstr, guest=None): def __init__(self, optstr, guest=None, editing=None):
self.optstr = optstr self.optstr = optstr
self.guest = guest self.guest = guest
self.editing = editing
self.optdict = _parse_optstr_to_dict(self.optstr, self.optdict = _parse_optstr_to_dict(self.optstr,
self._virtargs, xmlutil.listify(self.remove_first)[:]) self._virtargs, xmlutil.listify(self.remove_first)[:])
@ -1412,7 +1413,7 @@ class VirtCLIParser(metaclass=_InitClass):
self._check_leftover_opts(optdict) self._check_leftover_opts(optdict)
return inst return inst
def parse(self, inst, validate=True): def parse(self, inst):
""" """
Main entry point. Iterate over self._virtargs, and serialize Main entry point. Iterate over self._virtargs, and serialize
self.optdict into 'inst'. self.optdict into 'inst'.
@ -1439,7 +1440,7 @@ class VirtCLIParser(metaclass=_InitClass):
try: try:
objs = self._parse(inst is None and self.guest or inst) objs = self._parse(inst is None and self.guest or inst)
for obj in xmlutil.listify(objs): for obj in xmlutil.listify(objs):
if validate and hasattr(obj, "validate"): if not self.editing and hasattr(obj, "validate"):
obj.validate() obj.validate()
if not new_object: if not new_object:
continue continue
@ -3871,13 +3872,13 @@ class ParserLaunchSecurity(VirtCLIParser):
# Public virt parser APIs # # Public virt parser APIs #
########################### ###########################
def parse_option_strings(options, guest, instlist, update=False): def parse_option_strings(options, guest, instlist, editing=False):
""" """
Iterate over VIRT_PARSERS, and launch the associated parser Iterate over VIRT_PARSERS, and launch the associated parser
function for every value that was filled in on 'options', which function for every value that was filled in on 'options', which
came from argparse/the command line. came from argparse/the command line.
@update: If we are updating an existing guest, like from virt-xml @editing: If we are updating an existing guest, like from virt-xml
""" """
instlist = xmlutil.listify(instlist) instlist = xmlutil.listify(instlist)
if not instlist: if not instlist:
@ -3896,8 +3897,8 @@ def parse_option_strings(options, guest, instlist, update=False):
optlist = [optlist[-1]] optlist = [optlist[-1]]
for optstr in optlist: for optstr in optlist:
parserobj = parserclass(optstr, guest=guest) parserobj = parserclass(optstr, guest=guest, editing=editing)
parseret = parserobj.parse(inst, validate=not update) parseret = parserobj.parse(inst)
ret += xmlutil.listify(parseret) ret += xmlutil.listify(parseret)
return ret return ret