pacemaker  2.0.2-debe490
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-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 
28 uint32_t
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_NAGIOS)) {
62  return pcmk_ra_cap_params;
63  }
64  return pcmk_ra_cap_none;
65 }
66 
67 char *
68 crm_generate_ra_key(const char *standard, const char *provider,
69  const char *type)
70 {
71  if (!standard && !provider && !type) {
72  return NULL;
73  }
74 
75  return crm_strdup_printf("%s%s%s:%s",
76  (standard? standard : ""),
77  (provider? ":" : ""), (provider? provider : ""),
78  (type? type : ""));
79 }
80 
89 bool
90 crm_provider_required(const char *standard)
91 {
92  return is_set(pcmk_get_ra_caps(standard), pcmk_ra_cap_provider);
93 }
94 
109 int
110 crm_parse_agent_spec(const char *spec, char **standard, char **provider,
111  char **type)
112 {
113  char *colon;
114 
115  CRM_CHECK(spec && standard && provider && type, return -EINVAL);
116  *standard = NULL;
117  *provider = NULL;
118  *type = NULL;
119 
120  colon = strchr(spec, ':');
121  if ((colon == NULL) || (colon == spec)) {
122  return -EINVAL;
123  }
124 
125  *standard = strndup(spec, colon - spec);
126  spec = colon + 1;
127 
128  if (is_set(pcmk_get_ra_caps(*standard), pcmk_ra_cap_provider)) {
129  colon = strchr(spec, ':');
130  if ((colon == NULL) || (colon == spec)) {
131  free(*standard);
132  return -EINVAL;
133  }
134  *provider = strndup(spec, colon - spec);
135  spec = colon + 1;
136  }
137 
138  if (*spec == '\0') {
139  free(*standard);
140  free(*provider);
141  return -EINVAL;
142  }
143 
144  *type = strdup(spec);
145  return pcmk_ok;
146 }
#define CRM_CHECK(expr, failure_action)
Definition: logging.h:156
A dumping ground.
char * crm_generate_ra_key(const char *standard, const char *provider, const char *type)
Definition: agents.c:68
#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:110
#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:29
#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:57
bool crm_provider_required(const char *standard)
Check whether a resource standard requires a provider to be specified.
Definition: agents.c:90
char * crm_strdup_printf(char const *format,...) __attribute__((__format__(__printf__
enum crm_ais_msg_types type
Definition: internal.h:85