diff --git a/confluent/config/configmanager.py b/confluent/config/configmanager.py index 7abb099b..6b3f43d1 100644 --- a/confluent/config/configmanager.py +++ b/confluent/config/configmanager.py @@ -390,11 +390,18 @@ class ConfigManager(object): } self._bg_sync_to_file() + def is_node(self, node): + if 'nodes' not in self._cfgstore: + return False + if node not in self._cfgstore['nodes']: + return False + return True + 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/pluginapi.py b/confluent/pluginapi.py index 4f3fb73a..288424be 100644 --- a/confluent/pluginapi.py +++ b/confluent/pluginapi.py @@ -52,15 +52,15 @@ def load_plugins(): nodecollections = { - '/power/': ['state'], - '/boot/': ['device'], - '/console/': ['session', 'logging'], - '/attributes/': [], # TODO: put in the 'categories' automaticly from + 'power/': ['state'], + 'boot/': ['device'], + 'console/': ['session', 'logging'], + 'attributes/': [], # TODO: put in the 'categories' automaticly from # confluent.config.attributes } rootcollections = { - '/node/': nodecollections + 'node/': nodecollections } # _ elements are for internal use (e.g. special console scheme) nodeelements = { @@ -91,13 +91,27 @@ def stripnode(iterablersp, node): i.strip_node(node) yield i +def iterate_collections(iterable): + for coll in iterable: + if coll[-1] != '/': + coll = coll + '/' + yield msg.ChildCollection(coll) + 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 + '/') + if collection.startswith("/"): + collection = collection[1:] + if collection == 'node/': + return iterate_collections(configmanager.get_nodes()) + elif collection.startswith('node/'): + nodecoll = collection.replace('node/','') + print nodecoll + if '/' not in nodecoll[:-1]: # it is supposed to be a node + node = nodecoll[:-1] + if not configmanager.is_node(node): + raise exc.NotFoundException("Invalid node requested") + return iterate_collections(nodecollections.iterkeys()) + else: + raise exc.NotFoundException("Invalid path") def enumerate_collections(collections): @@ -113,7 +127,7 @@ def handle_path(path, operation, configmanager, inputdata=None): ''' if path == '/': return enumerate_collections(rootcollections) - elif path in rootcollections: + elif path[-1] == '/': return enumerate_collection(path, configmanager) elif (path.startswith("/node/") or path.startswith("/system/") or # single node requests