summaryrefslogtreecommitdiffstats
path: root/filters/cib/configuration/__init__.py
blob: e7017c01249a0c6b114148a5a6399f621dff77e0 (plain)
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
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
# -*- coding: UTF-8 -*-
# Copyright 2016 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>"


cibprelude2cibcompact = '''\
    <clufter:descent-mix preserve-rest="true"/>
    <!-- strip empty optional elements -->
    <xsl:template match="fencing-topology[count(*) = 0]"/>
'''

###

from .... import package_name

cibcompact2cib = ('''\
    <xsl:template match="crm_config[
                             not(
                                 following-sibling::resources/primitive[
                                     @class = 'stonith'
                                 ]|following-sibling::resources/primitive[
                                     preceding-sibling::template[
                                         @class = 'stonith'
                                         and
                                         @id = current()/@template
                                     ]
                                 ]
                             )
                         ]">
        <xsl:copy>
            <xsl:comment> %(note_stonith)s </xsl:comment>
            <xsl:message>%(note_stonith)s</xsl:message>
            <cluster_property_set id="CRMCONFIG-bootstrap">
                <nvpair id="CRMCONFIG-bootstrap-STONITH-ENABLED"
                        name="stonith-enabled"
                        value="false"/>
            </cluster_property_set>
        </xsl:copy>
    </xsl:template>

    <xsl:template match="constraints">
        <xsl:copy>
            <xsl:for-each select="../resources/template[
                                      @provider = '%(package_name)s'
                                      and
                                      @type = 'temporary-failoverdomain'
                                  ]">
                <xsl:variable name="FailoverDomain" select="."/>
                <xsl:for-each select="../template[
                                        @provider = '%(package_name)s'
                                        and
                                        @type = 'temporary-service'
                                        and
                                        meta_attributes/nvpair[
                                            @name = 'domain'
                                        ]/@value = $FailoverDomain/@id
                                    ]">
                    <xsl:variable name="Service" select="."/>
                    <xsl:variable name="Resources"
                                  select="../primitive[
                                              meta_attributes/nvpair[
                                                  @name = 'rgmanager-service'
                                                  and
                                                  @value = $Service/@id
                                              ]
                                          ]
                                          |
                                          ../group[
                                            @id = concat($Service/@id, '-GROUP')
                                          ]"/>
                    <xsl:for-each select="$Resources">
                        <xsl:variable name="Resource" select="."/>

                        <!-- rsc_location ~ failoverdomain/failoverdomainnodes -->

                        <xsl:if test="count(
                                          $FailoverDomain/meta_attributes/nvpair[
                                              starts-with(@name, 'failoverdomainnode-')
                                          ]
                                      ) != 0">
                            <rsc_location id="CONSTRAINT-LOCATION-{$Resource/@id}"
                                          rsc="{$Resource/@id}">
                                <xsl:comment
                                ><xsl:value-of select="concat(' mimic failoverdomain (',
                                                              substring-after($FailoverDomain/@id, 'FAILOVERDOMAIN-'),
                                                              ') for ', $Service/@id, ' ')"
                                /></xsl:comment>
                                <xsl:for-each select="$FailoverDomain/meta_attributes/nvpair[
                                                          starts-with(@name, 'failoverdomainnode-')
                                                      ]">
                                    <rule id="CONSTRAINT-LOCATION-{$Resource/@id}-{@value}">
                                        <xsl:attribute name="score">
                                            <xsl:choose>
                                                <xsl:when test="$FailoverDomain/meta_attributes/nvpair[
                                                                    @name = 'ordered'
                                                                ]/@value = 1
                                                                and
                                                                number(
                                                                    substring-after(@name,
                                                                                    'failoverdomainnode-')
                                                                ) &gt; 0">
                                                    <xsl:variable name="Result"
                                                                  select="(101 - number(
                                                                              substring-after(@name,
                                                                                              'failoverdomainnode-')
                                                                          )) * 10000"/>
                                                    <xsl:choose>
                                                        <xsl:when test="$Result = 1000000">
                                                            <xsl:value-of select="'INFINITY'"/>
                                                        </xsl:when>
                                                        <xsl:otherwise>
                                                            <xsl:value-of select="$Result"/>
                                                        </xsl:otherwise>
                                                    </xsl:choose>
                                                </xsl:when>
                                                <xsl:when test="$FailoverDomain/meta_attributes/nvpair[
                                                                    @name = 'ordered'
                                                                ]/@value = 1">
                                                    <xsl:value-of select="500000"/>
                                                </xsl:when>
                                                <xsl:otherwise>
                                                    <xsl:value-of select="'INFINITY'"/>
                                                </xsl:otherwise>
                                            </xsl:choose>
                                        </xsl:attribute>
                                        <expression id="CONSTRAINT-LOCATION-{$Resource/@id}-{@value}-expr"
                                                    attribute="#uname"
                                                    operation="eq"
                                                    value="{@value}"/>
                                    </rule>
                                </xsl:for-each>
                                <xsl:if test="$FailoverDomain/meta_attributes/nvpair[
                                                  @name = 'restricted'
                                              ]/@value = 1">
                                    <xsl:comment
                                    ><xsl:value-of select="concat(' mimic RESTRICTED failoverdomain (',
                                                                  substring-after($FailoverDomain/@id, 'FAILOVERDOMAIN-'),
                                                                  ') for ', $Service/@id, ' ')"
                                    /></xsl:comment>
                                    <rule id="CONSTRAINT-LOCATION-{$Resource/@id}-RESTRICTED"
                                          boolean-op="and"
                                          score="-INFINITY">
                                        <xsl:choose>
                                            <xsl:when test="$FailoverDomain/meta_attributes/nvpair[
                                                                starts-with(@name, 'failoverdomainnode-')
                                                            ]">
                                                <xsl:for-each select="$FailoverDomain/meta_attributes/nvpair[
                                                                          starts-with(@name, 'failoverdomainnode-')
                                                                      ]">
                                                    <expression id="CONSTRAINT-LOCATION-{$Resource/@id}-RESTRICTED-{@value}-expr"
                                                                attribute="#uname"
                                                                operation="ne"
                                                                value="{@value}"/>
                                                </xsl:for-each>
                                            </xsl:when>
                                            <xsl:otherwise>
                                                <!-- see filters/ccs-revitalize[failoverdomains]:
                                                     warn on empty restricted failoverdomains -->
                                                <expression id="CONSTRAINT-LOCATION-{$Resource/@id}-RESTRICTED-all-expr"
                                                            attribute="#uname"
                                                            operation="defined"/>
                                            </xsl:otherwise>
                                        </xsl:choose>
                                    </rule>
                                </xsl:if>
                            </rsc_location>
                        </xsl:if>
                    </xsl:for-each>
                    <xsl:if test="count($Resources) &gt; 1">
                        <rsc_order id="CONSTRAINT-ORDER-{$Service/@id}"
                                score="INFINITY">
                            <resource_set id="CONSTRAINT-ORDER-{$Service/@id}-RESOURCES">
                                <xsl:for-each select="$Resources">
                                    <resource_ref id="{@id}"/>
                                </xsl:for-each>
                            </resource_set>
                        </rsc_order>
                    </xsl:if>
                </xsl:for-each>
            </xsl:for-each>
        </xsl:copy>
    </xsl:template>
''') % dict(
    note_stonith="NOTE: no fencing is configured hence stonith is disabled;"
                 " please note, however, that this is suboptimal, especially"
                 " in shared storage scenarios",
    package_name=package_name()
)

