From 3eb6eb26f93b65068efa54d871f1d43f76ba99d2 Mon Sep 17 00:00:00 2001 From: Chris Lumens Date: Jan 22 2021 12:12:33 +0000 Subject: Feature: tools: Use the existing resource-list message in crm_resource. This replaces cli_resource_print_list with existing formatted output code, getting rid of one more place where the older style output functions are still being used. Note that this does change the format for text output. The older output used indentation for displaying the members of a clone and probably other things. There's not really a good way to do this with the existing text output code, short of adding more command line options for controlling what parts of the list formatting are used. That seems like a bit much for this one use, so instead just enable the fancier list formatting if we are listing resources. --- diff --git a/cts/cli/regression.tools.exp b/cts/cli/regression.tools.exp index 35e7a8c..10ec53b 100644 --- a/cts/cli/regression.tools.exp +++ b/cts/cli/regression.tools.exp @@ -926,7 +926,8 @@ Set 'dummy' option: id=dummy-instance_attributes-delay set=dummy-instance_attrib =#=#=#= End test: Create a resource attribute - OK (0) =#=#=#= * Passed: crm_resource - Create a resource attribute =#=#=#= Begin test: List the configured resources =#=#=#= - dummy (ocf::pacemaker:Dummy): Stopped +Full List of Resources: + * dummy (ocf::pacemaker:Dummy): Stopped =#=#=#= Current cib after: List the configured resources =#=#=#= diff --git a/tools/crm_resource.c b/tools/crm_resource.c index 18766b4..89e475b 100644 --- a/tools/crm_resource.c +++ b/tools/crm_resource.c @@ -1610,8 +1610,13 @@ main(int argc, char **argv) } else { pcmk__force_args(context, &error, "%s --xml-substitute", g_get_prgname()); } + } else if (pcmk__str_eq(args->output_ty, "text", pcmk__str_null_matches)) { + if (options.rsc_cmd == cmd_list_resources) { + pcmk__force_args(context, &error, "%s --text-fancy", g_get_prgname()); + } } + pe__register_messages(out); crm_resource_register_messages(out); if (args->version) { @@ -1715,10 +1720,19 @@ main(int argc, char **argv) } switch (options.rsc_cmd) { - case cmd_list_resources: - rc = pcmk_rc_ok; - cli_resource_print_list(out, data_set, FALSE); + case cmd_list_resources: { + GListPtr all = NULL; + all = g_list_prepend(all, strdup("*")); + rc = out->message(out, "resource-list", data_set, + pe_print_rsconly | pe_print_pending, + FALSE, TRUE, FALSE, TRUE, all, all, FALSE); + g_list_free_full(all, free); + + if (rc == pcmk_rc_no_output) { + rc = ENXIO; + } break; + } case cmd_list_instances: rc = out->message(out, "resource-names-list", data_set->resources); diff --git a/tools/crm_resource.h b/tools/crm_resource.h index 28a3760..6b6dab2 100644 --- a/tools/crm_resource.h +++ b/tools/crm_resource.h @@ -46,7 +46,6 @@ void cli_resource_print_colocation(pcmk__output_t *out, pe_resource_t * rsc, int cli_resource_print(pcmk__output_t *out, pe_resource_t *rsc, pe_working_set_t *data_set, bool expanded); -int cli_resource_print_list(pcmk__output_t *out, pe_working_set_t * data_set, bool raw); int cli_resource_print_attribute(pcmk__output_t *out, pe_resource_t *rsc, const char *attr, const char *attr_set_type, pe_working_set_t *data_set); diff --git a/tools/crm_resource_print.c b/tools/crm_resource_print.c index e62122f..f7356fb 100644 --- a/tools/crm_resource_print.c +++ b/tools/crm_resource_print.c @@ -85,34 +85,6 @@ cli_resource_print_cts(pcmk__output_t *out, pe_resource_t * rsc) // \return Standard Pacemaker return code int -cli_resource_print_list(pcmk__output_t *out, pe_working_set_t * data_set, bool raw) -{ - int found = 0; - - GListPtr lpc = NULL; - int opts = pe_print_printf | pe_print_rsconly | pe_print_pending; - - for (lpc = data_set->resources; lpc != NULL; lpc = lpc->next) { - pe_resource_t *rsc = (pe_resource_t *) lpc->data; - - if (pcmk_is_set(rsc->flags, pe_rsc_orphan) - && rsc->fns->active(rsc, TRUE) == FALSE) { - continue; - } - rsc->fns->print(rsc, NULL, opts, stdout); - found++; - } - - if (found == 0) { - printf("NO resources configured\n"); - return ENXIO; - } - - return pcmk_rc_ok; -} - -// \return Standard Pacemaker return code -int cli_resource_print_operations(pcmk__output_t *out, const char *rsc_id, const char *host_uname, bool active, pe_working_set_t * data_set)