From f6ed5b5e14afc6b40cc968ebe0a7c53d84d55212 Mon Sep 17 00:00:00 2001 From: Jarrod Johnson Date: Sat, 22 Feb 2014 19:12:42 -0500 Subject: [PATCH] Have confetty interactive attribute show be more informative --- bin/confetty | 23 ++++++++++++++++++----- confluent/messages.py | 10 ++++++++++ plugins/configuration/attributes.py | 2 +- 3 files changed, 29 insertions(+), 6 deletions(-) diff --git a/bin/confetty b/bin/confetty index 6ef5f1f5..53a6a857 100755 --- a/bin/confetty +++ b/bin/confetty @@ -192,15 +192,28 @@ def do_command(command, server): print item["href"] else: # generic attributes to list for key in res.iterkeys(): + notes = [] if res[key] is None: - print "%s=" % key - elif 'value' in res[key]: - print "%s=%s" % (key, res[key]['value']) + attrstr = '%s=""' % key + elif type(res[key]) == list: + attrstr = '%s=["%s"]' % (key, '","'.join(res[key])) + elif 'value' in res[key] and res[key]['value'] is not None: + attrstr = '%s="%s"' % (key, res[key]['value']) + elif 'value' in res[key] and res[key]['value'] is None: + attrstr = '%s=""' % key else: if 'isset' in res[key] and res[key]['isset']: - print "%s=********" % key + attrstr = '%s="********"' % key else: - print "%s=" % key + attrstr = '%s=""' % key + if res[key] is not None and 'inheritedfrom' in res[key]: + notes.append('Inherited from %s' % res[key]['inheritedfrom']) + if res[key] is not None and 'expression' in res[key]: + notes.append('Derived from expression "%s"' % res[key]['expression']) + notestr = '(' + ', '.join(notes) + ')' + output = '{0:<40} {1:>39}'.format(attrstr, notestr) + print output + elif argv[0] == 'start': targpath = fullpath_target(argv[1]) currconsole = targpath diff --git a/confluent/messages.py b/confluent/messages.py index 65eccb23..b1550263 100644 --- a/confluent/messages.py +++ b/confluent/messages.py @@ -35,8 +35,13 @@ class ConfluentMessage(object): val = self.kvpairs[key] value = self.defaultvalue type = self.defaulttype + notes = [] if val is not None and 'value' in val: value = val['value'] + if 'inheritedfrom' in val: + notes.append('Inherited from %s' % val['inheritedfrom']) + if 'expression' in val: + notes.append('Derived from expression "%s"' % val['expression']) elif val is not None and 'expression' in val: value = val['expression'] if value is None: @@ -44,6 +49,8 @@ class ConfluentMessage(object): if val is not None and value == '' and 'isset' in val and val['isset'] is True: # an encrypted value, put some *** to show it is set # in the explorer + if 'inheritedfrom' in val: + notes.append('Inherited from %s' % val['inheritedfrom']) value = '********' if isinstance(val, list): snippet += key + ":" @@ -65,6 +72,8 @@ class ConfluentMessage(object): 'title="{3}">' ).format(type, key, value, self.desc) + if len(notes) > 0: + snippet += '(' + ','.join(notes) + ')' return snippet @@ -314,6 +323,7 @@ class CryptedAttributes(Attributes): try: if kv[key] is not None and kv[key]['cryptvalue'] != '': nkv[key] = {'isset': True} + nkv[key]['inheritedfrom'] = kv[key]['inheritedfrom'] except KeyError: pass if node is None: diff --git a/plugins/configuration/attributes.py b/plugins/configuration/attributes.py index ba1d4fa4..79b99dfc 100644 --- a/plugins/configuration/attributes.py +++ b/plugins/configuration/attributes.py @@ -104,7 +104,7 @@ def retrieve_nodes(nodes, element, configmanager, inputdata): desc = 'Unknown' if 'value' in currattr: yield msg.Attributes(node, - {attribute: currattr['value']}, + {attribute: currattr}, desc) elif 'cryptvalue' in currattr: yield msg.CryptedAttributes(node,