root/tools/crm_resource_print.c

/* [previous][next][first][last][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. print_constraint
  2. cli_resource_print_cts_constraints
  3. cli_resource_print_cts
  4. cli_resource_print_operations
  5. cli_resource_print
  6. PCMK__OUTPUT_ARGS
  7. PCMK__OUTPUT_ARGS
  8. PCMK__OUTPUT_ARGS
  9. PCMK__OUTPUT_ARGS
  10. PCMK__OUTPUT_ARGS
  11. PCMK__OUTPUT_ARGS
  12. PCMK__OUTPUT_ARGS
  13. PCMK__OUTPUT_ARGS
  14. PCMK__OUTPUT_ARGS
  15. PCMK__OUTPUT_ARGS
  16. PCMK__OUTPUT_ARGS
  17. PCMK__OUTPUT_ARGS
  18. PCMK__OUTPUT_ARGS
  19. PCMK__OUTPUT_ARGS
  20. PCMK__OUTPUT_ARGS
  21. PCMK__OUTPUT_ARGS
  22. PCMK__OUTPUT_ARGS
  23. PCMK__OUTPUT_ARGS
  24. PCMK__OUTPUT_ARGS
  25. PCMK__OUTPUT_ARGS
  26. add_resource_name
  27. PCMK__OUTPUT_ARGS
  28. crm_resource_register_messages

   1 /*
   2  * Copyright 2004-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 General Public License version 2
   7  * or later (GPLv2+) WITHOUT ANY WARRANTY.
   8  */
   9 
  10 #include <crm_internal.h>
  11 
  12 #include <stdint.h>
  13 
  14 #include <crm_resource.h>
  15 #include <crm/common/lists_internal.h>
  16 #include <crm/common/output.h>
  17 #include <crm/common/results.h>
  18 
  19 #define cons_string(x) x?x:"NA"
  20 static int
  21 print_constraint(xmlNode *xml_obj, void *userdata)
     /* [previous][next][first][last][top][bottom][index][help] */
  22 {
  23     pcmk_scheduler_t *scheduler = (pcmk_scheduler_t *) userdata;
  24     pcmk__output_t *out = scheduler->priv;
  25     xmlNode *lifetime = NULL;
  26     const char *id = crm_element_value(xml_obj, PCMK_XA_ID);
  27     pcmk_rule_input_t rule_input = {
  28         .now = scheduler->now,
  29     };
  30 
  31     if (id == NULL) {
  32         return pcmk_rc_ok;
  33     }
  34 
  35     // @COMPAT PCMK__XE_LIFETIME is deprecated
  36     lifetime = pcmk__xe_first_child(xml_obj, PCMK__XE_LIFETIME, NULL, NULL);
  37     if (pcmk__evaluate_rules(lifetime, &rule_input, NULL) != pcmk_rc_ok) {
  38         return pcmk_rc_ok;
  39     }
  40 
  41     if (!pcmk__xe_is(xml_obj, PCMK_XE_RSC_COLOCATION)) {
  42         return pcmk_rc_ok;
  43     }
  44 
  45     out->info(out, "Constraint %s %s %s %s %s %s %s",
  46               xml_obj->name,
  47               cons_string(crm_element_value(xml_obj, PCMK_XA_ID)),
  48               cons_string(crm_element_value(xml_obj, PCMK_XA_RSC)),
  49               cons_string(crm_element_value(xml_obj, PCMK_XA_WITH_RSC)),
  50               cons_string(crm_element_value(xml_obj, PCMK_XA_SCORE)),
  51               cons_string(crm_element_value(xml_obj, PCMK_XA_RSC_ROLE)),
  52               cons_string(crm_element_value(xml_obj, PCMK_XA_WITH_RSC_ROLE)));
  53 
  54     return pcmk_rc_ok;
  55 }
  56 
  57 void
  58 cli_resource_print_cts_constraints(pcmk_scheduler_t *scheduler)
     /* [previous][next][first][last][top][bottom][index][help] */
  59 {
  60     pcmk__xe_foreach_child(pcmk_find_cib_element(scheduler->input,
  61                                                  PCMK_XE_CONSTRAINTS),
  62                            NULL, print_constraint, scheduler);
  63 }
  64 
  65 void
  66 cli_resource_print_cts(pcmk_resource_t *rsc, pcmk__output_t *out)
     /* [previous][next][first][last][top][bottom][index][help] */
  67 {
  68     const char *host = NULL;
  69     bool needs_quorum = TRUE;
  70     const char *rtype = crm_element_value(rsc->xml, PCMK_XA_TYPE);
  71     const char *rprov = crm_element_value(rsc->xml, PCMK_XA_PROVIDER);
  72     const char *rclass = crm_element_value(rsc->xml, PCMK_XA_CLASS);
  73     pcmk_node_t *node = pcmk__current_node(rsc);
  74 
  75     if (pcmk_is_set(rsc->flags, pcmk_rsc_fence_device)) {
  76         needs_quorum = FALSE;
  77     } else {
  78         // @TODO check requires in resource meta-data and rsc_defaults
  79     }
  80 
  81     if (node != NULL) {
  82         host = node->details->uname;
  83     }
  84 
  85     out->info(out, "Resource: %s %s %s %s %s %s %s %s %d %lld %#.16llx",
  86               rsc->xml->name, rsc->id,
  87               rsc->clone_name ? rsc->clone_name : rsc->id, rsc->parent ? rsc->parent->id : "NA",
  88               rprov ? rprov : "NA", rclass, rtype, host ? host : "NA", needs_quorum, rsc->flags,
  89               rsc->flags);
  90 
  91     g_list_foreach(rsc->children, (GFunc) cli_resource_print_cts, out);
  92 }
  93 
  94 // \return Standard Pacemaker return code
  95 int
  96 cli_resource_print_operations(const char *rsc_id, const char *host_uname,
     /* [previous][next][first][last][top][bottom][index][help] */
  97                               bool active, pcmk_scheduler_t *scheduler)
  98 {
  99     pcmk__output_t *out = scheduler->priv;
 100     int rc = pcmk_rc_no_output;
 101     GList *ops = find_operations(rsc_id, host_uname, active, scheduler);
 102 
 103     if (!ops) {
 104         return rc;
 105     }
 106 
 107     out->begin_list(out, NULL, NULL, "Resource Operations");
 108     rc = pcmk_rc_ok;
 109 
 110     for (GList *lpc = ops; lpc != NULL; lpc = lpc->next) {
 111         xmlNode *xml_op = (xmlNode *) lpc->data;
 112         out->message(out, "node-and-op", scheduler, xml_op);
 113     }
 114 
 115     out->end_list(out);
 116     return rc;
 117 }
 118 
 119 // \return Standard Pacemaker return code
 120 int
 121 cli_resource_print(pcmk_resource_t *rsc, pcmk_scheduler_t *scheduler,
     /* [previous][next][first][last][top][bottom][index][help] */
 122                    bool expanded)
 123 {
 124     pcmk__output_t *out = scheduler->priv;
 125     uint32_t show_opts = pcmk_show_pending;
 126     GList *all = NULL;
 127 
 128     all = g_list_prepend(all, (gpointer) "*");
 129 
 130     out->begin_list(out, NULL, NULL, "Resource Config");
 131     out->message(out, pcmk__map_element_name(rsc->xml), show_opts, rsc, all,
 132                  all);
 133     out->message(out, "resource-config", rsc, !expanded);
 134     out->end_list(out);
 135 
 136     g_list_free(all);
 137     return pcmk_rc_ok;
 138 }
 139 
 140 PCMK__OUTPUT_ARGS("attribute-changed", "attr_update_data_t *")
     /* [previous][next][first][last][top][bottom][index][help] */
 141 static int
 142 attribute_changed_default(pcmk__output_t *out, va_list args)
 143 {
 144     attr_update_data_t *ud = va_arg(args, attr_update_data_t *);
 145 
 146     out->info(out, "Set '%s' option: "
 147               PCMK_XA_ID "=%s%s%s%s%s value=%s",
 148               ud->given_rsc_id, ud->found_attr_id,
 149               ((ud->attr_set_id == NULL)? "" : " " PCMK__XA_SET "="),
 150               pcmk__s(ud->attr_set_id, ""),
 151               ((ud->attr_name == NULL)? "" : " " PCMK_XA_NAME "="),
 152               pcmk__s(ud->attr_name, ""), ud->attr_value);
 153 
 154     return pcmk_rc_ok;
 155 }
 156 
 157 PCMK__OUTPUT_ARGS("attribute-changed", "attr_update_data_t *")
     /* [previous][next][first][last][top][bottom][index][help] */
 158 static int
 159 attribute_changed_xml(pcmk__output_t *out, va_list args)
 160 {
 161     attr_update_data_t *ud = va_arg(args, attr_update_data_t *);
 162 
 163     pcmk__output_xml_create_parent(out, (const char *) ud->rsc->xml->name,
 164                                    PCMK_XA_ID, ud->rsc->id,
 165                                    NULL);
 166 
 167     pcmk__output_xml_create_parent(out, ud->attr_set_type,
 168                                    PCMK_XA_ID, ud->attr_set_id,
 169                                    NULL);
 170 
 171     pcmk__output_create_xml_node(out, PCMK_XE_NVPAIR,
 172                                  PCMK_XA_ID, ud->found_attr_id,
 173                                  PCMK_XA_VALUE, ud->attr_value,
 174                                  PCMK_XA_NAME, ud->attr_name,
 175                                  NULL);
 176 
 177     pcmk__output_xml_pop_parent(out);
 178     pcmk__output_xml_pop_parent(out);
 179 
 180     return pcmk_rc_ok;
 181 }
 182 
 183 PCMK__OUTPUT_ARGS("attribute-changed-list", "GList *")
     /* [previous][next][first][last][top][bottom][index][help] */
 184 static int
 185 attribute_changed_list_default(pcmk__output_t *out, va_list args)
 186 {
 187     GList *results = va_arg(args, GList *);
 188 
 189     if (results == NULL) {
 190         return pcmk_rc_no_output;
 191     }
 192 
 193     for (GList *iter = results; iter != NULL; iter = iter->next) {
 194         attr_update_data_t *ud = iter->data;
 195         out->message(out, "attribute-changed", ud);
 196     }
 197 
 198     return pcmk_rc_ok;
 199 }
 200 
 201 PCMK__OUTPUT_ARGS("attribute-changed-list", "GList *")
     /* [previous][next][first][last][top][bottom][index][help] */
 202 static int
 203 attribute_changed_list_xml(pcmk__output_t *out, va_list args)
 204 {
 205     GList *results = va_arg(args, GList *);
 206 
 207     if (results == NULL) {
 208         return pcmk_rc_no_output;
 209     }
 210 
 211     pcmk__output_xml_create_parent(out, PCMK__XE_RESOURCE_SETTINGS, NULL);
 212 
 213     for (GList *iter = results; iter != NULL; iter = iter->next) {
 214         attr_update_data_t *ud = iter->data;
 215         out->message(out, "attribute-changed", ud);
 216     }
 217 
 218     pcmk__output_xml_pop_parent(out);
 219     return pcmk_rc_ok;
 220 }
 221 
 222 PCMK__OUTPUT_ARGS("attribute-list", "pcmk_resource_t *", "const char *",
     /* [previous][next][first][last][top][bottom][index][help] */
 223                   "const char *")
 224 static int
 225 attribute_list_default(pcmk__output_t *out, va_list args) {
 226     pcmk_resource_t *rsc = va_arg(args, pcmk_resource_t *);
 227     const char *attr = va_arg(args, char *);
 228     const char *value = va_arg(args, const char *);
 229 
 230     if (value != NULL) {
 231         out->begin_list(out, NULL, NULL, "Attributes");
 232         out->list_item(out, attr, "%s", value);
 233         out->end_list(out);
 234         return pcmk_rc_ok;
 235     } else {
 236         out->err(out, "Attribute '%s' not found for '%s'", attr, rsc->id);
 237     }
 238     return pcmk_rc_ok;
 239 }
 240 
 241 PCMK__OUTPUT_ARGS("agent-status", "int", "const char *", "const char *", "const char *",
     /* [previous][next][first][last][top][bottom][index][help] */
 242                   "const char *", "const char *", "crm_exit_t", "const char *")
 243 static int
 244 agent_status_default(pcmk__output_t *out, va_list args) {
 245     int status = va_arg(args, int);
 246     const char *action = va_arg(args, const char *);
 247     const char *name = va_arg(args, const char *);
 248     const char *class = va_arg(args, const char *);
 249     const char *provider = va_arg(args, const char *);
 250     const char *type = va_arg(args, const char *);
 251     crm_exit_t rc = va_arg(args, crm_exit_t);
 252     const char *exit_reason = va_arg(args, const char *);
 253 
 254     if (status == PCMK_EXEC_DONE) {
 255         /* Operation <action> [for <resource>] (<class>[:<provider>]:<agent>)
 256          * returned <exit-code> (<exit-description>[: <exit-reason>])
 257          */
 258         out->info(out, "Operation %s%s%s (%s%s%s:%s) returned %d (%s%s%s)",
 259                   action,
 260                   ((name == NULL)? "" : " for "), ((name == NULL)? "" : name),
 261                   class,
 262                   ((provider == NULL)? "" : ":"),
 263                   ((provider == NULL)? "" : provider),
 264                   type, (int) rc, services_ocf_exitcode_str((int) rc),
 265                   ((exit_reason == NULL)? "" : ": "),
 266                   ((exit_reason == NULL)? "" : exit_reason));
 267     } else {
 268         /* Operation <action> [for <resource>] (<class>[:<provider>]:<agent>)
 269          * could not be executed (<execution-status>[: <exit-reason>])
 270          */
 271         out->err(out,
 272                  "Operation %s%s%s (%s%s%s:%s) could not be executed (%s%s%s)",
 273                  action,
 274                  ((name == NULL)? "" : " for "), ((name == NULL)? "" : name),
 275                  class,
 276                  ((provider == NULL)? "" : ":"),
 277                  ((provider == NULL)? "" : provider),
 278                  type, pcmk_exec_status_str(status),
 279                  ((exit_reason == NULL)? "" : ": "),
 280                  ((exit_reason == NULL)? "" : exit_reason));
 281     }
 282 
 283     return pcmk_rc_ok;
 284 }
 285 
 286 PCMK__OUTPUT_ARGS("agent-status", "int", "const char *", "const char *", "const char *",
     /* [previous][next][first][last][top][bottom][index][help] */
 287                   "const char *", "const char *", "crm_exit_t", "const char *")
 288 static int
 289 agent_status_xml(pcmk__output_t *out, va_list args) {
 290     int status = va_arg(args, int);
 291     const char *action G_GNUC_UNUSED = va_arg(args, const char *);
 292     const char *name G_GNUC_UNUSED = va_arg(args, const char *);
 293     const char *class G_GNUC_UNUSED = va_arg(args, const char *);
 294     const char *provider G_GNUC_UNUSED = va_arg(args, const char *);
 295     const char *type G_GNUC_UNUSED = va_arg(args, const char *);
 296     crm_exit_t rc = va_arg(args, crm_exit_t);
 297     const char *exit_reason = va_arg(args, const char *);
 298 
 299     char *exit_s = pcmk__itoa(rc);
 300     const char *message = services_ocf_exitcode_str((int) rc);
 301     char *status_s = pcmk__itoa(status);
 302     const char *execution_message = pcmk_exec_status_str(status);
 303 
 304     pcmk__output_create_xml_node(out, PCMK_XE_AGENT_STATUS,
 305                                  PCMK_XA_CODE, exit_s,
 306                                  PCMK_XA_MESSAGE, message,
 307                                  PCMK_XA_EXECUTION_CODE, status_s,
 308                                  PCMK_XA_EXECUTION_MESSAGE, execution_message,
 309                                  PCMK_XA_REASON, exit_reason,
 310                                  NULL);
 311 
 312     free(exit_s);
 313     free(status_s);
 314 
 315     return pcmk_rc_ok;
 316 }
 317 
 318 PCMK__OUTPUT_ARGS("attribute-list", "pcmk_resource_t *", "const char *",
     /* [previous][next][first][last][top][bottom][index][help] */
 319                   "const char *")
 320 static int
 321 attribute_list_text(pcmk__output_t *out, va_list args) {
 322     pcmk_resource_t *rsc = va_arg(args, pcmk_resource_t *);
 323     const char *attr = va_arg(args, char *);
 324     const char *value = va_arg(args, const char *);
 325 
 326     if (value != NULL) {
 327         pcmk__formatted_printf(out, "%s\n", value);
 328         return pcmk_rc_ok;
 329     } else {
 330         out->err(out, "Attribute '%s' not found for '%s'", attr, rsc->id);
 331     }
 332     return pcmk_rc_ok;
 333 }
 334 PCMK__OUTPUT_ARGS("override", "const char *", "const char *", "const char *")
     /* [previous][next][first][last][top][bottom][index][help] */
 335 static int
 336 override_default(pcmk__output_t *out, va_list args) {
 337     const char *rsc_name = va_arg(args, const char *);
 338     const char *name = va_arg(args, const char *);
 339     const char *value = va_arg(args, const char *);
 340 
 341     if (rsc_name == NULL) {
 342         out->list_item(out, NULL, "Overriding the cluster configuration with '%s' = '%s'",
 343                        name, value);
 344     } else {
 345         out->list_item(out, NULL, "Overriding the cluster configuration for '%s' with '%s' = '%s'",
 346                        rsc_name, name, value);
 347     }
 348 
 349     return pcmk_rc_ok;
 350 }
 351 
 352 PCMK__OUTPUT_ARGS("override", "const char *", "const char *", "const char *")
     /* [previous][next][first][last][top][bottom][index][help] */
 353 static int
 354 override_xml(pcmk__output_t *out, va_list args) {
 355     const char *rsc_name = va_arg(args, const char *);
 356     const char *name = va_arg(args, const char *);
 357     const char *value = va_arg(args, const char *);
 358 
 359     xmlNodePtr node = pcmk__output_create_xml_node(out, PCMK_XE_OVERRIDE,
 360                                                    PCMK_XA_NAME, name,
 361                                                    PCMK_XA_VALUE, value,
 362                                                    NULL);
 363 
 364     if (rsc_name != NULL) {
 365         crm_xml_add(node, PCMK_XA_RSC, rsc_name);
 366     }
 367 
 368     return pcmk_rc_ok;
 369 }
 370 
 371 PCMK__OUTPUT_ARGS("property-list", "pcmk_resource_t *", "const char *")
     /* [previous][next][first][last][top][bottom][index][help] */
 372 static int
 373 property_list_default(pcmk__output_t *out, va_list args) {
 374     pcmk_resource_t *rsc = va_arg(args, pcmk_resource_t *);
 375     const char *attr = va_arg(args, char *);
 376 
 377     const char *value = crm_element_value(rsc->xml, attr);
 378 
 379     if (value != NULL) {
 380         out->begin_list(out, NULL, NULL, "Properties");
 381         out->list_item(out, attr, "%s", value);
 382         out->end_list(out);
 383     }
 384 
 385     return pcmk_rc_ok;
 386 }
 387 
 388 PCMK__OUTPUT_ARGS("property-list", "pcmk_resource_t *", "const char *")
     /* [previous][next][first][last][top][bottom][index][help] */
 389 static int
 390 property_list_text(pcmk__output_t *out, va_list args) {
 391     pcmk_resource_t *rsc = va_arg(args, pcmk_resource_t *);
 392     const char *attr = va_arg(args, const char *);
 393 
 394     const char *value = crm_element_value(rsc->xml, attr);
 395 
 396     if (value != NULL) {
 397         pcmk__formatted_printf(out, "%s\n", value);
 398     }
 399 
 400     return pcmk_rc_ok;
 401 }
 402 
 403 PCMK__OUTPUT_ARGS("resource-agent-action", "int", "const char *", "const char *",
     /* [previous][next][first][last][top][bottom][index][help] */
 404                   "const char *", "const char *", "const char *", "GHashTable *",
 405                   "crm_exit_t", "int", "const char *", "const char *", "const char *")
 406 static int
 407 resource_agent_action_default(pcmk__output_t *out, va_list args) {
 408     int verbose = va_arg(args, int);
 409 
 410     const char *class = va_arg(args, const char *);
 411     const char *provider = va_arg(args, const char *);
 412     const char *type = va_arg(args, const char *);
 413     const char *rsc_name = va_arg(args, const char *);
 414     const char *action = va_arg(args, const char *);
 415     GHashTable *overrides = va_arg(args, GHashTable *);
 416     crm_exit_t rc = va_arg(args, crm_exit_t);
 417     int status = va_arg(args, int);
 418     const char *exit_reason = va_arg(args, const char *);
 419     const char *stdout_data = va_arg(args, const char *);
 420     const char *stderr_data = va_arg(args, const char *);
 421 
 422     if (overrides) {
 423         GHashTableIter iter;
 424         const char *name = NULL;
 425         const char *value = NULL;
 426 
 427         out->begin_list(out, NULL, NULL, PCMK_XE_OVERRIDES);
 428 
 429         g_hash_table_iter_init(&iter, overrides);
 430         while (g_hash_table_iter_next(&iter, (gpointer *) &name, (gpointer *) &value)) {
 431             out->message(out, "override", rsc_name, name, value);
 432         }
 433 
 434         out->end_list(out);
 435     }
 436 
 437     out->message(out, "agent-status", status, action, rsc_name, class, provider,
 438                  type, rc, exit_reason);
 439 
 440     /* hide output for validate-all if not in verbose */
 441     if ((verbose == 0)
 442         && pcmk__str_eq(action, PCMK_ACTION_VALIDATE_ALL, pcmk__str_casei)) {
 443         return pcmk_rc_ok;
 444     }
 445 
 446     if (stdout_data || stderr_data) {
 447         xmlNodePtr doc = NULL;
 448 
 449         if (stdout_data != NULL) {
 450             doc = pcmk__xml_parse(stdout_data);
 451         }
 452         if (doc != NULL) {
 453             out->output_xml(out, PCMK_XE_COMMAND, stdout_data);
 454             free_xml(doc);
 455         } else {
 456             out->subprocess_output(out, rc, stdout_data, stderr_data);
 457         }
 458     }
 459 
 460     return pcmk_rc_ok;
 461 }
 462 
 463 PCMK__OUTPUT_ARGS("resource-agent-action", "int", "const char *", "const char *",
     /* [previous][next][first][last][top][bottom][index][help] */
 464                   "const char *", "const char *", "const char *", "GHashTable *",
 465                   "crm_exit_t", "int", "const char *", "const char *", "const char *")
 466 static int
 467 resource_agent_action_xml(pcmk__output_t *out, va_list args) {
 468     int verbose G_GNUC_UNUSED = va_arg(args, int);
 469 
 470     const char *class = va_arg(args, const char *);
 471     const char *provider = va_arg(args, const char *);
 472     const char *type = va_arg(args, const char *);
 473     const char *rsc_name = va_arg(args, const char *);
 474     const char *action = va_arg(args, const char *);
 475     GHashTable *overrides = va_arg(args, GHashTable *);
 476     crm_exit_t rc = va_arg(args, crm_exit_t);
 477     int status = va_arg(args, int);
 478     const char *exit_reason = va_arg(args, const char *);
 479     const char *stdout_data = va_arg(args, const char *);
 480     const char *stderr_data = va_arg(args, const char *);
 481 
 482     xmlNodePtr node = NULL;
 483 
 484     node = pcmk__output_xml_create_parent(out, PCMK_XE_RESOURCE_AGENT_ACTION,
 485                                           PCMK_XA_ACTION, action,
 486                                           PCMK_XA_CLASS, class,
 487                                           PCMK_XA_TYPE, type,
 488                                           NULL);
 489 
 490     if (rsc_name) {
 491         crm_xml_add(node, PCMK_XA_RSC, rsc_name);
 492     }
 493 
 494     crm_xml_add(node, PCMK_XA_PROVIDER, provider);
 495 
 496     if (overrides) {
 497         GHashTableIter iter;
 498         const char *name = NULL;
 499         const char *value = NULL;
 500 
 501         out->begin_list(out, NULL, NULL, PCMK_XE_OVERRIDES);
 502 
 503         g_hash_table_iter_init(&iter, overrides);
 504         while (g_hash_table_iter_next(&iter, (gpointer *) &name, (gpointer *) &value)) {
 505             out->message(out, "override", rsc_name, name, value);
 506         }
 507 
 508         out->end_list(out);
 509     }
 510 
 511     out->message(out, "agent-status", status, action, rsc_name, class, provider,
 512                  type, rc, exit_reason);
 513 
 514     if (stdout_data || stderr_data) {
 515         xmlNodePtr doc = NULL;
 516 
 517         if (stdout_data != NULL) {
 518             doc = pcmk__xml_parse(stdout_data);
 519         }
 520         if (doc != NULL) {
 521             out->output_xml(out, PCMK_XE_COMMAND, stdout_data);
 522             free_xml(doc);
 523         } else {
 524             out->subprocess_output(out, rc, stdout_data, stderr_data);
 525         }
 526     }
 527 
 528     pcmk__output_xml_pop_parent(out);
 529     return pcmk_rc_ok;
 530 }
 531 
 532 PCMK__OUTPUT_ARGS("resource-check-list", "resource_checks_t *")
     /* [previous][next][first][last][top][bottom][index][help] */
 533 static int
 534 resource_check_list_default(pcmk__output_t *out, va_list args) {
 535     resource_checks_t *checks = va_arg(args, resource_checks_t *);
 536 
 537     const pcmk_resource_t *parent = pe__const_top_resource(checks->rsc, false);
 538 
 539     if (checks->flags == 0) {
 540         return pcmk_rc_no_output;
 541     }
 542 
 543     out->begin_list(out, NULL, NULL, "Resource Checks");
 544 
 545     if (pcmk_is_set(checks->flags, rsc_remain_stopped)) {
 546         out->list_item(out, "check", "Configuration specifies '%s' should remain stopped",
 547                        parent->id);
 548     }
 549 
 550     if (pcmk_is_set(checks->flags, rsc_unpromotable)) {
 551         out->list_item(out, "check", "Configuration specifies '%s' should not be promoted",
 552                        parent->id);
 553     }
 554 
 555     if (pcmk_is_set(checks->flags, rsc_unmanaged)) {
 556         out->list_item(out, "check", "Configuration prevents cluster from stopping or starting unmanaged '%s'",
 557                        parent->id);
 558     }
 559 
 560     if (pcmk_is_set(checks->flags, rsc_locked)) {
 561         out->list_item(out, "check", "'%s' is locked to node %s due to shutdown",
 562                        parent->id, checks->lock_node);
 563     }
 564 
 565     if (pcmk_is_set(checks->flags, rsc_node_health)) {
 566         out->list_item(out, "check",
 567                        "'%s' cannot run on unhealthy nodes due to "
 568                        PCMK_OPT_NODE_HEALTH_STRATEGY "='%s'",
 569                        parent->id,
 570                        pcmk__cluster_option(checks->rsc->cluster->config_hash,
 571                                             PCMK_OPT_NODE_HEALTH_STRATEGY));
 572     }
 573 
 574     out->end_list(out);
 575     return pcmk_rc_ok;
 576 }
 577 
 578 PCMK__OUTPUT_ARGS("resource-check-list", "resource_checks_t *")
     /* [previous][next][first][last][top][bottom][index][help] */
 579 static int
 580 resource_check_list_xml(pcmk__output_t *out, va_list args) {
 581     resource_checks_t *checks = va_arg(args, resource_checks_t *);
 582 
 583     const pcmk_resource_t *parent = pe__const_top_resource(checks->rsc, false);
 584 
 585     xmlNodePtr node = pcmk__output_create_xml_node(out, PCMK_XE_CHECK,
 586                                                    PCMK_XA_ID, parent->id,
 587                                                    NULL);
 588 
 589     if (pcmk_is_set(checks->flags, rsc_remain_stopped)) {
 590         pcmk__xe_set_bool_attr(node, PCMK_XA_REMAIN_STOPPED, true);
 591     }
 592 
 593     if (pcmk_is_set(checks->flags, rsc_unpromotable)) {
 594         pcmk__xe_set_bool_attr(node, PCMK_XA_PROMOTABLE, false);
 595     }
 596 
 597     if (pcmk_is_set(checks->flags, rsc_unmanaged)) {
 598         pcmk__xe_set_bool_attr(node, PCMK_XA_UNMANAGED, true);
 599     }
 600 
 601     if (pcmk_is_set(checks->flags, rsc_locked)) {
 602         crm_xml_add(node, PCMK_XA_LOCKED_TO_HYPHEN, checks->lock_node);
 603     }
 604 
 605     if (pcmk_is_set(checks->flags, rsc_node_health)) {
 606         pcmk__xe_set_bool_attr(node, PCMK_XA_UNHEALTHY, true);
 607     }
 608 
 609     return pcmk_rc_ok;
 610 }
 611 
 612 PCMK__OUTPUT_ARGS("resource-search-list", "GList *", "const gchar *")
     /* [previous][next][first][last][top][bottom][index][help] */
 613 static int
 614 resource_search_list_default(pcmk__output_t *out, va_list args)
 615 {
 616     GList *nodes = va_arg(args, GList *);
 617     const gchar *requested_name = va_arg(args, const gchar *);
 618 
 619     bool printed = false;
 620     int rc = pcmk_rc_no_output;
 621 
 622     if (!out->is_quiet(out) && nodes == NULL) {
 623         out->err(out, "resource %s is NOT running", requested_name);
 624         return rc;
 625     }
 626 
 627     for (GList *lpc = nodes; lpc != NULL; lpc = lpc->next) {
 628         node_info_t *ni = (node_info_t *) lpc->data;
 629 
 630         if (!printed) {
 631             out->begin_list(out, NULL, NULL, "Nodes");
 632             printed = true;
 633             rc = pcmk_rc_ok;
 634         }
 635 
 636         if (out->is_quiet(out)) {
 637             out->list_item(out, "node", "%s", ni->node_name);
 638         } else {
 639             const char *role_text = "";
 640 
 641             if (ni->promoted) {
 642 #ifdef PCMK__COMPAT_2_0
 643                 role_text = " " PCMK__ROLE_PROMOTED_LEGACY;
 644 #else
 645                 role_text = " " PCMK_ROLE_PROMOTED;
 646 #endif
 647             }
 648             out->list_item(out, "node", "resource %s is running on: %s%s",
 649                            requested_name, ni->node_name, role_text);
 650         }
 651     }
 652 
 653     if (printed) {
 654         out->end_list(out);
 655     }
 656 
 657     return rc;
 658 }
 659 
 660 PCMK__OUTPUT_ARGS("resource-search-list", "GList *", "const gchar *")
     /* [previous][next][first][last][top][bottom][index][help] */
 661 static int
 662 resource_search_list_xml(pcmk__output_t *out, va_list args)
 663 {
 664     GList *nodes = va_arg(args, GList *);
 665     const gchar *requested_name = va_arg(args, const gchar *);
 666 
 667     pcmk__output_xml_create_parent(out, PCMK_XE_NODES,
 668                                    PCMK_XA_RESOURCE, requested_name,
 669                                    NULL);
 670 
 671     for (GList *lpc = nodes; lpc != NULL; lpc = lpc->next) {
 672         node_info_t *ni = (node_info_t *) lpc->data;
 673         xmlNodePtr sub_node = pcmk__output_create_xml_text_node(out,
 674                                                                 PCMK_XE_NODE,
 675                                                                 ni->node_name);
 676 
 677         if (ni->promoted) {
 678             crm_xml_add(sub_node, PCMK_XA_STATE, "promoted");
 679         }
 680     }
 681 
 682     pcmk__output_xml_pop_parent(out);
 683     return pcmk_rc_ok;
 684 }
 685 
 686 PCMK__OUTPUT_ARGS("resource-reasons-list", "GList *", "pcmk_resource_t *",
     /* [previous][next][first][last][top][bottom][index][help] */
 687                   "pcmk_node_t *")
 688 static int
 689 resource_reasons_list_default(pcmk__output_t *out, va_list args)
 690 {
 691     GList *resources = va_arg(args, GList *);
 692     pcmk_resource_t *rsc = va_arg(args, pcmk_resource_t *);
 693     pcmk_node_t *node = va_arg(args, pcmk_node_t *);
 694 
 695     const char *host_uname = (node == NULL)? NULL : node->details->uname;
 696 
 697     out->begin_list(out, NULL, NULL, "Resource Reasons");
 698 
 699     if ((rsc == NULL) && (host_uname == NULL)) {
 700         GList *lpc = NULL;
 701         GList *hosts = NULL;
 702 
 703         for (lpc = resources; lpc != NULL; lpc = lpc->next) {
 704             pcmk_resource_t *rsc = (pcmk_resource_t *) lpc->data;
 705             rsc->fns->location(rsc, &hosts, TRUE);
 706 
 707             if (hosts == NULL) {
 708                 out->list_item(out, "reason", "Resource %s is not running", rsc->id);
 709             } else {
 710                 out->list_item(out, "reason", "Resource %s is running", rsc->id);
 711             }
 712 
 713             cli_resource_check(out, rsc, NULL);
 714             g_list_free(hosts);
 715             hosts = NULL;
 716         }
 717 
 718     } else if ((rsc != NULL) && (host_uname != NULL)) {
 719         if (resource_is_running_on(rsc, host_uname)) {
 720             out->list_item(out, "reason", "Resource %s is running on host %s",
 721                            rsc->id, host_uname);
 722         } else {
 723             out->list_item(out, "reason", "Resource %s is not running on host %s",
 724                            rsc->id, host_uname);
 725         }
 726 
 727         cli_resource_check(out, rsc, node);
 728 
 729     } else if ((rsc == NULL) && (host_uname != NULL)) {
 730         const char* host_uname =  node->details->uname;
 731         GList *allResources = node->details->allocated_rsc;
 732         GList *activeResources = node->details->running_rsc;
 733         GList *unactiveResources = pcmk__subtract_lists(allResources, activeResources, (GCompareFunc) strcmp);
 734         GList *lpc = NULL;
 735 
 736         for (lpc = activeResources; lpc != NULL; lpc = lpc->next) {
 737             pcmk_resource_t *rsc = (pcmk_resource_t *) lpc->data;
 738             out->list_item(out, "reason", "Resource %s is running on host %s",
 739                            rsc->id, host_uname);
 740             cli_resource_check(out, rsc, node);
 741         }
 742 
 743         for(lpc = unactiveResources; lpc != NULL; lpc = lpc->next) {
 744             pcmk_resource_t *rsc = (pcmk_resource_t *) lpc->data;
 745             out->list_item(out, "reason", "Resource %s is assigned to host %s but not running",
 746                            rsc->id, host_uname);
 747             cli_resource_check(out, rsc, node);
 748         }
 749 
 750         g_list_free(allResources);
 751         g_list_free(activeResources);
 752         g_list_free(unactiveResources);
 753 
 754     } else if ((rsc != NULL) && (host_uname == NULL)) {
 755         GList *hosts = NULL;
 756 
 757         rsc->fns->location(rsc, &hosts, TRUE);
 758         out->list_item(out, "reason", "Resource %s is %srunning",
 759                        rsc->id, (hosts? "" : "not "));
 760         cli_resource_check(out, rsc, NULL);
 761         g_list_free(hosts);
 762     }
 763 
 764     out->end_list(out);
 765     return pcmk_rc_ok;
 766 }
 767 
 768 PCMK__OUTPUT_ARGS("resource-reasons-list", "GList *", "pcmk_resource_t *",
     /* [previous][next][first][last][top][bottom][index][help] */
 769                   "pcmk_node_t *")
 770 static int
 771 resource_reasons_list_xml(pcmk__output_t *out, va_list args)
 772 {
 773     GList *resources = va_arg(args, GList *);
 774     pcmk_resource_t *rsc = va_arg(args, pcmk_resource_t *);
 775     pcmk_node_t *node = va_arg(args, pcmk_node_t *);
 776 
 777     const char *host_uname = (node == NULL)? NULL : node->details->uname;
 778 
 779     xmlNodePtr xml_node = pcmk__output_xml_create_parent(out, PCMK_XE_REASON,
 780                                                          NULL);
 781 
 782     if ((rsc == NULL) && (host_uname == NULL)) {
 783         GList *lpc = NULL;
 784         GList *hosts = NULL;
 785 
 786         pcmk__output_xml_create_parent(out, PCMK_XE_RESOURCES, NULL);
 787 
 788         for (lpc = resources; lpc != NULL; lpc = lpc->next) {
 789             pcmk_resource_t *rsc = (pcmk_resource_t *) lpc->data;
 790             const char *running = NULL;
 791 
 792             rsc->fns->location(rsc, &hosts, TRUE);
 793             running = pcmk__btoa(hosts != NULL);
 794 
 795             pcmk__output_xml_create_parent(out, PCMK_XE_RESOURCE,
 796                                            PCMK_XA_ID, rsc->id,
 797                                            PCMK_XA_RUNNING, running,
 798                                            NULL);
 799 
 800             cli_resource_check(out, rsc, NULL);
 801             pcmk__output_xml_pop_parent(out);
 802             g_list_free(hosts);
 803             hosts = NULL;
 804         }
 805 
 806         pcmk__output_xml_pop_parent(out);
 807 
 808     } else if ((rsc != NULL) && (host_uname != NULL)) {
 809         if (resource_is_running_on(rsc, host_uname)) {
 810             crm_xml_add(xml_node, PCMK_XA_RUNNING_ON, host_uname);
 811         }
 812 
 813         cli_resource_check(out, rsc, node);
 814 
 815     } else if ((rsc == NULL) && (host_uname != NULL)) {
 816         const char* host_uname =  node->details->uname;
 817         GList *allResources = node->details->allocated_rsc;
 818         GList *activeResources = node->details->running_rsc;
 819         GList *unactiveResources = pcmk__subtract_lists(allResources, activeResources, (GCompareFunc) strcmp);
 820         GList *lpc = NULL;
 821 
 822         pcmk__output_xml_create_parent(out, PCMK_XE_RESOURCES, NULL);
 823 
 824         for (lpc = activeResources; lpc != NULL; lpc = lpc->next) {
 825             pcmk_resource_t *rsc = (pcmk_resource_t *) lpc->data;
 826 
 827             pcmk__output_xml_create_parent(out, PCMK_XE_RESOURCE,
 828                                            PCMK_XA_ID, rsc->id,
 829                                            PCMK_XA_RUNNING, PCMK_VALUE_TRUE,
 830                                            PCMK_XA_HOST, host_uname,
 831                                            NULL);
 832 
 833             cli_resource_check(out, rsc, node);
 834             pcmk__output_xml_pop_parent(out);
 835         }
 836 
 837         for(lpc = unactiveResources; lpc != NULL; lpc = lpc->next) {
 838             pcmk_resource_t *rsc = (pcmk_resource_t *) lpc->data;
 839 
 840             pcmk__output_xml_create_parent(out, PCMK_XE_RESOURCE,
 841                                            PCMK_XA_ID, rsc->id,
 842                                            PCMK_XA_RUNNING, PCMK_VALUE_FALSE,
 843                                            PCMK_XA_HOST, host_uname,
 844                                            NULL);
 845 
 846             cli_resource_check(out, rsc, node);
 847             pcmk__output_xml_pop_parent(out);
 848         }
 849 
 850         pcmk__output_xml_pop_parent(out);
 851         g_list_free(allResources);
 852         g_list_free(activeResources);
 853         g_list_free(unactiveResources);
 854 
 855     } else if ((rsc != NULL) && (host_uname == NULL)) {
 856         GList *hosts = NULL;
 857 
 858         rsc->fns->location(rsc, &hosts, TRUE);
 859         crm_xml_add(xml_node, PCMK_XA_RUNNING, pcmk__btoa(hosts != NULL));
 860         cli_resource_check(out, rsc, NULL);
 861         g_list_free(hosts);
 862     }
 863 
 864     pcmk__output_xml_pop_parent(out);
 865     return pcmk_rc_ok;
 866 }
 867 
 868 static void
 869 add_resource_name(pcmk_resource_t *rsc, pcmk__output_t *out)
     /* [previous][next][first][last][top][bottom][index][help] */
 870 {
 871     if (rsc->children == NULL) {
 872         /* Sometimes PCMK_XE_RESOURCE might act as a PCMK_XA_NAME instead of an
 873          * XML element name, depending on whether pcmk__output_enable_list_element
 874          * was called.
 875          */
 876         out->list_item(out, PCMK_XE_RESOURCE, "%s", rsc->id);
 877     } else {
 878         g_list_foreach(rsc->children, (GFunc) add_resource_name, out);
 879     }
 880 }
 881 
 882 PCMK__OUTPUT_ARGS("resource-names-list", "GList *")
     /* [previous][next][first][last][top][bottom][index][help] */
 883 static int
 884 resource_names(pcmk__output_t *out, va_list args) {
 885     GList *resources = va_arg(args, GList *);
 886 
 887     if (resources == NULL) {
 888         out->err(out, "NO resources configured\n");
 889         return pcmk_rc_no_output;
 890     }
 891 
 892     out->begin_list(out, NULL, NULL, "Resource Names");
 893     g_list_foreach(resources, (GFunc) add_resource_name, out);
 894     out->end_list(out);
 895     return pcmk_rc_ok;
 896 }
 897 
 898 static pcmk__message_entry_t fmt_functions[] = {
 899     { "agent-status", "default", agent_status_default },
 900     { "agent-status", "xml", agent_status_xml },
 901     { "attribute-changed", "default", attribute_changed_default },
 902     { "attribute-changed", "xml", attribute_changed_xml },
 903     { "attribute-changed-list", "default", attribute_changed_list_default },
 904     { "attribute-changed-list", "xml", attribute_changed_list_xml },
 905     { "attribute-list", "default", attribute_list_default },
 906     { "attribute-list", "text", attribute_list_text },
 907     { "override", "default", override_default },
 908     { "override", "xml", override_xml },
 909     { "property-list", "default", property_list_default },
 910     { "property-list", "text", property_list_text },
 911     { "resource-agent-action", "default", resource_agent_action_default },
 912     { "resource-agent-action", "xml", resource_agent_action_xml },
 913     { "resource-check-list", "default", resource_check_list_default },
 914     { "resource-check-list", "xml", resource_check_list_xml },
 915     { "resource-search-list", "default", resource_search_list_default },
 916     { "resource-search-list", "xml", resource_search_list_xml },
 917     { "resource-reasons-list", "default", resource_reasons_list_default },
 918     { "resource-reasons-list", "xml", resource_reasons_list_xml },
 919     { "resource-names-list", "default", resource_names },
 920 
 921     { NULL, NULL, NULL }
 922 };
 923 
 924 void
 925 crm_resource_register_messages(pcmk__output_t *out) {
     /* [previous][next][first][last][top][bottom][index][help] */
 926     pcmk__register_messages(out, fmt_functions);
 927 }

/* [previous][next][first][last][top][bottom][index][help] */