2
0
mirror of https://github.com/xcat2/confluent.git synced 2024-11-22 09:32:21 +00:00

Add comparedefault to nodeconfig command

This allows gathering relevant settings that differ from default
This commit is contained in:
Jarrod Johnson 2018-02-06 16:31:20 -05:00
parent bd5d8c85d8
commit 8ef90a457a
2 changed files with 28 additions and 6 deletions

View File

@ -43,6 +43,10 @@ def bailout(msg, code=1):
argparser = optparse.OptionParser()
argparser.add_option('-c', '--comparedefault', dest='comparedefault',
action='store_true', default=False,
help='Compare given settings to default or list settings '
'that are non default')
(options, args) = argparser.parse_args()
cfgpaths = {
@ -154,6 +158,8 @@ if setmode:
print('{0}: {1}: {2}'.format(node, key, val))
else:
for path in queryparms:
if options.comparedefault:
continue
client.print_attrib_path(path, session, list(queryparms[path]),
NullOpt(), queryparms[path])
if printsys:
@ -161,5 +167,5 @@ else:
printsys = []
path = '/noderange/{0}/configuration/system/all'.format(noderange)
client.print_attrib_path(path, session, printsys,
NullOpt())
options)
sys.exit(rcode)

View File

@ -315,8 +315,8 @@ def print_attrib_path(path, session, requestargs, options, rename=None):
for node in sorted(res['databynode']):
for attr in sorted(res['databynode'][node]):
seenattributes.add(attr)
if rename and attr in rename:
printattr = rename[attr]
if rename:
printattr = rename.get(attr, attr)
else:
printattr = attr
currattr = res['databynode'][node][attr]
@ -347,8 +347,11 @@ def print_attrib_path(path, session, requestargs, options, rename=None):
attrout = '{0}: {1}: {2}'.format(node, printattr, ','.join(map(str, dictout)))
else:
cprint("CODE ERROR" + repr(attr))
if options.blame or 'broken' in currattr:
try:
blame = options.blame
except AttributeError:
blame = False
if blame or 'broken' in currattr:
blamedata = []
if 'inheritedfrom' in currattr:
blamedata.append('inherited from group {0}'.format(
@ -360,7 +363,20 @@ def print_attrib_path(path, session, requestargs, options, rename=None):
currattr['expression']))
if blamedata:
attrout += ' (' + ', '.join(blamedata) + ')'
cprint(attrout)
try:
comparedefault = options.comparedefault
except AttributeError:
comparedefault = False
if comparedefault:
if (requestargs or
(currattr.get('default', None) is not None and
currattr.get('value', None) is not None and
currattr['value'] != currattr['default'])):
cprint('{0}: {1}: {2} (Default: {3})'.format(
node, printattr, currattr['value'],
currattr['default']))
else:
cprint(attrout)
if not exitcode:
if requestargs:
for attr in requestargs: