-
Notifications
You must be signed in to change notification settings - Fork 0
/
cluconf2cib.xsl
242 lines (213 loc) · 7.61 KB
/
cluconf2cib.xsl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
<?xml version="1.0" ?>
<!-- Convert a flattened cluster.conf into a cib.xml -->
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:cluster="http://dev/null"
version="2.0">
<xsl:output method="xml" indent="yes"/>
<xsl:function name="cluster:normalize">
<xsl:param name="val"/>
<xsl:value-of select="translate($val, ': .=', '____')"/>
</xsl:function>
<!-- transpose failover domain score -->
<!-- TODO - make order of magnitude? -->
<xsl:function name="cluster:domscore">
<xsl:param name="val"/>
<xsl:param name="prioritized"/>
<xsl:choose>
<xsl:when test="($prioritized = 1)">
<xsl:choose>
<xsl:when test="($val >= 1)">
<xsl:value-of select="(101-$val)*10000"/>
</xsl:when>
<xsl:otherwise>
500000
</xsl:otherwise>
</xsl:choose>
</xsl:when>
<xsl:otherwise>
1000000
</xsl:otherwise>
</xsl:choose>
</xsl:function>
<xsl:function name="cluster:textify-score">
<xsl:param name="val"/>
<xsl:choose>
<xsl:when test="(number($val) = 1000000)">INFINITY</xsl:when>
<xsl:when test="(number($val) = -1000000)">-INFINITY</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$val"/>
</xsl:otherwise>
</xsl:choose>
</xsl:function>
<xsl:function name="cluster:getname">
<xsl:param name="ele" as="element()" />
<xsl:value-of select="$ele" />
</xsl:function>
<xsl:function name="cluster:makeresname">
<xsl:param name="ele" as="element()" />
<xsl:choose>
<xsl:when test="name($ele) = 'ip'">
<xsl:sequence select="concat(name($ele),'_',cluster:normalize($ele/@address))"/>
</xsl:when>
<xsl:otherwise>
<xsl:sequence select="concat(name($ele),'_',cluster:normalize($ele/@name))"/>
</xsl:otherwise>
</xsl:choose>
</xsl:function>
<!-- STONITH host map generator -->
<xsl:function name="cluster:stonith-map-int" >
<xsl:param name="device" />
<xsl:param name="pos" as="element()" />
<xsl:for-each select="$pos/../../clusternodes/clusternode">
<xsl:variable name="node" select="@name"/>
<xsl:for-each select="fence/method/device[@name=$device]">
<xsl:if test="$node != @port" >
<xsl:sequence select="concat($node,':',@port)"/>
</xsl:if>
</xsl:for-each>
</xsl:for-each>
</xsl:function>
<xsl:function name="cluster:stonith-host-map" >
<xsl:param name="device" />
<xsl:param name="pos" as="element()" />
<xsl:variable name="ret" select="cluster:stonith-map-int($device,$pos)" />
<xsl:sequence select="string-join($ret,',')" />
</xsl:function>
<!-- STONITH host list generator -->
<xsl:function name="cluster:stonith-host-list" >
<xsl:param name="device" />
<xsl:param name="pos" as="element()" />
<xsl:for-each select="$pos/../../clusternodes/clusternode">
<xsl:variable name="node" select="@name"/>
<xsl:for-each select="fence/method/device[@name=$device]">
<xsl:sequence select="$node"/>
</xsl:for-each>
</xsl:for-each>
</xsl:function>
<xsl:template match="service" mode="#default">
<!-- Pacemaker doesn't like empty groups -->
<xsl:if test="child::*">
<group id="{concat('service_', @name)}">
<xsl:for-each select="child::*">
<xsl:variable name="resname" select="cluster:makeresname(self::node())"/>
<!-- rgmanager uses the agent-supplied "class"; pacemaker
uses the agent script itself as the type -->
<primitive class="ocf" id="{$resname}" provider="redhat" type="{@rgmanager-meta-agent}" >
<instance_attributes id="{$resname}_inst_attrs" >
<xsl:for-each select="@*">
<nvpair id="{$resname}_{name()}" name="{name()}" value="{.}" />
</xsl:for-each>
</instance_attributes>
</primitive>
</xsl:for-each>
</group>
</xsl:if>
</xsl:template>
<xsl:template match="vm" mode="#default">
<xsl:variable name="resname" select="cluster:makeresname(self::node())"/>
<primitive class="ocf" id="{$resname}" provider="redhat" type="{.}" >
<instance_attributes id="{$resname}_inst_attrs" >
<xsl:for-each select="@*">
<nvpair id="{$resname}_{name()}" name="{name()}" value="{.}" />
</xsl:for-each>
</instance_attributes>
</primitive>
</xsl:template>
<!-- Failover Domains -->
<!-- Node definition:
failoverdomainnode -> node
priority (1..100) -> value, 1000000 .. 1000;
(101-priority)*10000
-->
<xsl:template match="failoverdomainnode">
<node name="{@name}" score="{cluster:textify-score(format-number(cluster:domscore(@priority,../@ordered),'#'))}"/>
</xsl:template>
<!-- failoverdomain definition:
failoverdomain -> domain
name -> id
ordered -> N/A
restricted -> N/A
-->
<xsl:template match="failoverdomain" mode="#default">
<domain id="{@name}">
<xsl:apply-templates select="failoverdomainnode"/>
</domain>
</xsl:template>
<xsl:template match="failoverdomains" mode="#default">
<domains><xsl:apply-templates select="failoverdomain"/>
</domains>
</xsl:template>
<!-- Service / VMs - link with domain constraint -->
<xsl:template match="service|vm" mode="domlink">
<xsl:variable name="resname" select="cluster:makeresname(self::node())"/>
<xsl:if test="@domain">
<rsc_location id="{$resname}_{@domain}" rsc="{$resname}" domain="{@domain}"/>
</xsl:if>
</xsl:template>
<!-- rgmanager tag handling -->
<xsl:template match="rm" mode="#default">
<xsl:apply-templates select="failoverdomains"/>
<resources>
<xsl:apply-templates select="service|vm" />
<!-- todo: STONITH resources here -->
<xsl:apply-templates select="../fencedevices" />
</resources>
<constraints>
<xsl:apply-templates select="service|vm" mode="domlink"/>
</constraints>
</xsl:template>
<xsl:template match="clusternode" mode="#default">
<node id="{@name}" uname="{@name}" type="normal"/>
</xsl:template>
<xsl:template match="clusternodes" mode="#default">
<nodes><xsl:apply-templates select="clusternode"/>
</nodes>
</xsl:template>
<!-- STONITH configuration -->
<xsl:template match="fencedevice" mode="#default">
<xsl:variable name="name" select="concat('st_',@name)"/>
<primitive class="stonith" id="{$name}" type="{@agent}">
<operations>
<op id="{$name}_mon" name="monitor" interval="120s"/>
</operations>
<instance_attributes id="{$name}_attrs">
<xsl:for-each select="@*">
<xsl:choose>
<xsl:when test="name() = 'name'" />
<xsl:when test="name() = 'agent'" />
<xsl:otherwise>
<nvpair id="{$name}_{name()}" name="{name()}" value="{.}" />
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
<xsl:variable name="hostlist" select="cluster:stonith-host-list(@name,self::node())" />
<xsl:variable name="hostmap" select="cluster:stonith-host-map(@name,self::node())" />
<xsl:if test="$hostlist != ''" >
<nvpair id="{$name}_hosts" name="pcmk_host_list" value="{$hostlist}"/>
</xsl:if>
<xsl:if test="$hostmap != ''" >
<nvpair id="{$name}_map" name="pcmk_host_map" value="{$hostmap}"/>
</xsl:if>
</instance_attributes>
</primitive>
</xsl:template>
<xsl:template match="fencedevices" mode="#default">
<xsl:apply-templates select="fencedevice" />
</xsl:template>
<xsl:template match="/cluster">
<cib validate-with="pacemaker-1.1" admin_epoch="1" epoch="1" num_updates="0" have-quorum="1">
<configuration>
<crm_config>
<cluster_property_set id="cib-bootstrap-options">
<nvpair id="startup-fencing" name="startup-fencing" value="true"/>
<nvpair id="stonith-enabled" name="stonith-enabled" value="true"/>
<nvpair id="default-resource-stickiness" name="default-resource-stickiness" value="INFINITY"/>
</cluster_property_set>
</crm_config>
<xsl:apply-templates select="clusternodes"/>
<xsl:apply-templates select="rm"/>
</configuration>
<status/>
</cib>
</xsl:template>
</xsl:stylesheet>