[PATCH] Convert xml config file

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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

Signed-off-by: Jan Friesse <jfriesse@xxxxxxxxxx>
---
 Makefile.am                |   10 ++++-
 conf/corosync.xml.example  |  110 ++++++++++++++++++++++++++++++++++++++++++++
 conf/xml2conf.xsl          |   94 +++++++++++++++++++++++++++++++++++++
 configure.ac               |   10 ++++-
 tools/.gitignore           |    1 +
 tools/Makefile.am          |    7 +++
 tools/corosync-xml2conf.sh |   54 +++++++++++++++++++++
 7 files changed, 284 insertions(+), 2 deletions(-)
 create mode 100644 conf/corosync.xml.example
 create mode 100644 conf/xml2conf.xsl
 create mode 100644 tools/corosync-xml2conf.sh

diff --git a/Makefile.am b/Makefile.am
index 176a762..0a1d033 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -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
 
diff --git a/conf/corosync.xml.example b/conf/corosync.xml.example
new file mode 100644
index 0000000..4c0db7b
--- /dev/null
+++ b/conf/corosync.xml.example
@@ -0,0 +1,110 @@
+<?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" threads="0">
+    <!--
+	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="AMF" debug="off" />
+</logging>
+
+<amf mode="disabled" />
+</corosync>
diff --git a/conf/xml2conf.xsl b/conf/xml2conf.xsl
new file mode 100644
index 0000000..c140d68
--- /dev/null
+++ b/conf/xml2conf.xsl
@@ -0,0 +1,94 @@
+<?xml version="1.0" encoding="utf-8"?>
+
+<!--
+  Copyright (c) 2011 Red Hat, Inc.
+
+  All rights reserved.
+
+  Author: Jan Friesse (jfriesse@xxxxxxxxxx)
+
+  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>
diff --git a/configure.ac b/configure.ac
index 50a1dc9..e7ca328 100644
--- a/configure.ac
+++ b/configure.ac
@@ -281,7 +281,7 @@ AC_ARG_ENABLE([augeas],
 AM_CONDITIONAL(INSTALL_AUGEAS, test x$enable_augeas = xyes)
 
 AC_ARG_ENABLE([systemd],
-	      [  --enable-systemd               : Install systemd service files],,
+	      [  --enable-systemd                : Install systemd service files],,
 	[ enable_systemd="no" ])
 AM_CONDITIONAL(INSTALL_SYSTEMD, test x$enable_systemd = xyes)
 
@@ -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=""
diff --git a/tools/.gitignore b/tools/.gitignore
index 9651044..ff6c736 100644
--- a/tools/.gitignore
+++ b/tools/.gitignore
@@ -7,3 +7,4 @@ corosync-pload
 corosync-quorumtool
 corosync-notifyd
 corosync-cmapctl
+corosync-xml2conf
diff --git a/tools/Makefile.am b/tools/Makefile.am
index c74af0f..143209a 100644
--- a/tools/Makefile.am
+++ b/tools/Makefile.am
@@ -40,6 +40,13 @@ sbin_PROGRAMS		= corosync-fplay corosync-cfgtool \
 
 bin_SCRIPTS		= corosync-blackbox
 
+if INSTALL_XMLCONF
+bin_SCRIPTS		+= corosync-xml2conf
+
+corosync-xml2conf: corosync-xml2conf.sh
+	sed -e 's#@''DATADIR@#${datadir}#g' $< > $@
+endif
+
 EXTRA_DIST		= $(bin_SCRIPTS) corosync-notifyd.sysconfig.example
 
 corosync_fplay_LDADD	= $(LIBQB_LIBS)
diff --git a/tools/corosync-xml2conf.sh b/tools/corosync-xml2conf.sh
new file mode 100644
index 0000000..6fcf934
--- /dev/null
+++ b/tools/corosync-xml2conf.sh
@@ -0,0 +1,54 @@
+#!/bin/bash
+
+# Copyright (c) 2011 Red Hat, Inc.
+#
+# All rights reserved.
+#
+# Author: Jan Friesse (jfriesse@xxxxxxxxxx)
+#
+# 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
+
+[ "$2" != "" ] && out_param="-o $2"
+
+$XSLT_PROC --stringparam inputfile "$1" $out_param @DATADIR@/corosync/xml2conf.xsl "$1"
-- 
1.7.1

_______________________________________________
discuss mailing list
discuss@xxxxxxxxxxxx
http://lists.corosync.org/mailman/listinfo/discuss


[Index of Archives]     [Linux Clusters]     [Corosync Project]     [Linux USB Devel]     [Linux Audio Users]     [Photo]     [Yosemite News]    [Yosemite Photos]    [Linux Kernel]     [Linux SCSI]     [X.Org]

  Powered by Linux