diff --git a/confluent/httpapi.py b/confluent/httpapi.py index d5a7741d..9dfd4943 100644 --- a/confluent/httpapi.py +++ b/confluent/httpapi.py @@ -200,8 +200,15 @@ def resourcehandler(env, start_response): yield "404 - Request path not recognized" return start_response('200 OK', headers) + yield '[' + docomma = False for rsp in hdlr: + if docomma: + yield ',' + else: + docomma = True yield rsp.json() + yield ']' def serve(): diff --git a/confluent/messages.py b/confluent/messages.py index cacda353..e8923f5f 100644 --- a/confluent/messages.py +++ b/confluent/messages.py @@ -31,4 +31,17 @@ class PowerState(ConfluentMessage): } } +class Attributes(ConfluentMessage): + def __init__(self, node, kv): + self.kvpairs = { + node: kv + } +class CryptedAttributes(Attributes): + def __init__(self, node, kv): + # for now, just keep the dictionary keys and discard crypt value + for currkey in kv.iterkeys(): + kv[currkey] = '*****ENCRYPTEDVALUE*****' + self.kvpairs = { + node: kv + } diff --git a/confluent/pluginapi.py b/confluent/pluginapi.py index 8e11da54..d55a8408 100644 --- a/confluent/pluginapi.py +++ b/confluent/pluginapi.py @@ -54,6 +54,8 @@ nodetree = { '/power/': ['state'], '/boot/': ['device'], '/console/': ['session', 'logging'], + '/attributes/all': [], # TODO: put in the 'categories' automaticly from + # confluent.config.attributes } # _ elements are for internal use (e.g. special console scheme) @@ -71,7 +73,10 @@ nodeelements = { 'boot/device': { 'pluginattrs': ['hardwaremanagement.method'], 'default': 'ipmi', - } + }, + 'attributes/all': { + 'handler': 'attributes', + }, } def stripnode(iterablersp, node): @@ -93,9 +98,13 @@ def handle_path(path, operation, configmanager): node = path[nodeidx:] node, _, element = node.partition("/") if element not in nodeelements: - raise Exception("Invalid element requested") + raise exc.NotFoundException("Invalid element requested") plugroute = nodeelements[element] - if 'pluginattrs' in plugroute: + if 'handler' in plugroute: #fixed handler definition + passvalue = pluginmap[plugroute['handler']].__dict__[operation]( + nodes=(node,), element=element, + configmanager=configmanager) + elif 'pluginattrs' in plugroute: nodeattr = configmanager.get_node_attributes( [node], plugroute['pluginattrs']) for attrname in plugroute['pluginattrs']: diff --git a/plugins/configuration/attributes.py b/plugins/configuration/attributes.py new file mode 100644 index 00000000..c6411e7a --- /dev/null +++ b/plugins/configuration/attributes.py @@ -0,0 +1,18 @@ +import confluent.messages as msg + +def retrieve(nodes, element, configmanager): + 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") + +