summaryrefslogtreecommitdiff
path: root/virtinst/virtxml.py
diff options
context:
space:
mode:
authorCole Robinson <crobinso@redhat.com>2020-09-10 13:52:07 -0400
committerCole Robinson <crobinso@redhat.com>2020-09-11 15:04:37 -0400
commit8560138cf2269b8bc8f3cf657ed282a2ac9d499f (patch)
tree47f158a75bc7bdad295aaaee13fb1a425898e0f5 /virtinst/virtxml.py
parentaa8572048bdc4947520de728fe2a3fec3b61815f (diff)
downloadvirt-manager-8560138cf2269b8bc8f3cf657ed282a2ac9d499f.tar.gz
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 <domain> XML to have <domain foo='bar' ... virt-xml works similarly. It can only be combined with --edit currently. This only works with xpaths rooted against the entire document. Signed-off-by: Cole Robinson <crobinso@redhat.com>
Diffstat (limited to 'virtinst/virtxml.py')
-rw-r--r--virtinst/virtxml.py16
1 files changed, 13 insertions, 3 deletions
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)