This source file includes following definitions.
- pcmk_get_ra_caps
- pcmk__effective_rc
- crm_generate_ra_key
- crm_parse_agent_spec
- pcmk_stonith_param
- crm_provider_required
1
2
3
4
5
6
7
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
23
24
25
26
27
28
29
30 uint32_t
31 pcmk_get_ra_caps(const char *standard)
32 {
33
34
35
36 if (standard == NULL) {
37 return pcmk_ra_cap_none;
38
39 } else if (!strcasecmp(standard, PCMK_RESOURCE_CLASS_OCF)) {
40 return pcmk_ra_cap_provider | pcmk_ra_cap_params
41 | pcmk_ra_cap_unique | pcmk_ra_cap_promotable;
42
43 } else if (!strcasecmp(standard, PCMK_RESOURCE_CLASS_STONITH)) {
44
45
46
47
48
49
50
51 return pcmk_ra_cap_params | pcmk_ra_cap_unique | pcmk_ra_cap_stdin
52 | pcmk_ra_cap_fence_params;
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
60
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
70 int
71 pcmk__effective_rc(int rc)
72 {
73 int remapped_rc = rc;
74
75 switch (rc) {
76 case PCMK_OCF_DEGRADED:
77 remapped_rc = PCMK_OCF_OK;
78 break;
79
80 case PCMK_OCF_DEGRADED_PROMOTED:
81 remapped_rc = PCMK_OCF_RUNNING_PROMOTED;
82 break;
83
84 default:
85 break;
86 }
87
88 return remapped_rc;
89 }
90
91 char *
92 crm_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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123 int
124 crm_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
142 if (pcmk_is_set(pcmk_get_ra_caps(*standard), pcmk_ra_cap_provider)) {
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
162
163
164
165
166
167
168
169
170
171
172
173 bool
174 pcmk_stonith_param(const char *param)
175 {
176 if (param == NULL) {
177 return false;
178 }
179 if (pcmk__str_any_of(param, PCMK_STONITH_PROVIDES,
180 PCMK_STONITH_STONITH_TIMEOUT, NULL)) {
181 return true;
182 }
183 if (!pcmk__starts_with(param, "pcmk_")) {
184 return false;
185 }
186 if (pcmk__str_any_of(param,
187 PCMK_STONITH_ACTION_LIMIT,
188 PCMK_STONITH_DELAY_BASE,
189 PCMK_STONITH_DELAY_MAX,
190 PCMK_STONITH_HOST_ARGUMENT,
191 PCMK_STONITH_HOST_CHECK,
192 PCMK_STONITH_HOST_LIST,
193 PCMK_STONITH_HOST_MAP,
194 NULL)) {
195 return true;
196 }
197 param = strchr(param + 5, '_');
198 return pcmk__str_any_of(param, "_action", "_timeout", "_retries", NULL);
199 }
200
201
202
203
204 #include <crm/common/agents_compat.h>
205
206 bool
207 crm_provider_required(const char *standard)
208 {
209 return pcmk_is_set(pcmk_get_ra_caps(standard), pcmk_ra_cap_provider);
210 }
211
212
213