2013-11-02 22:24:04 +00:00
|
|
|
import confluent.messages as msg
|
2013-11-03 15:36:03 +00:00
|
|
|
import confluent.config.attributes as allattributes
|
2013-11-02 22:24:04 +00:00
|
|
|
|
2013-11-02 23:45:10 +00:00
|
|
|
def retrieve(nodes, element, configmanager, inputdata):
|
2013-11-02 22:24:04 +00:00
|
|
|
attributes = configmanager.get_node_attributes(nodes)
|
2013-11-07 19:39:34 +00:00
|
|
|
if element[-1] == 'all':
|
2013-11-03 15:36:03 +00:00
|
|
|
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]
|
2013-11-13 20:12:57 +00:00
|
|
|
elif attribute == 'groups': # no setting, provide a blank
|
|
|
|
val = []
|
2013-11-03 15:36:03 +00:00
|
|
|
else: # no setting, provide a blank
|
|
|
|
val = {'value': '', 'cryptvalue': ''}
|
|
|
|
if attribute.startswith('secret.'):
|
|
|
|
yield msg.CryptedAttributes(node,
|
|
|
|
{attribute: val})
|
2013-11-13 20:12:57 +00:00
|
|
|
elif isinstance(val, list):
|
|
|
|
yield msg.ListAttributes(node,
|
|
|
|
{attribute: val})
|
2013-11-03 15:36:03 +00:00
|
|
|
else:
|
|
|
|
yield msg.Attributes(node,
|
|
|
|
{attribute: val['value']})
|
2013-11-07 19:39:34 +00:00
|
|
|
elif element[-1] == 'current':
|
2013-11-03 15:36:03 +00:00
|
|
|
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']})
|
2013-11-13 15:36:43 +00:00
|
|
|
elif isinstance(currattr, list):
|
|
|
|
yield msg.ListAttributes(node,
|
|
|
|
{attribute: currattr})
|
2013-11-03 15:36:03 +00:00
|
|
|
else:
|
|
|
|
print repr(currattr)
|
|
|
|
raise Exception("BUGGY ATTRIBUTE FOR NODE")
|
2013-11-03 15:21:54 +00:00
|
|
|
|
|
|
|
|
|
|
|
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)
|
2013-11-13 19:52:32 +00:00
|
|
|
return retrieve(nodes, element, configmanager, inputdata)
|