pacemaker  1.1.24-3850484742
Scalable High-Availability cluster resource manager
agents.c
Go to the documentation of this file.
1 /*
2  * Copyright 2004-2018 Andrew Beekhof <andrew@beekhof.net>
3  *
4  * This source code is licensed under the GNU Lesser General Public License
5  * version 2.1 or later (LGPLv2.1+) WITHOUT ANY WARRANTY.
6  */
7 
8 #include <crm_internal.h>
9 
10 #ifndef _GNU_SOURCE
11 # define _GNU_SOURCE
12 #endif
13 
14 #include <stdio.h>
15 #include <string.h>
16 #include <strings.h>
17 
18 #include <crm/crm.h>
19 #include <crm/common/util.h>
20 
29 pcmk_get_ra_caps(const char *standard)
30 {
31  /* @COMPAT This should probably be case-sensitive, but isn't,
32  * for backward compatibility.
33  */
34  if (standard == NULL) {
35  return pcmk_ra_cap_none;
36 
37  } else if (!strcasecmp(standard, PCMK_RESOURCE_CLASS_OCF)) {
40 
41  } else if (!strcasecmp(standard, PCMK_RESOURCE_CLASS_STONITH)) {
42  /* @COMPAT Stonith resources can't really be unique clones, but we've
43  * allowed it in the past and have it in some scheduler regression tests
44  * (which were likely never used as real configurations).
45  *
46  * @TODO Remove pcmk_ra_cap_unique at the next major schema version
47  * bump, with a transform to remove globally-unique from the config.
48  */
50 
51  } else if (!strcasecmp(standard, PCMK_RESOURCE_CLASS_SYSTEMD)
52  || !strcasecmp(standard, PCMK_RESOURCE_CLASS_SERVICE)
53  || !strcasecmp(standard, PCMK_RESOURCE_CLASS_LSB)
54  || !strcasecmp(standard, PCMK_RESOURCE_CLASS_UPSTART)) {
55 
56  /* Since service can map to LSB, systemd, or upstart, these should
57  * have identical capabilities
58  */
59  return pcmk_ra_cap_status;
60 
61  } else if (!strcasecmp(standard, PCMK_RESOURCE_CLASS_HB)) {
62  /* @COMPAT Heartbeat resources likely can't really be unique clones, but
63  * we've allowed it in the past and have it in some PE regression tests.
64  */
66 
67  } else if (!strcasecmp(standard, PCMK_RESOURCE_CLASS_NAGIOS)) {
68  return pcmk_ra_cap_params;
69  }
70  return pcmk_ra_cap_none;
71 }
72 
73 char *
74 crm_generate_ra_key(const char *standard, const char *provider,
75  const char *type)
76 {
77  if (!standard && !provider && !type) {
78  return NULL;
79  }
80 
81  return crm_strdup_printf("%s%s%s:%s",
82  (standard? standard : ""),
83  (provider? ":" : ""), (provider? provider : ""),
84  (type? type : ""));
85 }
86 
95 bool
96 crm_provider_required(const char *standard)
97 {
98  return is_set(pcmk_get_ra_caps(standard), pcmk_ra_cap_provider);
99 }
100 
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 (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 }
#define CRM_CHECK(expr, failure_action)
Definition: logging.h:190
A dumping ground.
#define PCMK_RESOURCE_CLASS_SYSTEMD
Definition: services.h:60
#define pcmk_ok
Definition: error.h:45
char * strndup(const char *str, size_t len)
#define PCMK_RESOURCE_CLASS_OCF
Definition: services.h:57
Utility functions.
#define PCMK_RESOURCE_CLASS_SERVICE
Definition: services.h:58
int crm_parse_agent_spec(const char *spec, char **standard, char **provider, char **type)
Parse a "standard[:provider]:type" agent specification.
Definition: agents.c:116
uint32_t pcmk_get_ra_caps(const char *standard)
Get capabilities of a resource agent standard.
Definition: agents.c:29
#define PCMK_RESOURCE_CLASS_STONITH
Definition: services.h:64
bool crm_provider_required(const char *standard)
Check whether a resource standard requires a provider to be specified.
Definition: agents.c:96
#define PCMK_RESOURCE_CLASS_NAGIOS
Definition: services.h:63
#define PCMK_RESOURCE_CLASS_LSB
Definition: services.h:59
#define PCMK_RESOURCE_CLASS_UPSTART
Definition: services.h:61
#define PCMK_RESOURCE_CLASS_HB
Definition: services.h:62
#define uint32_t
Definition: stdint.in.h:158
char * crm_generate_ra_key(const char *standard, const char *provider, const char *type)
Definition: agents.c:74
char * crm_strdup_printf(char const *format,...) __attribute__((__format__(__printf__
enum crm_ais_msg_types type
Definition: internal.h:79