Convert xml config file

Included are following parts:
 - XSLT template with actual conversion
 - simple wrapper on top of xsltproc called corosync-xmlproc
 - example XML file

Signed-off-by: Jan Friesse <jfriesse@redhat.com>
Reviewed-by: Steven Dake <sdake@redhat.com>
This commit is contained in:
Jan Friesse 2011-12-16 10:52:48 +01:00
parent e7e91e64f9
commit b1421fe1d2
7 changed files with 285 additions and 1 deletions

View File

@ -40,7 +40,7 @@ EXTRA_DIST = autogen.sh conf/corosync.conf.example $(SPEC).in \
conf/lenses/tests/test_corosync.aug \
conf/lenses/corosync.aug \
conf/corosync.conf.example.udpu \
.version
.version conf/corosync.xml.example
AUTOMAKE_OPTIONS = foreign
@ -63,6 +63,14 @@ corolenstestdir = ${corolensdir}/tests
corolenstest_DATA = conf/lenses/tests/test_corosync.aug
endif
if INSTALL_XMLCONF
corosysxmlconfdir = ${COROSYSCONFDIR}
corosysxmlconf_DATA = conf/corosync.xml.example
corosysxmlxsltdir = ${datadir}/corosync
corosysxmlxslt_DATA = conf/xml2conf.xsl
endif
SUBDIRS = include lcr lib exec services tools test cts pkgconfig \
man init conf

109
conf/corosync.xml.example Normal file
View File

@ -0,0 +1,109 @@
<?xml version="1.0"?>
<!--
Please read the corosync.xml.5 and corosync.conf.5 manual page
-->
<corosync compatibility="whitetank">
<!--
totem tag configures behavior of totem and interfaces.
secauth:
Enable mutual node authentication. If you choose to
enable this ("on"), then do remember to create a shared
secret with "corosync-keygen".
-->
<totem version="2" secauth="off">
<!--
interface tag to define at least one interface to communicate
over. If you define more than one interface stanza, you must
also set rrp_mode.
Main parameters:
ringnumber:
Rings must be consecutively numbered, starting at 0.
bindnetaddr:
This is normally the *network* address of the
interface to bind to. This ensures that you can use
identical instances of this configuration file
across all your cluster nodes, without having to
modify this option.
However, if you have multiple physical network
interfaces configured for the same subnet, then the
network address alone is not sufficient to identify
the interface Corosync should bind to. In that case,
configure the *host* address of the interface
instead: bindnetaddr="192.168.1.1"
mcastaddr:
When selecting a multicast address, consider RFC
2365 (which, among other things, specifies that
239.255.x.x addresses are left to the discretion of
the network administrator). Do not reuse multicast
addresses across multiple Corosync clusters sharing
the same network.
mcastport:
Corosync uses the port you specify here for UDP
messaging, and also the immediately preceding
port. Thus if you set this to 5405, Corosync send
messages over UDP ports 5405 and 5404.
ttl:
Time-to-live for cluster communication packets. The
number of hops (routers) that this ring will allow
itself to pass. Note that multicast routing must be
specifically enabled on most network routers.
-->
<interface ringnumber="0" bindnetaddr="192.168.1.0" mcastaddr="239.255.1.1"
mcastport="5405" ttl="1" />
</totem>
<!--
Logging tag for defining various logging options
Main parameters:
fileline:
Log the source file and line where messages are being
generated. When in doubt, leave off. Potentially useful for
debugging.
to_stderr:
Log to standard error. When in doubt, set to no. Useful when
running in the foreground (when invoking "corosync -f")
to_logfile:
logfile:
Log to a log file. When set to "no", the "logfile" option
must not be set.
to_syslog:
Log to the system log daemon. When in doubt, set to yes.
debug:
Log debug messages (very verbose). When in doubt, leave off.
timestamp:
Log messages with time stamps. When in doubt, set to on
(unless you are only logging to syslog, where double
timestamps can be annoying).
-->
<logging fileline="off" to_stderr="no" to_logfile="yes"
logfile="/var/log/cluster/corosync.log" to_syslog="yes" debug="off"
timestamp="on">
<!--
Logger susys tag is used to overwrite default settings for given
subsys if needed.
-->
<logger_subsys subsys="EVS" debug="off" />
</logging>
</corosync>

94
conf/xml2conf.xsl Normal file
View File

