13 #include <libxml/tree.h>
29 #define DEFAULT_MESSAGE_TIMEOUT_MS 30000
36 guint message_timer_id;
37 guint message_timeout_ms;
41 quit_main_loop(data_t *
data)
43 if (data->mainloop != NULL) {
44 GMainLoop *mloop = data->mainloop;
46 data->mainloop = NULL;
48 g_main_loop_unref(mloop);
53 admin_message_timeout(gpointer user_data)
55 data_t *data = user_data;
58 out->
err(out,
"error: No reply received from controller before timeout (%dms)",
59 data->message_timeout_ms);
60 data->message_timer_id = 0;
67 start_main_loop(data_t *data)
69 if (data->message_timeout_ms < 1) {
73 data->rc = ECONNRESET;
74 data->mainloop = g_main_loop_new(NULL, FALSE);
75 data->message_timer_id = g_timeout_add(data->message_timeout_ms,
76 admin_message_timeout,
78 g_main_loop_run(data->mainloop);
96 if (data->rc == ECONNRESET) {
97 out->
err(out,
"error: Lost connection to controller");
99 event_done(data, controld_api);
109 if (data->message_timer_id != 0) {
110 g_source_remove(data->message_timer_id);
111 data->message_timer_id = 0;
115 out->
err(out,
"error: Bad reply from controller: %s",
118 event_done(data, controld_api);
123 out->
err(out,
"error: Unknown reply type %d from controller",
126 event_done(data, controld_api);
136 void *event_data,
void *user_data)
138 data_t *data = user_data;
141 event_type, status, event_data);
152 event_done(data, controld_api);
158 void *event_data,
void *user_data)
160 data_t *data = user_data;
163 event_type, status, event_data);
170 event_done(data, controld_api);
176 void *event_data,
void *user_data)
178 data_t *data = user_data;
183 char *pinged_buf = NULL;
185 switch (event_type) {
187 if (data->rc == ECONNRESET) {
188 out->
err(out,
"error: Lost connection to pacemakerd");
190 event_done(data, pacemakerd_api);
200 if (data->message_timer_id != 0) {
201 g_source_remove(data->message_timer_id);
202 data->message_timer_id = 0;
206 out->
err(out,
"error: Bad reply from pacemakerd: %s",
208 event_done(data, pacemakerd_api);
213 out->
err(out,
"error: Unknown reply type %d from pacemakerd",
215 event_done(data, pacemakerd_api);
226 out->
message(out,
"pacemakerd-health",
230 reply->
data.
ping.state):
"query failed",
236 event_done(data, pacemakerd_api);
249 out->
err(out,
"error: Could not connect to %s: %s",
260 out->
err(out,
"error: Could not connect to %s: %s",
277 .message_timer_id = 0,
278 .message_timeout_ms = message_timeout_ms
282 if (controld_api != NULL) {
289 start_main_loop(&data);
322 .message_timer_id = 0,
323 .message_timeout_ms = message_timeout_ms
327 if (controld_api != NULL) {
334 start_main_loop(&data);
367 .message_timer_id = 0,
368 .message_timeout_ms = message_timeout_ms
372 if (pacemakerd_api != NULL) {
379 start_main_loop(&data);
411 gboolean BASH_EXPORT;
415 remote_node_print_helper(xmlNode *result,
void *user_data)
417 struct node_data *data = user_data;
423 out->
message(out,
"crmadmin-node", data->type,
435 xmlNode *xml_node = NULL;
438 if (the_cib == NULL) {
446 rc = the_cib->
cmds->
query(the_cib, NULL, &xml_node,
449 struct node_data data = {
452 .BASH_EXPORT = BASH_EXPORT
457 if (!pcmk__str_empty(node_types) && strstr(node_types,
"all")) {
461 if (pcmk__str_empty(node_types) || strstr(node_types,
"cluster")) {
463 data.type =
"cluster";
465 remote_node_print_helper, &data);
468 if (pcmk__str_empty(node_types) || strstr(node_types,
"guest")) {
469 data.field =
"value";
472 remote_node_print_helper, &data);
477 data.type =
"remote";
479 remote_node_print_helper, &data);
484 if (data.found == 0) {
485 out->
info(out,
"No nodes configured");
int(* query)(cib_t *cib, const char *section, xmlNode **output_data, int call_options)
enum pcmk_controld_api_reply reply_type
void(* pcmk_ipc_callback_t)(pcmk_ipc_api_t *api, enum pcmk_ipc_event event_type, crm_exit_t status, void *event_data, void *user_data)
Callback function type for Pacemaker daemon IPC APIs.
int pcmk__list_nodes(pcmk__output_t *out, char *node_types, gboolean BASH_EXPORT)
#define crm_time_log_timeofday
int pcmk_connect_ipc(pcmk_ipc_api_t *api, enum pcmk_ipc_dispatch dispatch_type)
Connect to a Pacemaker daemon via IPC.
const char * host_from
Name of node that sent reply.
struct crm_time_s crm_time_t
int pcmk_controld_api_ping(pcmk_ipc_api_t *api, const char *node_name)
Ask the controller for status.
int pcmk_pacemakerd_status(xmlNodePtr *xml, char *ipc_name, unsigned int message_timeout_ms)
Get pacemakerd status.
int pcmk_new_ipc_api(pcmk_ipc_api_t **api, enum pcmk_ipc_server server)
Create a new object for using Pacemaker daemon IPC.
struct pcmk_pacemakerd_api_reply_t::@4::@5 ping
int pcmk_designated_controller(xmlNodePtr *xml, unsigned int message_timeout_ms)
Get designated controller.
int(* message)(pcmk__output_t *out, const char *message_id,...)
enum crm_exit_e crm_exit_t
int(*) void(* err)(pcmk__output_t *out, const char *format,...) G_GNUC_PRINTF(2
enum crm_ais_msg_types type
const char * pcmk_rc_str(int rc)
Get a user-friendly description of a return code.
int pcmk__designated_controller(pcmk__output_t *out, guint message_timeout_ms)
Wrappers for and extensions to glib mainloop.
union pcmk_controld_api_reply_t::@0 data
int pcmk__out_prologue(pcmk__output_t **out, xmlNodePtr *xml)
struct pcmk_controld_api_reply_t::@0::@3 ping
void(* end_list)(pcmk__output_t *out)
enum pcmk_pacemakerd_api_reply reply_type
Formatted output for pacemaker tools.
union pcmk_pacemakerd_api_reply_t::@4 data
#define PCMK__XP_GUEST_NODE_CONFIG
pcmk_ipc_server
Available IPC interfaces.
const char * crm_exit_str(crm_exit_t exit_code)
cib_api_operations_t * cmds
void(* begin_list)(pcmk__output_t *out, const char *singular_noun, const char *plural_noun, const char *format,...) G_GNUC_PRINTF(4
const char * crm_element_value(const xmlNode *data, const char *name)
Retrieve the value of an XML attribute.
void crm_time_set_timet(crm_time_t *target, time_t *source)
int(* info)(pcmk__output_t *out, const char *format,...) G_GNUC_PRINTF(2
void pcmk__register_lib_messages(pcmk__output_t *out)
#define PCMK__XP_REMOTE_NODE_CONFIG
const char * pcmk_ipc_name(pcmk_ipc_api_t *api, bool for_log)
Get the IPC name used with an IPC API connection.
Wrappers for and extensions to libxml2.
int pcmk_legacy2rc(int legacy_rc)
IPC commands for Pacemakerd.
void free_xml(xmlNode *child)
#define crm_time_log_with_timezone
int pcmk_list_nodes(xmlNodePtr *xml, char *node_types)
Get nodes list.
void pcmk__out_epilogue(pcmk__output_t *out, xmlNodePtr *xml, int retval)
IPC commands for Pacemaker controller.
char * crm_time_as_string(crm_time_t *dt, int flags)
int pcmk_pacemakerd_api_ping(pcmk_ipc_api_t *api, const char *ipc_name)
int pcmk_controller_status(xmlNodePtr *xml, char *dest_node, unsigned int message_timeout_ms)
Get controller status.
pcmk_ipc_event
Possible event types that an IPC event callback can be called for.
Attach IPC to GMainLoop for dispatch.
Termination of IPC connection.
const char * pcmk_pacemakerd_api_daemon_state_enum2text(enum pcmk_pacemakerd_state state)
crm_time_t * crm_time_new(const char *string)
void pcmk_free_ipc_api(pcmk_ipc_api_t *api)
Free the contents of an IPC API object.
void pcmk_quit_main_loop(GMainLoop *mloop, unsigned int n)
Drain some remaining main loop events then quit it.
This structure contains everything that makes up a single output formatter.
int(* signon)(cib_t *cib, const char *name, enum cib_conn_type type)
int pcmk__pacemakerd_status(pcmk__output_t *out, char *ipc_name, guint message_timeout_ms)
int pcmk__strcmp(const char *s1, const char *s2, uint32_t flags)
void crm_foreach_xpath_result(xmlNode *xml, const char *xpath, void(*helper)(xmlNode *, void *), void *user_data)
Run a supplied function for each result of an xpath search.
int(* signoff)(cib_t *cib)
Daemon's reply to client IPC request.
#define PCMK__XP_MEMBER_NODE_CONFIG
void pcmk_register_ipc_callback(pcmk_ipc_api_t *api, pcmk_ipc_callback_t cb, void *user_data)
Register a callback for IPC API events.
void pcmk_disconnect_ipc(pcmk_ipc_api_t *api)
Disconnect an IPC API instance.
#define crm_time_log_date
int pcmk__controller_status(pcmk__output_t *out, char *dest_node, guint message_timeout_ms)
#define DEFAULT_MESSAGE_TIMEOUT_MS
void crm_time_free(crm_time_t *dt)