summaryrefslogtreecommitdiffstats
path: root/geo-replication
diff options
context:
space:
mode:
authorAravinda VK <avishwan@redhat.com>2017-11-23 15:28:07 +0530
committerAravinda VK <avishwan@redhat.com>2017-11-24 13:59:24 +0000
commitd395387f601c9fb57a5fd9f19385b4de3c870de8 (patch)
tree522bc9fc7bdecddb90ce84deab5103745ca2b7b4 /geo-replication
parentcd27e0ffb8afd69c1df28c38808c49a3af8cc75d (diff)
geo-rep: JSON output for status and config
For Glusterd2 integration, JSON output of status and config is very useful from gsyncd Fixes: #361 Change-Id: I53c61f19033ad4ac601ea49469e4e7c7c8e9af3d Signed-off-by: Aravinda VK <avishwan@redhat.com>
Diffstat (limited to 'geo-replication')
-rw-r--r--geo-replication/syncdaemon/gsyncd.py2
-rw-r--r--geo-replication/syncdaemon/gsyncdconfig.py2
-rw-r--r--geo-replication/syncdaemon/gsyncdstatus.py13
-rw-r--r--geo-replication/syncdaemon/subcmds.py13
4 files changed, 26 insertions, 4 deletions
diff --git a/geo-replication/syncdaemon/gsyncd.py b/geo-replication/syncdaemon/gsyncd.py
index fbab5cbf386..f58b532bcda 100644
--- a/geo-replication/syncdaemon/gsyncd.py
+++ b/geo-replication/syncdaemon/gsyncd.py
@@ -129,6 +129,7 @@ def main():
p.add_argument("-c", "--config-file", help="Config File")
p.add_argument("--local-path", help="Local Brick Path")
p.add_argument("--debug", action="store_true")
+ p.add_argument("--json", action="store_true")
# Config-check
p = sp.add_parser("config-check")
@@ -146,6 +147,7 @@ def main():
p.add_argument("--show-defaults", action="store_true")
p.add_argument("--only-value", action="store_true")
p.add_argument("--use-underscore", action="store_true")
+ p.add_argument("--json", action="store_true")
# Config-set
p = sp.add_parser("config-set")
diff --git a/geo-replication/syncdaemon/gsyncdconfig.py b/geo-replication/syncdaemon/gsyncdconfig.py
index 5aa354b8e6a..a5843801671 100644
--- a/geo-replication/syncdaemon/gsyncdconfig.py
+++ b/geo-replication/syncdaemon/gsyncdconfig.py
@@ -329,7 +329,7 @@ def to_float(value):
def to_bool(value):
- return True if value == "true" else False
+ return True if value in ["true", "True"] else False
def get(name, default_value=None):
diff --git a/geo-replication/syncdaemon/gsyncdstatus.py b/geo-replication/syncdaemon/gsyncdstatus.py
index 38ca92c73a9..1df24330438 100644
--- a/geo-replication/syncdaemon/gsyncdstatus.py
+++ b/geo-replication/syncdaemon/gsyncdstatus.py
@@ -399,6 +399,15 @@ class GeorepStatus(object):
return data
- def print_status(self, checkpoint_time=0):
- for key, value in self.get_status(checkpoint_time).items():
+ def print_status(self, checkpoint_time=0, json_output=False):
+ status_out = self.get_status(checkpoint_time)
+ if json_output:
+ out = {}
+ # Convert all values as string
+ for k, v in status_out.items():
+ out[k] = str(v)
+ print json.dumps(out)
+ return
+
+ for key, value in status_out.items():
print ("%s: %s" % (key, value))
diff --git a/geo-replication/syncdaemon/subcmds.py b/geo-replication/syncdaemon/subcmds.py
index 8ce5f219b6a..691c84401c5 100644
--- a/geo-replication/syncdaemon/subcmds.py
+++ b/geo-replication/syncdaemon/subcmds.py
@@ -32,7 +32,8 @@ def subcmd_status(args):
slave_data,
gconf.get("pid-file"))
checkpoint_time = gconf.get("checkpoint", 0)
- brick_status.print_status(checkpoint_time=checkpoint_time)
+ brick_status.print_status(checkpoint_time=checkpoint_time,
+ json_output=args.json)
def subcmd_monitor(args):
@@ -232,6 +233,7 @@ def config_name_format(val):
def subcmd_config_get(args):
import sys
+ import json
all_config = gconf.getall(show_defaults=args.show_defaults,
show_non_configurable=True)
@@ -245,6 +247,15 @@ def subcmd_config_get(args):
use_underscore=args.use_underscore)
return
+ if args.json:
+ out = {}
+ # Convert all values as string
+ for k, v in all_config.items():
+ out[k] = str(v)
+
+ print(json.dumps(out))
+ return
+
for k in sorted(all_config):
print_config(k, all_config[k], use_underscore=args.use_underscore)