2
0
mirror of https://github.com/xcat2/confluent.git synced 2024-11-22 17:43:14 +00:00
confluent/plugins/configuration/attributes.py
Jarrod Johnson 0d425f1f9f Add cli support for 'show'
confetty interactive mode can now do 'show' (aka read, retrieve, whatever) on
more abritrary resources.
2014-02-10 19:36:18 -05:00

50 lines
2.1 KiB
Python

import confluent.messages as msg
import confluent.config.attributes as allattributes
def retrieve(nodes, element, configmanager, inputdata):
attributes = configmanager.get_node_attributes(nodes)
if element[-1] == '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]
elif attribute == 'groups': # no setting, provide a blank
val = []
else: # no setting, provide a blank
val = {'value': '', 'cryptvalue': ''}
if attribute.startswith('secret.'):
yield msg.CryptedAttributes(node,
{attribute: val})
elif isinstance(val, list):
yield msg.ListAttributes(node,
{attribute: val})
else:
yield msg.Attributes(node,
{attribute: val['value']})
elif element[-1] == '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})
elif isinstance(currattr, list):
yield msg.ListAttributes(node,
{attribute: currattr})
else:
print repr(currattr)
raise Exception("BUGGY ATTRIBUTE FOR NODE")
def update(nodes, element, configmanager, inputdata):
updatedict = {}
for node in nodes:
updatenode = inputdata.get_attributes(node)
if updatenode:
updatedict[node] = updatenode
configmanager.set_node_attributes(updatedict)
return retrieve(nodes, element, configmanager, inputdata)