/usr/bin/virt-xml-validate is in libvirt-bin 1.3.1-1ubuntu10.
This file is owned by root:root, with mode 0o755.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 | #!/bin/sh
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library. If not, see
# <http://www.gnu.org/licenses/>.
set -e
case $1 in
-h | --h | --he | --hel | --help)
cat <<EOF
Usage:
$0 XML-FILE [SCHEMA-NAME]
$0 OPTION
Options:
-h | --help Display program help
-V | --version Display program version
EOF
exit ;;
-V | --v | --ve | --ver | --vers | --versi | --versio | --version)
cat <<EOF
$0 (libvirt) 1.3.1
EOF
exit ;;
--) shift ;;
-*)
echo "$0: unrecognized option '$1'" >&2
exit 1 ;;
esac
XMLFILE="$1"
TYPE="$2"
if [ -z "$XMLFILE" ]; then
echo "syntax: $0 XMLFILE [TYPE]" >&2
exit 1
fi
if [ ! -f "$XMLFILE" ]; then
echo "$0: document $XMLFILE does not exist" >&2
exit 2
fi
if [ -z "$TYPE" ]; then
ROOT=`xmllint --stream --debug "$XMLFILE" 2>/dev/null | grep "^0 1 " | awk '{ print $3 }'`
case "$ROOT" in
*domainsnapshot*) # Must come first, since *domain* is a substring
TYPE="domainsnapshot"
;;
*domain*)
TYPE="domain"
;;
*network*)
TYPE="network"
;;
*pool*)
TYPE="storagepool"
;;
*volume*)
TYPE="storagevol"
;;
*capabilities*)
TYPE="capability"
;;
*device*)
TYPE="nodedev"
;;
*filter*)
TYPE="nwfilter"
;;
*secret*)
TYPE="secret"
;;
*interface*)
TYPE="interface"
;;
*)
echo "$0: cannot determine schema type for $XMLFILE" >&2
exit 3
esac
fi
SCHEMA="/usr/share/libvirt/schemas/${TYPE}.rng"
if [ ! -f "$SCHEMA" ]; then
echo "$0: schema $SCHEMA does not exist" >&2
exit 4
fi
xmllint --noout --relaxng "$SCHEMA" "$XMLFILE"
exit
: <<=cut
=pod
=head1 NAME
virt-xml-validate - validate libvirt XML files against a schema
=head1 SYNOPSIS
virt-xml-validate XML-FILE [SCHEMA-NAME]
virt-xml-validate OPTION
=head1 DESCRIPTION
Validates a libvirt XML for compliance with the published schema.
The first compulsory argument is the path to the XML file to be
validated. The optional second argument is the name of the schema
to validate against. If omitted, the schema name will be inferred
from the name of the root element in the XML document.
Valid schema names currently include
=over 4
=item C<domainsnapshot>
The schema for the XML format used by domain snapshot configuration
=item C<domain>
The schema for the XML format used by guest domains configuration
=item C<network>
The schema for the XML format used by virtual network configuration
=item C<storagepool>
The schema for the XML format used by storage pool configuration
=item C<storagevol>
The schema for the XML format used by storage volume descriptions
=item C<nodedev>
The schema for the XML format used by node device descriptions
=item C<capability>
The schema for the XML format used to declare driver capabilities
=item C<nwfilter>
The schema for the XML format used by network traffic filters
=item C<secret>
The schema for the XML format used by secrets descriptions
=item C<interface>
The schema for the XML format used by physical host interfaces
=back
=head1 OPTIONS
=over
=item B<-h, --help>
Display command line help usage then exit.
=item B<-V, --version>
Display version information then exit.
=back
=head1 EXIT STATUS
Upon successful validation, an exit status of 0 will be set. Upon
failure a non-zero status will be set.
=head1 AUTHOR
Daniel P.Berrange
=head1 BUGS
Report any bugs discovered to the libvirt community via the
mailing list C<http://libvirt.org/contact.html> or bug tracker C<http://libvirt.org/bugs.html>.
Alternatively report bugs to your software distributor / vendor.
=head1 COPYRIGHT
Copyright (C) 2009-2013 by Red Hat, Inc.
Copyright (C) 2009 by Daniel P. Berrange
=head1 LICENSE
virt-xml-validate is distributed under the terms of the GNU GPL v2+.
This is free software; see the source for copying conditions. There
is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE
=head1 SEE ALSO
C<virsh(1)>, online XML format descriptions C<http://libvirt.org/format.html>
=cut
|