summaryrefslogtreecommitdiffstats
path: root/lib/common/roles.c
blob: 96aa72a511cd6b0195dd78fced1d10ea436cb5f8 (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
/*
 * Copyright 2004-2024 the Pacemaker project contributors
 *
 * The version control history for this file may have further details.
 *
 * This source code is licensed under the GNU Lesser General Public License
 * version 2.1 or later (LGPLv2.1+) WITHOUT ANY WARRANTY.
 */

#include <crm_internal.h>

#include <crm/common/scheduler.h>
#include <crm/common/scheduler_internal.h>

/*!
 * \brief Get readable description of a resource role
 *
 * \param[in] role  Resource role
 *
 * \return Static string describing \p role, suitable for logging or display
 */
const char *
pcmk_role_text(enum rsc_role_e role)
{
    switch (role) {
        case pcmk_role_stopped:
            return PCMK_ROLE_STOPPED;

        case pcmk_role_started:
            return PCMK_ROLE_STARTED;

        case pcmk_role_unpromoted:
#ifdef PCMK__COMPAT_2_0
            return PCMK__ROLE_UNPROMOTED_LEGACY;
#else
            return PCMK_ROLE_UNPROMOTED;
#endif

        case pcmk_role_promoted:
#ifdef PCMK__COMPAT_2_0
            return PCMK__ROLE_PROMOTED_LEGACY;
#else
            return PCMK_ROLE_PROMOTED;
#endif

        default: // pcmk_role_unknown
            return PCMK__ROLE_UNKNOWN;
    }
}

/*!
 * \brief Parse a resource role from a string role specification
 *
 * \param[in] role  Role specification
 *
 * \return Resource role corresponding to \p role
 */
enum rsc_role_e
pcmk_parse_role(const char *role)
{
    if (pcmk__str_eq(role, PCMK__ROLE_UNKNOWN,
                     pcmk__str_casei|pcmk__str_null_matches)) {
        return pcmk_role_unknown;
    } else if (pcmk__str_eq(role, PCMK_ROLE_STOPPED, pcmk__str_casei)) {
        return pcmk_role_stopped;
    } else if (pcmk__str_eq(role, PCMK_ROLE_STARTED, pcmk__str_casei)) {
        return pcmk_role_started;
    } else if (pcmk__str_eq(role, PCMK__ROLE_UNPROMOTED_LEGACY, pcmk__str_casei)) {
        pcmk__warn_once(pcmk__wo_slave_role,
                        "Support for the " PCMK__ROLE_UNPROMOTED_LEGACY
                        " role is deprecated and will be removed in a "
                        "future release. Use " PCMK_ROLE_UNPROMOTED
                        " instead.");
        return pcmk_role_unpromoted;
    } else if (pcmk__str_eq(role, PCMK_ROLE_UNPROMOTED, pcmk__str_casei)) {
        return pcmk_role_unpromoted;
    } else if (pcmk__str_eq(role, PCMK__ROLE_PROMOTED_LEGACY, pcmk__str_casei)) {
        pcmk__warn_once(pcmk__wo_master_role,
                        "Support for the " PCMK__ROLE_PROMOTED_LEGACY
                        " role is deprecated and will be removed in a "
                        "future release. Use " PCMK_ROLE_PROMOTED
                        " instead.");
        return pcmk_role_promoted;
    } else if (pcmk__str_eq(role, PCMK_ROLE_PROMOTED, pcmk__str_casei)) {
        return pcmk_role_promoted;
    }
    return pcmk_role_unknown; // Invalid role given
}