Blame SOURCES/005-crm_resource.patch

d49186
From a5a507d4e1abf242903472719a19977811e6f164 Mon Sep 17 00:00:00 2001
d49186
From: Chris Lumens <clumens@redhat.com>
d49186
Date: Thu, 20 May 2021 11:59:36 -0400
d49186
Subject: [PATCH 01/10] Feature: libcrmcommon: Add OCF_OUTPUT_FORMAT to
d49186
 crm_resource environment.
d49186
d49186
See: rhbz#1644628
d49186
---
d49186
 lib/common/output.c | 2 ++
d49186
 1 file changed, 2 insertions(+)
d49186
d49186
diff --git a/lib/common/output.c b/lib/common/output.c
d49186
index 6cb49b5..58872e0 100644
d49186
--- a/lib/common/output.c
d49186
+++ b/lib/common/output.c
d49186
@@ -71,6 +71,8 @@ pcmk__output_new(pcmk__output_t **out, const char *fmt_name, const char *filenam
d49186
         return ENOMEM;
d49186
     }
d49186
 
d49186
+    setenv("OCF_OUTPUT_FORMAT", (*out)->fmt_name, 1);
d49186
+
d49186
     return pcmk_rc_ok;
d49186
 }
d49186
 
d49186
-- 
d49186
1.8.3.1
d49186
d49186
d49186
From acc6ecdbfb797d69794e68f75a734d6252434e01 Mon Sep 17 00:00:00 2001
d49186
From: Chris Lumens <clumens@redhat.com>
d49186
Date: Fri, 21 May 2021 14:20:30 -0400
d49186
Subject: [PATCH 02/10] Feature: schemas: Copy crm_resource schema in
d49186
 preparation for changes.
d49186
d49186
See: rhbz#1644628
d49186
---
d49186
 xml/api/crm_resource-2.11.rng | 238 ++++++++++++++++++++++++++++++++++++++++++
d49186
 1 file changed, 238 insertions(+)
d49186
 create mode 100644 xml/api/crm_resource-2.11.rng
