From a68deebec81b6bf00a515cfedea161a2e006a634 Mon Sep 17 00:00:00 2001 From: Jarrod Johnson Date: Wed, 19 Feb 2014 20:36:39 -0500 Subject: [PATCH] Improve the get_nodegroup_attribute to be more full featured Also, move masking of the _expressionkeys attribute into the core of the class rather than working around it. --- confluent/config/configmanager.py | 19 ++++++++++++++++++- plugins/configuration/attributes.py | 11 ++++------- 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/confluent/config/configmanager.py b/confluent/config/configmanager.py index d9ab964d..fc6b357d 100644 --- a/confluent/config/configmanager.py +++ b/confluent/config/configmanager.py @@ -423,7 +423,18 @@ class ConfigManager(object): return self._cfgstore['nodes'].iterkeys() def get_nodegroup_attributes(self, nodegroup, attributes=[]): - return self._cfgstore['groups'][nodegroup] + cfgnodeobj = self._cfgstore['groups'][nodegroup] + if len(attributes) == 0: + attributes = cfgnodeobj.iterkeys() + nodeobj = {} + for attribute in attributes: + if attribute.startswith('_'): + continue + if attribute not in cfgnodeobj: + continue + nodeobj[attribute] = _decode_attribute(attribute, cfgnodeobj, + decrypt=self.decrypt) + return nodeobj def get_node_attributes(self, nodelist, attributes=[]): if 'nodes' not in self._cfgstore: @@ -439,8 +450,14 @@ class ConfigManager(object): if len(attributes) == 0: attributes = cfgnodeobj.iterkeys() for attribute in attributes: + if attribute.startswith('_'): + # skip private things + continue if attribute not in cfgnodeobj: continue + # since the formatter is not passed in, the calculator is + # skipped. The decryption, however, we want to do only on + # demand nodeobj[attribute] = _decode_attribute(attribute, cfgnodeobj, decrypt=self.decrypt) retdict[node] = nodeobj diff --git a/plugins/configuration/attributes.py b/plugins/configuration/attributes.py index 1f558044..fa30c462 100644 --- a/plugins/configuration/attributes.py +++ b/plugins/configuration/attributes.py @@ -36,8 +36,6 @@ def retrieve_nodegroup(nodegroup, element, configmanager, inputdata): desc=allattributes.node[attribute]['description']) if element == 'current': for attribute in sorted(grpcfg.iterkeys()): - if attribute.startswith("_"): - continue currattr = grpcfg[attribute] desc="" if attribute == 'nodes': @@ -51,6 +49,10 @@ def retrieve_nodegroup(nodegroup, element, configmanager, inputdata): yield msg.Attributes( kv={attribute: currattr['value']}, desc=desc) + elif 'expression' in currattr: + yield msg.Attributes( + kv={attribute: currattr['expression']}, + desc=desc) elif 'cryptvalue' in currattr: yield msg.CryptedAttributes( kv={attribute: currattr}, @@ -74,9 +76,6 @@ def retrieve_nodes(nodes, element, configmanager, inputdata): if element[-1] == 'all': for node in nodes: for attribute in sorted(allattributes.node.iterkeys()): - if attribute.startswith("_"): - # a 'private' attribute - continue if attribute in attributes[node]: #have a setting for it val = attributes[node][attribute] elif attribute == 'groups': # no setting, provide a blank @@ -98,8 +97,6 @@ def retrieve_nodes(nodes, element, configmanager, inputdata): elif element[-1] == 'current': for node in attributes.iterkeys(): for attribute in sorted(attributes[node].iterkeys()): - if attribute.startswith("_"): - continue currattr = attributes[node][attribute] try: desc = allattributes.node[attribute]['description']