|
|
fada68 |
From 11cbc8c2839f5579f682f13c48a18da750c4c079 Mon Sep 17 00:00:00 2001
|
|
|
fada68 |
From: Ken Gaillot <kgaillot@redhat.com>
|
|
|
fada68 |
Date: Wed, 3 Aug 2016 15:36:08 -0500
|
|
|
fada68 |
Subject: [PATCH] Low: tools: make crm_mon resources section more consistent
|
|
|
fada68 |
|
|
|
fada68 |
Always prints a header in HTML and console output, and
|
|
|
fada68 |
indicates if there are no resources of the requested type to show.
|
|
|
fada68 |
---
|
|
|
fada68 |
tools/crm_mon.c | 284 ++++++++++++++++++++++++++++++++++----------------------
|
|
|
fada68 |
1 file changed, 174 insertions(+), 110 deletions(-)
|
|
|
fada68 |
|
|
|
fada68 |
diff --git a/tools/crm_mon.c b/tools/crm_mon.c
|
|
|
fada68 |
index a141852..4352641 100644
|
|
|
fada68 |
--- a/tools/crm_mon.c
|
|
|
fada68 |
+++ b/tools/crm_mon.c
|
|
|
fada68 |
@@ -1042,6 +1042,174 @@ print_node_end(FILE *stream)
|
|
|
fada68 |
|
|
|
fada68 |
/*!
|
|
|
fada68 |
* \internal
|
|
|
fada68 |
+ * \brief Print resources section heading appropriate to options
|
|
|
fada68 |
+ *
|
|
|
fada68 |
+ * \param[in] stream File stream to display output to
|
|
|
fada68 |
+ */
|
|
|
fada68 |
+static void
|
|
|
fada68 |
+print_resources_heading(FILE *stream)
|
|
|
fada68 |
+{
|
|
|
fada68 |
+ const char *heading;
|
|
|
fada68 |
+
|
|
|
fada68 |
+ if (group_by_node) {
|
|
|
fada68 |
+
|
|
|
fada68 |
+ /* Active resources have already been printed by node */
|
|
|
fada68 |
+ heading = (inactive_resources? "Inactive resources" : NULL);
|
|
|
fada68 |
+
|
|
|
fada68 |
+ } else if (inactive_resources) {
|
|
|
fada68 |
+ heading = "Full list of resources";
|
|
|
fada68 |
+
|
|
|
fada68 |
+ } else {
|
|
|
fada68 |
+ heading = "Active resources";
|
|
|
fada68 |
+ }
|
|
|
fada68 |
+
|
|
|
fada68 |
+ /* Print section heading */
|
|
|
fada68 |
+ switch (output_format) {
|
|
|
fada68 |
+ case mon_output_plain:
|
|
|
fada68 |
+ case mon_output_console:
|
|
|
fada68 |
+ print_as("\n%s:\n\n", heading);
|
|
|
fada68 |
+ break;
|
|
|
fada68 |
+
|
|
|
fada68 |
+ case mon_output_html:
|
|
|
fada68 |
+ case mon_output_cgi:
|
|
|
fada68 |
+ fprintf(stream, " \n %s\n", heading);
|
|
|
fada68 |
+ break;
|
|
|
fada68 |
+
|
|
|
fada68 |
+ case mon_output_xml:
|
|
|
fada68 |
+ fprintf(stream, " <resources>\n");
|
|
|
fada68 |
+ break;
|
|
|
fada68 |
+
|
|
|
fada68 |
+ default:
|
|
|
fada68 |
+ break;
|
|
|
fada68 |
+ }
|
|
|
fada68 |
+
|
|
|
fada68 |
+}
|
|
|
fada68 |
+
|
|
|
fada68 |
+/*!
|
|
|
fada68 |
+ * \internal
|
|
|
fada68 |
+ * \brief Print whatever resource section closing is appropriate
|
|
|
fada68 |
+ *
|
|
|
fada68 |
+ * \param[in] stream File stream to display output to
|
|
|
fada68 |
+ */
|
|
|
fada68 |
+static void
|
|
|
fada68 |
+print_resources_closing(FILE *stream, gboolean printed_heading)
|
|
|
fada68 |
+{
|
|
|
fada68 |
+ const char *heading;
|
|
|
fada68 |
+
|
|
|
fada68 |
+ /* What type of resources we did or did not display */
|
|
|
fada68 |
+ if (group_by_node) {
|
|
|
fada68 |
+ heading = "inactive ";
|
|
|
fada68 |
+ } else if (inactive_resources) {
|
|
|
fada68 |
+ heading = "";
|
|
|
fada68 |
+ } else {
|
|
|
fada68 |
+ heading = "active ";
|
|
|
fada68 |
+ }
|
|
|
fada68 |
+
|
|
|
fada68 |
+ switch (output_format) {
|
|
|
fada68 |
+ case mon_output_plain:
|
|
|
fada68 |
+ case mon_output_console:
|
|
|
fada68 |
+ if (!printed_heading) {
|
|
|
fada68 |
+ print_as("\nNo %sresources\n\n", heading);
|
|
|
fada68 |
+ }
|
|
|
fada68 |
+ break;
|
|
|
fada68 |
+
|
|
|
fada68 |
+ case mon_output_html:
|
|
|
fada68 |
+ case mon_output_cgi:
|
|
|
fada68 |
+ if (!printed_heading) {
|
|
|
fada68 |
+ fprintf(stream, " \n No %sresources\n", heading);
|
|
|
fada68 |
+ }
|
|
|
fada68 |
+ break;
|
|
|
fada68 |
+
|
|
|
fada68 |
+ case mon_output_xml:
|
|
|
fada68 |
+ fprintf(stream, " %s\n",
|
|
|
fada68 |
+ (printed_heading? "</resources>" : "<resources/>"));
|
|
|
fada68 |
+ break;
|
|
|
fada68 |
+
|
|
|
fada68 |
+ default:
|
|
|
fada68 |
+ break;
|
|
|
fada68 |
+ }
|
|
|
fada68 |
+}
|
|
|
fada68 |
+
|
|
|
fada68 |
+/*!
|
|
|
fada68 |
+ * \internal
|
|
|
fada68 |
+ * \brief Print whatever resource section(s) are appropriate
|
|
|
fada68 |
+ *
|
|
|
fada68 |
+ * \param[in] stream File stream to display output to
|
|
|
fada68 |
+ * \param[in] data_set Cluster state to display
|
|
|
fada68 |
+ * \param[in] print_opts Bitmask of pe_print_options
|
|
|
fada68 |
+ */
|
|
|
fada68 |
+static void
|
|
|
fada68 |
+print_resources(FILE *stream, pe_working_set_t *data_set, int print_opts)
|
|
|
fada68 |
+{
|
|
|
fada68 |
+ GListPtr rsc_iter;
|
|
|
fada68 |
+ const char *prefix = NULL;
|
|
|
fada68 |
+ gboolean printed_heading = FALSE;
|
|
|
fada68 |
+ gboolean brief_output = print_brief;
|
|
|
fada68 |
+
|
|
|
fada68 |
+ /* If we already showed active resources by node, and
|
|
|
fada68 |
+ * we're not showing inactive resources, we have nothing to do
|
|
|
fada68 |
+ */
|
|
|
fada68 |
+ if (group_by_node && !inactive_resources) {
|
|
|
fada68 |
+ return;
|
|
|
fada68 |
+ }
|
|
|
fada68 |
+
|
|
|
fada68 |
+ /* XML uses an indent, and ignores brief option for resources */
|
|
|
fada68 |
+ if (output_format == mon_output_xml) {
|
|
|
fada68 |
+ prefix = " ";
|
|
|
fada68 |
+ brief_output = FALSE;
|
|
|
fada68 |
+ }
|
|
|
fada68 |
+
|
|
|
fada68 |
+ /* If we haven't already printed resources grouped by node,
|
|
|
fada68 |
+ * and brief output was requested, print resource summary */
|
|
|
fada68 |
+ if (brief_output && !group_by_node) {
|
|
|
fada68 |
+ print_resources_heading(stream);
|
|
|
fada68 |
+ printed_heading = TRUE;
|
|
|
fada68 |
+ print_rscs_brief(data_set->resources, NULL, print_opts, stream,
|
|
|
fada68 |
+ inactive_resources);
|
|
|
fada68 |
+ }
|
|
|
fada68 |
+
|
|
|
fada68 |
+ /* For each resource, display it if appropriate */
|
|
|
fada68 |
+ for (rsc_iter = data_set->resources; rsc_iter != NULL; rsc_iter = rsc_iter->next) {
|
|
|
fada68 |
+ resource_t *rsc = (resource_t *) rsc_iter->data;
|
|
|
fada68 |
+
|
|
|
fada68 |
+ /* Complex resources may have some sub-resources active and some inactive */
|
|
|
fada68 |
+ gboolean is_active = rsc->fns->active(rsc, TRUE);
|
|
|
fada68 |
+ gboolean partially_active = rsc->fns->active(rsc, FALSE);
|
|
|
fada68 |
+
|
|
|
fada68 |
+ /* Skip inactive orphans (deleted but still in CIB) */
|
|
|
fada68 |
+ if (is_set(rsc->flags, pe_rsc_orphan) && !is_active) {
|
|
|
fada68 |
+ continue;
|
|
|
fada68 |
+
|
|
|
fada68 |
+ /* Skip active resources if we already displayed them by node */
|
|
|
fada68 |
+ } else if (group_by_node) {
|
|
|
fada68 |
+ if (is_active) {
|
|
|
fada68 |
+ continue;
|
|
|
fada68 |
+ }
|
|
|
fada68 |
+
|
|
|
fada68 |
+ /* Skip primitives already counted in a brief summary */
|
|
|
fada68 |
+ } else if (brief_output && (rsc->variant == pe_native)) {
|
|
|
fada68 |
+ continue;
|
|
|
fada68 |
+
|
|
|
fada68 |
+ /* Skip resources that aren't at least partially active,
|
|
|
fada68 |
+ * unless we're displaying inactive resources
|
|
|
fada68 |
+ */
|
|
|
fada68 |
+ } else if (!partially_active && !inactive_resources) {
|
|
|
fada68 |
+ continue;
|
|
|
fada68 |
+ }
|
|
|
fada68 |
+
|
|
|
fada68 |
+ /* Print this resource */
|
|
|
fada68 |
+ if (printed_heading == FALSE) {
|
|
|
fada68 |
+ print_resources_heading(stream);
|
|
|
fada68 |
+ printed_heading = TRUE;
|
|
|
fada68 |
+ }
|
|
|
fada68 |
+ rsc->fns->print(rsc, prefix, print_opts, stream);
|
|
|
fada68 |
+ }
|
|
|
fada68 |
+
|
|
|
fada68 |
+ print_resources_closing(stream, printed_heading);
|
|
|
fada68 |
+}
|
|
|
fada68 |
+
|
|
|
fada68 |
+/*!
|
|
|
fada68 |
+ * \internal
|
|
|
fada68 |
* \brief Print heading for resource history
|
|
|
fada68 |
*
|
|
|
fada68 |
* \param[in] stream File stream to display output to
|
|
|
fada68 |
@@ -2852,58 +3020,8 @@ print_status(pe_working_set_t * data_set)
|
|
|
fada68 |
free(online_guest_nodes);
|
|
|
fada68 |
}
|
|
|
fada68 |
|
|
|
fada68 |
- /* If we haven't already displayed resources grouped by node,
|
|
|
fada68 |
- * or we need to print inactive resources, print a resources section */
|
|
|
fada68 |
- if (group_by_node == FALSE || inactive_resources) {
|
|
|
fada68 |
-
|
|
|
fada68 |
- /* If we're printing inactive resources, display a heading */
|
|
|
fada68 |
- if (inactive_resources) {
|
|
|
fada68 |
- if (group_by_node == FALSE) {
|
|
|
fada68 |
- print_as("\nFull list of resources:\n");
|
|
|
fada68 |
- } else {
|
|
|
fada68 |
- print_as("\nInactive resources:\n");
|
|
|
fada68 |
- }
|
|
|
fada68 |
- }
|
|
|
fada68 |
- print_as("\n");
|
|
|
fada68 |
-
|
|
|
fada68 |
- /* If we haven't already printed resources grouped by node,
|
|
|
fada68 |
- * and brief output was requested, print resource summary */
|
|
|
fada68 |
- if (print_brief && group_by_node == FALSE) {
|
|
|
fada68 |
- print_rscs_brief(data_set->resources, NULL, print_opts, stdout,
|
|
|
fada68 |
- inactive_resources);
|
|
|
fada68 |
- }
|
|
|
fada68 |
-
|
|
|
fada68 |
- /* For each resource, display it if appropriate */
|
|
|
fada68 |
- for (gIter = data_set->resources; gIter != NULL; gIter = gIter->next) {
|
|
|
fada68 |
- resource_t *rsc = (resource_t *) gIter->data;
|
|
|
fada68 |
-
|
|
|
fada68 |
- /* Complex resources may have some sub-resources active and some inactive */
|
|
|
fada68 |
- gboolean is_active = rsc->fns->active(rsc, TRUE);
|
|
|
fada68 |
- gboolean partially_active = rsc->fns->active(rsc, FALSE);
|
|
|
fada68 |
-
|
|
|
fada68 |
- /* Always ignore inactive orphan resources (deleted but not yet gone from CIB) */
|
|
|
fada68 |
- if (is_set(rsc->flags, pe_rsc_orphan) && (is_active == FALSE)) {
|
|
|
fada68 |
- continue;
|
|
|
fada68 |
- }
|
|
|
fada68 |
-
|
|
|
fada68 |
- /* If we already printed resources grouped by node,
|
|
|
fada68 |
- * only print inactive resources, if that was requested */
|
|
|
fada68 |
- if (group_by_node == TRUE) {
|
|
|
fada68 |
- if ((is_active == FALSE) && inactive_resources) {
|
|
|
fada68 |
- rsc->fns->print(rsc, NULL, print_opts, stdout);
|
|
|
fada68 |
- }
|
|
|
fada68 |
- continue;
|
|
|
fada68 |
- }
|
|
|
fada68 |
-
|
|
|
fada68 |
- /* Otherwise, print resource if it's at least partially active
|
|
|
fada68 |
- * or we're displaying inactive resources,
|
|
|
fada68 |
- * except for primitive resources already counted in a brief summary */
|
|
|
fada68 |
- if (!(print_brief && (rsc->variant == pe_native))
|
|
|
fada68 |
- && (partially_active || inactive_resources)) {
|
|
|
fada68 |
- rsc->fns->print(rsc, NULL, print_opts, stdout);
|
|
|
fada68 |
- }
|
|
|
fada68 |
- }
|
|
|
fada68 |
- }
|
|
|
fada68 |
+ /* Print resources section, if needed */
|
|
|
fada68 |
+ print_resources(stdout, data_set, print_opts);
|
|
|
fada68 |
|
|
|
fada68 |
/* print Node Attributes section if requested */
|
|
|
fada68 |
if (show & mon_show_attributes) {
|
|
|
fada68 |
@@ -3009,28 +3127,8 @@ print_xml_status(pe_working_set_t * data_set)
|
|
|
fada68 |
}
|
|
|
fada68 |
fprintf(stream, " </nodes>\n");
|
|
|
fada68 |
|
|
|
fada68 |
- /*** RESOURCES ***/
|
|
|
fada68 |
- if (group_by_node == FALSE || inactive_resources) {
|
|
|
fada68 |
- fprintf(stream, " <resources>\n");
|
|
|
fada68 |
- for (gIter = data_set->resources; gIter != NULL; gIter = gIter->next) {
|
|
|
fada68 |
- resource_t *rsc = (resource_t *) gIter->data;
|
|
|
fada68 |
- gboolean is_active = rsc->fns->active(rsc, TRUE);
|
|
|
fada68 |
- gboolean partially_active = rsc->fns->active(rsc, FALSE);
|
|
|
fada68 |
-
|
|
|
fada68 |
- if (is_set(rsc->flags, pe_rsc_orphan) && is_active == FALSE) {
|
|
|
fada68 |
- continue;
|
|
|
fada68 |
-
|
|
|
fada68 |
- } else if (group_by_node == FALSE) {
|
|
|
fada68 |
- if (partially_active || inactive_resources) {
|
|
|
fada68 |
- rsc->fns->print(rsc, " ", print_opts, stream);
|
|
|
fada68 |
- }
|
|
|
fada68 |
-
|
|
|
fada68 |
- } else if (is_active == FALSE && inactive_resources) {
|
|
|
fada68 |
- rsc->fns->print(rsc, " ", print_opts, stream);
|
|
|
fada68 |
- }
|
|
|
fada68 |
- }
|
|
|
fada68 |
- fprintf(stream, " </resources>\n");
|
|
|
fada68 |
- }
|
|
|
fada68 |
+ /* Print resources section, if needed */
|
|
|
fada68 |
+ print_resources(stream, data_set, print_opts);
|
|
|
fada68 |
|
|
|
fada68 |
/* print Node Attributes section if requested */
|
|
|
fada68 |
if (show & mon_show_attributes) {
|
|
|
fada68 |
@@ -3153,42 +3251,8 @@ print_html_status(pe_working_set_t * data_set, const char *filename)
|
|
|
fada68 |
}
|
|
|
fada68 |
fprintf(stream, "\n");
|
|
|
fada68 |
|
|
|
fada68 |
- if (group_by_node && inactive_resources) {
|
|
|
fada68 |
- fprintf(stream, "Inactive Resources\n");
|
|
|
fada68 |
-
|
|
|
fada68 |
- } else if (group_by_node == FALSE) {
|
|
|
fada68 |
- fprintf(stream, " \n Resource List\n");
|
|
|
fada68 |
- }
|
|
|
fada68 |
-
|
|
|
fada68 |
- if (group_by_node == FALSE || inactive_resources) {
|
|
|
fada68 |
- if (print_brief && group_by_node == FALSE) {
|
|
|
fada68 |
- print_rscs_brief(data_set->resources, NULL, print_opts, stream,
|
|
|
fada68 |
- inactive_resources);
|
|
|
fada68 |
- }
|
|
|
fada68 |
-
|
|
|
fada68 |
- for (gIter = data_set->resources; gIter != NULL; gIter = gIter->next) {
|
|
|
fada68 |
- resource_t *rsc = (resource_t *) gIter->data;
|
|
|
fada68 |
- gboolean is_active = rsc->fns->active(rsc, TRUE);
|
|
|
fada68 |
- gboolean partially_active = rsc->fns->active(rsc, FALSE);
|
|
|
fada68 |
-
|
|
|
fada68 |
- if (print_brief && group_by_node == FALSE
|
|
|
fada68 |
- && rsc->variant == pe_native) {
|
|
|
fada68 |
- continue;
|
|
|
fada68 |
- }
|
|
|
fada68 |
-
|
|
|
fada68 |
- if (is_set(rsc->flags, pe_rsc_orphan) && is_active == FALSE) {
|
|
|
fada68 |
- continue;
|
|
|
fada68 |
-
|
|
|
fada68 |
- } else if (group_by_node == FALSE) {
|
|
|
fada68 |
- if (partially_active || inactive_resources) {
|
|
|
fada68 |
- rsc->fns->print(rsc, NULL, print_opts, stream);
|
|
|
fada68 |
- }
|
|
|
fada68 |
-
|
|
|
fada68 |
- } else if (is_active == FALSE && inactive_resources) {
|
|
|
fada68 |
- rsc->fns->print(rsc, NULL, print_opts, stream);
|
|
|
fada68 |
- }
|
|
|
fada68 |
- }
|
|
|
fada68 |
- }
|
|
|
fada68 |
+ /* Print resources section, if needed */
|
|
|
fada68 |
+ print_resources(stream, data_set, print_opts);
|
|
|
fada68 |
|
|
|
fada68 |
/* print Node Attributes section if requested */
|
|
|
fada68 |
if (show & mon_show_attributes) {
|
|
|
fada68 |
--
|
|
|
fada68 |
1.8.3.1
|
|
|
fada68 |
|