d49186
d49186
diff --git a/xml/api/crm_resource-2.11.rng b/xml/api/crm_resource-2.11.rng
d49186
new file mode 100644
d49186
index 0000000..8e386db
d49186
--- /dev/null
d49186
+++ b/xml/api/crm_resource-2.11.rng
d49186
@@ -0,0 +1,238 @@
d49186
+
d49186
+
d49186
+         datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes">
d49186
+
d49186
+    <start>
d49186
+        <ref name="element-crm-resource"/>
d49186
+    </start>
d49186
+
d49186
+    <define name="element-crm-resource">
d49186
+        <choice>
d49186
+            <ref name="agents-list" />
d49186
+            <ref name="alternatives-list" />
d49186
+            <ref name="constraints-list" />
d49186
+            <externalRef href="generic-list-2.4.rng"/>
d49186
+            <element name="metadata"> <text/> </element>
d49186
+            <ref name="locate-list" />
d49186
+            <ref name="operations-list" />
d49186
+            <ref name="providers-list" />
d49186
+            <ref name="reasons-list" />
d49186
+            <ref name="resource-check" />
d49186
+            <ref name="resource-config" />
d49186
+            <ref name="resources-list" />
d49186
+        </choice>
d49186
+    </define>
d49186
+
d49186
+    <define name="agents-list">
d49186
+        <element name="agents">
d49186
+            <attribute name="standard"> <text/> </attribute>
d49186
+            <optional>
d49186
+                <attribute name="provider"> <text/> </attribute>
d49186
+            </optional>
d49186
+            <zeroOrMore>
d49186
+                <element name="agent"> <text/> </element>
d49186
+            </zeroOrMore>
d49186
+        </element>
d49186
+    </define>
d49186
+
d49186
+    <define name="alternatives-list">
d49186
+        <element name="providers">
d49186
+            <attribute name="for"> <text/> </attribute>
d49186
+            <zeroOrMore>
d49186
+                <element name="provider"> <text/> </element>
d49186
+            </zeroOrMore>
d49186
+        </element>
d49186
+    </define>
d49186
+
d49186
+    <define name="constraints-list">
d49186
+        <element name="constraints">
d49186
+            <interleave>
d49186
+                <zeroOrMore>
d49186
+                    <ref name="rsc-location" />
d49186
+                </zeroOrMore>
d49186
+                <zeroOrMore>
d49186
+                    <ref name="rsc-colocation" />
d49186
+                </zeroOrMore>
d49186
+            </interleave>
d49186
+        </element>
d49186
+    </define>
d49186
+
d49186
+    <define name="locate-list">
d49186
+        <element name="nodes">
d49186
+            <attribute name="resource"> <text/> </attribute>
d49186
+            <zeroOrMore>
d49186
+                <element name="node">
d49186
+                    <optional>
d49186
+                        <attribute name="state"><value>promoted</value></attribute>
d49186
+                    </optional>
d49186
+                    <text/>
d49186
+                </element>
d49186
+            </zeroOrMore>
d49186
+        </element>
d49186
+    </define>
d49186
+
d49186
+    <define name="rsc-location">
d49186
+        <element name="rsc_location">
d49186
+            <attribute name="node"> <text/> </attribute>
d49186
+            <attribute name="rsc"> <text/> </attribute>
d49186
+            <attribute name="id"> <text/> </attribute>
d49186
+            <externalRef href="../score.rng"/>
d49186
+        </element>
d49186
+    </define>
d49186
+
d49186
+    <define name="operations-list">
d49186
+        <element name="operations">
d49186
+            <oneOrMore>
d49186
+                <ref name="element-operation-list" />
d49186
+            </oneOrMore>
d49186
+        </element>
d49186
+    </define>
d49186
+
d49186
+    <define name="providers-list">
d49186
+        <element name="providers">
d49186
+            <attribute name="standard"> <value>ocf</value> </attribute>
d49186
+            <optional>
d49186
+                <attribute name="agent"> <text/> </attribute>
d49186
+            </optional>
d49186
+            <zeroOrMore>
d49186
+                <element name="provider"> <text/> </element>
d49186
+            </zeroOrMore>
d49186
+        </element>
d49186
+    </define>
d49186
+
d49186
+    <define name="reasons-list">
d49186
+        <choice>
d49186
+            <ref name="no-resource-or-uname"/>
d49186
+            <ref name="resource-and-uname"/>
d49186
+            <ref name="no-resource-but-uname"/>
d49186
+            <ref name="resource-but-no-uname"/>
d49186
+        </choice>
d49186
+    </define>
d49186
+
d49186
+    <define name="no-resource-or-uname">
d49186
+        <element name="reason">
d49186
+            <element name="resources">
d49186
+                <zeroOrMore>
d49186
+                    <element name="resource">
d49186
+                        <attribute name="id"> <text/> </attribute>
d49186
+                        <attribute name="running"> <data type="boolean"/> </attribute>
d49186
+                        <ref name="resource-check"/>
d49186
+                    </element>
d49186
+                </zeroOrMore>
d49186
+            </element>
d49186
+        </element>
d49186
+    </define>
d49186
+
d49186
+    <define name="resource-and-uname">
d49186
+        <element name="reason">
d49186
+            <attribute name="running_on"> <text/> </attribute>
d49186
+            <ref name="resource-check"/>
d49186
+        </element>
d49186
+    </define>
d49186
+
d49186
+    <define name="no-resource-but-uname">
d49186
+        <element name="reason">
d49186
+            <element name="resources">
d49186
+                <zeroOrMore>
d49186
+                    <element name="resource">
d49186
+                        <attribute name="id"> <text/> </attribute>
d49186
+                        <attribute name="running"> <data type="boolean"/> </attribute>
d49186
+                        <attribute name="host"> <text/> </attribute>
d49186
+                        <ref name="resource-check"/>
d49186
+                    </element>
d49186
+                </zeroOrMore>
d49186
+            </element>
d49186
+        </element>
d49186
+    </define>
d49186
+
d49186
+    <define name="resource-but-no-uname">
d49186
+        <element name="reason">
d49186
+            <attribute name="running"> <data type="boolean"/> </attribute>
d49186
+            <ref name="resource-check"/>
d49186
+        </element>
d49186
+    </define>
d49186
+
d49186
+    <define name="resource-config">
d49186
+        <element name="resource_config">
d49186
+            <externalRef href="resources-2.4.rng" />
d49186
+            <element name="xml"> <text/> </element>
d49186
+        </element>
d49186
+    </define>
d49186
+
d49186
+    <define name="resource-check">
d49186
+        <element name="check">
d49186
+            <attribute name="id"> <text/> </attribute>
d49186
+            <optional>
d49186
+                <choice>
d49186
+                    <attribute name="remain_stopped"><value>true</value></attribute>
d49186
+                    <attribute name="promotable"><value>false</value></attribute>
d49186
+                </choice>
d49186
+            </optional>
d49186
+            <optional>
d49186
+                <attribute name="unmanaged"><value>true</value></attribute>
d49186
+            </optional>
d49186
+            <optional>
d49186
+                <attribute name="locked-to"> <text/> </attribute>
d49186
+            </optional>
d49186
+        </element>
d49186
+    </define>
d49186
+
d49186
+    <define name="resources-list">
d49186
+        <element name="resources">
d49186
+            <zeroOrMore>
d49186
+                <externalRef href="resources-2.4.rng" />
d49186
+            </zeroOrMore>
d49186
+        </element>
d49186
+    </define>
d49186
+
d49186
+    <define name="rsc-colocation">
d49186
+        <element name="rsc_colocation">
d49186
+            <attribute name="id"> <text/> </attribute>
d49186
+            <attribute name="rsc"> <text/> </attribute>
d49186
+            <attribute name="with-rsc"> <text/> </attribute>
d49186
+            <externalRef href="../score.rng"/>
d49186
+            <optional>
d49186
+                <attribute name="node-attribute"> <text/> </attribute>
d49186
+            </optional>
d49186
+            <optional>
d49186
+                <attribute name="rsc-role">
d49186
+                    <ref name="attribute-roles"/>
d49186
+                </attribute>
d49186
+            </optional>
d49186
+            <optional>
d49186
+                <attribute name="with-rsc-role">
d49186
+                    <ref name="attribute-roles"/>
d49186
+                </attribute>
d49186
+            </optional>
d49186
+        </element>
d49186
+    </define>
d49186
+
d49186
+    <define name="element-operation-list">
d49186
+        <element name="operation">
d49186
+            <optional>
d49186
+                <group>
d49186
+                    <attribute name="rsc"> <text/> </attribute>
d49186
+                    <attribute name="agent"> <text/> </attribute>
d49186
+                </group>
d49186
+            </optional>
d49186
+            <attribute name="op"> <text/> </attribute>
d49186
+            <attribute name="node"> <text/> </attribute>
d49186
+            <attribute name="call"> <data type="integer" /> </attribute>
d49186
+            <attribute name="rc"> <data type="nonNegativeInteger" /> </attribute>
d49186
+            <optional>
d49186
+                <attribute name="last-rc-change"> <text/> </attribute>
d49186
+                <attribute name="exec-time"> <data type="nonNegativeInteger" /> </attribute>
d49186
+            </optional>
d49186
+            <attribute name="status"> <text/> </attribute>
d49186
+        </element>
d49186
+    </define>
d49186
+
d49186
+    <define name="attribute-roles">
d49186
+        <choice>
d49186
+            <value>Stopped</value>
d49186
+            <value>Started</value>
d49186
+            <value>Master</value>
d49186
+            <value>Slave</value>
d49186
+        </choice>
d49186
+    </define>
d49186
+</grammar>
d49186
-- 
d49186
1.8.3.1
d49186
d49186
d49186
From 1bbdf2149a111e9e19c388834f82001e0d31c427 Mon Sep 17 00:00:00 2001
d49186
From: Chris Lumens <clumens@redhat.com>
d49186
Date: Mon, 24 May 2021 12:23:55 -0400
d49186
Subject: [PATCH 03/10] Feature: xml: Update the crm_resource schema for XML
d49186
 output.
