diff options
author | Cole Robinson <crobinso@redhat.com> | 2016-06-13 16:05:56 -0400 |
---|---|---|
committer | Cole Robinson <crobinso@redhat.com> | 2016-06-13 18:37:30 -0400 |
commit | 4db0cd2eabb0e7b795b1a16fb91fe48faff6b246 (patch) | |
tree | 852a88dc62a64c4e67baf71d4160f7ce264c742e | |
parent | cb6853eea6d03ee3733a4a92dcc3408158618b93 (diff) | |
download | virt-manager-4db0cd2eabb0e7b795b1a16fb91fe48faff6b246.tar.gz |
cli: Tweak clearxml argument setup
Just unnest the callback to make it a little easier to follow
-rw-r--r-- | virtinst/cli.py | 50 |
1 files changed, 25 insertions, 25 deletions
diff --git a/virtinst/cli.py b/virtinst/cli.py index d076ea19..890e6fe7 100644 --- a/virtinst/cli.py +++ b/virtinst/cli.py @@ -1072,35 +1072,35 @@ class VirtCLIParser(object): self._params = [] self._inparse = False - self.__init_global_params() + self.set_param(None, "clearxml", + setter_cb=self._clearxml_cb, is_onoff=True) self._init_params() - def __init_global_params(self): - def set_clearxml_cb(inst, val, cbdata): - ignore = cbdata - if not self.objclass and not self.clear_attr: - raise RuntimeError("Don't know how to clearxml --%s" % - self.cli_arg_name) - if val is not True: - return - - clear_inst = inst - if self.clear_attr: - clear_inst = getattr(inst, self.clear_attr) - - # If there's any opts remaining, leave the root stub element - # in place, so virt-xml updates are done in place. - # - # So --edit --cpu clearxml=yes should remove the entire <cpu> - # block. But --edit --cpu clearxml=yes,model=foo should leave - # a <cpu> stub in place, so that it gets model=foo in place, - # otherwise the newly created cpu block gets appened to the - # end of the domain XML, which gives an ugly diff - clear_inst.clear(leave_stub=bool(cbdata.opts.optsdict)) + def _clearxml_cb(self, inst, val, cbdata): + """ + Callback that handles virt-xml clearxml=yes|no magic + """ + ignore = cbdata + if not self.objclass and not self.clear_attr: + raise RuntimeError("Don't know how to clearxml --%s" % + self.cli_arg_name) + if val is not True: + return - self.set_param(None, "clearxml", - setter_cb=set_clearxml_cb, is_onoff=True) + clear_inst = inst + if self.clear_attr: + clear_inst = getattr(inst, self.clear_attr) + + # If there's any opts remaining, leave the root stub element + # in place, so virt-xml updates are done in place. + # + # So --edit --cpu clearxml=yes should remove the entire <cpu> + # block. But --edit --cpu clearxml=yes,model=foo should leave + # a <cpu> stub in place, so that it gets model=foo in place, + # otherwise the newly created cpu block gets appened to the + # end of the domain XML, which gives an ugly diff + clear_inst.clear(leave_stub=bool(cbdata.opts.optsdict)) def check_introspection(self, option): for optstr in util.listify(option): |