mirror of
https://github.com/xcat2/confluent.git
synced 2025-06-15 19:01:45 +00:00
Add attribute retrieval facility
This commit is contained in:
@ -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():
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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']:
|
||||
|
18
plugins/configuration/attributes.py
Normal file
18
plugins/configuration/attributes.py
Normal file
@ -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")
|
||||
|
||||
|
Reference in New Issue
Block a user