@ -0,0 +1,94 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright (c) 2011 Red Hat, Inc.
All rights reserved.
Author: Jan Friesse (jfriesse@redhat.com)
This software licensed under BSD license, the text of which follows:
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
- Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
- Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
- Neither the name of the Red Hat, Inc. nor the names of its
contributors may be used to endorse or promote products derived from this
software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
THE POSSIBILITY OF SUCH DAMAGE.
-->
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:date="http://exslt.org/dates-and-times" extension-element-prefixes="date">
<xsl:output method="text" />
<xsl:strip-space elements="*" />
<xsl:param name="inputfile"/>
<xsl:variable name='newline'><xsl:text>
</xsl:text></xsl:variable>
<xsl:template match="/corosync">
<xsl:text># Corosync configuration file generated from </xsl:text>
<xsl:value-of select="$inputfile"/><xsl:text> at </xsl:text>
<xsl:value-of select="date:date-time()"/>
<xsl:apply-templates select="@*"/>
<xsl:apply-templates />
<xsl:value-of select="$newline" />
</xsl:template>
<xsl:template match="/corosync//*">
<xsl:value-of select="$newline" />
<xsl:value-of select="$newline" />
<xsl:call-template name="indent">
<xsl:with-param name="depth" select="count(ancestor::*) - 1"/>
</xsl:call-template>
<xsl:value-of select="name()"/> {<xsl:apply-templates select="@*"/>
<xsl:apply-templates />
<xsl:value-of select="$newline" />
<xsl:call-template name="indent">
<xsl:with-param name="depth" select="count(ancestor::*) - 1"/>
</xsl:call-template>
<xsl:text>}</xsl:text>
</xsl:template>
<xsl:template match="@*">
<xsl:value-of select="$newline" />
<xsl:call-template name="indent">
<xsl:with-param name="depth" select="count(ancestor::*) - 1"/>
</xsl:call-template>
<xsl:value-of select="name()"/><xsl:text>: </xsl:text><xsl:value-of select="."/>
</xsl:template>
<xsl:template match="text()">
</xsl:template>
<xsl:template name="indent">
<xsl:param name="depth"/>
<xsl:if test="$depth &gt; 0">
<xsl:text> </xsl:text>
<xsl:call-template name="indent">
<xsl:with-param name="depth" select="$depth - 1"/>
</xsl:call-template>
</xsl:if>
</xsl:template>
</xsl:stylesheet>

View File

@ -304,6 +304,11 @@ AC_ARG_ENABLE([snmp],
[ --enable-snmp : SNMP protocol support ],
[ default="no" ])
AC_ARG_ENABLE([xmlconf],
[ --enable-xmlconf : XML configuration support ],,
[ enable_xmlconf="no" ])
AM_CONDITIONAL(INSTALL_XMLCONF, test x$enable_xmlconf = xyes)
# OS detection
# THIS SECTION MUST DIE!
CP=cp
@ -457,6 +462,9 @@ fi
if test "x${enable_systemd}" = xyes; then
PACKAGE_FEATURES="$PACKAGE_FEATURES systemd"
fi
if test "x${enable_xmlconf}" = xyes; then
PACKAGE_FEATURES="$PACKAGE_FEATURES xmlconf"
fi
if test "x${enable_snmp}" = xyes; then
SNMPCONFIG=""

1
tools/.gitignore vendored
View File

@ -7,3 +7,4 @@ corosync-pload
corosync-quorumtool
corosync-notifyd
corosync-cmapctl
corosync-xmlproc

View File

@ -40,6 +40,13 @@ sbin_PROGRAMS = corosync-fplay corosync-cfgtool \
bin_SCRIPTS = corosync-blackbox
if INSTALL_XMLCONF
bin_PROGRAMS = corosync-xmlproc
corosync-xmlproc: corosync-xmlproc.sh
sed -e 's#@''DATADIR@#${datadir}#g' $< > $@
endif
EXTRA_DIST = $(bin_SCRIPTS) corosync-notifyd.sysconfig.example
corosync_fplay_LDADD = $(LIBQB_LIBS)

57
tools/corosync-xmlproc.sh Normal file
View File

@ -0,0 +1,57 @@
#!/bin/bash
# Copyright (c) 2011 Red Hat, Inc.
#
# All rights reserved.
#
# Author: Jan Friesse (jfriesse@redhat.com)
#
# This software licensed under BSD license, the text of which follows:
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# - Redistributions of source code must retain the above copyright notice,
# this list of conditions and the following disclaimer.
# - Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
# - Neither the name of the Red Hat, Inc. nor the names of its
# contributors may be used to endorse or promote products derived from this
# software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
# THE POSSIBILITY OF SUCH DAMAGE.
XSLT_PROC=xsltproc
usage() {
echo "$0 input_config [output]"
echo " where input_config is valid XML configuration file"
exit 1
}
[ "$1" == "" ] && usage
$XSLT_PROC -V >/dev/null 2>&1
if [ "$?" != 0 ];then
echo "Can't find xslt processor $XSLT_PROC"
exit 2
fi
# TODO:
# Validation should occur before actual processing
[ "$2" != "" ] && out_param="-o $2"
$XSLT_PROC --stringparam inputfile "$1" $out_param @DATADIR@/corosync/xml2conf.xsl "$1"