summaryrefslogtreecommitdiffstats
path: root/commands/ccs2pcs.py
blob: 9dc91d1f77783e933c868151d9e24bbeec192805 (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
# -*- coding: UTF-8 -*-
# Copyright 2014 Red Hat, Inc.
# Part of clufter project
# Licensed under GPLv2+ (a copy included | http://gnu.org/licenses/gpl-2.0.txt)
"""ccs2pcs command"""
__author__ = "Jan Pokorný <jpokorny @at@ Red Hat .dot. com>"

from ..command import Command, CommandAlias


@Command.deco(('ccs2flatccs',
                  ('ccs2ccs-pcmk'),
                  ('flatccs2pcs',
                      ('pcs2simplepcs')),
                  ('ccs2flatironxml',
                      ('xml2simpleconfig'))))
def ccs2pcs_flatiron(cmd_ctxt,
                     input="/etc/cluster/cluster.conf",
                     ccs_pcmk="./cluster.conf",
                     cib="./cib.xml",
                     coro="./corosync.conf",
                     nocheck=False,
                     raw=False):
    """CMAN -> Pacemaker-based cluster config. (corosync v1)

    More specifically, the output is suitable for Pacemaker integrated
    with Corosync ver. 1 (Flatiron) as present, e.g., in el6.{5, ..},
    and consists of Pacemaker pass-through CMAN configuration (~cluster.conf)
    along with Pacemaker (~cib.xml) and corosync ones (~corosync.conf).

    Options:
        input     input CMAN-based cluster configuration file
        ccs_pcmk  output Pacemaker pass-through CMAN configuration
        cib       output Pacemaker-based cluster configuration file
        coro      output Corosync v1 configuration file
        nocheck   do not validate any step (even if self-checks present)
        raw       do not ensure pretty-printed output where applicable
    """
    cmd_ctxt.filter()['raw'] = raw
    cmd_ctxt.filter()['validate'] = not nocheck
    return (
        ('file', input),
        (
            ('file', ccs_pcmk),
            (
                ('file', cib),
            ),
            (
                ('file', coro),
            )
        )
    )


@Command.deco(('ccs2flatccs',
                  ('flatccs2pcs',
                      ('pcs2simplepcs')),
                  ('ccs2needlexml',
                      ('xml2simpleconfig'))))
def ccs2pcs_needle(cmd_ctxt,
                   input="/etc/cluster/cluster.conf",
                   cib="./cib.xml",
                   coro="./corosync.conf",
                   nocheck=False,
                   raw=False):
    """CMAN -> Pacemaker-based cluster config. (corosync v2)

    More specifically, the output is suitable for Pacemaker integrated
    with Corosync ver. 2 (Needle) as present, e.g., in el7, and consists
    of Pacemaker (~cib.xml) and corosync (~corosync.conf) configurations.

    Options:
        input    input CMAN-based cluster configuration file
        cib      output Pacemaker-based cluster configuration file
        coro     output Corosync v2 configuration file
        nocheck  do not validate any step (even if self-checks present)
        raw      do not ensure pretty-printed output where applicable
    """
    cmd_ctxt.filter()['raw'] = raw
    cmd_ctxt.filter()['validate'] = not nocheck
    return (
        ('file', input),
        (
            (
                ('file', cib),
            ),
            (
                ('file', coro),
            )
        )
    )


@CommandAlias.deco
def ccs2pcs(cmds, system, system_extra):
    # unless el <7.0 (XXX identification of SL and other derivates unknown)
    if system == 'Linux' and system_extra[0] in ('redhat', 'centos'):
        v = system_extra[1] if system_extra else '7'  # default if undecidable
        v = v[:-len(v.lstrip('0123456789.'))] or str.isdigit(v[0]) and v or '0'
        v = tuple(map(int, (v.rstrip('.') + '.0.0').split('.')[:2]))
        if v < (7, 0):
            return 'ccs2pcs-flatiron'
    return 'ccs2pcs-needle'