From e01c96e534c63cce91b172d541725081c3a2e398 Mon Sep 17 00:00:00 2001 From: Jarrod Johnson Date: Thu, 13 Feb 2014 16:57:03 -0500 Subject: [PATCH] Implement nodegroup deletion Nodegroup deletion is now enabled. --- confluent/config/configmanager.py | 9 +++++++++ confluent/messages.py | 2 +- confluent/pluginapi.py | 17 +++++++++++++++-- 3 files changed, 25 insertions(+), 3 deletions(-) diff --git a/confluent/config/configmanager.py b/confluent/config/configmanager.py index 80ab0eea..c13daa8a 100644 --- a/confluent/config/configmanager.py +++ b/confluent/config/configmanager.py @@ -561,6 +561,15 @@ class ConfigManager(object): del self._cfgstore['nodes'][node] self._bg_sync_to_file() + def del_groups(self, groups): + if 'groups' not in self._cfgstore: + return + for group in groups: + if group in self._cfgstore['groups']: + self._sync_nodes_to_group(group=group, nodes=[]) + del self._cfgstore['groups'][group] + 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 d20c0e99..7952f8ae 100644 --- a/confluent/messages.py +++ b/confluent/messages.py @@ -67,7 +67,7 @@ class ConfluentMessage(object): class DeletedResource(ConfluentMessage): - def __init__(self): + def __init__(self, resource): self.kvpairs = {} diff --git a/confluent/pluginapi.py b/confluent/pluginapi.py index 1098b7ee..da412d09 100644 --- a/confluent/pluginapi.py +++ b/confluent/pluginapi.py @@ -114,11 +114,19 @@ def iterate_resources(fancydict): yield msg.ChildCollection(resource) +def delete_nodegroup_collection(collectionpath, configmanager): + if len(collectionpath) == 2: # just the nodegroup + group = collectionpath[-1] + configmanager.del_groups([group]) + yield msg.DeletedResource(group) + else: + raise Exception("Not implemented") + def delete_node_collection(collectionpath, configmanager): if len(collectionpath) == 2: # just node node = collectionpath[-1] - configmanager.del_nodes([node]) - yield msg.DeletedResource() + configmanager.del_groups([node]) + yield msg.DeletedResource(node) else: raise Exception("Not implemented") @@ -169,6 +177,11 @@ def handle_path(path, operation, configmanager, inputdata=None): group = pathcomponents[1] except IndexError: return iterate_collections(configmanager.get_groups()) + if iscollection: + if operation == "delete": + return delete_nodegroup_collection(pathcomponents, configmanager) + else: + raise Exception("TODO") elif pathcomponents[0] in ('node', 'system', 'vm'): #single node request of some sort try: