13 #include <libxml/tree.h> 30 #define DEFAULT_MESSAGE_TIMEOUT_MS 30000 37 guint message_timer_id;
38 guint message_timeout_ms;
43 quit_main_loop(data_t *
data)
45 if (
data->mainloop != NULL) {
46 GMainLoop *mloop =
data->mainloop;
48 data->mainloop = NULL;
50 g_main_loop_unref(mloop);
55 admin_message_timeout(gpointer user_data)
57 data_t *
data = user_data;
60 out->
err(out,
"error: No reply received from controller before timeout (%dms)",
61 data->message_timeout_ms);
62 data->message_timer_id = 0;
69 start_main_loop(data_t *
data)
71 if (
data->message_timeout_ms < 1) {
75 data->rc = ECONNRESET;
76 data->mainloop = g_main_loop_new(NULL, FALSE);
77 data->message_timer_id = g_timeout_add(
data->message_timeout_ms,
78 admin_message_timeout,
80 g_main_loop_run(
data->mainloop);
98 if (
data->rc == ECONNRESET) {
99 out->
err(out,
"error: Lost connection to controller");
101 event_done(
data, controld_api);
111 if (
data->message_timer_id != 0) {
112 g_source_remove(
data->message_timer_id);
113 data->message_timer_id = 0;
117 out->
err(out,
"error: Bad reply from controller: %s",
120 event_done(
data, controld_api);
125 out->
err(out,
"error: Unknown reply type %d from controller",
128 event_done(
data, controld_api);
138 void *event_data,
void *user_data)
140 data_t *
data = user_data;
143 event_type, status, event_data);
154 event_done(
data, controld_api);
160 void *event_data,
void *user_data)
162 data_t *
data = user_data;
165 event_type, status, event_data);
172 event_done(
data, controld_api);
178 void *event_data,
void *user_data)
180 data_t *
data = user_data;
184 switch (event_type) {
186 if (
data->rc == ECONNRESET) {
187 out->
err(out,
"error: Lost connection to pacemakerd");
189 event_done(
data, pacemakerd_api);
199 if (
data->message_timer_id != 0) {
200 g_source_remove(
data->message_timer_id);
201 data->message_timer_id = 0;
205 out->
err(out,
"error: Bad reply from pacemakerd: %s",
207 event_done(
data, pacemakerd_api);
213 out->
err(out,
"error: Unknown reply type %d from pacemakerd",
215 event_done(
data, pacemakerd_api);
232 out->
message(out,
"pacemakerd-health",
240 out->
message(out,
"pacemakerd-health",
242 "query failed", NULL);
245 event_done(
data, pacemakerd_api);
258 out->
err(out,
"error: Could not connect to %s: %s",
276 out->
err(out,
"error: Could not connect to %s: %s",
294 .message_timer_id = 0,
295 .message_timeout_ms = message_timeout_ms,
301 if (message_timeout_ms == 0) {
305 controller_status_event_cb, dispatch_type,
308 if (controld_api != NULL) {
311 out->
err(out,
"error: Could not ping controller API: %s",
317 start_main_loop(&
data);
351 .message_timer_id = 0,
352 .message_timeout_ms = message_timeout_ms,
358 if (message_timeout_ms == 0) {
362 designated_controller_event_cb, dispatch_type,
365 if (controld_api != NULL) {
368 out->
err(out,
"error: Could not ping controller API: %s",
374 start_main_loop(&
data);
426 guint message_timeout_ms,
433 .message_timer_id = 0,
434 .message_timeout_ms = message_timeout_ms,
440 if (message_timeout_ms == 0) {
444 pacemakerd_event_cb, dispatch_type,
true);
446 if (pacemakerd_api != NULL) {
449 out->
err(out,
"error: Could not ping launcher API: %s",
455 start_main_loop(&
data);
461 *state =
data.pcmkd_state;
469 unsigned int message_timeout_ms)
493 gboolean bash_export;
497 remote_node_print_helper(xmlNode *
result,
void *user_data)
499 struct node_data *
data = user_data;
516 xmlNode *xml_node = NULL;
522 struct node_data
data = {
525 .bash_export = bash_export
530 if (!pcmk__str_empty(node_types) && strstr(node_types,
"all")) {
534 if (pcmk__str_empty(node_types) || strstr(node_types,
"cluster")) {
536 data.type =
"cluster";
538 remote_node_print_helper, &
data);
541 if (pcmk__str_empty(node_types) || strstr(node_types,
"guest")) {
542 data.field =
"value";
545 remote_node_print_helper, &
data);
550 data.type =
"remote";
552 remote_node_print_helper, &
data);
557 if (
data.found == 0) {
558 out->
info(out,
"No nodes configured");
void(* end_list)(pcmk__output_t *out)
struct pcmk_controld_api_reply_t::@1::@4 ping
union pcmk_controld_api_reply_t::@1 data
enum pcmk_controld_api_reply reply_type
int pcmk_designated_controller(xmlNodePtr *xml, unsigned int message_timeout_ms)
Get designated controller.
#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.
int(* message)(pcmk__output_t *out, const char *message_id,...)
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_new_ipc_api(pcmk_ipc_api_t **api, enum pcmk_ipc_server server)
Create a new object for using Pacemaker daemon IPC.
enum crm_exit_e crm_exit_t
int(* info)(pcmk__output_t *out, const char *format,...) G_GNUC_PRINTF(2
enum crm_ais_msg_types type
struct pcmk_pacemakerd_api_reply_t::@5::@6 ping
const char * pcmk_rc_str(int rc)
Get a user-friendly description of a return code.
Wrappers for and extensions to glib mainloop.
union pcmk_pacemakerd_api_reply_t::@5 data
int cib__signon_query(cib_t **cib, xmlNode **cib_object)
char * crm_time_as_string(const crm_time_t *dt, int flags)
enum pcmk_pacemakerd_api_reply reply_type
Formatted output for pacemaker tools.
#define PCMK__XP_GUEST_NODE_CONFIG
pcmk_ipc_server
Available IPC interfaces.
const char * crm_exit_str(crm_exit_t exit_code)
void crm_time_set_timet(crm_time_t *target, const time_t *source)
const char * crm_element_value(const xmlNode *data, const char *name)
Retrieve the value of an XML attribute.
int pcmk__xml_output_new(pcmk__output_t **out, xmlNodePtr *xml)
int(*) void(* err)(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
Wrappers for and extensions to libxml2.
IPC commands for Pacemakerd.
void free_xml(xmlNode *child)
#define crm_time_log_with_timezone
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.
IPC commands for Pacemaker controller.
int pcmk_pacemakerd_api_ping(pcmk_ipc_api_t *api, const char *ipc_name)
pcmk_ipc_dispatch
How IPC replies should be dispatched.
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.
int pcmk_controller_status(xmlNodePtr *xml, char *dest_node, unsigned int message_timeout_ms)
Get controller status.
pcmk__action_result_t result
int pcmk__controller_status(pcmk__output_t *out, char *dest_node, guint message_timeout_ms)
int pcmk__pacemakerd_status(pcmk__output_t *out, const char *ipc_name, guint message_timeout_ms, enum pcmk_pacemakerd_state *state)
Sending a command will wait for any reply.
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.
const char * pcmk_ipc_name(const pcmk_ipc_api_t *api, bool for_log)
Get the IPC name used with an IPC API connection.
int pcmk__strcmp(const char *s1, const char *s2, uint32_t flags)
void(* begin_list)(pcmk__output_t *out, const char *singular_noun, const char *plural_noun, const char *format,...) G_GNUC_PRINTF(4
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.
void pcmk__xml_output_finish(pcmk__output_t *out, xmlNodePtr *xml)
Daemon's reply to client IPC request.
int pcmk_pacemakerd_status(xmlNodePtr *xml, const char *ipc_name, unsigned int message_timeout_ms)
Get and output pacemakerd status.
int pcmk__designated_controller(pcmk__output_t *out, guint message_timeout_ms)
#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__list_nodes(pcmk__output_t *out, char *node_types, gboolean bash_export)
int pcmk_list_nodes(xmlNodePtr *xml, char *node_types)
Get nodes list.
#define DEFAULT_MESSAGE_TIMEOUT_MS
void crm_time_free(crm_time_t *dt)