summaryrefslogtreecommitdiffstats
path: root/extras
diff options
context:
space:
mode:
authorAravinda VK <avishwan@redhat.com>2016-11-17 15:42:24 +0530
committerAravinda VK <avishwan@redhat.com>2016-12-02 00:20:39 -0800
commitda71bdcf82a8dc71a1170ad3f190702fa49d2838 (patch)
treee5e1c43307333475dd0bf5d255c44948e5815d3b /extras
parent47e69455d3aede77960fd81a7cf3d6b4a869dbfa (diff)
eventsapi: JSON output and different error codes
JSON outputs are added to all commands, use `--json` to get JSON output. Following error codes are added to differenciate between errors. Any other Unknown errors will have return code 1 ERROR_SAME_CONFIG = 2 ERROR_ALL_NODES_STATUS_NOT_OK = 3 ERROR_PARTIAL_SUCCESS = 4 ERROR_WEBHOOK_ALREADY_EXISTS = 5 ERROR_WEBHOOK_NOT_EXISTS = 6 ERROR_INVALID_CONFIG = 7 ERROR_WEBHOOK_SYNC_FAILED = 8 ERROR_CONFIG_SYNC_FAILED = 9 Also hidden `node-` commands in the help message. BUG: 1357753 Change-Id: I962b5435c8a448b4573059da0eae42f3f93cc97e Signed-off-by: Aravinda VK <avishwan@redhat.com> Reviewed-on: http://review.gluster.org/15867 Smoke: Gluster Build System <jenkins@build.gluster.org> Reviewed-by: Prashanth Pai <ppai@redhat.com> NetBSD-regression: NetBSD Build System <jenkins@build.gluster.org> CentOS-regression: Gluster Build System <jenkins@build.gluster.org>
Diffstat (limited to 'extras')
-rw-r--r--extras/cliutils/__init__.py6
-rw-r--r--extras/cliutils/cliutils.py21
2 files changed, 23 insertions, 4 deletions
diff --git a/extras/cliutils/__init__.py b/extras/cliutils/__init__.py
index 4bb8395bb46..9c930982be0 100644
--- a/extras/cliutils/__init__.py
+++ b/extras/cliutils/__init__.py
@@ -11,7 +11,8 @@ from cliutils import (runcli,
yesno,
get_node_uuid,
Cmd,
- GlusterCmdException)
+ GlusterCmdException,
+ set_common_args_func)
# This will be useful when `from cliutils import *`
@@ -26,4 +27,5 @@ __all__ = ["runcli",
"yesno",
"get_node_uuid",
"Cmd",
- "GlusterCmdException"]
+ "GlusterCmdException",
+ "set_common_args_func"]
diff --git a/extras/cliutils/cliutils.py b/extras/cliutils/cliutils.py
index 4e035d7ff5c..d805ac6d100 100644
--- a/extras/cliutils/cliutils.py
+++ b/extras/cliutils/cliutils.py
@@ -16,6 +16,7 @@ subparsers = parser.add_subparsers(dest="mode")
subcommands = {}
cache_data = {}
ParseError = etree.ParseError if hasattr(etree, 'ParseError') else SyntaxError
+_common_args_func = lambda p: True
class GlusterCmdException(Exception):
@@ -50,9 +51,9 @@ def oknotok(flag):
return "OK" if flag else "NOT OK"
-def output_error(message):
+def output_error(message, errcode=1):
print (message, file=sys.stderr)
- sys.exit(1)
+ sys.exit(errcode)
def node_output_ok(message=""):
@@ -186,6 +187,7 @@ def runcli():
# a subcommand as specified in the Class name. Call the args
# method by passing subcommand parser, Derived class can add
# arguments to the subcommand parser.
+ metavar_data = []
for c in Cmd.__subclasses__():
cls = c()
if getattr(cls, "name", "") == "":
@@ -193,14 +195,24 @@ def runcli():
"to \"{0}\"".format(
cls.__class__.__name__))
+ # Do not show in help message if subcommand starts with node-
+ if not cls.name.startswith("node-"):
+ metavar_data.append(cls.name)
+
p = subparsers.add_parser(cls.name)
args_func = getattr(cls, "args", None)
if args_func is not None:
args_func(p)
+ # Apply common args if any
+ _common_args_func(p)
+
# A dict to save subcommands, key is name of the subcommand
subcommands[cls.name] = cls
+ # Hide node commands in Help message
+ subparsers.metavar = "{" + ",".join(metavar_data) + "}"
+
# Get all parsed arguments
args = parser.parse_args()
@@ -210,3 +222,8 @@ def runcli():
# Run
if cls is not None:
cls.run(args)
+
+
+def set_common_args_func(func):
+ global _common_args_func
+ _common_args_func = func