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

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