diff --git a/man/virt-xml.pod b/man/virt-xml.pod index 834eae1dd..a98ace703 100644 --- a/man/virt-xml.pod +++ b/man/virt-xml.pod @@ -17,7 +17,7 @@ Each B invocation requires 3 things: name of an existing domain to alt --add-device: Append a new device definition to the XML --remove-device: Remove an existing device definition --edit: Edit an existing XML block ---build-xml: Just build the requested XML block and print it (no domain or input XML are required here). +--build-xml: Just build the requested XML block and print it. No domain or input are required here, but it's recommended to provide them, so virt-xml can fill in optimal defaults. An XML change is one instance of any of the XML options provided by virt-xml, for example --disk or --boot. @@ -118,6 +118,8 @@ This option will error if specified with a non-device XML option (see --edit sec Just build the specified XML, and print it to stdout. No input domain or input XML is required. Example: '--build-xml --disk DISK-OPTIONS' will just print the new device. +However if the generated XML is targeted for a specific domain, it's recommended to pass it to virt-xml, so the tool can set optimal defaults. + This option will error if specified with an XML option that does not map cleanly to a specific XML block, like --vcpus or --memory. =back diff --git a/tests/cli-test-xml/compare/virt-xml-build-disk-domain.xml b/tests/cli-test-xml/compare/virt-xml-build-disk-domain.xml new file mode 100644 index 000000000..76af6280f --- /dev/null +++ b/tests/cli-test-xml/compare/virt-xml-build-disk-domain.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/tests/cli-test-xml/compare/virt-xml-build-disk-plain.xml b/tests/cli-test-xml/compare/virt-xml-build-disk-plain.xml new file mode 100644 index 000000000..ee17622a7 --- /dev/null +++ b/tests/cli-test-xml/compare/virt-xml-build-disk-plain.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/tests/clitest.py b/tests/clitest.py index 5a80242ea..a33ab0b83 100644 --- a/tests/clitest.py +++ b/tests/clitest.py @@ -1119,6 +1119,8 @@ c.add_compare("--build-xml --cpu pentium3,+x2apic", "build-cpu") c.add_compare("--build-xml --tpm path=/dev/tpm", "build-tpm") c.add_compare("--build-xml --blkiotune weight=100,device0.path=/dev/sdf,device.weight=200", "build-blkiotune") c.add_compare("--build-xml --idmap uid.start=0,uid.target=1000,uid.count=10,gid.start=0,gid.target=1000,gid.count=10", "build-idmap") +c.add_compare("--connect %(URI-KVM)s --build-xml --disk %(EXISTIMG1)s", "build-disk-plain") +c.add_compare("--connect %(URI-KVM)s test-many-devices --build-xml --disk %(EXISTIMG1)s", "build-disk-domain") c.add_compare("4a64cc71-19c4-2fd0-2323-3050941ea3c3 --edit --boot network,cdrom", "edit-bootorder") # basic bootorder test, also using UUID lookup c.add_compare("--confirm 1 --edit --cpu host-passthrough", "prompt-response", input_text="yes") # prompt response, also using domid lookup c.add_compare("--edit --print-diff --qemu-commandline clearxml=yes", "edit-clearxml-qemu-commandline", input_file=(XMLDIR + "/virtxml-qemu-commandline-clear.xml")) diff --git a/virt-xml b/virt-xml index 432da74c9..6487aa7c2 100755 --- a/virt-xml +++ b/virt-xml @@ -217,14 +217,13 @@ def action_remove_device(guest, options, parserclass): return devs -def action_build_xml(conn, options, parserclass): +def action_build_xml(conn, options, parserclass, guest): if not parserclass.guest_propname: fail(_("--build-xml not supported for --%s") % parserclass.cli_arg_name) if options.os_variant is not None: fail(_("--os-variant is not supported with --build-xml")) - guest = virtinst.Guest(conn) inst = parserclass.lookup_prop(guest) if parserclass.prop_is_list(guest): inst = inst.new() @@ -374,7 +373,8 @@ def parse_args(): help=_("Add specified device. Example:\n" "--add-device --disk ...")) actg.add_argument("--build-xml", action="store_true", - help=_("Just output the built device XML, no domain required.")) + help=_("Output built device XML. Domain is optional but " + "recommended to ensure optimal defaults.")) outg = parser.add_argument_group(_("Output options")) outg.add_argument("--update", action="store_true", @@ -467,8 +467,9 @@ def main(conn=None): if options.domain: domain, inactive_xmlobj, active_xmlobj = get_domain_and_guest( conn, options.domain) - elif not options.build_xml: - inactive_xmlobj = virtinst.Guest(conn, options.stdinxml) + else: + inactive_xmlobj = virtinst.Guest(conn, + parsexml=options.stdinxml) check_action_collision(options) parserclass = check_xmlopt_collision(options) @@ -478,7 +479,7 @@ def main(conn=None): (parserclass.cli_arg_name)) if options.build_xml: - devs = action_build_xml(conn, options, parserclass) + devs = action_build_xml(conn, options, parserclass, inactive_xmlobj) for dev in devs: # pylint: disable=no-member print_stdout(dev.get_xml())