File: DrbdRole.cpp

package info (click to toggle)
drbd-utils 9.5.0-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 5,388 kB
  • sloc: ansic: 43,698; xml: 15,968; cpp: 7,783; sh: 3,699; makefile: 1,353; perl: 353
file content (49 lines) | stat: -rw-r--r-- 1,182 bytes parent folder | download | duplicates (2)
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
#include <DrbdRole.h>

const std::string DrbdRole::PROP_KEY_ROLE = "role";

const char* DrbdRole::ROLE_LABEL_PRIMARY   = "Primary";
const char* DrbdRole::ROLE_LABEL_SECONDARY = "Secondary";
const char* DrbdRole::ROLE_LABEL_UNKNOWN   = "Unknown";

DrbdRole::resource_role DrbdRole::get_role() const
{
    return role;
}

const char* DrbdRole::get_role_label() const
{
    const char* label = ROLE_LABEL_UNKNOWN;
    switch (role)
    {
        case DrbdRole::resource_role::PRIMARY:
            label = ROLE_LABEL_PRIMARY;
            break;
        case DrbdRole::resource_role::SECONDARY:
            label = ROLE_LABEL_SECONDARY;
            break;
        case DrbdRole::resource_role::UNKNOWN:
            // fall-through
        default:
            break;
    }
    return label;
}

// @throws EventMessageException
DrbdRole::resource_role DrbdRole::parse_role(std::string& role_name)
{
    DrbdRole::resource_role role = DrbdRole::resource_role::UNKNOWN;

    if (role_name == "Primary")
    {
        role = DrbdRole::resource_role::PRIMARY;
    }
    else
    if (role_name == "Secondary")
    {
        role = DrbdRole::resource_role::SECONDARY;
    }

    return role;
}