diff --git a/confluent/config/configmanager.py b/confluent/config/configmanager.py index c13daa8a..2a780637 100644 --- a/confluent/config/configmanager.py +++ b/confluent/config/configmanager.py @@ -522,7 +522,7 @@ class ConfigManager(object): elif 'groups' not in self._cfgstore['nodes'][node]: self._cfgstore['nodes'][node]['groups'] = [group] elif group not in self._cfgstore['nodes'][node]['groups']: - self._cfgstore['nodes'][node]['groups'].append(group) + self._cfgstore['nodes'][node]['groups'].insert(0, group) else: continue # next node, this node already in self._node_added_to_group(node, group) @@ -536,7 +536,11 @@ class ConfigManager(object): cfgobj = self._cfgstore['groups'][group] for attr in attribmap[group].iterkeys(): newdict = {} - if (isinstance(attribmap[group][attr], str)): + if attr == 'nodes': + if not isinstance(attribmap[group][attr], list): + raise ValueError + newdict = set(attribmap[group][attr]) + elif (isinstance(attribmap[group][attr], str)): newdict = { 'value': attribmap[group][attr] } else: newdict = attribmap[group][attr] diff --git a/confluent/httpapi.py b/confluent/httpapi.py index 72a216dd..18b767ae 100644 --- a/confluent/httpapi.py +++ b/confluent/httpapi.py @@ -31,6 +31,28 @@ opmap = { } +def group_creation_resources(): + yield confluent.messages.Attributes( + kv={'name': None}, desc="Name of the group").html() + '
' + yield confluent.messages.ListAttributes(kv={'nodes': []}, + desc='Nodes to add to the group').html() + '
\n' + for attr in sorted(attribs.node.iterkeys()): + if attr == 'groups': + continue + if attr.startswith("secret."): + yield confluent.messages.CryptedAttributes( + kv={attr: None}, + desc=attribs.node[attr]['description']).html() + '
\n' + elif 'type' in attribs.node[attr] and list == attribs.node[attr]['type']: + yield confluent.messages.ListAttributes( + kv={attr: []}, + desc=attribs.node[attr]['description']).html() + '
\n' + else: + yield confluent.messages.Attributes( + kv={attr: None}, + desc=attribs.node[attr]['description']).html() + '
\n' + + def node_creation_resources(): yield confluent.messages.Attributes( kv={'name': None}, desc="Name of the node").html() + '
' @@ -50,6 +72,7 @@ def node_creation_resources(): create_resource_functions = { '/node/': node_creation_resources, + '/nodegroup/': group_creation_resources, } diff --git a/confluent/pluginapi.py b/confluent/pluginapi.py index eb1948ad..493503b6 100644 --- a/confluent/pluginapi.py +++ b/confluent/pluginapi.py @@ -142,6 +142,16 @@ def enumerate_node_collection(collectionpath, configmanager): return iterate_resources(collection) +def create_group(inputdata, configmanager): + try: + groupname = inputdata['name'] + del inputdata['name'] + attribmap = {groupname: inputdata} + except KeyError: + raise exc.InvalidArgumenTException() + configmanager.set_group_attributes(attribmap) + + def create_node(inputdata, configmanager): try: nodename = inputdata['name'] @@ -176,6 +186,8 @@ def handle_path(path, operation, configmanager, inputdata=None): try: group = pathcomponents[1] except IndexError: + if operation == "create": + create_group(inputdata, configmanager) return iterate_collections(configmanager.get_groups()) if iscollection: if operation == "delete":