pacemaker 3.0.1-16e74fc4da
Scalable High-Availability cluster resource manager
Loading...
Searching...
No Matches
pcmk_agents.c
Go to the documentation of this file.
1/*
2 * Copyright 2023-2024 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#include <crm/lrmd_internal.h>
13#include <pacemaker.h>
14#include <pacemaker-internal.h>
15
16int
17pcmk__list_alternatives(pcmk__output_t *out, const char *agent_spec)
18{
19 int rc = pcmk_rc_ok;
20 lrmd_t *lrmd_conn = NULL;
21 lrmd_list_t *list = NULL;
22
23 pcmk__assert((out != NULL) && (agent_spec != NULL));
24
25 rc = lrmd__new(&lrmd_conn, NULL, NULL, 0);
26 if (rc != pcmk_rc_ok) {
27 goto error;
28 }
29
30 rc = lrmd_conn->cmds->list_ocf_providers(lrmd_conn, agent_spec, &list);
31
32 if (rc > 0) {
33 rc = out->message(out, "alternatives-list", list, agent_spec);
34 } else {
35 rc = pcmk_rc_error;
36 }
37
38error:
39 if (rc != pcmk_rc_ok) {
40 out->err(out, _("No %s found for %s"), "OCF providers", agent_spec);
41 rc = ENXIO;
42 }
43
44 lrmd_api_delete(lrmd_conn);
45 return rc;
46}
47
48// Documented in pacemaker.h
49int
50pcmk_list_alternatives(xmlNodePtr *xml, const char *agent_spec)
51{
52 pcmk__output_t *out = NULL;
53 int rc = pcmk_rc_ok;
54
55 rc = pcmk__xml_output_new(&out, xml);
56 if (rc != pcmk_rc_ok) {
57 return rc;
58 }
59
61
62 rc = pcmk__list_alternatives(out, agent_spec);
64 return rc;
65}
66
76int
77pcmk__list_agents(pcmk__output_t *out, char *agent_spec)
78{
79 int rc = pcmk_rc_ok;
80 char *provider = NULL;
81 lrmd_t *lrmd_conn = NULL;
82 lrmd_list_t *list = NULL;
83
84 pcmk__assert((out != NULL) && (agent_spec != NULL));
85
86 rc = lrmd__new(&lrmd_conn, NULL, NULL, 0);
87 if (rc != pcmk_rc_ok) {
88 goto error;
89 }
90
91 provider = strchr(agent_spec, ':');
92
93 if (provider) {
94 *provider++ = 0;
95 }
96
97 rc = lrmd_conn->cmds->list_agents(lrmd_conn, &list, agent_spec, provider);
98
99 if (rc > 0) {
100 rc = out->message(out, "agents-list", list, agent_spec, provider);
101 } else {
102 rc = pcmk_rc_error;
103 }
104
105error:
106 if (rc != pcmk_rc_ok) {
107 if (provider == NULL) {
108 out->err(out, _("No agents found for standard '%s'"), agent_spec);
109 } else {
110 out->err(out, _("No agents found for standard '%s' and provider '%s'"),
111 agent_spec, provider);
112 }
113 }
114
115 lrmd_api_delete(lrmd_conn);
116 return rc;
117}
118
119// Documented in pacemaker.h
120int
121pcmk_list_agents(xmlNodePtr *xml, char *agent_spec)
122{
123 pcmk__output_t *out = NULL;
124 int rc = pcmk_rc_ok;
125
126 rc = pcmk__xml_output_new(&out, xml);
127 if (rc != pcmk_rc_ok) {
128 return rc;
129 }
130
132
133 rc = pcmk__list_agents(out, agent_spec);
135 return rc;
136}
137
138int
139pcmk__list_providers(pcmk__output_t *out, const char *agent_spec)
140{
141 int rc = pcmk_rc_ok;
142 lrmd_t *lrmd_conn = NULL;
143 lrmd_list_t *list = NULL;
144
145 pcmk__assert(out != NULL);
146
147 rc = lrmd__new(&lrmd_conn, NULL, NULL, 0);
148 if (rc != pcmk_rc_ok) {
149 goto error;
150 }
151
152 rc = lrmd_conn->cmds->list_ocf_providers(lrmd_conn, agent_spec, &list);
153
154 if (rc > 0) {
155 rc = out->message(out, "providers-list", list, agent_spec);
156 } else {
157 rc = pcmk_rc_error;
158 }
159
160error:
161 if (rc != pcmk_rc_ok) {
162 if (agent_spec == NULL) {
163 out->err(out, _("No %s found"), "OCF providers");
164 } else {
165 out->err(out, _("No %s found for %s"), "OCF providers", agent_spec);
166 }
167
168 rc = ENXIO;
169 }
170
171 lrmd_api_delete(lrmd_conn);
172 return rc;
173}
174
175// Documented in pacemaker.h
176int
177pcmk_list_providers(xmlNodePtr *xml, const char *agent_spec)
178{
179 pcmk__output_t *out = NULL;
180 int rc = pcmk_rc_ok;
181
182 rc = pcmk__xml_output_new(&out, xml);
183 if (rc != pcmk_rc_ok) {
184 return rc;
185 }
186
188
189 rc = pcmk__list_providers(out, agent_spec);
191 return rc;
192}
193
194int
196{
197 int rc = pcmk_rc_ok;
198 lrmd_t *lrmd_conn = NULL;
199 lrmd_list_t *list = NULL;
200
201 pcmk__assert(out != NULL);
202
203 rc = lrmd__new(&lrmd_conn, NULL, NULL, 0);
204 if (rc != pcmk_rc_ok) {
205 goto error;
206 }
207
208 rc = lrmd_conn->cmds->list_standards(lrmd_conn, &list);
209
210 if (rc > 0) {
211 rc = out->message(out, "standards-list", list);
212 } else {
213 rc = pcmk_rc_error;
214 }
215
216error:
217 if (rc != pcmk_rc_ok) {
218 out->err(out, _("No %s found"), "standards");
219 rc = ENXIO;
220 }
221
222 lrmd_api_delete(lrmd_conn);
223 return rc;
224}
225
226// Documented in pacemaker.h
227int
228pcmk_list_standards(xmlNodePtr *xml)
229{
230 pcmk__output_t *out = NULL;
231 int rc = pcmk_rc_ok;
232
233 rc = pcmk__xml_output_new(&out, xml);
234 if (rc != pcmk_rc_ok) {
235 return rc;
236 }
237
239
240 rc = pcmk__list_standards(out);
242 return rc;
243}
#define _(String)
void lrmd_api_delete(lrmd_t *lrmd)
Destroy executor connection object.
int lrmd__new(lrmd_t **api, const char *nodename, const char *server, int port)
void lrmd__register_messages(pcmk__output_t *out)
void pcmk__xml_output_finish(pcmk__output_t *out, crm_exit_t exit_status, xmlNodePtr *xml)
Definition output.c:273
int pcmk__xml_output_new(pcmk__output_t **out, xmlNodePtr *xml)
Definition output.c:246
High Level API.
int pcmk_list_providers(xmlNodePtr *xml, const char *agent_spec)
List all available OCF providers for the given agent.
int pcmk__list_providers(pcmk__output_t *out, const char *agent_spec)
int pcmk__list_agents(pcmk__output_t *out, char *agent_spec)
Definition pcmk_agents.c:77
int pcmk__list_alternatives(pcmk__output_t *out, const char *agent_spec)
Definition pcmk_agents.c:17
int pcmk__list_standards(pcmk__output_t *out)
int pcmk_list_standards(xmlNodePtr *xml)
List all available resource agent standards.
int pcmk_list_alternatives(xmlNodePtr *xml, const char *agent_spec)
List available providers for the given OCF agent.
Definition pcmk_agents.c:50
int pcmk_list_agents(xmlNodePtr *xml, char *agent_spec)
List all agents available for the named standard and/or provider.
@ pcmk_rc_ok
Definition results.h:159
@ pcmk_rc_error
Definition results.h:154
crm_exit_t pcmk_rc2exitc(int rc)
Map a function return code to the most similar exit code.
Definition results.c:820
#define pcmk__assert(expr)
int(* list_standards)(lrmd_t *lrmd, lrmd_list_t **standards)
Retrieve a list of supported standards.
Definition lrmd.h:426
int(* list_agents)(lrmd_t *lrmd, lrmd_list_t **agents, const char *standard, const char *provider)
Retrieve a list of installed resource agents.
Definition lrmd.h:397
int(* list_ocf_providers)(lrmd_t *lrmd, const char *agent, lrmd_list_t **providers)
Retrieve a list of resource agent providers.
Definition lrmd.h:412
Definition lrmd.h:473
lrmd_api_operations_t * cmds
Definition lrmd.h:474
This structure contains everything that makes up a single output formatter.
int(* message)(pcmk__output_t *out, const char *message_id,...)
int int void(* err)(pcmk__output_t *out, const char *format,...) G_GNUC_PRINTF(2