2
0
mirror of https://github.com/xcat2/confluent.git synced 2025-01-15 12:17:47 +00:00

Start rendering parts of the links required for api exploring

This commit is contained in:
Jarrod Johnson 2013-11-03 13:16:28 -05:00
parent 4ee6f2bdb3
commit 78bc2e8338
3 changed files with 39 additions and 6 deletions

View File

@ -390,6 +390,11 @@ class ConfigManager(object):
}
self._bg_sync_to_file()
def get_nodes(self):
if 'nodes' not in self._cfgstore:
return []
return self._cfgstore['nodes'].iterkeys()
def get_node_attributes(self, nodelist, attributes=[]):
if 'nodes' not in self._cfgstore:
return None

View File

@ -60,6 +60,16 @@ class ConfluentChoiceMessage(ConfluentMessage):
snippet += 'value="%s">' % (key)
return snippet
class LinkRelation(ConfluentMessage):
def html(self):
return '<a href="%s" rel="%s">%s</a>' % (self.href, self.rel, self.href)
class ChildCollection(LinkRelation):
def __init__(self, collname):
self.rel = 'item'
self.href = collname
def get_input_message(path, operation, inputdata, nodes=None):
if 'power/state' in path and operation != 'retrieve':

View File

@ -50,17 +50,18 @@ def load_plugins():
else:
pluginmap[plugin] = tmpmod
nodetree = {
'/': ['power/', 'boot/', 'console/', 'attributes/'],
nodecollections = {
'/power/': ['state'],
'/boot/': ['device'],
'/console/': ['session', 'logging'],
'/attributes/all': [], # TODO: put in the 'categories' automaticly from
# confluent.config.attributes
'/attributes/current': [], # TODO: put in the 'categories' automaticly from
'/attributes/': [], # TODO: put in the 'categories' automaticly from
# confluent.config.attributes
}
rootcollections = {
'/node/': nodecollections
}
# _ elements are for internal use (e.g. special console scheme)
nodeelements = {
'_console/session': {
@ -90,6 +91,19 @@ def stripnode(iterablersp, node):
i.strip_node(node)
yield i
def enumerate_collection(collection, configmanager):
print collection
if collection == '/node/':
print 'node col'
for node in configmanager.get_nodes():
print node
yield msg.ChildCollection(node + '/')
def enumerate_collections(collections):
for collection in collections.iterkeys():
yield msg.ChildCollection(collection)
def handle_path(path, operation, configmanager, inputdata=None):
'''Given a full path request, return an object.
@ -97,7 +111,11 @@ def handle_path(path, operation, configmanager, inputdata=None):
An exception is made for console/session, which should return
a class with connect(), read(), write(bytes), and close()
'''
if (path.startswith("/node/") or path.startswith("/system/") or
if path == '/':
return enumerate_collections(rootcollections)
elif path in rootcollections:
return enumerate_collection(path, configmanager)
elif (path.startswith("/node/") or path.startswith("/system/") or
# single node requests
path.startswith("/vm/")):
nodeidx = path.find("/",1) + 1