2009-04-19 15:10:45 +00:00
#!/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.
#
2012-07-26 16:58:02 -06:00
# You should have received a copy of the GNU Lesser General Public
2012-09-20 16:30:55 -06:00
# License along with this library. If not, see
2012-07-26 16:58:02 -06:00
# <http://www.gnu.org/licenses/>.
2009-04-19 15:10:45 +00:00
set -e
2013-08-19 16:26:41 -06:00
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) @VERSION@
EOF
exit ;;
--) shift ;;
-*)
echo "$0: unrecognized option '$1'" >&2
exit 1 ;;
esac
2011-02-20 22:29:26 +02:00
XMLFILE="$1"
TYPE="$2"
2009-04-19 15:10:45 +00:00
if [ -z "$XMLFILE" ]; then
2013-08-19 16:26:41 -06:00
echo "syntax: $0 XMLFILE [TYPE]" >&2
2009-04-19 15:10:45 +00:00
exit 1
fi
if [ ! -f "$XMLFILE" ]; then
2013-08-19 16:26:41 -06:00
echo "$0: document $XMLFILE does not exist" >&2
2009-04-19 15:10:45 +00:00
exit 2
fi
if [ -z "$TYPE" ]; then
2011-02-20 22:29:26 +02:00
ROOT=`xmllint --stream --debug "$XMLFILE" 2>/dev/null | grep "^0 1 " | awk '{ print $3 }'`
case "$ROOT" in
2013-08-19 16:32:31 -06:00
*domainsnapshot*) # Must come first, since *domain* is a substring
TYPE="domainsnapshot"
;;
2009-04-19 15:10:45 +00:00
*domain*)
TYPE="domain"
;;
*network*)
TYPE="network"
;;
*pool*)
TYPE="storagepool"
;;
*volume*)
TYPE="storagevol"
;;
*capabilities*)
TYPE="capability"
;;
*device*)
TYPE="nodedev"
;;
2013-08-19 16:32:31 -06:00
*filter*)
TYPE="nwfilter"
;;
*secret*)
TYPE="secret"
;;
2013-09-11 11:47:14 +08:00
*interface*)
TYPE="interface"
;;
2009-04-19 15:10:45 +00:00
*)
2013-08-19 16:26:41 -06:00
echo "$0: cannot determine schema type for $XMLFILE" >&2
2009-04-19 15:10:45 +00:00
exit 3
esac
fi
build: use common .in replacement mechanism
We had several different styles of .in conversion in our Makefiles:
ALLCAPS, @ALLCAPS@, @lower@, ::lower::
Canonicalize on one form, to make it easier to copy and paste
between .in files.
Also, we were using some non-portable sed constructs: \@ is an
undefined escape sequence (it happens to be @ itself in GNU sed,
but POSIX allows it to mean something else), as well as risky
behavior (failure to consistently quote things means a space
in $(sysconfdir) could throw things off; also, Autoconf recommends
using | rather than , or ! in the s||| operator, because | has to
be quoted in shell and is therefore less likely to appear in file
names than , or !).
Fix all of these uses to follow the same syntax.
* daemon/libvirtd.8.in: Switch to @var@.
* tools/virt-xml-validate.in: Likewise.
* tools/virt-pki-validate.in: Likewise.
* src/locking/virtlockd.init.in: Likewise.
* daemon/Makefile.am: Prefer | over ! in sed.
(libvirtd.8): Prefer consistent substitution.
(libvirtd.init, libvirtd.service): Avoid non-portable sed.
* tools/Makefile.am (libvirt-guests.sh, libvirt-guests.init)
(libvirt-guests.service): Likewise.
(virt-xml-validate, virt-pki-validate, virt-sanlock-cleanup):
Prefer consistent capitalization.
* src/Makefile.am (virtlockd.init, virtlockd.service)
(virtlockd.socket): Prefer consistent substitution.
2013-01-04 13:35:04 -07:00
SCHEMA="@schemadir@/${TYPE}.rng"
2009-04-19 15:10:45 +00:00
if [ ! -f "$SCHEMA" ]; then
2013-08-19 16:26:41 -06:00
echo "$0: schema $SCHEMA does not exist" >&2
2009-04-19 15:10:45 +00:00
exit 4
fi
2011-02-20 22:29:26 +02:00
xmllint --noout --relaxng "$SCHEMA" "$XMLFILE"
2009-04-19 15:10:45 +00:00
2013-08-19 16:26:41 -06:00
exit
2009-04-19 15:10:45 +00:00
: <<=cut
=pod
=head1 NAME
virt-xml-validate - validate libvirt XML files against a schema
=head1 SYNOPSIS
virt-xml-validate XML-FILE [SCHEMA-NAME]
2013-08-19 16:26:41 -06:00
virt-xml-validate OPTION
2009-04-19 15:10:45 +00:00
=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
2013-09-11 11:47:14 +08:00
=item C<domainsnapshot>
The schema for the XML format used by domain snapshot configuration
2009-04-19 15:10:45 +00:00
=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
2013-09-11 11:47:14 +08:00
=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
2009-04-19 15:10:45 +00:00
=back
2013-08-19 16:26:41 -06:00
=head1 OPTIONS
=over
=item B<-h, --help>
Display command line help usage then exit.
=item B<-V, --version>
Display version information then exit.
=back
2009-04-19 15:10:45 +00:00
=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
2013-08-19 16:26:41 -06:00
Copyright (C) 2009-2013 by Red Hat, Inc.
2010-03-12 10:47:26 -07:00
Copyright (C) 2009 by Daniel P. Berrange
2009-04-19 15:10:45 +00:00
=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