diff --git a/confluent_client/bin/nodeconfig b/confluent_client/bin/nodeconfig index 29b085a0..01bdd278 100755 --- a/confluent_client/bin/nodeconfig +++ b/confluent_client/bin/nodeconfig @@ -51,6 +51,10 @@ argparser.add_option('-d', '--detail', dest='detail', action='store_true', default=False, help='Provide verbose information as available, such as ' 'help text and possible valid values') +argparser.add_option('-x', '--exclude', dest='exclude', + action='store_true', default=False, + help='Treat positional arguments as items to not ' + 'examine, compare, or restore default') (options, args) = argparser.parse_args() cfgpaths = { @@ -81,8 +85,9 @@ queryparms = {} printsys = [] setsys = {} -if len(args) == 1: - printsys = 'all' +if len(args) == 1 or options.exclude: + if not options.exclude: + printsys = 'all' for candidate in cfgpaths: path, attrib = cfgpaths[candidate] path = '/noderange/{0}/{1}'.format(noderange, path) @@ -111,11 +116,17 @@ for param in args[1:]: for candidate in cfgpaths: if candidate.startswith('{0}.'.format(param)): matchedparms = True - path, attrib = cfgpaths[candidate] - path = '/noderange/{0}/{1}'.format(noderange, path) - if path not in queryparms: - queryparms[path] = {} - queryparms[path][attrib] = candidate + if not options.exclude: + path, attrib = cfgpaths[candidate] + path = '/noderange/{0}/{1}'.format(noderange, path) + if path not in queryparms: + queryparms[path] = {} + queryparms[path][attrib] = candidate + else: + try: + del queryparms[path] + except KeyError: + pass if not matchedparms: printsys.append(param) elif param not in cfgpaths: @@ -129,6 +140,9 @@ for param in args[1:]: session = client.Command() rcode = 0 if setmode: + if options.exclude: + sys.stderr.write('Cannot use exclude and assign at the same time\n') + sys.exit(1) updatebypath = {} attrnamebypath = {} for key in assignment: @@ -166,7 +180,7 @@ else: continue client.print_attrib_path(path, session, list(queryparms[path]), NullOpt(), queryparms[path]) - if printsys: + if printsys or options.exclude: if printsys == 'all': printsys = [] path = '/noderange/{0}/configuration/system/all'.format(noderange) diff --git a/confluent_client/confluent/client.py b/confluent_client/confluent/client.py index f4a23992..4b2803d8 100644 --- a/confluent_client/confluent/client.py +++ b/confluent_client/confluent/client.py @@ -313,19 +313,23 @@ def print_attrib_path(path, session, requestargs, options, rename=None): exitcode = 1 continue for node in sorted(res['databynode']): - for attr in sorted(res['databynode'][node]): + for attr, val in sorted( + res['databynode'][node].items(), + key=lambda (k, v): v.get('sortid', k) if v else k): seenattributes.add(attr) if rename: printattr = rename.get(attr, attr) else: printattr = attr currattr = res['databynode'][node][attr] - if (requestargs is None or requestargs == [] or attrrequested( - attr, requestargs, seenattributes)): + if show_attr(attr, requestargs, seenattributes, options): if 'value' in currattr: if currattr['value'] is not None: + val = currattr['value'] + if isinstance(val, list): + val = ','.join(val) attrout = '{0}: {1}: {2}'.format( - node, printattr, currattr['value']) + node, printattr, val) else: attrout = '{0}: {1}:'.format(node, printattr) elif 'isset' in currattr: @@ -368,7 +372,11 @@ def print_attrib_path(path, session, requestargs, options, rename=None): except AttributeError: comparedefault = False if comparedefault: - if (requestargs or + try: + exclude = options.exclude + except AttributeError: + exclude = False + if ((requestargs and not exclude) or (currattr.get('default', None) is not None and currattr.get('value', None) is not None and currattr['value'] != currattr['default'])): @@ -398,6 +406,19 @@ def print_attrib_path(path, session, requestargs, options, rename=None): return exitcode +def show_attr(attr, requestargs, seenattributes, options): + try: + reverse = options.exclude + except AttributeError: + reverse = False + if requestargs is None or requestargs == []: + return True + processattr = attrrequested(attr, requestargs, seenattributes) + if reverse: + processattr = not processattr + return processattr + + def printgroupattributes(session, requestargs, showtype, nodetype, noderange, options): exitcode = 0 seenattributes = set([])