virt-xml-validate
Validate virtual machine XML configuration files
TLDR
Validate an XML file against a specific schema
Validate the domain XML against the domain schema
SYNOPSIS
virt-xml-validate [OPTIONS] FILE [SCHEMA_FILE]
virt-xml-validate [OPTIONS] --stdin [SCHEMA_FILE]
PARAMETERS
-h, --help
Displays a brief help message and exits.
-q, --quiet
Suppresses all standard output upon successful validation. Only error messages are printed.
--stdin
Reads the XML document for validation from standard input instead of a specified file.
-V, --version
Shows the version information of the virt-xml-validate utility and exits.
--schema
Forces validation against a specific schema type, overriding the automatic inference. Common types include 'domain', 'network', 'pool', 'volume', 'nodedev', 'secret', 'interface', 'nwfilter', etc.
The path to the XML file to be validated. This is typically a libvirt XML definition.
[SCHEMA_FILE]
An optional path to a custom XML schema (XSD) file to use for validation. If omitted, virt-xml-validate attempts to infer the schema from the XML content.
DESCRIPTION
virt-xml-validate is a crucial command-line utility within the libvirt ecosystem, designed to verify the structural and semantic correctness of libvirt XML configuration files. It ensures that various libvirt object definitions—such as domains (virtual machines), networks, storage pools, storage volumes, node devices, secrets, and more—adhere to their respective XML schemas. By validating these files, virt-xml-validate helps prevent configuration errors and ensures that libvirt can parse and apply the settings correctly. When a schema file is not explicitly provided, the tool intelligently infers the appropriate schema based on the root element of the XML document, making its usage straightforward for common scenarios. It leverages libxml2's powerful validation capabilities, providing clear error messages if the XML does not conform to the schema. A successful validation returns an exit code of 0, while any non-zero code indicates an error, making it suitable for scripting and automated deployment pipelines.
CAVEATS
virt-xml-validate primarily validates against XML Schemas (XSD). While it can check the structural correctness and adherence to the schema, it does not perform semantic checks that require deeper understanding of libvirt's runtime state or specific hardware capabilities. For example, it won't verify if a specified bridge actually exists or if a CPU feature is supported by the host. It also relies on the libxml2 library; issues or limitations within libxml2's schema validation engine could indirectly affect virt-xml-validate.
EXIT STATUS
The command returns an exit status of 0 on successful validation, indicating that the XML file conforms to the schema. A non-zero exit status (typically 1) signifies a validation failure, meaning the XML is malformed or does not adhere to the specified or inferred schema. This makes it highly suitable for use in shell scripts for automated checking.
SCHEMA INFERENCE
When no explicit SCHEMA_FILE or --schema type is provided, virt-xml-validate intelligently attempts to determine the correct XML schema based on the root element of the XML document. For example, if the root element is <domain>, it will automatically attempt to validate against the libvirt domain schema. This simplifies usage for most common libvirt XML types.
HISTORY
virt-xml-validate is an integral part of the libvirt project, an open-source virtualization management toolkit. It was introduced to provide a robust method for validating XML configurations, which are central to libvirt's declarative approach to managing virtual machines and other virtualization resources. As libvirt evolved and its XML schemas became more complex with new features and objects, the need for a dedicated validation tool grew. Its development paralleled libvirt's growth, ensuring that administrators and developers could reliably verify their configurations against the continually updated and refined schemas. Its simple command-line interface makes it a staple for both manual debugging and automated CI/CD pipelines where configuration integrity is paramount.
SEE ALSO
virsh(1), virsh-define(1), virsh-dumpxml(1), virt-install(1), libvirtd(8)