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. add_resource_name
  23. PCMK__OUTPUT_ARGS
  24. crm_resource_register_messages

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

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