From 78bc2e833801df18211c45068a51db8b04475eee Mon Sep 17 00:00:00 2001 From: Jarrod Johnson Date: Sun, 3 Nov 2013 13:16:28 -0500 Subject: [PATCH] Start rendering parts of the links required for api exploring --- confluent/config/configmanager.py | 5 +++++ confluent/messages.py | 10 ++++++++++ confluent/pluginapi.py | 30 ++++++++++++++++++++++++------ 3 files changed, 39 insertions(+), 6 deletions(-) diff --git a/confluent/config/configmanager.py b/confluent/config/configmanager.py index a62609d3..7abb099b 100644 --- a/confluent/config/configmanager.py +++ b/confluent/config/configmanager.py @@ -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 diff --git a/confluent/messages.py b/confluent/messages.py index 608451a8..97f24ab6 100644 --- a/confluent/messages.py +++ b/confluent/messages.py @@ -60,6 +60,16 @@ class ConfluentChoiceMessage(ConfluentMessage): snippet += 'value="%s">' % (key) return snippet +class LinkRelation(ConfluentMessage): + def html(self): + return '%s' % (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': diff --git a/confluent/pluginapi.py b/confluent/pluginapi.py index 526ebad9..4f3fb73a 100644 --- a/confluent/pluginapi.py +++ b/confluent/pluginapi.py @@ -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