|
|
15f218 |
From 0cfbd1bd87d4484eca054d41aea1d8ac9b55e93c Mon Sep 17 00:00:00 2001
|
|
|
15f218 |
From: Tomas Jelinek <tojeline@redhat.com>
|
|
|
15f218 |
Date: Mon, 8 Aug 2016 13:32:07 +0200
|
|
|
15f218 |
Subject: [PATCH] add possibility to hide inactive resources in "pcs resource
|
|
|
15f218 |
show"
|
|
|
15f218 |
|
|
|
15f218 |
---
|
|
|
15f218 |
.pylintrc | 2 +-
|
|
|
15f218 |
pcs/pcs.8 | 12 ++++++------
|
|
|
15f218 |
pcs/resource.py | 33 +++++++++++++++++++++++++++------
|
|
|
15f218 |
pcs/test/test_resource.py | 21 ++++++++++++++-------
|
|
|
15f218 |
pcs/usage.py | 16 ++++++++++------
|
|
|
15f218 |
5 files changed, 58 insertions(+), 26 deletions(-)
|
|
|
15f218 |
|
|
|
15f218 |
diff --git a/.pylintrc b/.pylintrc
|
|
|
15f218 |
index e378e6a..1dd6d5d 100644
|
|
|
15f218 |
--- a/.pylintrc
|
|
|
15f218 |
+++ b/.pylintrc
|
|
|
15f218 |
@@ -92,7 +92,7 @@ dummy-variables-rgx=_$|dummy
|
|
|
15f218 |
|
|
|
15f218 |
[FORMAT]
|
|
|
15f218 |
# Maximum number of lines in a module
|
|
|
15f218 |
-max-module-lines=4577
|
|
|
15f218 |
+max-module-lines=4584
|
|
|
15f218 |
# Maximum number of characters on a single line.
|
|
|
15f218 |
max-line-length=1291
|
|
|
15f218 |
|
|
|
15f218 |
diff --git a/pcs/pcs.8 b/pcs/pcs.8
|
|
|
15f218 |
index 52497a0..9064054 100644
|
|
|
15f218 |
--- a/pcs/pcs.8
|
|
|
15f218 |
+++ b/pcs/pcs.8
|
|
|
15f218 |
@@ -64,8 +64,8 @@ alert
|
|
|
15f218 |
Manage pacemaker alerts.
|
|
|
15f218 |
.SS "resource"
|
|
|
15f218 |
.TP
|
|
|
15f218 |
-[show [resource id]] [\fB\-\-full\fR] [\fB\-\-groups\fR]
|
|
|
15f218 |
-Show all currently configured resources or if a resource is specified show the options for the configured resource. If \fB\-\-full\fR is specified all configured resource options will be displayed. If \fB\-\-groups\fR is specified, only show groups (and their resources).
|
|
|
15f218 |
+[show [<resource id>] | \fB\-\-full\fR | \fB\-\-groups\fR | \fB\-\-hide\-inactive\fR]
|
|
|
15f218 |
+Show all currently configured resources or if a resource is specified show the options for the configured resource. If \fB\-\-full\fR is specified, all configured resource options will be displayed. If \fB\-\-groups\fR is specified, only show groups (and their resources). If \fB\-\-hide\-inactive\fR is specified, only show active resources.
|
|
|
15f218 |
.TP
|
|
|
15f218 |
list [<standard|provider|type>] [\fB\-\-nodesc\fR]
|
|
|
15f218 |
Show list of all available resources, optionally filtered by specified type, standard or provider. If \fB\-\-nodesc\fR is used then descriptions of resources are not printed.
|
|
|
15f218 |
@@ -627,11 +627,11 @@ stop
|
|
|
15f218 |
Stop booth arbitrator service.
|
|
|
15f218 |
.SS "status"
|
|
|
15f218 |
.TP
|
|
|
15f218 |
-[status] [\fB\-\-full\fR | \fB\-\-hide-inactive\fR]
|
|
|
15f218 |
-View all information about the cluster and resources (\fB\-\-full\fR provides more details, \fB\-\-hide-inactive\fR hides inactive resources).
|
|
|
15f218 |
+[status] [\fB\-\-full\fR | \fB\-\-hide\-inactive\fR]
|
|
|
15f218 |
+View all information about the cluster and resources (\fB\-\-full\fR provides more details, \fB\-\-hide\-inactive\fR hides inactive resources).
|
|
|
15f218 |
.TP
|
|
|
15f218 |
-resources
|
|
|
15f218 |
-View current status of cluster resources.
|
|
|
15f218 |
+resources [<resource id> | \fB\-\-full\fR | \fB\-\-groups\fR | \fB\-\-hide\-inactive\fR]
|
|
|
15f218 |
+Show all currently configured resources or if a resource is specified show the options for the configured resource. If \fB\-\-full\fR is specified, all configured resource options will be displayed. If \fB\-\-groups\fR is specified, only show groups (and their resources). If \fB\-\-hide\-inactive\fR is specified, only show active resources.
|
|
|
15f218 |
.TP
|
|
|
15f218 |
groups
|
|
|
15f218 |
View currently configured groups and their resources.
|
|
|
15f218 |
diff --git a/pcs/resource.py b/pcs/resource.py
|
|
|
15f218 |
index 66c743c..74adac6 100644
|
|
|
15f218 |
--- a/pcs/resource.py
|
|
|
15f218 |
+++ b/pcs/resource.py
|
|
|
15f218 |
@@ -1993,6 +1993,17 @@ def resource_group_list(argv):
|
|
|
15f218 |
print(" ".join(line_parts))
|
|
|
15f218 |
|
|
|
15f218 |
def resource_show(argv, stonith=False):
|
|
|
15f218 |
+ mutually_exclusive_opts = ("--full", "--groups", "--hide-inactive")
|
|
|
15f218 |
+ modifiers = [
|
|
|
15f218 |
+ key for key in utils.pcs_options if key in mutually_exclusive_opts
|
|
|
15f218 |
+ ]
|
|
|
15f218 |
+ if (len(modifiers) > 1) or (argv and modifiers):
|
|
|
15f218 |
+ utils.err(
|
|
|
15f218 |
+ "you can specify only one of resource id, {0}".format(
|
|
|
15f218 |
+ ", ".join(mutually_exclusive_opts)
|
|
|
15f218 |
+ )
|
|
|
15f218 |
+ )
|
|
|
15f218 |
+
|
|
|
15f218 |
if "--groups" in utils.pcs_options:
|
|
|
15f218 |
resource_group_list(argv)
|
|
|
15f218 |
return
|
|
|
15f218 |
@@ -2009,15 +2020,28 @@ def resource_show(argv, stonith=False):
|
|
|
15f218 |
return
|
|
|
15f218 |
|
|
|
15f218 |
if len(argv) == 0:
|
|
|
15f218 |
- output, retval = utils.run(["crm_mon", "-1", "-r"])
|
|
|
15f218 |
+ monitor_command = ["crm_mon", "--one-shot"]
|
|
|
15f218 |
+ if "--hide-inactive" not in utils.pcs_options:
|
|
|
15f218 |
+ monitor_command.append('--inactive')
|
|
|
15f218 |
+ output, retval = utils.run(monitor_command)
|
|
|
15f218 |
if retval != 0:
|
|
|
15f218 |
utils.err("unable to get cluster status from crm_mon\n"+output.rstrip())
|
|
|
15f218 |
preg = re.compile(r'.*(stonith:.*)')
|
|
|
15f218 |
resources_header = False
|
|
|
15f218 |
in_resources = False
|
|
|
15f218 |
has_resources = False
|
|
|
15f218 |
+ no_resources_line = (
|
|
|
15f218 |
+ "NO stonith devices configured" if stonith
|
|
|
15f218 |
+ else "NO resources configured"
|
|
|
15f218 |
+ )
|
|
|
15f218 |
for line in output.split('\n'):
|
|
|
15f218 |
- if line == "Full list of resources:":
|
|
|
15f218 |
+ if line == "No active resources":
|
|
|
15f218 |
+ print(line)
|
|
|
15f218 |
+ return
|
|
|
15f218 |
+ if line == "No resources":
|
|
|
15f218 |
+ print(no_resources_line)
|
|
|
15f218 |
+ return
|
|
|
15f218 |
+ if line in ("Full list of resources:", "Active resources:"):
|
|
|
15f218 |
resources_header = True
|
|
|
15f218 |
continue
|
|
|
15f218 |
if line == "":
|
|
|
15f218 |
@@ -2026,10 +2050,7 @@ def resource_show(argv, stonith=False):
|
|
|
15f218 |
in_resources = True
|
|
|
15f218 |
elif in_resources:
|
|
|
15f218 |
if not has_resources:
|
|
|
15f218 |
- if not stonith:
|
|
|
15f218 |
- print("NO resources configured")
|
|
|
15f218 |
- else:
|
|
|
15f218 |
- print("NO stonith devices configured")
|
|
|
15f218 |
+ print(no_resources_line)
|
|
|
15f218 |
return
|
|
|
15f218 |
continue
|
|
|
15f218 |
if in_resources:
|
|
|
15f218 |
diff --git a/pcs/test/test_resource.py b/pcs/test/test_resource.py
|
|
|
15f218 |
index 2fa5088..614b895 100644
|
|
|
15f218 |
--- a/pcs/test/test_resource.py
|
|
|
15f218 |
+++ b/pcs/test/test_resource.py
|
|
|
15f218 |
@@ -213,8 +213,7 @@ the health of a system via IPMI.
|
|
|
15f218 |
ClusterIP7\t(ocf::heartbeat:IPaddr2):\tStopped (disabled)
|
|
|
15f218 |
""")
|
|
|
15f218 |
|
|
|
15f218 |
- output, returnVal = pcs(temp_cib, "resource show ClusterIP6 --full")
|
|
|
15f218 |
- assert returnVal == 0
|
|
|
15f218 |
+ output, returnVal = pcs(temp_cib, "resource show --full")
|
|
|
15f218 |
ac(output, """\
|
|
|
15f218 |
Resource: ClusterIP (class=ocf provider=heartbeat type=IPaddr2)
|
|
|
15f218 |
Attributes: ip=192.168.0.99 cidr_netmask=32
|
|
|
15f218 |
@@ -241,6 +240,7 @@ the health of a system via IPMI.
|
|
|
15f218 |
Meta Attrs: target-role=Stopped
|
|
|
15f218 |
Operations: monitor interval=30s (ClusterIP7-monitor-interval-30s)
|
|
|
15f218 |
""")
|
|
|
15f218 |
+ self.assertEqual(0, returnVal)
|
|
|
15f218 |
|
|
|
15f218 |
output, returnVal = pcs(
|
|
|
15f218 |
temp_cib,
|
|
|
15f218 |
@@ -785,7 +785,7 @@ monitor interval=60s (state-monitor-interval-60s)
|
|
|
15f218 |
assert returnVal == 0
|
|
|
15f218 |
assert output == ""
|
|
|
15f218 |
|
|
|
15f218 |
- line = 'resource show ClusterIP --full'
|
|
|
15f218 |
+ line = 'resource show ClusterIP'
|
|
|
15f218 |
output, returnVal = pcs(temp_cib, line)
|
|
|
15f218 |
ac(output, """\
|
|
|
15f218 |
Resource: ClusterIP (class=ocf provider=heartbeat type=IPaddr2)
|
|
|
15f218 |
@@ -3463,16 +3463,23 @@ Error: Cannot remove more than one resource from cloned group
|
|
|
15f218 |
ac(o,"")
|
|
|
15f218 |
assert r == 0
|
|
|
15f218 |
|
|
|
15f218 |
- o,r = pcs(temp_cib, "resource show D1 --full")
|
|
|
15f218 |
- ac(o," Resource: D1 (class=ocf provider=heartbeat type=Dummy)\n Meta Attrs: target-role=Stopped \n Operations: monitor interval=60s (D1-monitor-interval-60s)\n")
|
|
|
15f218 |
+ o,r = pcs(temp_cib, "resource show D1")
|
|
|
15f218 |
+ ac(o, """\
|
|
|
15f218 |
+ Resource: D1 (class=ocf provider=heartbeat type=Dummy)
|
|
|
15f218 |
+ Meta Attrs: target-role=Stopped
|
|
|
15f218 |
+ Operations: monitor interval=60s (D1-monitor-interval-60s)
|
|
|
15f218 |
+""")
|
|
|
15f218 |
assert r == 0
|
|
|
15f218 |
|
|
|
15f218 |
o,r = pcs(temp_cib, "resource enable D1")
|
|
|
15f218 |
ac(o,"")
|
|
|
15f218 |
assert r == 0
|
|
|
15f218 |
|
|
|
15f218 |
- o,r = pcs(temp_cib, "resource show D1 --full")
|
|
|
15f218 |
- ac(o," Resource: D1 (class=ocf provider=heartbeat type=Dummy)\n Operations: monitor interval=60s (D1-monitor-interval-60s)\n")
|
|
|
15f218 |
+ o,r = pcs(temp_cib, "resource show D1")
|
|
|
15f218 |
+ ac(o, """\
|
|
|
15f218 |
+ Resource: D1 (class=ocf provider=heartbeat type=Dummy)
|
|
|
15f218 |
+ Operations: monitor interval=60s (D1-monitor-interval-60s)
|
|
|
15f218 |
+""")
|
|
|
15f218 |
assert r == 0
|
|
|
15f218 |
|
|
|
15f218 |
# bad resource name
|
|
|
15f218 |
diff --git a/pcs/usage.py b/pcs/usage.py
|
|
|
15f218 |
index baa70d0..b11a5fa 100644
|
|
|
15f218 |
--- a/pcs/usage.py
|
|
|
15f218 |
+++ b/pcs/usage.py
|
|
|
15f218 |
@@ -189,12 +189,12 @@ Usage: pcs resource [commands]...
|
|
|
15f218 |
Manage pacemaker resources
|
|
|
15f218 |
|
|
|
15f218 |
Commands:
|
|
|
15f218 |
- [show [resource id]] [--full] [--groups]
|
|
|
15f218 |
+ [show [<resource id>] | --full | --groups | --hide-inactive]
|
|
|
15f218 |
Show all currently configured resources or if a resource is specified
|
|
|
15f218 |
- show the options for the configured resource. If --full is specified
|
|
|
15f218 |
+ show the options for the configured resource. If --full is specified,
|
|
|
15f218 |
all configured resource options will be displayed. If --groups is
|
|
|
15f218 |
- specified, only show groups (and their resources).
|
|
|
15f218 |
-
|
|
|
15f218 |
+ specified, only show groups (and their resources). If --hide-inactive
|
|
|
15f218 |
+ is specified, only show active resources.
|
|
|
15f218 |
|
|
|
15f218 |
list [<standard|provider|type>] [--nodesc]
|
|
|
15f218 |
Show list of all available resources, optionally filtered by specified
|
|
|
15f218 |
@@ -1108,8 +1108,12 @@ Commands:
|
|
|
15f218 |
View all information about the cluster and resources (--full provides
|
|
|
15f218 |
more details, --hide-inactive hides inactive resources).
|
|
|
15f218 |
|
|
|
15f218 |
- resources
|
|
|
15f218 |
- View current status of cluster resources.
|
|
|
15f218 |
+ resources [<resource id> | --full | --groups | --hide-inactive]
|
|
|
15f218 |
+ Show all currently configured resources or if a resource is specified
|
|
|
15f218 |
+ show the options for the configured resource. If --full is specified,
|
|
|
15f218 |
+ all configured resource options will be displayed. If --groups is
|
|
|
15f218 |
+ specified, only show groups (and their resources). If --hide-inactive
|
|
|
15f218 |
+ is specified, only show active resources.
|
|
|
15f218 |
|
|
|
15f218 |
groups
|
|
|
15f218 |
View currently configured groups and their resources.
|
|
|
15f218 |
--
|
|
|
15f218 |
1.8.3.1
|
|
|
15f218 |
|