###

from ....filters._2pcscmd import verbose_ec_test, verbose_inform
from ....utils_xslt import NL

cib2pcscmd = ('''\
    <xsl:if test="not($pcscmd_dryrun) and $pcscmd_tmpcib">
''' + (
        verbose_inform('"get initial/working CIB: ", $pcscmd_tmpcib')
) + '''
        <xsl:value-of select="concat('pcs cluster cib ',
                                     $pcscmd_tmpcib, ' --config')"/>
        <xsl:value-of select="'%(NL)s'"/>
''' + (
        verbose_ec_test
) + '''
    </xsl:if>
    <clufter:descent-mix at="crm_config"/>
    <clufter:descent-mix at="rsc_defaults"/>
    <clufter:descent-mix at="op_defaults"/>
    <clufter:descent-mix at="nodes"/>
    <clufter:descent-mix at="resources"/>
    <clufter:descent-mix at="constraints"/>
    <clufter:descent-mix at="fencing-topology"/>
    <xsl:if test="not($pcscmd_dryrun) and $pcscmd_tmpcib">
''' + (
        verbose_inform('"push CIB: ", $pcscmd_tmpcib')
) + '''
        <xsl:value-of select="concat('pcs cluster cib-push ',
                                     $pcscmd_tmpcib, ' --config')"/>
        <xsl:value-of select="'%(NL)s'"/>
''' + (
        verbose_ec_test
) + '''
    </xsl:if>
''') % dict(
    NL=NL,
)

###

from ....utils_xslt import xslt_is_member, xslt_string_mapping

cib_revitalize_deprecated_props_cluster_rsc = {
    'default-resource-stickiness': 'resource-stickiness',
    'is-managed-default':          'is-managed',
}

