This source file includes following definitions.
- pcmk_get_ra_caps
- pcmk__effective_rc
- crm_generate_ra_key
- crm_parse_agent_spec
- pcmk_stonith_param
1
2
3
4
5
6
7
8
9
10 #include <crm_internal.h>
11
12 #include <stdio.h>
13 #include <string.h>
14 #include <strings.h>
15
16 #include <crm/crm.h>
17 #include <crm/common/util.h>
18
19
20
21
22
23
24
25
26 uint32_t
27 pcmk_get_ra_caps(const char *standard)
28 {
29
30
31
32 if (standard == NULL) {
33 return pcmk_ra_cap_none;
34
35 } else if (!strcasecmp(standard, PCMK_RESOURCE_CLASS_OCF)) {
36 return pcmk_ra_cap_provider | pcmk_ra_cap_params
37 | pcmk_ra_cap_unique | pcmk_ra_cap_promotable
38 | pcmk_ra_cap_cli_exec;
39
40 } else if (!strcasecmp(standard, PCMK_RESOURCE_CLASS_STONITH)) {
41
42
43
44
45
46
47
48
49 return pcmk_ra_cap_params | pcmk_ra_cap_unique | pcmk_ra_cap_stdin
50 | pcmk_ra_cap_fence_params;
51
52 } else if (!strcasecmp(standard, PCMK_RESOURCE_CLASS_LSB)) {
53 return pcmk_ra_cap_status | pcmk_ra_cap_cli_exec;
54
55 } else if (!strcasecmp(standard, PCMK_RESOURCE_CLASS_SYSTEMD)
56 || !strcasecmp(standard, PCMK_RESOURCE_CLASS_SERVICE)) {
57 return pcmk_ra_cap_status;
58 }
59 return pcmk_ra_cap_none;
60 }
61
62 int
63 pcmk__effective_rc(int rc)
64 {
65 int remapped_rc = rc;
66
67 switch (rc) {
68 case PCMK_OCF_DEGRADED:
69 remapped_rc = PCMK_OCF_OK;
70 break;
71
72 case PCMK_OCF_DEGRADED_PROMOTED:
73 remapped_rc = PCMK_OCF_RUNNING_PROMOTED;
74 break;
75
76 default:
77 break;
78 }
79
80 return remapped_rc;
81 }
82
83 char *
84 crm_generate_ra_key(const char *standard, const char *provider,
85 const char *type)
86 {
87 bool std_empty = pcmk__str_empty(standard);
88 bool prov_empty = pcmk__str_empty(provider);
89 bool ty_empty = pcmk__str_empty(type);
90
91 if (std_empty || ty_empty) {
92 return NULL;
93 }
94
95 return crm_strdup_printf("%s%s%s:%s",
96 standard,
97 (prov_empty ? "" : ":"), (prov_empty ? "" : provider),
98 type);
99 }
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115 int
116 crm_parse_agent_spec(const char *spec, char **standard, char **provider,
117 char **type)
118 {
119 char *colon;
120
121 CRM_CHECK(spec && standard && provider && type, return -EINVAL);
122 *standard = NULL;
123 *provider = NULL;
124 *type = NULL;
125
126 colon = strchr(spec, ':');
127 if ((colon == NULL) || (colon == spec)) {
128 return -EINVAL;
129 }
130
131 *standard = strndup(spec, colon - spec);
132 spec = colon + 1;
133
134 if (pcmk_is_set(pcmk_get_ra_caps(*standard), pcmk_ra_cap_provider)) {
135 colon = strchr(spec, ':');
136 if ((colon == NULL) || (colon == spec)) {
137 free(*standard);
138 return -EINVAL;
139 }
140 *provider = strndup(spec, colon - spec);
141 spec = colon + 1;
142 }
143
144 if (*spec == '\0') {
145 free(*standard);
146 free(*provider);
147 return -EINVAL;
148 }
149
150 *type = strdup(spec);
151 return pcmk_ok;
152 }
153
154
155
156
157
158
159
160
161
162
163
164
165 bool
166 pcmk_stonith_param(const char *param)
167 {
168 if (param == NULL) {
169 return false;
170 }
171 if (pcmk__str_any_of(param, PCMK_STONITH_PROVIDES,
172 PCMK_STONITH_STONITH_TIMEOUT, NULL)) {
173 return true;
174 }
175 if (!pcmk__starts_with(param, "pcmk_")) {
176 return false;
177 }
178 if (pcmk__str_any_of(param,
179 PCMK_STONITH_ACTION_LIMIT,
180 PCMK_STONITH_DELAY_BASE,
181 PCMK_STONITH_DELAY_MAX,
182 PCMK_STONITH_HOST_ARGUMENT,
183 PCMK_STONITH_HOST_CHECK,
184 PCMK_STONITH_HOST_LIST,
185 PCMK_STONITH_HOST_MAP,
186 NULL)) {
187 return true;
188 }
189 param = strchr(param + 5, '_');
190 return pcmk__str_any_of(param, "_action", "_timeout", "_retries", NULL);
191 }