Blob Blame History Raw
From be56e49edd4e844e20c8b41a05b42728f66e1455 Mon Sep 17 00:00:00 2001
From: Tomas Jelinek <tojeline@redhat.com>
Date: Fri, 18 Jan 2019 17:18:18 +0100
Subject: [PATCH] re-add and deprecate 'pcs resource show'

---
 pcs/cli/common/parse_args.py           |  6 +++
 pcs/cli/common/test/test_parse_args.py |  3 ++
 pcs/resource.py                        | 63 ++++++++++++++++++++++++++
 pcs/stonith.py                         |  5 ++
 4 files changed, 77 insertions(+)

diff --git a/pcs/cli/common/parse_args.py b/pcs/cli/common/parse_args.py
index 9b5a2be6..efce977f 100644
--- a/pcs/cli/common/parse_args.py
+++ b/pcs/cli/common/parse_args.py
@@ -22,6 +22,9 @@ PCS_LONG_OPTIONS = [
     "hide-inactive",
     # pcs resource (un)manage - enable or disable monitor operations
     "monitor",
+    # TODO remove
+    # used only in deprecated 'pcs resource|stonith show'
+    "groups",
 ]
 
 def split_list(arg_list, separator):
@@ -319,6 +322,9 @@ class InputModifiers():
             "--enable": "--enable" in options,
             "--force": "--force" in options,
             "--full": "--full" in options,
+            # TODO remove
+            # used only in deprecated 'pcs resource|stonith show'
+            "--groups": "--groups" in options,
             "--hide-inactive": "--hide-inactive" in options,
             "--interactive": "--interactive" in options,
             "--local": "--local" in options,
diff --git a/pcs/cli/common/test/test_parse_args.py b/pcs/cli/common/test/test_parse_args.py
index 09b98162..56bb2f41 100644
--- a/pcs/cli/common/test/test_parse_args.py
+++ b/pcs/cli/common/test/test_parse_args.py
@@ -496,6 +496,9 @@ class InputModifiersTest(TestCase):
             "--enable",
             "--force",
             "--full",
+            # TODO remove
+            # used only in deprecated 'pcs resource|stonith show'
+            "--groups",
             "--hide-inactive",
             "--interactive",
             "--local",
diff --git a/pcs/resource.py b/pcs/resource.py
index eaca7126..862553e0 100644
--- a/pcs/resource.py
+++ b/pcs/resource.py
@@ -111,6 +111,10 @@ def resource_cmd(lib, argv, modifiers):
             resource_meta(lib, argv_next, modifiers)
         elif sub_cmd in {"delete", "remove"}:
             resource_remove_cmd(lib, argv_next, modifiers)
+        # TODO remove, deprecated command
+        # replaced with 'resource status' and 'resource config'
+        elif sub_cmd == "show":
+            resource_show(lib, argv_next, modifiers)
         elif sub_cmd == "status":
             resource_status(lib, argv_next, modifiers)
         elif sub_cmd == "config":
@@ -2225,6 +2229,65 @@ def resource_group_list(lib, argv, modifiers):
             line_parts.append(resource.getAttribute("id"))
         print(" ".join(line_parts))
 
+def resource_show(lib, argv, modifiers, stonith=False):
+    # TODO remove, deprecated command
+    # replaced with 'resource status' and 'resource config'
+    """
+    Options:
+      * -f - CIB file
+      * --full - print all configured options
+      * --groups - print resource groups
+      * --hide-inactive - print only active resources
+    """
+    modifiers.ensure_only_supported(
+        "-f", "--full", "--groups", "--hide-inactive"
+    )
+    mutually_exclusive_opts = ("--full", "--groups", "--hide-inactive")
+    specified_modifiers = [
+        opt for opt in mutually_exclusive_opts if modifiers.is_specified(opt)
+    ]
+    if (len(specified_modifiers) > 1) or (argv and specified_modifiers):
+        utils.err(
+            "you can specify only one of resource id, {0}".format(
+                ", ".join(mutually_exclusive_opts)
+            )
+        )
+
+    if modifiers.get("--groups"):
+        warn(
+            "This command is deprecated and will be removed. "
+            "Please use 'pcs resource group list' instead."
+        )
+        resource_group_list(lib, argv, modifiers.get_subset("-f"))
+        return
+
+    if modifiers.get("--full") or argv:
+        warn(
+            "This command is deprecated and will be removed. "
+            "Please use 'pcs {} config' instead.".format(
+                "stonith" if stonith else "resource"
+            )
+        )
+        resource_config(
+            lib,
+            argv,
+            modifiers.get_subset("-f"),
+            stonith=stonith
+        )
+        return
+
+    warn(
+        "This command is deprecated and will be removed. "
+        "Please use 'pcs {} status' instead.".format(
+            "stonith" if stonith else "resource"
+        )
+    )
+    resource_status(
+        lib,
+        argv,
+        modifiers.get_subset("-f", "--hide-inactive"),
+        stonith=stonith
+    )
 
 def resource_status(lib, argv, modifiers, stonith=False):
     """
diff --git a/pcs/stonith.py b/pcs/stonith.py
index 3f08efe3..c5270c84 100644
--- a/pcs/stonith.py
+++ b/pcs/stonith.py
@@ -40,6 +40,11 @@ def stonith_cmd(lib, argv, modifiers):
             resource.resource_update(lib, argv_next, modifiers)
         elif sub_cmd in {"delete", "remove"}:
             resource.resource_remove_cmd(lib, argv_next, modifiers)
+        # TODO remove, deprecated command
+        # replaced with 'stonith status' and 'stonith config'
+        elif sub_cmd == "show":
+            resource.resource_show(lib, argv_next, modifiers, stonith=True)
+            print_stonith_levels(lib)
         elif sub_cmd == "status":
             resource.resource_status(lib, argv_next, modifiers, stonith=True)
             print_stonith_levels(lib)
-- 
2.17.0