pacemaker  2.0.4-2deceaa
Scalable High-Availability cluster resource manager
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
agents.c
Go to the documentation of this file.
1 /*
2  * Copyright 2004-2020 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 
30 uint32_t
31 pcmk_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  */
52 
53  } else if (!strcasecmp(standard, PCMK_RESOURCE_CLASS_SYSTEMD)
54  || !strcasecmp(standard, PCMK_RESOURCE_CLASS_SERVICE)
55  || !strcasecmp(standard, PCMK_RESOURCE_CLASS_LSB)
56  || !strcasecmp(standard, PCMK_RESOURCE_CLASS_UPSTART)) {
57 
58  /* Since service can map to LSB, systemd, or upstart, these should
59  * have identical capabilities
60  */
61  return pcmk_ra_cap_status;
62 
63  } else if (!strcasecmp(standard, PCMK_RESOURCE_CLASS_NAGIOS)) {
64  return pcmk_ra_cap_params;
65  }
66  return pcmk_ra_cap_none;
67 }
68 
69 char *
70 crm_generate_ra_key(const char *standard, const char *provider,
71  const char *type)
72 {
73  if (!standard && !provider && !type) {
74  return NULL;
75  }
76 
77  return crm_strdup_printf("%s%s%s:%s",
78  (standard? standard : ""),
79  (provider? ":" : ""), (provider? provider : ""),
80  (type? type : ""));
81 }
82 
97 int
98 crm_parse_agent_spec(const char *spec, char **standard, char **provider,
99  char **type)
100 {
101  char *colon;
102 
103  CRM_CHECK(spec && standard && provider && type, return -EINVAL);
104  *standard = NULL;
105  *provider = NULL;
106  *type = NULL;
107 
108  colon = strchr(spec, ':');
109  if ((colon == NULL) || (colon == spec)) {
110  return -EINVAL;
111  }
112 
113  *standard = strndup(spec, colon - spec);
114  spec = colon + 1;
115 
116  if (is_set(pcmk_get_ra_caps(*standard), pcmk_ra_cap_provider)) {
117  colon = strchr(spec, ':');
118  if ((colon == NULL) || (colon == spec)) {
119  free(*standard);
120  return -EINVAL;
121  }
122  *provider = strndup(spec, colon - spec);
123  spec = colon + 1;
124  }
125 
126  if (*spec == '\0') {
127  free(*standard);
128  free(*provider);
129  return -EINVAL;
130  }
131 
132  *type = strdup(spec);
133  return pcmk_ok;
134 }
135 
136 // Deprecated functions kept only for backward API compatibility
137 bool crm_provider_required(const char *standard);
138 
147 bool
148 crm_provider_required(const char *standard)
149 {
150  return is_set(pcmk_get_ra_caps(standard), pcmk_ra_cap_provider);
151 }
#define CRM_CHECK(expr, failure_action)
Definition: logging.h:233
A dumping ground.
char * crm_generate_ra_key(const char *standard, const char *provider, const char *type)
Definition: agents.c:70
#define PCMK_RESOURCE_CLASS_SYSTEMD
Definition: services.h:46
char * strndup(const char *str, size_t len)
int crm_parse_agent_spec(const char *spec, char **standard, char **provider, char **type)
Parse a &quot;standard[:provider]:type&quot; agent specification.
Definition: agents.c:98
#define PCMK_RESOURCE_CLASS_OCF
Definition: services.h:43
Utility functions.
#define PCMK_RESOURCE_CLASS_SERVICE
Definition: services.h:44
uint32_t pcmk_get_ra_caps(const char *standard)
Get capabilities of a resource agent standard.
Definition: agents.c:31
#define PCMK_RESOURCE_CLASS_STONITH
Definition: services.h:49
#define PCMK_RESOURCE_CLASS_NAGIOS
Definition: services.h:48
#define PCMK_RESOURCE_CLASS_LSB
Definition: services.h:45
#define PCMK_RESOURCE_CLASS_UPSTART
Definition: services.h:47
#define pcmk_ok
Definition: results.h:67
bool crm_provider_required(const char *standard)
Check whether a resource standard requires a provider to be specified.
Definition: agents.c:148
char * crm_strdup_printf(char const *format,...) __attribute__((__format__(__printf__
enum crm_ais_msg_types type
Definition: internal.h:83