From 8560138cf2269b8bc8f3cf657ed282a2ac9d499f Mon Sep 17 00:00:00 2001 From: Cole Robinson Date: Thu, 10 Sep 2020 13:52:07 -0400 Subject: cli: Add --xml xpath option for virt-install and virt-xml The --xml option allows users to request raw XML edits to virt-install or virt-xml generated XML. This gives users a bit of a workaround incase we don't have proper support for some XML property. The --xml option can gain more features in the future if it makes sense, like setting XML namespaces for example. Basic usage is like: virt-install --xml ./@foo=bar ... Which will change the generated XML to have --- virtinst/virtxml.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) (limited to 'virtinst/virtxml.py') diff --git a/virtinst/virtxml.py b/virtinst/virtxml.py index b80a84db..4cb542e2 100644 --- a/virtinst/virtxml.py +++ b/virtinst/virtxml.py @@ -127,7 +127,7 @@ def check_action_collision(options): def check_xmlopt_collision(options): collisions = [] - for parserclass in cli.VIRT_PARSERS: + for parserclass in cli.VIRT_PARSERS + [cli.ParserXML]: if getattr(options, parserclass.cli_arg_name): collisions.append(parserclass) @@ -297,9 +297,18 @@ def update_changes(domain, devs, action, confirm): def prepare_changes(xmlobj, options, parserclass): origxml = xmlobj.get_xml() + has_edit = options.edit != -1 + is_xmlcli = parserclass is cli.ParserXML - if options.edit != -1: - devs = action_edit(xmlobj, options, parserclass) + if is_xmlcli and not has_edit: + fail(_("--xml can only be used with --edit")) + + if has_edit: + if is_xmlcli: + devs = [] + cli.parse_xmlcli(xmlobj, options) + else: + devs = action_edit(xmlobj, options, parserclass) action = "update" elif options.add_device: @@ -391,6 +400,7 @@ def parse_args(): cli.add_metadata_option(g) cli.add_memory_option(g) cli.vcpu_cli_options(g, editexample=True) + cli.add_xml_option(g) cli.add_guest_xml_options(g) cli.add_boot_options(g) cli.add_device_options(g) -- cgit v1.2.1