From 9faa62f0701801f1d420462025e863d8ca3d6a06 Mon Sep 17 00:00:00 2001 From: Chris Lumens Date: Mon, 21 Sep 2020 14:19:19 -0400 Subject: [PATCH 1/6] Fix: libcrmcommon: Automatically lower case XML list names. --- lib/common/output_xml.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/lib/common/output_xml.c b/lib/common/output_xml.c index 1710fac..6a6ed6e 100644 --- a/lib/common/output_xml.c +++ b/lib/common/output_xml.c @@ -50,7 +50,6 @@ typedef struct subst_s { } subst_t; static subst_t substitutions[] = { - { "Attributes", "attributes" }, { "Active Resources", "resources" }, { "Full List of Resources", "resources" }, { "Inactive Resources", "resources" }, @@ -61,8 +60,6 @@ static subst_t substitutions[] = { { "Operations", "node_history" }, { "Negative Location Constraints", "bans" }, { "Node Attributes", "node_attributes" }, - { "Resources", "resources" }, - { "Tickets", "tickets" }, { NULL, NULL } }; @@ -288,7 +285,7 @@ static void xml_begin_list(pcmk__output_t *out, const char *singular_noun, const char *plural_noun, const char *format, ...) { va_list ap; - const char *name = NULL; + char *name = NULL; char *buf = NULL; int len; @@ -300,14 +297,14 @@ xml_begin_list(pcmk__output_t *out, const char *singular_noun, const char *plura if (substitute) { for (subst_t *s = substitutions; s->from != NULL; s++) { if (!strcmp(s->from, buf)) { - name = s->to; + name = g_strdup(s->to); break; } } } if (name == NULL) { - name = buf; + name = g_ascii_strdown(buf, -1); } if (legacy_xml || simple_list) { @@ -319,6 +316,7 @@ xml_begin_list(pcmk__output_t *out, const char *singular_noun, const char *plura xmlSetProp(list_node, (pcmkXmlStr) "name", (pcmkXmlStr) name); } + g_free(name); free(buf); } -- 1.8.3.1 From 7a77441ae8d3ab943dfafebfc06b63402be323e1 Mon Sep 17 00:00:00 2001 From: Chris Lumens Date: Tue, 27 Oct 2020 12:49:45 -0400 Subject: [PATCH 2/6] Feature: xml: Move resource-related XML schema into its own file. This allows it to be shared between the crm_mon and crm_resource schemas. Also, this adds support for resource XML to crm_mon given that this is now technically possible as part of the library output. --- xml/Makefile.am | 2 +- xml/api/crm_mon-2.4.rng | 311 ++++++++++++++++++++++++++++++++++++++++++++++ xml/api/resources-2.4.rng | 109 ++++++++++++++++ 3 files changed, 421 insertions(+), 1 deletion(-) create mode 100644 xml/api/crm_mon-2.4.rng create mode 100644 xml/api/resources-2.4.rng diff --git a/xml/Makefile.am b/xml/Makefile.am index 892c811..79ce900 100644 --- a/xml/Makefile.am +++ b/xml/Makefile.am @@ -51,7 +51,7 @@ API_request_base = command-output crm_mon crmadmin stonith_admin version CIB_cfg_base = options nodes resources constraints fencing acls tags alerts # Names of all schemas (including top level and those included by others) -API_base = $(API_request_base) fence-event item status +API_base = $(API_request_base) fence-event item resources status CIB_base = cib $(CIB_cfg_base) status score rule nvset # Static schema files and transforms (only CIB has transforms) diff --git a/xml/api/crm_mon-2.4.rng b/xml/api/crm_mon-2.4.rng new file mode 100644 index 0000000..88973a4 --- /dev/null +++ b/xml/api/crm_mon-2.4.rng @@ -0,0 +1,311 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + unknown + member + remote + ping + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + granted + revoked + + + + + + + + + + + + + + + + + + + diff --git a/xml/api/resources-2.4.rng b/xml/api/resources-2.4.rng new file mode 100644 index 0000000..e279583 --- /dev/null +++ b/xml/api/resources-2.4.rng @@ -0,0 +1,109 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + docker + rkt + podman + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + -- 1.8.3.1 From 814eb921cd429692220f33722c9bc061266bd838 Mon Sep 17 00:00:00 2001 From: Chris Lumens Date: Thu, 29 Oct 2020 14:45:02 -0400 Subject: [PATCH 3/6] Feature: xml: Add a generic list XML schema file. Formatted output supports a generic list structure that isn't used in too many places at the moment, but it could be getting used more in the future. It's also really easy to have a schema for this piece of XML. --- xml/Makefile.am | 7 ++++++- xml/api/generic-list-2.4.rng | 21 +++++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 xml/api/generic-list-2.4.rng diff --git a/xml/Makefile.am b/xml/Makefile.am index 79ce900..2f99f1c 100644 --- a/xml/Makefile.am +++ b/xml/Makefile.am @@ -44,6 +44,11 @@ version_pairs_last = $(wordlist \ ),$(1),$(2) \ ) +# NOTE: All files in API_request_base, CIB_cfg_base, API_base, and CIB_base +# need to start with a unique prefix. These variables all get iterated over +# and globbed, and two files starting with the same prefix will cause +# problems. + # Names of API schemas that form the choices for pacemaker-result content API_request_base = command-output crm_mon crmadmin stonith_admin version @@ -51,7 +56,7 @@ API_request_base = command-output crm_mon crmadmin stonith_admin version CIB_cfg_base = options nodes resources constraints fencing acls tags alerts # Names of all schemas (including top level and those included by others) -API_base = $(API_request_base) fence-event item resources status +API_base = $(API_request_base) fence-event generic-list item resources status CIB_base = cib $(CIB_cfg_base) status score rule nvset # Static schema files and transforms (only CIB has transforms) diff --git a/xml/api/generic-list-2.4.rng b/xml/api/generic-list-2.4.rng new file mode 100644 index 0000000..fee93a9 --- /dev/null +++ b/xml/api/generic-list-2.4.rng @@ -0,0 +1,21 @@ + + + + + + + + + + + + + + + + + + + + -- 1.8.3.1 From 316b6f66ca5425093503c51c2f8738922287ebca Mon Sep 17 00:00:00 2001 From: Chris Lumens Date: Wed, 16 Sep 2020 15:59:34 -0400 Subject: [PATCH 4/6] Fix: tools: Save the optarg parameter for --list-ocf-alternatives. We need this so it can be added to the XML output of crm_resource. --- tools/crm_resource.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/tools/crm_resource.c b/tools/crm_resource.c index 6573ad5..acaddc0 100644 --- a/tools/crm_resource.c +++ b/tools/crm_resource.c @@ -720,9 +720,7 @@ list_alternatives_cb(const gchar *option_name, const gchar *optarg, gpointer data, GError **error) { SET_COMMAND(cmd_list_alternatives); - options.require_cib = FALSE; - options.require_dataset = FALSE; - options.require_resource = FALSE; + get_agent_spec(optarg); return TRUE; } -- 1.8.3.1 From c063ce9b193f2022611e651c13afcb3ceb5969e3 Mon Sep 17 00:00:00 2001 From: Chris Lumens Date: Wed, 2 Sep 2020 16:20:10 -0400 Subject: [PATCH 5/6] Fix: scheduler: Use the default format handler in a few more places. --- lib/pengine/pe_output.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/lib/pengine/pe_output.c b/lib/pengine/pe_output.c index d0f96f4..9d43e5f 100644 --- a/lib/pengine/pe_output.c +++ b/lib/pengine/pe_output.c @@ -1847,9 +1847,7 @@ static pcmk__message_entry_t fmt_functions[] = { { "cluster-times", "log", pe__cluster_times_text }, { "cluster-times", "text", pe__cluster_times_text }, { "cluster-times", "xml", pe__cluster_times_xml }, - { "failed-action", "html", pe__failed_action_text }, - { "failed-action", "log", pe__failed_action_text }, - { "failed-action", "text", pe__failed_action_text }, + { "failed-action", "default", pe__failed_action_text }, { "failed-action", "xml", pe__failed_action_xml }, { "group", "xml", pe__group_xml }, { "group", "html", pe__group_html }, @@ -1868,9 +1866,7 @@ static pcmk__message_entry_t fmt_functions[] = { { "node-attribute", "log", pe__node_attribute_text }, { "node-attribute", "text", pe__node_attribute_text }, { "node-attribute", "xml", pe__node_attribute_xml }, - { "op-history", "html", pe__op_history_text }, - { "op-history", "log", pe__op_history_text }, - { "op-history", "text", pe__op_history_text }, + { "op-history", "default", pe__op_history_text }, { "op-history", "xml", pe__op_history_xml }, { "primitive", "xml", pe__resource_xml }, { "primitive", "html", pe__resource_html }, -- 1.8.3.1 From a32b99f5fd09ec15dbba6785c5d8dc2e220417a3 Mon Sep 17 00:00:00 2001 From: Chris Lumens Date: Thu, 3 Sep 2020 10:23:16 -0400 Subject: [PATCH 6/6] Refactor: scheduler: Expose native_output_string as pcmk__native_output_string. The plan is that this function can be used to help build the string that is output for each line of "crm_resource -o" output. It appears that output only happens for primitive resources. However, I've added a check at the beginning just in case it's called for some other type of resource. --- include/crm/pengine/internal.h | 3 +++ lib/pengine/native.c | 24 ++++++++++++++---------- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/include/crm/pengine/internal.h b/include/crm/pengine/internal.h index abe7a76..d658e86 100644 --- a/include/crm/pengine/internal.h +++ b/include/crm/pengine/internal.h @@ -243,6 +243,9 @@ void clone_print(pe_resource_t * rsc, const char *pre_text, long options, void * void pe__print_bundle(pe_resource_t *rsc, const char *pre_text, long options, void *print_data); +gchar * pcmk__native_output_string(pe_resource_t *rsc, const char *name, pe_node_t *node, + long options, const char *target_role, bool show_nodes); + int pe__name_and_nvpairs_xml(pcmk__output_t *out, bool is_list, const char *tag_name , size_t pairs_count, ...); char *pe__node_display_name(pe_node_t *node, bool print_detail); diff --git a/lib/pengine/native.c b/lib/pengine/native.c index 8f0c5c9..bf1f5c0 100644 --- a/lib/pengine/native.c +++ b/lib/pengine/native.c @@ -570,17 +570,21 @@ add_output_node(GString *s, const char *node, bool have_nodes) * \return Newly allocated string description of resource * \note Caller must free the result with g_free(). */ -static gchar * -native_output_string(pe_resource_t *rsc, const char *name, pe_node_t *node, - long options, const char *target_role, bool show_nodes) +gchar * +pcmk__native_output_string(pe_resource_t *rsc, const char *name, pe_node_t *node, + long options, const char *target_role, bool show_nodes) { const char *class = crm_element_value(rsc->xml, XML_AGENT_ATTR_CLASS); const char *provider = NULL; const char *kind = crm_element_value(rsc->xml, XML_ATTR_TYPE); - char *retval = NULL; + gchar *retval = NULL; GString *outstr = NULL; bool have_flags = false; + if (rsc->variant != pe_native) { + return NULL; + } + CRM_CHECK(name != NULL, name = "unknown"); CRM_CHECK(kind != NULL, kind = "unknown"); CRM_CHECK(class != NULL, class = "unknown"); @@ -758,8 +762,8 @@ pe__common_output_html(pcmk__output_t *out, pe_resource_t * rsc, } { - gchar *s = native_output_string(rsc, name, node, options, target_role, - true); + gchar *s = pcmk__native_output_string(rsc, name, node, options, + target_role, true); list_node = pcmk__output_create_html_node(out, "li", NULL, NULL, NULL); pcmk_create_html_node(list_node, "span", NULL, cl, s); @@ -826,8 +830,8 @@ pe__common_output_text(pcmk__output_t *out, pe_resource_t * rsc, } { - gchar *s = native_output_string(rsc, name, node, options, target_role, - true); + gchar *s = pcmk__native_output_string(rsc, name, node, options, + target_role, true); out->list_item(out, NULL, "%s", s); g_free(s); @@ -923,8 +927,8 @@ common_print(pe_resource_t * rsc, const char *pre_text, const char *name, pe_nod } { - gchar *resource_s = native_output_string(rsc, name, node, options, - target_role, false); + gchar *resource_s = pcmk__native_output_string(rsc, name, node, options, + target_role, false); status_print("%s%s", (pre_text? pre_text : ""), resource_s); g_free(resource_s); } -- 1.8.3.1