diff --git a/confluent/config/configmanager.py b/confluent/config/configmanager.py index 4feebcce..c09c7f6c 100644 --- a/confluent/config/configmanager.py +++ b/confluent/config/configmanager.py @@ -554,6 +554,15 @@ class ConfigManager(object): nodecfg = self._cfgstore['nodes'][node] self._do_inheritance(nodecfg, attr, group) + def del_nodes(self, nodes): + if 'nodes' not in self._cfgstore: + return + for node in nodes: + if node in self._cfgstore['nodes']: + self._sync_groups_to_node(node=node, groups=[]) + del self._cfgstore['nodes'][node] + self._bg_sync_to_file() + def set_node_attributes(self, attribmap): if 'nodes' not in self._cfgstore: self._cfgstore['nodes'] = {} diff --git a/confluent/messages.py b/confluent/messages.py index 09a22905..42acb9ea 100644 --- a/confluent/messages.py +++ b/confluent/messages.py @@ -58,6 +58,9 @@ class ConfluentMessage(object): snippet += 'value="%s">' % (key) return snippet +class DeletedResource(ConfluentMessage): + def __init__(self): + self.kvpairs = {} class ConfluentChoiceMessage(ConfluentMessage): diff --git a/confluent/pluginapi.py b/confluent/pluginapi.py index 6992dcc1..44d43626 100644 --- a/confluent/pluginapi.py +++ b/confluent/pluginapi.py @@ -107,6 +107,12 @@ def iterate_resources(fancydict): resource += '/' yield msg.ChildCollection(resource) +def delete_node_collection(collectionpath, configmanager): + if len(collectionpath) == 2: #just node + node = collectionpath[-1] + configmanager.del_nodes([node]) + yield msg.DeletedResource() + def enumerate_node_collection(collectionpath, configmanager): if collectionpath == [ 'node' ]: #it is simple '/node/', need a list of nodes return iterate_collections(configmanager.get_nodes()) @@ -146,7 +152,12 @@ def handle_path(path, operation, configmanager, inputdata=None): except IndexError: # doesn't actually have a long enough path return iterate_collections(configmanager.get_nodes()) if iscollection: - return enumerate_node_collection(pathcomponents, configmanager) + if operation == "delete": + return delete_node_collection(pathcomponents, configmanager) + elif operation == "retrieve": + return enumerate_node_collection(pathcomponents, configmanager) + else: + raise Exception("TODO here") del pathcomponents[0:2] try: plugroute = nested_lookup(noderesources, pathcomponents).routeinfo