d49186
d49186
See: rhbz#1644628
d49186
---
d49186
 xml/api/crm_resource-2.11.rng | 50 +++++++++++++++++++++++++++++++++++++++++++
d49186
 1 file changed, 50 insertions(+)
d49186
d49186
diff --git a/xml/api/crm_resource-2.11.rng b/xml/api/crm_resource-2.11.rng
d49186
index 8e386db..aaa54d6 100644
d49186
--- a/xml/api/crm_resource-2.11.rng
d49186
+++ b/xml/api/crm_resource-2.11.rng
d49186
@@ -20,6 +20,7 @@
d49186
             <ref name="resource-check" />
d49186
             <ref name="resource-config" />
d49186
             <ref name="resources-list" />
d49186
+            <ref name="resource-agent-action" />
d49186
         </choice>
d49186
     </define>
d49186
 
d49186
@@ -227,6 +228,55 @@
d49186
         </element>
d49186
     </define>
d49186
 
d49186
+    <define name="resource-agent-action">
d49186
+        <element name="resource-agent-action">
d49186
+            <attribute name="action"> <text/> </attribute>
d49186
+            <optional>
d49186
+                <attribute name="rsc"> <text/> </attribute>
d49186
+            </optional>
d49186
+            <attribute name="class"> <text/> </attribute>
d49186
+            <attribute name="type"> <text/> </attribute>
d49186
+            <optional>
d49186
+                <attribute name="provider"> <text/> </attribute>
d49186
+            </optional>
d49186
+            <optional>
d49186
+                <ref name="overrides-list"/>
d49186
+            </optional>
d49186
+            <ref name="agent-status"/>
d49186
+            <optional>
d49186
+                <choice>
d49186
+                    <element name="command">
d49186
+                        <text />
d49186
+                    </element>
d49186
+                    <externalRef href="command-output-1.0.rng"/>
d49186
+                </choice>
d49186
+            </optional>
d49186
+        </element>
d49186
+    </define>
d49186
+
d49186
+    <define name="overrides-list">
d49186
+        <element name="overrides">
d49186
+            <zeroOrMore>
d49186
+                <element name="override">
d49186
+                    <optional>
d49186
+                        <attribute name="rsc"> <text/> </attribute>
d49186
+                    </optional>
d49186
+                    <attribute name="name"> <text/> </attribute>
d49186
+                    <attribute name="value"> <text/> </attribute>
d49186
+                </element>
d49186
+            </zeroOrMore>
d49186
+        </element>
d49186
+    </define>
d49186
+
d49186
+    <define name="agent-status">
d49186
+        <element name="agent-status">
d49186
+            <attribute name="code"> <data type="integer" /> </attribute>
d49186
+            <optional>
d49186
+                <attribute name="message"> <text/> </attribute>
d49186
+            </optional>
d49186
+        </element>
d49186
+    </define>
d49186
+
d49186
     <define name="attribute-roles">
d49186
         <choice>
d49186
             <value>Stopped</value>
d49186
-- 
d49186
1.8.3.1
d49186
d49186
d49186
From d89f5bc7fec856fdcd32fa14edbd0019507d5d15 Mon Sep 17 00:00:00 2001
d49186
From: Chris Lumens <clumens@redhat.com>
d49186
Date: Tue, 1 Jun 2021 15:26:58 -0400
d49186
Subject: [PATCH 04/10] Low: libcrmcommon: Increase PCMK__API_VERSION for new
d49186
 crm_resource output.
d49186
d49186
See: rhbz#1644628
d49186
---
d49186
 include/crm/common/output_internal.h | 2 +-
d49186
 1 file changed, 1 insertion(+), 1 deletion(-)
d49186
d49186
diff --git a/include/crm/common/output_internal.h b/include/crm/common/output_internal.h
d49186
index 10b315b..0436cde 100644
d49186
--- a/include/crm/common/output_internal.h
d49186
+++ b/include/crm/common/output_internal.h
d49186
@@ -27,7 +27,7 @@ extern "C" {
d49186
 #  include <glib.h>
d49186
 #  include <crm/common/results.h>
d49186
 
d49186
-#  define PCMK__API_VERSION "2.9"
d49186
+#  define PCMK__API_VERSION "2.11"
d49186
 
d49186
 #if defined(PCMK__WITH_ATTRIBUTE_OUTPUT_ARGS)
d49186
 #  define PCMK__OUTPUT_ARGS(ARGS...) __attribute__((output_args(ARGS)))
d49186
-- 
d49186
1.8.3.1
d49186
d49186
d49186
From 30bd2ddf43ee2a911681e51f40ed9ba20ec250b0 Mon Sep 17 00:00:00 2001
d49186
From: Chris Lumens <clumens@redhat.com>
d49186
Date: Thu, 27 May 2021 13:57:12 -0400
d49186
Subject: [PATCH 05/10] Low: tools: Pass NULL to
d49186
 cli_resource_execute_from_params...
d49186
d49186
if no resource name is given.  This happens if we are validating based
d49186
on the --class/--agent/--provider command line options instead.
d49186
---
d49186
 tools/crm_resource.c         | 2 +-
d49186
 tools/crm_resource_runtime.c | 8 ++++----
d49186
 2 files changed, 5 insertions(+), 5 deletions(-)
d49186
d49186
diff --git a/tools/crm_resource.c b/tools/crm_resource.c
d49186
index 24f1121..37a0bb0 100644
d49186
--- a/tools/crm_resource.c
d49186
+++ b/tools/crm_resource.c
d49186
@@ -1840,7 +1840,7 @@ main(int argc, char **argv)
d49186
 
d49186
         case cmd_execute_agent:
d49186
             if (options.cmdline_config) {
d49186
-                exit_code = cli_resource_execute_from_params(out, "test",
d49186
+                exit_code = cli_resource_execute_from_params(out, NULL,
d49186
                     options.v_class, options.v_provider, options.v_agent,
d49186
                     "validate-all", options.cmdline_params,
d49186
                     options.override_params, options.timeout_ms,
d49186
diff --git a/tools/crm_resource_runtime.c b/tools/crm_resource_runtime.c
d49186
index 48a4b40..ebf48bb 100644
d49186
--- a/tools/crm_resource_runtime.c
d49186
+++ b/tools/crm_resource_runtime.c
d49186
@@ -1717,14 +1717,14 @@ cli_resource_execute_from_params(pcmk__output_t *out, const char *rsc_name,
d49186
      */
d49186
     params_copy = pcmk__str_table_dup(params);
d49186
 
d49186
-    op = resources_action_create(rsc_name, rsc_class, rsc_prov, rsc_type, action, 0,
d49186
-                                 timeout_ms, params_copy, 0);
d49186
+    op = resources_action_create(rsc_name ? rsc_name : "test", rsc_class, rsc_prov,
d49186
+                                 rsc_type, action, 0, timeout_ms, params_copy, 0);
d49186
     if (op == NULL) {
d49186
         /* Re-run with stderr enabled so we can display a sane error message */
d49186
         crm_enable_stderr(TRUE);
d49186
         params_copy = pcmk__str_table_dup(params);
d49186
-        op = resources_action_create(rsc_name, rsc_class, rsc_prov, rsc_type, action, 0,
d49186
-                                     timeout_ms, params_copy, 0);
d49186
+        op = resources_action_create(rsc_name ? rsc_name : "test", rsc_class, rsc_prov,
d49186
+                                     rsc_type, action, 0, timeout_ms, params_copy, 0);
d49186
 
d49186
         /* Callers of cli_resource_execute expect that the params hash table will
d49186
          * be freed.  That function uses this one, so for that reason and for
d49186
-- 
d49186
1.8.3.1
d49186
d49186
d49186
From ee56efd53d14cfc4f902769540b72b3bb6096a73 Mon Sep 17 00:00:00 2001
d49186
From: Chris Lumens <clumens@redhat.com>
d49186
Date: Mon, 24 May 2021 12:08:52 -0400
d49186
Subject: [PATCH 06/10] Feature: tools: Add an agent-status message for
d49186
 crm_resource.
d49186
d49186
This moves what was previously only done in an out->info call to its own
d49186
output message, which means it will appear in XML output as well.  Also,
d49186
note that if --class/--agent/--provider are given, the resource name
d49186
will be set to "test".  In that case, do not display the resource name
d49186
in the output.
d49186
d49186
This message will be used for --validate and the --force-* command line
d49186
options to crm_resource.
d49186
d49186
See: rhbz#1644628
d49186
---
d49186
 tools/crm_resource_print.c | 53 ++++++++++++++++++++++++++++++++++++++++++++++
d49186
 1 file changed, 53 insertions(+)
d49186
d49186
diff --git a/tools/crm_resource_print.c b/tools/crm_resource_print.c
d49186
index 9d82cf8..88d5878 100644
d49186
--- a/tools/crm_resource_print.c
d49186
+++ b/tools/crm_resource_print.c
d49186
@@ -152,6 +152,57 @@ attribute_list_default(pcmk__output_t *out, va_list args) {
d49186
     return pcmk_rc_ok;
d49186
 }
d49186
 
d49186
+PCMK__OUTPUT_ARGS("agent-status", "int", "const char *", "const char *", "const char *",
d49186
+                  "const char *", "const char *", "int")
d49186
+static int
d49186
+agent_status_default(pcmk__output_t *out, va_list args) {
d49186
+    int status = va_arg(args, int);
d49186
+    const char *action = va_arg(args, const char *);
d49186
+    const char *name = va_arg(args, const char *);
d49186
+    const char *class = va_arg(args, const char *);
d49186
+    const char *provider = va_arg(args, const char *);
d49186
+    const char *type = va_arg(args, const char *);
d49186
+    int rc = va_arg(args, int);
d49186
+
d49186
+    if (status == PCMK_LRM_OP_DONE) {
d49186
+        out->info(out, "Operation %s%s%s (%s%s%s:%s) returned: '%s' (%d)",
d49186
+                  action, name ? " for " : "", name ? name : "",
d49186
+                  class, provider ? ":" : "", provider ? provider : "", type,
d49186
+                  services_ocf_exitcode_str(rc), rc);
d49186
+    } else {
d49186
+        out->err(out, "Operation %s%s%s (%s%s%s:%s) failed: '%s' (%d)",
d49186
+                 action, name ? " for " : "", name ? name : "",
d49186
+                 class, provider ? ":" : "", provider ? provider : "", type,
d49186
+                 services_lrm_status_str(status), status);
d49186
+    }
d49186
+
d49186
+    return pcmk_rc_ok;
d49186
+}
d49186
+
d49186
+PCMK__OUTPUT_ARGS("agent-status", "int", "const char *", "const char *", "const char *",
d49186
+                  "const char *", "const char *", "int")
d49186
+static int
d49186
+agent_status_xml(pcmk__output_t *out, va_list args) {
d49186
+    int status G_GNUC_UNUSED = va_arg(args, int);
d49186
+    const char *action G_GNUC_UNUSED = va_arg(args, const char *);
d49186
+    const char *name G_GNUC_UNUSED = va_arg(args, const char *);
d49186
+    const char *class G_GNUC_UNUSED = va_arg(args, const char *);
d49186
+    const char *provider G_GNUC_UNUSED = va_arg(args, const char *);
d49186
+    const char *type G_GNUC_UNUSED = va_arg(args, const char *);
d49186
+    int rc = va_arg(args, int);
d49186
+
d49186
+    char *status_str = pcmk__itoa(rc);
d49186
+
d49186
+    pcmk__output_create_xml_node(out, "agent-status",
d49186
+                                 "code", status_str,
d49186
+                                 "message", services_ocf_exitcode_str(rc),
d49186
+                                 NULL);
d49186
+
d49186
+    free(status_str);
d49186
+
d49186
+    return pcmk_rc_ok;
d49186
+}
d49186
+
d49186
 PCMK__OUTPUT_ARGS("attribute-list", "pe_resource_t *", "char *", "GHashTable *")
d49186
 static int
d49186
 attribute_list_text(pcmk__output_t *out, va_list args) {
d49186
@@ -562,6 +613,8 @@ resource_names(pcmk__output_t *out, va_list args) {
d49186
 }
d49186
 
d49186
 static pcmk__message_entry_t fmt_functions[] = {
d49186
+    { "agent-status", "default", agent_status_default },
d49186
+    { "agent-status", "xml", agent_status_xml },
d49186
     { "attribute-list", "default", attribute_list_default },
d49186
     { "attribute-list", "text", attribute_list_text },
d49186
     { "property-list", "default", property_list_default },
d49186
-- 
d49186
1.8.3.1
d49186
d49186
d49186
From 85cb6b6bff96b18c5174d11e4de4d49cbfb20bb7 Mon Sep 17 00:00:00 2001
d49186
From: Chris Lumens <clumens@redhat.com>
d49186
Date: Tue, 1 Jun 2021 14:47:30 -0400
d49186
Subject: [PATCH 07/10] Feature: tools: Add an overridden params output
d49186
 message.
d49186
d49186
This also replaces what was previously being done in an out->info call
d49186
with an output message.  This means it shows up in XML output as well.
d49186
Also, note that if --class/--agent/--provider are given, the resource
d49186
name will be set to "test".  In that case, do not display the resource
d49186
name in the output.
d49186
d49186
See: rhbz#1644628
d49186
---
d49186
 tools/crm_resource_print.c | 39 +++++++++++++++++++++++++++++++++++++++
d49186
 1 file changed, 39 insertions(+)
d49186
d49186
diff --git a/tools/crm_resource_print.c b/tools/crm_resource_print.c
d49186
index 88d5878..119d83f 100644
d49186
--- a/tools/crm_resource_print.c
d49186
+++ b/tools/crm_resource_print.c
d49186
@@ -224,6 +224,43 @@ attribute_list_text(pcmk__output_t *out, va_list args) {
d49186
     return pcmk_rc_ok;
d49186
 }
d49186
 
d49186
+PCMK__OUTPUT_ARGS("override", "const char *", "const char *", "const char *")
d49186
+static int
d49186
+override_default(pcmk__output_t *out, va_list args) {
d49186
+    const char *rsc_name = va_arg(args, const char *);
d49186
+    const char *name = va_arg(args, const char *);
d49186
+    const char *value = va_arg(args, const char *);
d49186
+
d49186
+    if (rsc_name == NULL) {
d49186
+        out->list_item(out, NULL, "Overriding the cluster configuration with '%s' = '%s'",
d49186
+                       name, value);
d49186
+    } else {
d49186
+        out->list_item(out, NULL, "Overriding the cluster configuration for '%s' with '%s' = '%s'",
d49186
+                       rsc_name, name, value);
d49186
+    }
d49186
+
d49186
+    return pcmk_rc_ok;
d49186
+}
d49186
+
d49186
+PCMK__OUTPUT_ARGS("override", "const char *", "const char *", "const char *")
d49186
+static int
d49186
+override_xml(pcmk__output_t *out, va_list args) {
d49186
+    const char *rsc_name = va_arg(args, const char *);
d49186
+    const char *name = va_arg(args, const char *);
d49186
+    const char *value = va_arg(args, const char *);
d49186
+
d49186
+    xmlNodePtr node = pcmk__output_create_xml_node(out, "override",
d49186
+                                                   "name", name,
d49186
+                                                   "value", value,
d49186
+                                                   NULL);
d49186
+
d49186
+    if (rsc_name != NULL) {
d49186
+        crm_xml_add(node, "rsc", rsc_name);
d49186
+    }
d49186
+
d49186
+    return pcmk_rc_ok;
d49186
+}
d49186
+
d49186
 PCMK__OUTPUT_ARGS("property-list", "pe_resource_t *", "char *")
d49186
 static int
d49186
 property_list_default(pcmk__output_t *out, va_list args) {
d49186
@@ -617,6 +654,8 @@ static pcmk__message_entry_t fmt_functions[] = {
d49186
     { "agent-status", "xml", agent_status_xml },
d49186
     { "attribute-list", "default", attribute_list_default },
d49186
     { "attribute-list", "text", attribute_list_text },
d49186
+    { "override", "default", override_default },
d49186
+    { "override", "xml", override_xml },
d49186
     { "property-list", "default", property_list_default },
d49186
     { "property-list", "text", property_list_text },
d49186
     { "resource-check-list", "default", resource_check_list_default },
d49186
-- 
d49186
1.8.3.1
d49186
d49186
d49186
From e5e24592c7c3231c619fb5253e7925ffbc634a99 Mon Sep 17 00:00:00 2001
d49186
From: Chris Lumens <clumens@redhat.com>
d49186
Date: Fri, 4 Jun 2021 10:24:51 -0400
d49186
Subject: [PATCH 08/10] Low: tools: Use simple XML lists for resource actions
d49186
 as well.
d49186
d49186
See: rhbz#1644628
d49186
---
d49186
 tools/crm_resource.c | 1 +
d49186
 1 file changed, 1 insertion(+)
d49186
d49186
diff --git a/tools/crm_resource.c b/tools/crm_resource.c
d49186
index 37a0bb0..e957011 100644
d49186
--- a/tools/crm_resource.c
d49186
+++ b/tools/crm_resource.c
d49186
@@ -1643,6 +1643,7 @@ main(int argc, char **argv)
d49186
          * saves from having to write custom messages to build the lists around all these things
d49186
          */
d49186
         switch (options.rsc_cmd) {
d49186
+            case cmd_execute_agent:
d49186
             case cmd_list_resources:
d49186
             case cmd_query_xml:
d49186
             case cmd_query_raw_xml:
d49186
-- 
d49186
1.8.3.1
d49186
d49186
d49186
From 3e75174d0bc31b261adb1994214a5878b79da85b Mon Sep 17 00:00:00 2001
d49186
From: Chris Lumens <clumens@redhat.com>
d49186
Date: Fri, 4 Jun 2021 10:30:10 -0400
d49186
Subject: [PATCH 09/10] Feature: tools: Add an output message for resource
d49186
 actions.
d49186
d49186
This wraps up the override and agent-status messages into a single
d49186
message, along with any stdout/stderr from the resource action.  This
d49186
message should be called after taking the action.
d49186
d49186
This also implements handling XML output from resource actions.  Check
d49186
to see if the validate-all action returns XML.  If so, output it as a
d49186
CDATA block under a "command" element.  If not, treat it as plain text
d49186
and output it as stdout/stderr from a command.
d49186
d49186
See: rhbz#1644628
d49186
---
d49186
 tools/crm_resource_print.c | 122 +++++++++++++++++++++++++++++++++++++++++++++
d49186
 1 file changed, 122 insertions(+)
d49186
d49186
diff --git a/tools/crm_resource_print.c b/tools/crm_resource_print.c
d49186
index 119d83f..19a366d 100644
d49186
--- a/tools/crm_resource_print.c
d49186
+++ b/tools/crm_resource_print.c
d49186
@@ -293,6 +293,126 @@ property_list_text(pcmk__output_t *out, va_list args) {
d49186
     return pcmk_rc_ok;
d49186
 }
d49186
 
d49186
+PCMK__OUTPUT_ARGS("resource-agent-action", "int", "const char *", "const char *",
d49186
+                  "const char *", "const char *", "const char *", "GHashTable *",
d49186
+                  "int", "int", "char *", "char *")
d49186
+static int
d49186
+resource_agent_action_default(pcmk__output_t *out, va_list args) {
d49186
+    int verbose = va_arg(args, int);
d49186
+
d49186
+    const char *class = va_arg(args, const char *);
d49186
+    const char *provider = va_arg(args, const char *);
d49186
+    const char *type = va_arg(args, const char *);
d49186
+    const char *rsc_name = va_arg(args, const char *);
d49186
+    const char *action = va_arg(args, const char *);
d49186
+    GHashTable *overrides = va_arg(args, GHashTable *);
d49186
+    int rc = va_arg(args, int);
d49186
+    int status = va_arg(args, int);
d49186
+    char *stdout_data = va_arg(args, char *);
d49186
+    char *stderr_data = va_arg(args, char *);
d49186
+
d49186
+    if (overrides) {
d49186
+        GHashTableIter iter;
d49186
+        char *name = NULL;
d49186
+        char *value = NULL;
d49186
+
d49186
+        out->begin_list(out, NULL, NULL, "overrides");
d49186
+
d49186
+        g_hash_table_iter_init(&iter, overrides);
d49186
+        while (g_hash_table_iter_next(&iter, (gpointer *) &name, (gpointer *) &value)) {
d49186
+            out->message(out, "override", rsc_name, name, value);
d49186
+        }
d49186
+
d49186
+        out->end_list(out);
d49186
+    }
d49186
+
d49186
+    out->message(out, "agent-status", status, action, rsc_name, class, provider,
d49186
+                 type, rc);
d49186
+
d49186
+    /* hide output for validate-all if not in verbose */
d49186
+    if (verbose == 0 && pcmk__str_eq(action, "validate-all", pcmk__str_casei)) {
d49186
+        return pcmk_rc_ok;
d49186
+    }
d49186
+
d49186
+    if (stdout_data || stderr_data) {
d49186
+        xmlNodePtr doc = string2xml(stdout_data);
d49186
+
d49186
+        if (doc != NULL) {
d49186
+            out->output_xml(out, "command", stdout_data);
d49186
+            xmlFreeNode(doc);
d49186
+        } else {
d49186
+            out->subprocess_output(out, rc, stdout_data, stderr_data);
d49186
+        }
d49186
+    }
d49186
+
d49186
+    return pcmk_rc_ok;
d49186
+}
d49186
+
d49186
+PCMK__OUTPUT_ARGS("resource-agent-action", "int", "const char *", "const char *",
d49186
+                  "const char *", "const char *", "const char *", "GHashTable *",
d49186
+                  "int", "int", "char *", "char *")
d49186
+static int
d49186
+resource_agent_action_xml(pcmk__output_t *out, va_list args) {
d49186
+    int verbose G_GNUC_UNUSED = va_arg(args, int);
d49186
+
d49186
+    const char *class = va_arg(args, const char *);
d49186
+    const char *provider = va_arg(args, const char *);
d49186
+    const char *type = va_arg(args, const char *);
d49186
+    const char *rsc_name = va_arg(args, const char *);
d49186
+    const char *action = va_arg(args, const char *);
d49186
+    GHashTable *overrides = va_arg(args, GHashTable *);
d49186
+    int rc = va_arg(args, int);
d49186
+    int status = va_arg(args, int);
d49186
+    char *stdout_data = va_arg(args, char *);
d49186
+    char *stderr_data = va_arg(args, char *);
d49186
+
d49186
+    xmlNodePtr node = pcmk__output_xml_create_parent(out, "resource-agent-action",
d49186
+                                                     "action", action,
d49186
+                                                     "class", class,
d49186
+                                                     "type", type,
d49186
+                                                     NULL);
d49186
+
d49186
+    if (rsc_name) {
d49186
+        crm_xml_add(node, "rsc", rsc_name);
d49186
+    }
d49186
+
d49186
+    if (provider) {
d49186
+        crm_xml_add(node, "provider", provider);
d49186
+    }
d49186
+
d49186
+    if (overrides) {
d49186
+        GHashTableIter iter;
d49186
+        char *name = NULL;
d49186
+        char *value = NULL;
d49186
+
d49186
+        out->begin_list(out, NULL, NULL, "overrides");
d49186
+
d49186
+        g_hash_table_iter_init(&iter, overrides);
d49186
+        while (g_hash_table_iter_next(&iter, (gpointer *) &name, (gpointer *) &value)) {
d49186
+            out->message(out, "override", rsc_name, name, value);
d49186
+        }
d49186
+
d49186
+        out->end_list(out);
d49186
+    }
d49186
+
d49186
+    out->message(out, "agent-status", status, action, rsc_name, class, provider,
d49186
+                 type, rc);
d49186
+
d49186
+    if (stdout_data || stderr_data) {
d49186
+        xmlNodePtr doc = string2xml(stdout_data);
d49186
+
d49186
+        if (doc != NULL) {
d49186
+            out->output_xml(out, "command", stdout_data);
d49186
+            xmlFreeNode(doc);
d49186
+        } else {
d49186
+            out->subprocess_output(out, rc, stdout_data, stderr_data);
d49186
+        }
d49186
+    }
d49186
+
d49186
+    pcmk__output_xml_pop_parent(out);
d49186
+    return pcmk_rc_ok;
d49186
+}
d49186
+
d49186
 PCMK__OUTPUT_ARGS("resource-check-list", "resource_checks_t *")
d49186
 static int
d49186
 resource_check_list_default(pcmk__output_t *out, va_list args) {
d49186
@@ -658,6 +778,8 @@ static pcmk__message_entry_t fmt_functions[] = {
d49186
     { "override", "xml", override_xml },
d49186
     { "property-list", "default", property_list_default },
d49186
     { "property-list", "text", property_list_text },
d49186
+    { "resource-agent-action", "default", resource_agent_action_default },
d49186
+    { "resource-agent-action", "xml", resource_agent_action_xml },
d49186
     { "resource-check-list", "default", resource_check_list_default },
d49186
     { "resource-check-list", "xml", resource_check_list_xml },
d49186
     { "resource-search-list", "default", resource_search_list_default },
d49186
-- 
d49186
1.8.3.1
d49186
d49186
d49186
From b50b2418e1e997b42f5370b4672a3f105d74634f Mon Sep 17 00:00:00 2001
d49186
From: Chris Lumens <clumens@redhat.com>
d49186
Date: Fri, 4 Jun 2021 10:40:16 -0400
d49186
Subject: [PATCH 10/10] Feature: tools: Use the new resource-agent-action
d49186
 message.
d49186
d49186
See: rhbz#1644628
d49186
---
d49186
 tools/crm_resource_runtime.c | 21 +++------------------
d49186
 1 file changed, 3 insertions(+), 18 deletions(-)
d49186
d49186
diff --git a/tools/crm_resource_runtime.c b/tools/crm_resource_runtime.c
d49186
index ebf48bb..755be9f 100644
d49186
--- a/tools/crm_resource_runtime.c
d49186
+++ b/tools/crm_resource_runtime.c
d49186
@@ -1765,28 +1765,13 @@ cli_resource_execute_from_params(pcmk__output_t *out, const char *rsc_name,
d49186
     if (services_action_sync(op)) {
d49186
         exit_code = op->rc;
d49186
 
d49186
-        if (op->status == PCMK_LRM_OP_DONE) {
d49186
-            out->info(out, "Operation %s for %s (%s:%s:%s) returned: '%s' (%d)",
d49186
-                      action, rsc_name, rsc_class, rsc_prov ? rsc_prov : "", rsc_type,
d49186
-                      services_ocf_exitcode_str(op->rc), op->rc);
d49186
-        } else {
d49186
-            out->err(out, "Operation %s for %s (%s:%s:%s) failed: '%s' (%d)",
d49186
-                     action, rsc_name, rsc_class, rsc_prov ? rsc_prov : "", rsc_type,
d49186
-                     services_lrm_status_str(op->status), op->status);
d49186
-        }
d49186
-
d49186
-        /* hide output for validate-all if not in verbose */
d49186
-        if (resource_verbose == 0 && pcmk__str_eq(action, "validate-all", pcmk__str_casei))
d49186
-            goto done;
d49186
-
d49186
-        if (op->stdout_data || op->stderr_data) {
d49186
-            out->subprocess_output(out, op->rc, op->stdout_data, op->stderr_data);
d49186
-        }
d49186
+        out->message(out, "resource-agent-action", resource_verbose, rsc_class,
d49186
+                     rsc_prov, rsc_type, rsc_name, action, override_hash, op->rc,
d49186
+                     op->status, op->stdout_data, op->stderr_data);
d49186
     } else {
d49186
         exit_code = op->rc == 0 ? CRM_EX_ERROR : op->rc;
d49186
     }
d49186
 
d49186
-done:
d49186
     services_action_free(op);
d49186
     /* See comment above about why we free params here. */
d49186
     g_hash_table_destroy(params);
d49186
-- 
d49186
1.8.3.1
d49186