18 #include <libxml/tree.h>
25 static GMainLoop *mainloop = NULL;
53 value = strchr(target,
'=');
57 }
else if (*target ==
'@') {
66 name, value, fence_level,
70 name, value, fence_level);
86 async_fence_data.rc = e->
result;
87 g_main_loop_quit(mainloop);
94 async_fence_data.rc = data->
rc;
96 g_main_loop_quit(mainloop);
100 async_fence_helper(gpointer user_data)
107 fprintf(stderr,
"Could not connect to fencer: %s\n",
pcmk_strerror(rc));
108 g_main_loop_quit(mainloop);
116 async_fence_data.target,
117 async_fence_data.action,
118 async_fence_data.timeout/1000,
119 async_fence_data.tolerance/1000,
120 async_fence_data.delay);
123 g_main_loop_quit(mainloop);
129 async_fence_data.timeout/1000,
142 async_fence_data.st =
st;
143 async_fence_data.name = strdup(name);
144 async_fence_data.target =
target;
145 async_fence_data.action =
action;
146 async_fence_data.timeout =
timeout;
148 async_fence_data.delay =
delay;
154 mainloop = g_main_loop_new(NULL, FALSE);
155 g_main_loop_run(mainloop);
157 free(async_fence_data.name);
162 #ifdef BUILD_PUBLIC_LIBPACEMAKER
164 pcmk_fence_action(
stonith_t *st,
const char *target,
const char *
action,
174 unsigned int timeout,
int verbose,
bool broadcast,
181 out->
info(out,
"cleaning up fencing-history%s%s",
182 target ?
" for node " :
"", target ? target :
"");
185 out->
info(out,
"gather fencing-history from all nodes");
197 &history, timeout/1000);
205 out->
begin_list(out,
"event",
"events",
"Fencing history");
208 for (hp = history; hp; hp = hp->
next) {
213 if (out->
is_quiet(out) || !verbose) {
224 }
else if (!verbose) {
225 out->
message(out,
"stonith-event", latest, 0, FALSE);
236 #ifdef BUILD_PUBLIC_LIBPACEMAKER
238 pcmk_fence_history(xmlNodePtr *xml,
stonith_t *st,
char *target,
unsigned int timeout,
239 bool quiet,
int verbose,
bool broadcast,
bool cleanup) {
269 out->
begin_list(out,
"fence device",
"fence devices",
"Installed fence devices");
271 out->
list_item(out,
"device",
"%s", dIter->value);
279 #ifdef BUILD_PUBLIC_LIBPACEMAKER
281 pcmk_fence_installed(xmlNodePtr *xml,
stonith_t *st,
unsigned int timeout) {
302 if (target == NULL) {
312 return out->
message(out,
"last-fenced", target, when);
315 #ifdef BUILD_PUBLIC_LIBPACEMAKER
317 pcmk_fence_last(xmlNodePtr *xml,
const char *target,
bool as_nodeid) {
336 const char *device_id,
unsigned int timeout) {
337 GList *targets = NULL;
341 rc = st->
cmds->
list(st, st_opts, device_id, &lists, timeout/1000);
348 out->
begin_list(out,
"fence target",
"fence targets",
"Fence Targets");
349 while (targets != NULL) {
350 out->
list_item(out, NULL,
"%s", (
const char *) targets->data);
351 targets = targets->next;
359 #ifdef BUILD_PUBLIC_LIBPACEMAKER
361 pcmk_fence_list_targets(xmlNodePtr *xml,
stonith_t *st,
const char *device_id,
362 unsigned int timeout) {
381 unsigned int timeout) {
395 #ifdef BUILD_PUBLIC_LIBPACEMAKER
397 pcmk_fence_metadata(xmlNodePtr *xml,
stonith_t *st,
char *agent,
398 unsigned int timeout) {
417 unsigned int timeout) {
421 rc = st->
cmds->
query(st, st_opts, target, &devices, timeout/1000);
427 out->
begin_list(out,
"fence device",
"fence devices",
"Registered fence devices");
429 out->
list_item(out,
"device",
"%s", dIter->value);
441 #ifdef BUILD_PUBLIC_LIBPACEMAKER
443 pcmk_fence_registered(xmlNodePtr *xml,
stonith_t *st,
char *target,
444 unsigned int timeout) {
464 return handle_level(st, target, fence_level, devices,
true);
467 #ifdef BUILD_PUBLIC_LIBPACEMAKER
469 pcmk_fence_register_level(
stonith_t *st,
char *target,
int fence_level,
477 return handle_level(st, target, fence_level, NULL,
false);
480 #ifdef BUILD_PUBLIC_LIBPACEMAKER
482 pcmk_fence_unregister_level(
stonith_t *st,
char *target,
int fence_level) {
490 unsigned int timeout) {
492 char *error_output = NULL;
496 timeout/1000, &output, &error_output);
497 out->
message(out,
"validate", agent,
id, output, error_output, rc);
501 #ifdef BUILD_PUBLIC_LIBPACEMAKER
503 pcmk_fence_validate(xmlNodePtr *xml,
stonith_t *st,
const char *agent,
505 unsigned int timeout) {
540 for (np =
new; ; np = np->
next) {
int(* query)(stonith_t *st, int options, const char *node, stonith_key_value_t **devices, int timeout)
Retrieve a list of registered stonith devices.
struct stonith_history_s * next
const char * pcmk_strerror(int rc)
int pcmk__fence_history(pcmk__output_t *out, stonith_t *st, char *target, unsigned int timeout, int verbose, bool broadcast, bool cleanup)
List the fencing operations that have occurred for a specific node.
int(* register_notification)(stonith_t *st, const char *event, void(*notify)(stonith_t *st, stonith_event_t *e))
int(* register_level_full)(stonith_t *st, int options, const char *node, const char *pattern, const char *attr, const char *value, int level, stonith_key_value_t *device_list)
Register fencing level for specific node, node regex or attribute.
void stonith__register_messages(pcmk__output_t *out)
int pcmk__fence_last(pcmk__output_t *out, const char *target, bool as_nodeid)
When was a device last fenced?
int(* history)(stonith_t *st, int options, const char *node, stonith_history_t **output, int timeout)
Retrieve a list of fencing operations that have occurred for a specific node.
stonith_history_t * stonith__sort_history(stonith_history_t *history)
struct stonith_key_value_s * next
void mainloop_set_trigger(crm_trigger_t *source)
int(* message)(pcmk__output_t *out, const char *message_id,...)
int(* list)(stonith_t *st, int options, const char *id, char **list_output, int timeout)
Retrieve string listing hosts and port assignments from a local stonith device.
int pcmk__fence_registered(pcmk__output_t *out, stonith_t *st, char *target, unsigned int timeout)
List registered fence devices.
int pcmk__fence_action(stonith_t *st, const char *target, const char *action, const char *name, unsigned int timeout, unsigned int tolerance, int delay)
Perform a STONITH action.
Wrappers for and extensions to glib mainloop.
int stonith_api_connect_retry(stonith_t *st, const char *name, int max_attempts)
Make a blocking connection attempt to the fencer.
void void void pcmk__formatted_printf(pcmk__output_t *out, const char *format,...) G_GNUC_PRINTF(2
int pcmk__fence_unregister_level(stonith_t *st, char *target, int fence_level)
Unregister a fencing level for a specific node, node regex, or attribute.
struct trigger_s crm_trigger_t
int pcmk__out_prologue(pcmk__output_t **out, xmlNodePtr *xml)
GList * stonith__parse_targets(const char *hosts)
bool(* is_quiet)(pcmk__output_t *out)
void(* end_list)(pcmk__output_t *out)
Formatted output for pacemaker tools.
int(* register_callback)(stonith_t *st, int call_id, int timeout, int options, void *userdata, const char *callback_name, void(*callback)(stonith_t *st, stonith_callback_data_t *data))
Register a callback to receive the result of an asynchronous call.
void(* begin_list)(pcmk__output_t *out, const char *singular_noun, const char *plural_noun, const char *format,...) G_GNUC_PRINTF(4
bool quiet
Should this formatter supress most output?
int(* info)(pcmk__output_t *out, const char *format,...) G_GNUC_PRINTF(2
#define stonith__set_call_options(st_call_opts, call_for, flags_to_set)
int(* metadata)(stonith_t *st, int options, const char *device, const char *provider, char **output, int timeout)
Get the metadata documentation for a resource.
gboolean stonith__later_succeeded(stonith_history_t *event, stonith_history_t *top_history)
crm_trigger_t * mainloop_add_trigger(int priority, int(*dispatch)(gpointer user_data), gpointer userdata)
Create a trigger to be used as a mainloop source.
int(* list_agents)(stonith_t *stonith, int call_options, const char *provider, stonith_key_value_t **devices, int timeout)
Retrieve a list of installed stonith agents.
void stonith_key_value_freeall(stonith_key_value_t *kvp, int keys, int values)
int pcmk_legacy2rc(int legacy_rc)
int pcmk__fence_metadata(pcmk__output_t *out, stonith_t *st, char *agent, unsigned int timeout)
Get metadata for a resource.
int pcmk__fence_list_targets(pcmk__output_t *out, stonith_t *st, const char *device_id, unsigned int timeout)
List nodes that can be fenced.
void pcmk__out_epilogue(pcmk__output_t *out, xmlNodePtr *xml, int retval)
Function and executable result codes.
int(* remove_level_full)(stonith_t *st, int options, const char *node, const char *pattern, const char *attr, const char *value, int level)
Remove fencing level for specific node, node regex or attribute.
int pcmk__fence_register_level(stonith_t *st, char *target, int fence_level, stonith_key_value_t *devices)
Register a fencing level for a specific node, node regex, or attribute.
int(* fence_with_delay)(stonith_t *st, int options, const char *node, const char *action, int timeout, int tolerance, int delay)
Issue a fencing action against a node with requested fencing delay.
void(*) void(*) void(* increment_list)(pcmk__output_t *out)
stonith_api_operations_t * cmds
int pcmk__fence_installed(pcmk__output_t *out, stonith_t *st, unsigned int timeout)
List all installed STONITH agents.
void stonith_history_free(stonith_history_t *history)
This structure contains everything that makes up a single output formatter.
time_t stonith_api_time(uint32_t nodeid, const char *uname, bool in_progress)
#define T_STONITH_NOTIFY_FENCE
int pcmk__fence_validate(pcmk__output_t *out, stonith_t *st, const char *agent, const char *id, stonith_key_value_t *params, unsigned int timeout)
Validate a STONITH device configuration.
stonith_history_t * pcmk__reduce_fence_history(stonith_history_t *history)
Reduce the STONITH history.
int(* validate)(stonith_t *st, int call_options, const char *rsc_id, const char *namespace_s, const char *agent, stonith_key_value_t *params, int timeout, char **output, char **error_output)
Validate an arbitrary stonith device configuration.
int(*) void(*) void(* output_xml)(pcmk__output_t *out, const char *name, const char *buf)
void(*) void(* list_item)(pcmk__output_t *out, const char *name, const char *format,...) G_GNUC_PRINTF(3