pacemaker 2.1.5-a3f44794f94
Scalable High-Availability cluster resource manager
agents.c
Go to the documentation of this file.
1/*
2 * Copyright 2004-2021 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#ifndef _GNU_SOURCE
13# define _GNU_SOURCE
14#endif
15
16#include <stdio.h>
17#include <string.h>
18#include <strings.h>
19
20#include <crm/crm.h>
21#include <crm/common/util.h>
22
30uint32_t
31pcmk_get_ra_caps(const char *standard)
32{
33 /* @COMPAT This should probably be case-sensitive, but isn't,
34 * for backward compatibility.
35 */
36 if (standard == NULL) {
37 return pcmk_ra_cap_none;
38
39 } else if (!strcasecmp(standard, PCMK_RESOURCE_CLASS_OCF)) {
42
43 } else if (!strcasecmp(standard, PCMK_RESOURCE_CLASS_STONITH)) {
44 /* @COMPAT Stonith resources can't really be unique clones, but we've
45 * allowed it in the past and have it in some scheduler regression tests
46 * (which were likely never used as real configurations).
47 *
48 * @TODO Remove pcmk_ra_cap_unique at the next major schema version
49 * bump, with a transform to remove globally-unique from the config.
50 */
53
54 } else if (!strcasecmp(standard, PCMK_RESOURCE_CLASS_SYSTEMD)
55 || !strcasecmp(standard, PCMK_RESOURCE_CLASS_SERVICE)
56 || !strcasecmp(standard, PCMK_RESOURCE_CLASS_LSB)
57 || !strcasecmp(standard, PCMK_RESOURCE_CLASS_UPSTART)) {
58
59 /* Since service can map to LSB, systemd, or upstart, these should
60 * have identical capabilities
61 */
62 return pcmk_ra_cap_status;
63
64 } else if (!strcasecmp(standard, PCMK_RESOURCE_CLASS_NAGIOS)) {
65 return pcmk_ra_cap_params;
66 }
67 return pcmk_ra_cap_none;
68}
69
70int
72{
73 int remapped_rc = rc;
74
75 switch (rc) {
77 remapped_rc = PCMK_OCF_OK;
78 break;
79
81 remapped_rc = PCMK_OCF_RUNNING_PROMOTED;
82 break;
83
84 default:
85 break;
86 }
87
88 return remapped_rc;
89}
90
91char *
92crm_generate_ra_key(const char *standard, const char *provider,
93 const char *type)
94{
95 bool std_empty = pcmk__str_empty(standard);
96 bool prov_empty = pcmk__str_empty(provider);
97 bool ty_empty = pcmk__str_empty(type);
98
99 if (std_empty || ty_empty) {
100 return NULL;
101 }
102
103 return crm_strdup_printf("%s%s%s:%s",
104 standard,
105 (prov_empty ? "" : ":"), (prov_empty ? "" : provider),
106 type);
107}
108
123int
124crm_parse_agent_spec(const char *spec, char **standard, char **provider,
125 char **type)
126{
127 char *colon;
128
129 CRM_CHECK(spec && standard && provider && type, return -EINVAL);
130 *standard = NULL;
131 *provider = NULL;
132 *type = NULL;
133
134 colon = strchr(spec, ':');
135 if ((colon == NULL) || (colon == spec)) {
136 return -EINVAL;
137 }
138
139 *standard = strndup(spec, colon - spec);
140 spec = colon + 1;
141
143 colon = strchr(spec, ':');
144 if ((colon == NULL) || (colon == spec)) {
145 free(*standard);
146 return -EINVAL;
147 }
148 *provider = strndup(spec, colon - spec);
149 spec = colon + 1;
150 }
151
152 if (*spec == '\0') {
153 free(*standard);
154 free(*provider);
155 return -EINVAL;
156 }
157
158 *type = strdup(spec);
159 return pcmk_ok;
160}
161
173bool
174pcmk_stonith_param(const char *param)
175{
176 if (param == NULL) {
177 return false;
178 }
181 return true;
182 }
183 if (!pcmk__starts_with(param, "pcmk_")) { // Short-circuit common case
184 return false;
185 }
186 if (pcmk__str_any_of(param,
194 NULL)) {
195 return true;
196 }
197 param = strchr(param + 5, '_'); // Skip past "pcmk_ACTION"
198 return pcmk__str_any_of(param, "_action", "_timeout", "_retries", NULL);
199}
200
201// Deprecated functions kept only for backward API compatibility
202// LCOV_EXCL_START
203
205
206bool
207crm_provider_required(const char *standard)
208{
210}
211
212// LCOV_EXCL_STOP
213// End deprecated API
int crm_parse_agent_spec(const char *spec, char **standard, char **provider, char **type)
Parse a "standard[:provider]:type" agent specification.
Definition: agents.c:124
uint32_t pcmk_get_ra_caps(const char *standard)
Get capabilities of a resource agent standard.
Definition: agents.c:31
bool pcmk_stonith_param(const char *param)
Check whether a given stonith parameter is handled by Pacemaker.
Definition: agents.c:174
int pcmk__effective_rc(int rc)
Definition: agents.c:71
bool crm_provider_required(const char *standard)
Definition: agents.c:207
char * crm_generate_ra_key(const char *standard, const char *provider, const char *type)
Definition: agents.c:92
#define PCMK_RESOURCE_CLASS_NAGIOS
Definition: agents.h:32
#define PCMK_RESOURCE_CLASS_SYSTEMD
Definition: agents.h:30
#define PCMK_STONITH_HOST_LIST
Definition: agents.h:44
#define PCMK_STONITH_STONITH_TIMEOUT
Definition: agents.h:47
#define PCMK_STONITH_HOST_ARGUMENT
Definition: agents.h:42
#define PCMK_RESOURCE_CLASS_SERVICE
Definition: agents.h:28
#define PCMK_RESOURCE_CLASS_STONITH
Definition: agents.h:33
#define PCMK_STONITH_HOST_MAP
Definition: agents.h:45
#define PCMK_RESOURCE_CLASS_OCF
Definition: agents.h:27
@ pcmk_ra_cap_status
Definition: agents.h:58
@ pcmk_ra_cap_none
Definition: agents.h:56
@ pcmk_ra_cap_unique
Definition: agents.h:60
@ pcmk_ra_cap_params
Definition: agents.h:59
@ pcmk_ra_cap_promotable
Definition: agents.h:61
@ pcmk_ra_cap_provider
Definition: agents.h:57
@ pcmk_ra_cap_fence_params
Definition: agents.h:63
@ pcmk_ra_cap_stdin
Definition: agents.h:62
#define PCMK_RESOURCE_CLASS_UPSTART
Definition: agents.h:31
#define PCMK_STONITH_DELAY_BASE
Definition: agents.h:40
#define PCMK_STONITH_ACTION_LIMIT
Definition: agents.h:39
#define PCMK_STONITH_HOST_CHECK
Definition: agents.h:43
#define PCMK_STONITH_PROVIDES
Definition: agents.h:46
#define PCMK_STONITH_DELAY_MAX
Definition: agents.h:41
#define PCMK_RESOURCE_CLASS_LSB
Definition: agents.h:29
Deprecated Pacemaker resource agent API.
Utility functions.
char * crm_strdup_printf(char const *format,...) G_GNUC_PRINTF(1
#define pcmk_is_set(g, f)
Convenience alias for pcmk_all_flags_set(), to check single flag.
Definition: util.h:121
enum crm_ais_msg_types type
Definition: cpg.c:3
A dumping ground.
#define CRM_CHECK(expr, failure_action)
Definition: logging.h:227
char * strndup(const char *str, size_t len)
@ PCMK_OCF_RUNNING_PROMOTED
Service active and promoted.
Definition: results.h:172
@ PCMK_OCF_DEGRADED_PROMOTED
Service promoted but more likely to fail soon.
Definition: results.h:175
@ PCMK_OCF_DEGRADED
Service active but more likely to fail soon.
Definition: results.h:174
@ PCMK_OCF_OK
Success.
Definition: results.h:164
#define pcmk_ok
Definition: results.h:68
bool pcmk__starts_with(const char *str, const char *prefix)
Check whether a string starts with a certain sequence.
Definition: strings.c:484
bool pcmk__str_any_of(const char *s,...) G_GNUC_NULL_TERMINATED
Definition: strings.c:952