From 8ef90a457a3725d06ce226b7a1448786c5558fd9 Mon Sep 17 00:00:00 2001 From: Jarrod Johnson Date: Tue, 6 Feb 2018 16:31:20 -0500 Subject: [PATCH] Add comparedefault to nodeconfig command This allows gathering relevant settings that differ from default --- confluent_client/bin/nodeconfig | 8 +++++++- confluent_client/confluent/client.py | 26 +++++++++++++++++++++----- 2 files changed, 28 insertions(+), 6 deletions(-) diff --git a/confluent_client/bin/nodeconfig b/confluent_client/bin/nodeconfig index d6a00f34..d23613fb 100755 --- a/confluent_client/bin/nodeconfig +++ b/confluent_client/bin/nodeconfig @@ -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) \ No newline at end of file diff --git a/confluent_client/confluent/client.py b/confluent_client/confluent/client.py index bfe62756..a61543ad 100644 --- a/confluent_client/confluent/client.py +++ b/confluent_client/confluent/client.py @@ -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: