Blame SOURCES/005-crm_resource.patch

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