pacemaker  3.0.0-d8340737c4
Scalable High-Availability cluster resource manager
roles.c
Go to the documentation of this file.
1 /*
2  * Copyright 2004-2024 the Pacemaker project contributors
3  *
4  * The version control history for this file may have further details.
5  *
6  * This source code is licensed under the GNU Lesser General Public License
7  * version 2.1 or later (LGPLv2.1+) WITHOUT ANY WARRANTY.
8  */
9 
10 #include <crm_internal.h>
11 
12 #include <crm/common/scheduler.h>
14 
22 const char *
24 {
25  switch (role) {
26  case pcmk_role_stopped:
27  return PCMK_ROLE_STOPPED;
28 
29  case pcmk_role_started:
30  return PCMK_ROLE_STARTED;
31 
33  return PCMK_ROLE_UNPROMOTED;
34 
35  case pcmk_role_promoted:
36  return PCMK_ROLE_PROMOTED;
37 
38  default: // pcmk_role_unknown
39  return PCMK__ROLE_UNKNOWN;
40  }
41 }
42 
50 enum rsc_role_e
51 pcmk_parse_role(const char *role)
52 {
53  if (pcmk__str_eq(role, PCMK__ROLE_UNKNOWN,
55  return pcmk_role_unknown;
56  } else if (pcmk__str_eq(role, PCMK_ROLE_STOPPED, pcmk__str_casei)) {
57  return pcmk_role_stopped;
58  } else if (pcmk__str_eq(role, PCMK_ROLE_STARTED, pcmk__str_casei)) {
59  return pcmk_role_started;
60  } else if (pcmk__str_eq(role, PCMK__ROLE_UNPROMOTED_LEGACY, pcmk__str_casei)) {
62  "Support for the " PCMK__ROLE_UNPROMOTED_LEGACY
63  " role is deprecated and will be removed in a "
64  "future release. Use " PCMK_ROLE_UNPROMOTED
65  " instead.");
66  return pcmk_role_unpromoted;
67  } else if (pcmk__str_eq(role, PCMK_ROLE_UNPROMOTED, pcmk__str_casei)) {
68  return pcmk_role_unpromoted;
69  } else if (pcmk__str_eq(role, PCMK__ROLE_PROMOTED_LEGACY, pcmk__str_casei)) {
71  "Support for the " PCMK__ROLE_PROMOTED_LEGACY
72  " role is deprecated and will be removed in a "
73  "future release. Use " PCMK_ROLE_PROMOTED
74  " instead.");
75  return pcmk_role_promoted;
76  } else if (pcmk__str_eq(role, PCMK_ROLE_PROMOTED, pcmk__str_casei)) {
77  return pcmk_role_promoted;
78  }
79  return pcmk_role_unknown; // Invalid role given
80 }
Stopped.
Definition: roles.h:36
Promoted.
Definition: roles.h:39
const char * pcmk_role_text(enum rsc_role_e role)
Get readable description of a resource role.
Definition: roles.c:23
Scheduler API.
#define PCMK__ROLE_PROMOTED_LEGACY
#define PCMK__ROLE_UNPROMOTED_LEGACY
#define PCMK_ROLE_STOPPED
Definition: roles.h:25
Unpromoted.
Definition: roles.h:38
rsc_role_e
Definition: roles.h:34
enum rsc_role_e pcmk_parse_role(const char *role)
Parse a resource role from a string role specification.
Definition: roles.c:51
#define pcmk__warn_once(wo_flag, fmt...)
#define PCMK__ROLE_UNKNOWN
#define PCMK_ROLE_PROMOTED
Definition: roles.h:28
#define PCMK_ROLE_STARTED
Definition: roles.h:26
Started.
Definition: roles.h:37
#define PCMK_ROLE_UNPROMOTED
Definition: roles.h:27
Resource role is unknown.
Definition: roles.h:35