From a56cb28e9fa3d92b5ee0a238befcf0f7ac6f3287 Mon Sep 17 00:00:00 2001 From: Chris Lumens Date: Feb 05 2021 06:22:50 +0000 Subject: Feature: tools: Add an output message for a list of resource names. This is kind of an unusual output message in that it just dumps a list of resource names with no other information. It appears to only list primitive resources, too. This doesn't seem especially useful anywhere else, so I am just adding it to crm_resource. Note that this is one of the basic XML lists, wrapped with and tags. There's no additional useful information for the items of this list. --- diff --git a/tools/crm_resource.c b/tools/crm_resource.c index e30b9a7..18766b4 100644 --- a/tools/crm_resource.c +++ b/tools/crm_resource.c @@ -1176,28 +1176,6 @@ list_providers(pcmk__output_t *out, const char *agent_spec, crm_exit_t *exit_cod return rc; } -static int -list_raw(pcmk__output_t *out) -{ - int rc = pcmk_rc_ok; - int found = 0; - GListPtr lpc = NULL; - - for (lpc = data_set->resources; lpc != NULL; lpc = lpc->next) { - pe_resource_t *rsc = (pe_resource_t *) lpc->data; - - found++; - cli_resource_print_raw(out, rsc); - } - - if (found == 0) { - printf("NO resources configured\n"); - rc = ENXIO; - } - - return rc; -} - static void list_stacks_and_constraints(pcmk__output_t *out, pe_resource_t *rsc, bool recursive) { @@ -1634,6 +1612,8 @@ main(int argc, char **argv) } } + crm_resource_register_messages(out); + if (args->version) { out->version(out, false); goto done; @@ -1741,7 +1721,12 @@ main(int argc, char **argv) break; case cmd_list_instances: - rc = list_raw(out); + rc = out->message(out, "resource-names-list", data_set->resources); + + if (rc != pcmk_rc_ok) { + rc = ENXIO; + } + break; case cmd_list_standards: diff --git a/tools/crm_resource.h b/tools/crm_resource.h index 0100488..28a3760 100644 --- a/tools/crm_resource.h +++ b/tools/crm_resource.h @@ -14,6 +14,7 @@ #include #include #include +#include #include #include @@ -105,3 +106,5 @@ int update_working_set_xml(pe_working_set_t *data_set, xmlNode **xml); int wait_till_stable(pcmk__output_t *out, int timeout_ms, cib_t * cib); void cli_resource_why(pcmk__output_t *out, cib_t *cib_conn, GListPtr resources, pe_resource_t *rsc, pe_node_t *node); + +void crm_resource_register_messages(pcmk__output_t *out); diff --git a/tools/crm_resource_print.c b/tools/crm_resource_print.c index de1c608..e62122f 100644 --- a/tools/crm_resource_print.c +++ b/tools/crm_resource_print.c @@ -9,6 +9,7 @@ #include #include +#include #define cons_string(x) x?x:"NA" void @@ -82,24 +83,6 @@ cli_resource_print_cts(pcmk__output_t *out, pe_resource_t * rsc) } } - -void -cli_resource_print_raw(pcmk__output_t *out, pe_resource_t * rsc) -{ - GListPtr lpc = NULL; - GListPtr children = rsc->children; - - if (children == NULL) { - printf("%s\n", rsc->id); - } - - for (lpc = children; lpc != NULL; lpc = lpc->next) { - pe_resource_t *child = (pe_resource_t *) lpc->data; - - cli_resource_print_raw(out, child); - } -} - // \return Standard Pacemaker return code int cli_resource_print_list(pcmk__output_t *out, pe_working_set_t * data_set, bool raw) @@ -338,3 +321,47 @@ cli_resource_print_property(pcmk__output_t *out, pe_resource_t *rsc, } return ENXIO; } + +static void +add_resource_name(pcmk__output_t *out, pe_resource_t *rsc) { + if (rsc->children == NULL) { + out->list_item(out, "resource", "%s", rsc->id); + } else { + for (GListPtr lpc = rsc->children; lpc != NULL; lpc = lpc->next) { + pe_resource_t *child = (pe_resource_t *) lpc->data; + add_resource_name(out, child); + } + } +} + +PCMK__OUTPUT_ARGS("resource-names-list", "GListPtr") +static int +resource_names(pcmk__output_t *out, va_list args) { + GListPtr resources = va_arg(args, GListPtr); + + if (resources == NULL) { + out->err(out, "NO resources configured\n"); + return pcmk_rc_no_output; + } + + out->begin_list(out, NULL, NULL, "Resource Names"); + + for (GListPtr lpc = resources; lpc != NULL; lpc = lpc->next) { + pe_resource_t *rsc = (pe_resource_t *) lpc->data; + add_resource_name(out, rsc); + } + + out->end_list(out); + return pcmk_rc_ok; +} + +static pcmk__message_entry_t fmt_functions[] = { + { "resource-names-list", "default", resource_names }, + + { NULL, NULL, NULL } +}; + +void +crm_resource_register_messages(pcmk__output_t *out) { + pcmk__register_messages(out, fmt_functions); +}