geo-rep: Detailed JSON output for config
JSON output of `config-get` command now returns in the following format { "name": CONFIG_NAME, "value": CONFIG_VALUE, "default_value": DEFAULT_VALUE, # Only if modified == true "configurable": true|false, "modified": true|false } Change-Id: I6193de48cd33655df7ecef5a0d83d7cb147089cf Fixes: #361 Signed-off-by: Aravinda VK <avishwan@redhat.com>
This commit is contained in:
parent
c3647b747a
commit
5d3c90d148
@ -16,10 +16,12 @@ configurable=false
|
||||
[master-replica-count]
|
||||
configurable=false
|
||||
type=int
|
||||
value=1
|
||||
|
||||
[master-disperse_count]
|
||||
[master-disperse-count]
|
||||
configurable=false
|
||||
type=int
|
||||
value=1
|
||||
|
||||
[glusterd-workdir]
|
||||
value = @GLUSTERD_WORKDIR@
|
||||
|
@ -36,6 +36,8 @@ class Gconf(object):
|
||||
self.args = args
|
||||
self.extra_tmpl_args = extra_tmpl_args
|
||||
self.override_from_args = override_from_args
|
||||
# Store default values only if overwriten, Only for JSON/CLI output
|
||||
self.default_values = {}
|
||||
self._load()
|
||||
|
||||
def _tmpl_substitute(self):
|
||||
@ -63,6 +65,8 @@ class Gconf(object):
|
||||
"to_" + self.gconf_typecast.get(k, "string"), None)
|
||||
if cast_func is not None:
|
||||
self.gconf[k] = cast_func(v)
|
||||
if self.default_values.get(k, None) is not None:
|
||||
self.default_values[k] = cast_func(v)
|
||||
|
||||
def reset(self, name):
|
||||
# If custom conf file is not set then it is only read only configs
|
||||
@ -150,6 +154,7 @@ class Gconf(object):
|
||||
self.gconf_typecast = {}
|
||||
self.non_configurable_configs = []
|
||||
self.session_conf_items = []
|
||||
self.default_values = {}
|
||||
|
||||
conf = ConfigParser()
|
||||
# Default Template config file
|
||||
@ -196,6 +201,7 @@ class Gconf(object):
|
||||
if conf.has_section("vars"):
|
||||
for k, v in conf.items("vars"):
|
||||
self.session_conf_items.append(k)
|
||||
self.default_values[k] = self.gconf.get(k, "")
|
||||
self.gconf[k] = v.strip()
|
||||
|
||||
# Overwrite the Slave configurations which are sent as
|
||||
@ -221,17 +227,36 @@ class Gconf(object):
|
||||
if not show_defaults:
|
||||
for k in self.session_conf_items:
|
||||
if k not in self.non_configurable_configs:
|
||||
cnf[k] = self.get(k)
|
||||
|
||||
dv = self.default_values.get(k, "")
|
||||
cnf[k] = {
|
||||
"value": self.get(k),
|
||||
"default": dv,
|
||||
"configurable": True,
|
||||
"modified": False if dv == "" else True
|
||||
}
|
||||
return cnf
|
||||
|
||||
# Show all configs including defaults
|
||||
for k, v in self.gconf.items():
|
||||
configurable = False if k in self.non_configurable_configs \
|
||||
else True
|
||||
dv = self.default_values.get(k, "")
|
||||
modified = False if dv == "" else True
|
||||
if show_non_configurable:
|
||||
cnf[k] = v
|
||||
cnf[k] = {
|
||||
"value": v,
|
||||
"default": dv,
|
||||
"configurable": configurable,
|
||||
"modified": modified
|
||||
}
|
||||
else:
|
||||
if k not in self.non_configurable_configs:
|
||||
cnf[k] = v
|
||||
cnf[k] = {
|
||||
"value": v,
|
||||
"default": dv,
|
||||
"configurable": configurable,
|
||||
"modified": modified
|
||||
}
|
||||
|
||||
return cnf
|
||||
|
||||
|
@ -243,21 +243,29 @@ def subcmd_config_get(args):
|
||||
sys.stderr.write("Invalid config name \"%s\"\n" % args.name)
|
||||
sys.exit(ERROR_CONFIG_INVALID)
|
||||
|
||||
print_config(args.name, val, only_value=args.only_value,
|
||||
print_config(args.name, val["value"], only_value=args.only_value,
|
||||
use_underscore=args.use_underscore)
|
||||
return
|
||||
|
||||
if args.json:
|
||||
out = {}
|
||||
out = []
|
||||
# Convert all values as string
|
||||
for k, v in all_config.items():
|
||||
out[k] = str(v)
|
||||
for k in sorted(all_config):
|
||||
v = all_config[k]
|
||||
out.append({
|
||||
"name": k,
|
||||
"value": str(v["value"]),
|
||||
"default": str(v["default"]),
|
||||
"configurable": v["configurable"],
|
||||
"modified": v["modified"]
|
||||
})
|
||||
|
||||
print(json.dumps(out))
|
||||
return
|
||||
|
||||
for k in sorted(all_config):
|
||||
print_config(k, all_config[k], use_underscore=args.use_underscore)
|
||||
print_config(k, all_config[k]["value"],
|
||||
use_underscore=args.use_underscore)
|
||||
|
||||
|
||||
def subcmd_config_check(args):
|
||||
|
Loading…
x
Reference in New Issue
Block a user