summaryrefslogtreecommitdiffstats
ModeNameSize
-rw-r--r--.gitignore1844logstatsplain
-rw-r--r--.mailmap2227logstatsplain
-rw-r--r--AUTHORS0logstatsplain
-rw-r--r--CONTRIBUTING1291logstatsplain
-rw-r--r--COPYING-GPLV218092logstatsplain
-rw-r--r--COPYING-LGPLV37651logstatsplain
-rw-r--r--ChangeLog38logstatsplain
-rw-r--r--INSTALL1423logstatsplain
-rw-r--r--MAINTAINERS7162logstatsplain
-rw-r--r--Makefile.am1862logstatsplain
-rw-r--r--NEWS25logstatsplain
-rw-r--r--README.md608logstatsplain
-rw-r--r--THANKS90logstatsplain
d---------api104logstatsplain
-rwxr-xr-xautogen.sh1987logstatsplain
d---------build-aux73logstatsplain
d---------cli69logstatsplain
-rw-r--r--configure.ac45191logstatsplain
d---------contrib632logstatsplain
d---------doc528logstatsplain
d---------extras2031logstatsplain
d---------geo-replication298logstatsplain
-rw-r--r--glusterfs-api.pc.in413logstatsplain
d---------glusterfs-hadoop102logstatsplain
-rw-r--r--glusterfs.spec.in58464logstatsplain
d---------glusterfsd69logstatsplain
d---------heal69logstatsplain
-rw-r--r--libgfchangelog.pc.in351logstatsplain
-rw-r--r--libgfdb.pc.in282logstatsplain
d---------libglusterfs69logstatsplain
-rwxr-xr-xrfc.sh3583logstatsplain
d---------rpc143logstatsplain
-rwxr-xr-xrun-tests.sh7878logstatsplain
d---------tests715logstatsplain
d---------tools123logstatsplain
d---------xlators508logstatsplain
_handle("reload")
+ out = action_handle("reload", args.json)
+ if args.json:
+ print (json.dumps({
+ "output": out,
+ "error": ""
+ }))
+ else:
+ print (out)
class NodeStatus(Cmd):
@@ -202,12 +279,25 @@ class StatusCmd(Cmd):
if os.path.exists(WEBHOOKS_FILE):
webhooks = json.load(open(WEBHOOKS_FILE))
- print ("Webhooks: " + ("" if webhooks else "None"))
- for w in webhooks:
- print (w)
-
- print ()
- action_handle("status")
+ json_out = {"webhooks": [], "data": []}
+ if args.json:
+ json_out["webhooks"] = webhooks.keys()
+ else:
+ print ("Webhooks: " + ("" if webhooks else "None"))
+ for w in webhooks:
+ print (w)
+
+ print ()
+
+ out = action_handle("status", args.json)
+ if args.json:
+ json_out["data"] = out
+ print (json.dumps({
+ "output": json_out,
+ "error": ""
+ }))
+ else:
+ print (out)
class WebhookAddCmd(Cmd):
@@ -219,17 +309,19 @@ class WebhookAddCmd(Cmd):
default="")
def run(self, args):
- create_webhooks_file_if_not_exists()
+ create_webhooks_file_if_not_exists(args)
with LockedOpen(WEBHOOKS_FILE, 'r+'):
data = json.load(open(WEBHOOKS_FILE))
if data.get(args.url, None) is not None:
- output_error("Webhook already exists")
+ handle_output_error("Webhook already exists",
+ errcode=ERROR_WEBHOOK_ALREADY_EXISTS,
+ json_output=args.json)
data[args.url] = args.bearer_token
file_content_overwrite(WEBHOOKS_FILE, data)
- sync_to_peers()
+ sync_to_peers(args)
class WebhookModCmd(Cmd):
@@ -241,17 +333,19 @@ class WebhookModCmd(Cmd):
default="")
def run(self, args):
- create_webhooks_file_if_not_exists()
+ create_webhooks_file_if_not_exists(args)
with LockedOpen(WEBHOOKS_FILE, 'r+'):
data = json.load(open(WEBHOOKS_FILE))
if data.get(args.url, None) is None:
- output_error("Webhook does not exists")
+ handle_output_error("Webhook does not exists",
+ errcode=ERROR_WEBHOOK_NOT_EXISTS,
+ json_output=args.json)
data[args.url] = args.bearer_token
file_content_overwrite(WEBHOOKS_FILE, data)
- sync_to_peers()
+ sync_to_peers(args)
class WebhookDelCmd(Cmd):
@@ -261,17 +355,19 @@ class WebhookDelCmd(Cmd):
parser.add_argument("url", help="URL of Webhook")
def run(self, args):
- create_webhooks_file_if_not_exists()
+ create_webhooks_file_if_not_exists(args)
with LockedOpen(WEBHOOKS_FILE, 'r+'):
data = json.load(open(WEBHOOKS_FILE))
if data.get(args.url, None) is None:
- output_error("Webhook does not exists")
+ handle_output_error("Webhook does not exists",
+ errcode=ERROR_WEBHOOK_NOT_EXISTS,
+ json_output=args.json)
del data[args.url]
file_content_overwrite(WEBHOOKS_FILE, data)
- sync_to_peers()
+ sync_to_peers(args)
class NodeWebhookTestCmd(Cmd):
@@ -314,17 +410,33 @@ class WebhookTestCmd(Cmd):
out = execute_in_peers("node-webhook-test", [url, bearer_token])
- table = PrettyTable(["NODE", "NODE STATUS", "WEBHOOK STATUS"])
- table.align["NODE STATUS"] = "r"
- table.align["WEBHOOK STATUS"] = "r"
+ if not args.json:
+ table = PrettyTable(["NODE", "NODE STATUS", "WEBHOOK STATUS"])
+ table.align["NODE STATUS"] = "r"
+ table.align["WEBHOOK STATUS"] = "r"
- for p in out:
- table.add_row([p.hostname,
- "UP" if p.node_up else "DOWN",
- "OK" if p.ok else "NOT OK: {0}".format(
- p.error)])
+ num_ok_rows = 0
+ json_out = []
+ if args.json:
+ num_ok_rows = rows_to_json(json_out, "webhook_status", out)
+ else:
+ num_ok_rows = rows_to_table(table, out)
+
+ ret = 0
+ if num_ok_rows == 0:
+ ret = ERROR_ALL_NODES_STATUS_NOT_OK
+ elif num_ok_rows != len(out):
+ ret = ERROR_PARTIAL_SUCCESS
+
+ if args.json:
+ print (json.dumps({
+ "output": json_out,
+ "error": ""
+ }))
+ else:
+ print (table)
- print (table)
+ sys.exit(ret)
class ConfigGetCmd(Cmd):
@@ -339,16 +451,30 @@ class ConfigGetCmd(Cmd):
data.update(json.load(open(CUSTOM_CONFIG_FILE)))
if args.name is not None and args.name not in CONFIG_KEYS:
- output_error("Invalid Config item")
+ handle_output_error("Invalid Config item",
+ errcode=ERROR_INVALID_CONFIG,
+ json_output=args.json)
+
+ if args.json:
+ json_out = {}
+ if args.name is None:
+ json_out = data
+ else:
+ json_out[args.name] = data[args.name]
- table = PrettyTable(["NAME", "VALUE"])
- if args.name is None:
- for k, v in data.items():
- table.add_row([k, v])
+ print (json.dumps({
+ "output": json_out,
+ "error": ""
+ }))
else:
- table.add_row([args.name, data[args.name]])
+ table = PrettyTable(["NAME", "VALUE"])
+ if args.name is None:
+ for k, v in data.items():
+ table.add_row([k, v])
+ else:
+ table.add_row([args.name, data[args.name]])
- print (table)
+ print (table)
def read_file_content_json(fname):
@@ -370,9 +496,11 @@ class ConfigSetCmd(Cmd):
def run(self, args):
if args.name not in CONFIG_KEYS:
- output_error("Invalid Config item")
+ handle_output_error("Invalid Config item",
+ errcode=ERROR_INVALID_CONFIG,
+ json_output=args.json)
- create_custom_config_file_if_not_exists()
+ create_custom_config_file_if_not_exists(args)
with LockedOpen(CUSTOM_CONFIG_FILE, 'r+'):
data = json.load(open(DEFAULT_CONFIG_FILE))
@@ -382,7 +510,9 @@ class ConfigSetCmd(Cmd):
# Do Nothing if same as previous value
if data[args.name] == args.value:
- return
+ handle_output_error("Config value not changed. Same config",
+ errcode=ERROR_SAME_CONFIG,
+ json_output=args.json)
# TODO: Validate Value
new_data = read_file_content_json(CUSTOM_CONFIG_FILE)
@@ -402,10 +532,11 @@ class ConfigSetCmd(Cmd):
if args.name in RESTART_CONFIGS:
restart = True
- sync_to_peers()
if restart:
print ("\nRestart glustereventsd in all nodes")
+ sync_to_peers(args)
+
class ConfigResetCmd(Cmd):
name = "config-reset"
@@ -414,7 +545,7 @@ class ConfigResetCmd(Cmd):
parser.add_argument("name", help="Config Name or all")
def run(self, args):
- create_custom_config_file_if_not_exists()
+ create_custom_config_file_if_not_exists(args)
with LockedOpen(CUSTOM_CONFIG_FILE, 'r+'):
changed_keys = []
@@ -422,8 +553,14 @@ class ConfigResetCmd(Cmd):
if os.path.exists(CUSTOM_CONFIG_FILE):
data = read_file_content_json(CUSTOM_CONFIG_FILE)
- if not data:
- return
+ # If No data available in custom config or, the specific config
+ # item is not available in custom config
+ if not data or \
+ (args.name != "all" and data.get(args.name, None) is None):
+ handle_output_error("Config value not reset. Already "
+ "set to default value",
+ errcode=ERROR_SAME_CONFIG,
+ json_output=args.json)
if args.name.lower() == "all":
for k, v in data.items():
@@ -443,17 +580,23 @@ class ConfigResetCmd(Cmd):
restart = True
break
- sync_to_peers()
if restart:
print ("\nRestart glustereventsd in all nodes")
+ sync_to_peers(args)
+
class SyncCmd(Cmd):
name = "sync"
def run(self, args):
- sync_to_peers()
+ sync_to_peers(args)
+
+
+def common_args(parser):
+ parser.add_argument("--json", help="JSON Output", action="store_true")
if __name__ == "__main__":
+ set_common_args_func(common_args)
runcli()