From 659f85eaa0ca31f32637bdb1a89454c1c3d35dac Mon Sep 17 00:00:00 2001 From: Jarrod Johnson Date: Sun, 3 Nov 2013 10:36:03 -0500 Subject: [PATCH] Add support for showing all as well as current attributes --- confluent/config/attributes.py | 2 +- confluent/pluginapi.py | 5 ++++ plugins/configuration/attributes.py | 39 ++++++++++++++++++++--------- 3 files changed, 33 insertions(+), 13 deletions(-) diff --git a/confluent/config/attributes.py b/confluent/config/attributes.py index 07e7686f..baece07e 100644 --- a/confluent/config/attributes.py +++ b/confluent/config/attributes.py @@ -131,7 +131,7 @@ node = { 'The managed node.') }, 'virtualization.host': { - 'description': ('Hypervisor where this node does/should reside', + 'description': ('Hypervisor where this node does/should reside'), 'appliesto': ['vm'], }, 'virtualization.computepool': { diff --git a/confluent/pluginapi.py b/confluent/pluginapi.py index bdf642f1..526ebad9 100644 --- a/confluent/pluginapi.py +++ b/confluent/pluginapi.py @@ -57,6 +57,8 @@ nodetree = { '/console/': ['session', 'logging'], '/attributes/all': [], # TODO: put in the 'categories' automaticly from # confluent.config.attributes + '/attributes/current': [], # TODO: put in the 'categories' automaticly from + # confluent.config.attributes } # _ elements are for internal use (e.g. special console scheme) @@ -78,6 +80,9 @@ nodeelements = { 'attributes/all': { 'handler': 'attributes', }, + 'attributes/current': { + 'handler': 'attributes', + }, } def stripnode(iterablersp, node): diff --git a/plugins/configuration/attributes.py b/plugins/configuration/attributes.py index ca036f17..05ba5eb3 100644 --- a/plugins/configuration/attributes.py +++ b/plugins/configuration/attributes.py @@ -1,19 +1,34 @@ import confluent.messages as msg +import confluent.config.attributes as allattributes def retrieve(nodes, element, configmanager, inputdata): attributes = configmanager.get_node_attributes(nodes) - for node in attributes.iterkeys(): - for attribute in attributes[node].iterkeys(): - currattr = attributes[node][attribute] - if 'value' in currattr: - yield msg.Attributes(node, - {attribute: currattr['value']}) - elif 'cryptvalue' in currattr: - yield msg.CryptedAttributes(node, - {attribute: currattr['cryptvalue']}) - else: - print repr(currattr) - raise Exception("BUGGY ATTRIBUTE FOR NODE") + if element.endswith('/all'): + for node in nodes: + for attribute in sorted(allattributes.node.iterkeys()): + if attribute in attributes[node]: #have a setting for it + val = attributes[node][attribute] + else: # no setting, provide a blank + val = {'value': '', 'cryptvalue': ''} + if attribute.startswith('secret.'): + yield msg.CryptedAttributes(node, + {attribute: val}) + else: + yield msg.Attributes(node, + {attribute: val['value']}) + elif element.endswith('/current'): + for node in attributes.iterkeys(): + for attribute in sorted(attributes[node].iterkeys()): + currattr = attributes[node][attribute] + if 'value' in currattr: + yield msg.Attributes(node, + {attribute: currattr['value']}) + elif 'cryptvalue' in currattr: + yield msg.CryptedAttributes(node, + {attribute: currattr['cryptvalue']}) + else: + print repr(currattr) + raise Exception("BUGGY ATTRIBUTE FOR NODE") def update(nodes, element, configmanager, inputdata):