pacemaker  2.1.7-0f7f88312f
Scalable High-Availability cluster resource manager
pcmk_agents.c
Go to the documentation of this file.
1 /*
2  * Copyright 2023 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 
16 int
17 pcmk__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  CRM_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 
38 error:
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
49 int
50 pcmk_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);
63  pcmk__xml_output_finish(out, xml);
64  return rc;
65 }
66 
76 int
77 pcmk__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  CRM_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 
105 error:
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
120 int
121 pcmk_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);
134  pcmk__xml_output_finish(out, xml);
135  return rc;
136 }
137 
138 int
139 pcmk__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  CRM_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 
160 error:
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
176 int
177 pcmk_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);
190  pcmk__xml_output_finish(out, xml);
191  return rc;
192 }
193 
194 int
196 {
197  int rc = pcmk_rc_ok;
198  lrmd_t *lrmd_conn = NULL;
199  lrmd_list_t *list = NULL;
200 
201  CRM_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 
216 error:
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
227 int
228 pcmk_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);
241  pcmk__xml_output_finish(out, xml);
242  return rc;
243 }
int pcmk_list_agents(xmlNodePtr *xml, char *agent_spec)
List all agents available for the named standard and/or provider.
Definition: pcmk_agents.c:121
int pcmk__list_agents(pcmk__output_t *out, char *agent_spec)
Definition: pcmk_agents.c:77
int(* message)(pcmk__output_t *out, const char *message_id,...)
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_standards(xmlNodePtr *xml)
List all available resource agent standards.
Definition: pcmk_agents.c:228
High Level API.
int pcmk__list_providers(pcmk__output_t *out, const char *agent_spec)
Definition: pcmk_agents.c:139
int pcmk__xml_output_new(pcmk__output_t **out, xmlNodePtr *xml)
Definition: output.c:236
int lrmd__new(lrmd_t **api, const char *nodename, const char *server, int port)
Definition: lrmd_client.c:2247
int(*) int(*) void(* err)(pcmk__output_t *out, const char *format,...) G_GNUC_PRINTF(2
int pcmk__list_alternatives(pcmk__output_t *out, const char *agent_spec)
Definition: pcmk_agents.c:17
#define _(String)
Definition: crm_internal.h:53
void lrmd__register_messages(pcmk__output_t *out)
Definition: lrmd_output.c:144
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:454
lrmd_api_operations_t * cmds
Definition: lrmd.h:531
int pcmk_list_providers(xmlNodePtr *xml, const char *agent_spec)
List all available OCF providers for the given agent.
Definition: pcmk_agents.c:177
#define CRM_ASSERT(expr)
Definition: results.h:42
This structure contains everything that makes up a single output formatter.
int(* list_standards)(lrmd_t *lrmd, lrmd_list_t **standards)
Retrieve a list of supported standards.
Definition: lrmd.h:483
Definition: lrmd.h:530
void pcmk__xml_output_finish(pcmk__output_t *out, xmlNodePtr *xml)
Definition: output.c:258
int(* list_ocf_providers)(lrmd_t *lrmd, const char *agent, lrmd_list_t **providers)
Retrieve a list of resource agent providers.
Definition: lrmd.h:469
void lrmd_api_delete(lrmd_t *lrmd)
Destroy executor connection object.
Definition: lrmd_client.c:2353
int pcmk__list_standards(pcmk__output_t *out)
Definition: pcmk_agents.c:195