summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJan Pokorný <jpokorny@redhat.com>2015-06-24 23:45:09 +0200
committerJan Pokorný <jpokorny@redhat.com>2015-07-02 23:43:28 +0200
commit1c4992df96b55af5588983b49f33074b3c2f27f4 (patch)
treeb293a3411fda37610403c0505e2e39ad551e4551
parente192e1439b5eabf892d2783ac06822374b80c277 (diff)
downloadclufter-1c4992df96b55af5588983b49f33074b3c2f27f4.tar.gz
clufter-1c4992df96b55af5588983b49f33074b3c2f27f4.tar.xz
clufter-1c4992df96b55af5588983b49f33074b3c2f27f4.zip
filters/needlexml2pcscmd: implement the filter
Signed-off-by: Jan Pokorný <jpokorny@redhat.com>
-rw-r--r--filters/corosync/__init__.py15
-rw-r--r--filters/corosync/nodelist/__init__.py0
-rw-r--r--filters/corosync/nodelist/node/__init__.py14
-rw-r--r--filters/corosync/quorum/__init__.py30
-rw-r--r--filters/corosync/totem/__init__.py59
-rw-r--r--filters/corosync/totem/interface/__init__.py42
-rw-r--r--filters/needlexml2pcscmd.py28
7 files changed, 186 insertions, 2 deletions
diff --git a/filters/corosync/__init__.py b/filters/corosync/__init__.py
new file mode 100644
index 0000000..cff1a2a
--- /dev/null
+++ b/filters/corosync/__init__.py
@@ -0,0 +1,15 @@
+# -*- coding: UTF-8 -*-
+# Copyright 2015 Red Hat, Inc.
+# Part of clufter project
+# Licensed under GPLv2+ (a copy included | http://gnu.org/licenses/gpl-2.0.txt)
+__author__ = "Jan Pokorný <jpokorny @at@ Red Hat .dot. com>"
+
+###
+
+# following 2nd chance import is to allow direct usage context (testing, etc.)
+try:
+ from ....filters._2pcscmd import coro2pcscmd
+except ValueError: # Value?
+ from ...filters._2pcscmd import coro2pcscmd
+
+needlexml2pcscmd = coro2pcscmd(node='', quorum='', totem='')
diff --git a/filters/corosync/nodelist/__init__.py b/filters/corosync/nodelist/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/filters/corosync/nodelist/__init__.py
diff --git a/filters/corosync/nodelist/node/__init__.py b/filters/corosync/nodelist/node/__init__.py
new file mode 100644
index 0000000..785a48c
--- /dev/null
+++ b/filters/corosync/nodelist/node/__init__.py
@@ -0,0 +1,14 @@
+# -*- coding: UTF-8 -*-
+# Copyright 2015 Red Hat, Inc.
+# Part of clufter project
+# Licensed under GPLv2+ (a copy included | http://gnu.org/licenses/gpl-2.0.txt)
+
+
+###
+
+needlexml2pcscmd = '''\
+ <xsl:value-of select="concat(' ', @ring0_addr)"/>
+ <xsl:if test="@ring1_addr">
+ <xsl:value-of select="concat(',', @ring1_addr)"/>
+ </xsl:if>
+'''
diff --git a/filters/corosync/quorum/__init__.py b/filters/corosync/quorum/__init__.py
new file mode 100644
index 0000000..4233a12
--- /dev/null
+++ b/filters/corosync/quorum/__init__.py
@@ -0,0 +1,30 @@
+# -*- coding: UTF-8 -*-
+# Copyright 2015 Red Hat, Inc.
+# Part of clufter project
+# Licensed under GPLv2+ (a copy included | http://gnu.org/licenses/gpl-2.0.txt)
+
+###
+
+from ....utils_xslt import xslt_is_member
+
+# 1:1 mapping of supported params to pcs arguments
+needlexml2pcscmd_supported = (
+ # binary 0|1 values
+ 'auto_tie_breaker',
+ 'last_man_standing',
+ 'wait_for_all',
+ # standard values
+ 'last_man_standing_window',
+)
+
+needlexml2pcscmd = '''\
+ <xsl:for-each select="@*[
+''' + (
+ xslt_is_member('name()', needlexml2pcscmd_supported)
+) + ''']">
+ <xsl:if test=".">
+ <!-- but see https://bugzilla.redhat.com/1235452 -->
+ <xsl:value-of select="concat(' --', name(), '=', .)"/>
+ </xsl:if>
+ </xsl:for-each>
+'''
diff --git a/filters/corosync/totem/__init__.py b/filters/corosync/totem/__init__.py
new file mode 100644
index 0000000..e53f057
--- /dev/null
+++ b/filters/corosync/totem/__init__.py
@@ -0,0 +1,59 @@
+# -*- coding: UTF-8 -*-
+# Copyright 2015 Red Hat, Inc.
+# Part of clufter project
+# Licensed under GPLv2+ (a copy included | http://gnu.org/licenses/gpl-2.0.txt)
+
+###
+
+# NOTE pcs doesn't support udpb directly via --transport (unless forced),
+# one has to specify --broadcast0 parameter instead and transport
+# will get silently switched to udpb
+
+from ....utils_xslt import xslt_is_member
+
+needlexml2pcscmd_transports = ('udp', 'udpu')
+needlexml2pcscmd_rrp_mode = ('active', 'passive')
+# 1:1 mapping of supported params to pcs arguments (not: rrpmode)
+needlexml2pcscmd_supported = (
+ 'consensus',
+ 'join',
+ 'token',
+ 'token_coefficients',
+ 'fail_recv_const',
+ 'miss_count_const',
+ 'token_coefficient',
+)
+
+needlexml2pcscmd = '''\
+ <!-- transport -->
+ <xsl:if test="
+''' + (
+ xslt_is_member('@transport', needlexml2pcscmd_transports)
+) + '''">
+ <xsl:value-of select="concat(' --transport ', @transport)"/>
+ </xsl:if>
+
+ <!-- rrpmode -->
+ <xsl:if test="
+''' + (
+ xslt_is_member('@rrp_mode', needlexml2pcscmd_rrp_mode)
+) + '''">
+ <xsl:value-of select="concat(' --rrpmode ', @rrp_mode)"/>
+ </xsl:if>
+
+ <clufter:descent-mix at="interface"/>
+
+ <!-- ipv6? -->
+ <xsl:if test="@ip_version = 'ipv6'">
+ <xsl:value-of select="' --ipv6 '"/>
+ </xsl:if>
+
+ <xsl:for-each select="@*[
+''' + (
+ xslt_is_member('name()', needlexml2pcscmd_supported)
+) + ''']">
+ <xsl:if test=".">
+ <xsl:value-of select="concat(' --', name(), ' ', .)"/>
+ </xsl:if>
+ </xsl:for-each>
+'''
diff --git a/filters/corosync/totem/interface/__init__.py b/filters/corosync/totem/interface/__init__.py
new file mode 100644
index 0000000..c098fb0
--- /dev/null
+++ b/filters/corosync/totem/interface/__init__.py
@@ -0,0 +1,42 @@
+# -*- coding: UTF-8 -*-
+# Copyright 2015 Red Hat, Inc.
+# Part of clufter project
+# Licensed under GPLv2+ (a copy included | http://gnu.org/licenses/gpl-2.0.txt)
+
+###
+
+needlexml2pcscmd = '''\
+ <xsl:variable name="RingNumber">
+ <xsl:choose>
+ <xsl:when test="@ringnumber">
+ <xsl:value-of select="@ringnumber"/>
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:value-of select="count(
+ preceding-sibling::interface[not(@ringnumber)]
+ )"/>
+ </xsl:otherwise>
+ <xsl:choose>
+ </xsl:variable>
+ <xsl:if test="$RingNumber &gt;= 0 or $RingNumber &lt;= 1">
+ <xsl:if test="@bindnetaddr">
+ <xsl:value-of select="concat(' --addr', $RingNumber, ' ', @bindnetaddr)"/>
+ </xsl:if>
+ <xsl:choose>
+ <xsl:when test="@broadcast = 'yes'">
+ <xsl:value-of select="concat(' --broadcast', $RingNumber)"/>
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:if test="@mcastaddr">
+ <xsl:value-of select="concat(' --mcast', $RingNumber, ' ', @mcastaddr)"/>
+ </xsl:if>
+ <xsl:if test="@mcastport">
+ <xsl:value-of select="concat(' --mcastport', $RingNumber, ' ', @mcastport)"/>
+ </xsl:if>
+ <xsl:if test="@ttl">
+ <xsl:value-of select="concat(' --ttl', $RingNumber, ' ', @ttl)"/>
+ </xsl:if>
+ <xsl:otherwise>
+ </xsl:choose>
+ </xsl:if>
+'''
diff --git a/filters/needlexml2pcscmd.py b/filters/needlexml2pcscmd.py
index 146adf2..88c5914 100644
--- a/filters/needlexml2pcscmd.py
+++ b/filters/needlexml2pcscmd.py
@@ -6,9 +6,33 @@
__author__ = "Jan Pokorný <jpokorny @at@ Red Hat .dot. com>"
from ..filter import XMLFilter
+from ..utils_xslt import xslt_params
-@XMLFilter.deco('coroxml-needle', 'string-list')
+@XMLFilter.deco('coroxml-needle', 'string-list', defs=dict(
+ pcscmd_force=False,
+ pcscmd_noauth=False,
+ pcscmd_verbose=True,
+ pcscmd_dryrun=False,
+ pcscmd_enable=False,
+ pcscmd_start_wait=60,
+ pcscmd_noguidance=0,
+))
def needlexml2pcscmd(flt_ctxt, in_obj):
"""Outputs set of pcs commands to reinstate the cluster per corosync.conf"""
- raise NotImplementedError("expected to come soon")
+ return (
+ 'bytestring',
+ flt_ctxt.ctxt_proceed_xslt(
+ in_obj,
+ textmode=True,
+ def_first=xslt_params(
+ pcscmd_force=flt_ctxt['pcscmd_force'],
+ pcscmd_noauth=flt_ctxt['pcscmd_noauth'],
+ pcscmd_verbose=flt_ctxt['pcscmd_verbose'],
+ pcscmd_dryrun=flt_ctxt['pcscmd_dryrun'],
+ pcscmd_enable=flt_ctxt['pcscmd_enable'],
+ pcscmd_start_wait=flt_ctxt['pcscmd_start_wait'],
+ pcscmd_noguidance=flt_ctxt['pcscmd_noguidance'],
+ ),
+ ),
+ )