cib_revitalize_deprecated_props_cluster_op = {
    'default-action-timeout': 'timeout',
}

cib_revitalize_deprecated_props_cluster = \
    cib_revitalize_deprecated_props_cluster_rsc.keys() \
    + cib_revitalize_deprecated_props_cluster_op.keys()

cib_revitalize = ('''\
    <xsl:copy>

    <!-- nested handling of crm_config: drop the innovated nvpairs -->
    <clufter:descent-mix at="crm_config"/>

    <!-- move deprecated crm_config properties to rsc_defaults -->
    <xsl:choose>
        <xsl:when test="crm_config/cluster_property_set/nvpair[
''' + (
                             xslt_is_member('@name',
                                            cib_revitalize_deprecated_props_cluster_rsc)
) + ''']">
            <rsc_defaults>
                <xsl:apply-templates select="rsc_defaults/nvpair"/>
                <xsl:for-each select="crm_config/cluster_property_set[nvpair[
''' + (
                             xslt_is_member('@name',
                                            cib_revitalize_deprecated_props_cluster_rsc)
) + ''']]">
                    <meta_attributes id="{concat(@id, '-', generate-id(.))}">
                    <!-- XXX make rewrite-id a generalized helper -->
                    <!-- xsl:if test="rule">
                        <xsl:call-template name="rewrite-id">
                            <xsl:with-param name="Elem" select="rule"/>
                            <xsl:with-param name="InstanceId" select="generate-id(rule)"/>
                        </xsl:call-template>
                    </xsl:if -->
                    <xsl:for-each select="nvpair[
''' + (
                             xslt_is_member('@name',
                                            cib_revitalize_deprecated_props_cluster_rsc)
) + ''']">
                        <nvpair id="{concat(@id, '-', generate-id(.))}">
                            <xsl:attribute name="name">
                                <xsl:choose>
''' + (
                                xslt_string_mapping(cib_revitalize_deprecated_props_cluster_rsc, '@name')
) + '''
                                </xsl:choose>
                            </xsl:attribute>
                            <xsl:attribute name="value">
                                <xsl:value-of select="@value"/>
                            </xsl:attribute>
                        </nvpair>
                    </xsl:for-each>
                    </meta_attributes>
                    <xsl:apply-templates select="rsc_defaults/score"/>
                </xsl:for-each>
            </rsc_defaults>
        </xsl:when>
        <xsl:otherwise>
            <xsl:apply-templates select="rsc_defaults"/>
        </xsl:otherwise>
    </xsl:choose>

    <!-- move deprecated crm_config properties to op_defaults -->
    <xsl:choose>
        <xsl:when test="crm_config/cluster_property_set/nvpair[
''' + (
                             xslt_is_member('@name',
                                            cib_revitalize_deprecated_props_cluster_op)
) + ''']">
            <op_defaults>
                <xsl:apply-templates select="op_defaults/nvpair"/>
                <xsl:for-each select="crm_config/cluster_property_set[nvpair[
''' + (
                             xslt_is_member('@name',
                                            cib_revitalize_deprecated_props_cluster_op)
) + ''']]">
                    <meta_attributes id="{concat(@id, '-', generate-id(.))}">
                    <!-- XXX make rewrite-id a generalized helper -->
                    <!-- xsl:if test="rule">
                        <xsl:call-template name="rewrite-id">
                            <xsl:with-param name="Elem" select="rule"/>
                            <xsl:with-param name="InstanceId" select="generate-id(rule)"/>
                        </xsl:call-template>
                    </xsl:if -->
                    <xsl:for-each select="nvpair[
''' + (
                             xslt_is_member('@name',
                                            cib_revitalize_deprecated_props_cluster_op)
) + ''']">
                        <nvpair id="{concat(@id, generate-id(.))}">
                            <xsl:attribute name="name">
                                <xsl:choose>
''' + (
                                xslt_string_mapping(cib_revitalize_deprecated_props_cluster_op)
) + '''
                                </xsl:choose>
                            </xsl:attribute>
                            <xsl:attribute name="value">
                                <xsl:value-of select="."/>
                            </xsl:attribute>
                        </nvpair>
                    </xsl:for-each>
                    </meta_attributes>
                    <xsl:apply-templates select="op_defaults/score"/>
                </xsl:for-each>
            </op_defaults>
        </xsl:when>
        <xsl:otherwise>
            <xsl:apply-templates select="op_defaults"/>
        </xsl:otherwise>
    </xsl:choose>

    <xsl:apply-templates select="*[not(
''' + (
        xslt_is_member('name()',
                       ('crm_config', 'rsc_defaults', 'op_defaults'))
) + ''')]"/>

    </xsl:copy>
''')