summaryrefslogtreecommitdiffstats
path: root/filters
diff options
context:
space:
mode:
authorJan Pokorný <jpokorny@redhat.com>2015-12-04 23:01:02 +0100
committerJan Pokorný <jpokorny@redhat.com>2015-12-17 23:36:18 +0100
commita754cc71e11ebdeb3b867cfd9c075d01a1a98642 (patch)
tree4c458b89b2883d3466a64408ed8a369097fd9448 /filters
parent34592f289fa9a62e4f1fe6b081a875186d599eb7 (diff)
downloadclufter-a754cc71e11ebdeb3b867cfd9c075d01a1a98642.tar.gz
clufter-a754cc71e11ebdeb3b867cfd9c075d01a1a98642.tar.xz
clufter-a754cc71e11ebdeb3b867cfd9c075d01a1a98642.zip
filters/cib-meld-templates: compensate pcs template incompat.
See <https://bugzilla.redhat.com/1281359>. Signed-off-by: Jan Pokorný <jpokorny@redhat.com>
Diffstat (limited to 'filters')
-rw-r--r--filters/cib/configuration/resources/__init__.py96
-rw-r--r--filters/cib_meld_templates.py12
2 files changed, 108 insertions, 0 deletions
diff --git a/filters/cib/configuration/resources/__init__.py b/filters/cib/configuration/resources/__init__.py
index 9865f7d..7349ce3 100644
--- a/filters/cib/configuration/resources/__init__.py
+++ b/filters/cib/configuration/resources/__init__.py
@@ -426,3 +426,99 @@ cib2pcscmd = ('''\
''') % dict(
NL=NL,
)
+
+###
+
+from ....utils_xslt import xslt_is_member
+
+cib_meld_templates_op_roles = ('Started', 'Slave')
+
+# see lib/pengine/complex.c: unpack_template
+cib_meld_templates = ('''\
+ <!-- drop any occurrence as we meld them into proper primitives -->
+ <xsl:template match="template"/>
+
+ <xsl:template name="rewrite-id">
+ <xsl:param name="Elem"/>
+ <xsl:param name="InstanceId"/>
+ <xsl:copy>
+ <xsl:for-each select="@*">
+ <xsl:choose>
+ <xsl:when test="name() = 'id'">
+ <xsl:attribute name="{name()}">
+ <xsl:value-of select="concat(., '-', $InstanceId)"/>
+ </xsl:attribute>
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:copy/>
+ </xsl:otherwise>
+ </xsl:choose>
+ </xsl:for-each>
+ <xsl:for-each select="*">
+ <xsl:call-template name="rewrite-id">
+ <xsl:with-param name="Elem" select="."/>
+ <xsl:with-param name="InstanceId" select="$InstanceId"/>
+ </xsl:call-template>
+ </xsl:for-each>
+ </xsl:copy>
+ </xsl:template>
+
+ <xsl:template match="primitive[@template]">
+ <xsl:variable name="Template"
+ select="//template[@id = current()/@template]"/>
+ <xsl:variable name="InstanceId" select="generate-id()"/>
+ <xsl:copy>
+ <xsl:copy-of select="@id|$Template/@*[name() != 'id']"/>
+ <xsl:for-each select="$Template/*[name() != 'operations']">
+ <xsl:call-template name="rewrite-id">
+ <xsl:with-param name="Elem" select="."/>
+ <xsl:with-param name="InstanceId" select="$InstanceId"/>
+ </xsl:call-template>
+ </xsl:for-each>
+ <xsl:for-each select="*">
+ <xsl:copy>
+ <xsl:copy-of select="@*"/>
+ <xsl:if test="name() = 'operations'">
+ <xsl:variable name="Operations" select="."/>
+ <xsl:for-each select="$Template/op[
+ not(
+ $Operations/op[
+ @name = current()/@name
+ and
+ (
+ @role = current()/@role
+ or
+ ((
+ not(@role)
+ or
+''' + (
+ xslt_is_member('@role',
+ cib_meld_templates_op_roles)
+) + '''
+ ) and (
+ not(current()/@role)
+ or
+''' + (
+ xslt_is_member('current()/@role',
+ cib_meld_templates_op_roles)
+) + '''
+
+ ))
+ )
+ ]
+ )
+ ]">
+ <xsl:call-template name="rewrite-id">
+ <xsl:with-param name="Elem" select="."/>
+ <xsl:with-param name="InstanceId" select="$InstanceId"/>
+ </xsl:call-template>
+ </xsl:for-each>
+ </xsl:if>
+ <xsl:if test="name() != 'operations'">
+ <xsl:apply-templates/>
+ </xsl:if>
+ </xsl:copy>
+ </xsl:for-each>
+ </xsl:copy>
+ </xsl:template>
+''')
diff --git a/filters/cib_meld_templates.py b/filters/cib_meld_templates.py
new file mode 100644
index 0000000..540f6f6
--- /dev/null
+++ b/filters/cib_meld_templates.py
@@ -0,0 +1,12 @@
+# -*- 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)
+"""cib-meld-templates filter"""
+__author__ = "Jan Pokorný <jpokorny @at@ Red Hat .dot. com>"
+
+from ..filter import XMLFilter
+
+
+@XMLFilter.deco_xslt('cib', 'cib')
+class cib_meld_templates: pass