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
|
# -*- 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)
"""cib2pcscmd filter"""
__author__ = "Jan Pokorný <jpokorny @at@ Red Hat .dot. com>"
from ..filter import XMLFilter
from ..filters._2pcscmd import verbose_ec_test, verbose_inform
from ..utils_xml import squote
from ..utils_xslt import NL, xslt_params
def attrset_xsl(attrset, cmd=None, inform=None):
return ('''\
<xsl:if test="{attrset}/nvpair">
<xsl:choose>
<xsl:when test="{attrset}/rule">
<xsl:message>
<!-- TODO:PCS -->
<xsl:value-of select="concat('WARNING: has to skip rule-based',
' {attrset} ', @id,
' (rhbz#1250744)')"/>
</xsl:message>
</xsl:when>
<xsl:otherwise>
''' + (
(verbose_inform(inform) + '\n' if inform else '')
+
('''<xsl:value-of select='concat("", {cmd})'/>'''
if cmd else '')
) + '''
<xsl:for-each select="{attrset}">
<xsl:for-each select="nvpair">
<xsl:value-of select='concat(" '",
@name, "=", @value,
"'")'/>
</xsl:for-each>
</xsl:for-each>
''' + (
('''<xsl:value-of select="'{NL}'"/>''' + '\n'
+ verbose_ec_test) if cmd else ''
) + '''
</xsl:otherwise>
</xsl:choose>
</xsl:if>
''').format(NL=NL, attrset=attrset, cmd=cmd)
@XMLFilter.deco('cib', 'string-list', defs=dict(
pcscmd_force=False,
pcscmd_verbose=True,
pcscmd_tmpcib='tmp-cib.xml',
pcscmd_dryrun=False,
))
def cib2pcscmd(flt_ctxt, in_obj):
"""Outputs set of pcs commands to reinstate the cluster per existing CIB"""
self = flt_ctxt.ctxt_wrapped
dry_run, tmp_cib = flt_ctxt['pcscmd_dryrun'], flt_ctxt['pcscmd_tmpcib']
tmp_cib = (tmp_cib or self.defs['pcscmd_tmpcib']) if dry_run else tmp_cib
return (
'bytestring',
flt_ctxt.ctxt_proceed_xslt(
in_obj,
textmode=True,
def_first=xslt_params(
pcscmd_force=flt_ctxt['pcscmd_force'],
pcscmd_verbose=flt_ctxt['pcscmd_verbose'],
pcscmd_tmpcib=squote(flt_ctxt['pcscmd_tmpcib']),
pcscmd_dryrun=dry_run,
pcscmd_pcs=squote("pcs -f {0} ".format(tmp_cib)
if tmp_cib else "pcs "),
),
),
)
|