From ea7d3a268c17d5cdbd670285904596dee0387864 Mon Sep 17 00:00:00 2001 From: Jarrod Johnson Date: Sat, 22 Feb 2014 21:53:34 -0500 Subject: [PATCH] Implement 'unset' in confetty interactive cli. Provide a means to clear node specific settings so that inheritance can be restored. In JSON, send a null as a value for a parameter instead of a string or 'object'. --- bin/confetty | 16 ++++++++++++++++ plugins/configuration/attributes.py | 10 +++++++++- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/bin/confetty b/bin/confetty index fe97c455..3cc8753d 100755 --- a/bin/confetty +++ b/bin/confetty @@ -70,6 +70,7 @@ valid_commands = [ 'cd', 'show', 'set', + 'unset', 'create', ] @@ -234,9 +235,24 @@ def do_command(command, server): return elif argv[0] == 'set': setvalues(argv[1:]) + elif argv[0] in ('unset', 'clear'): + clearvalues(argv[1], argv[2:]) else: sys.stderr.write("%s: command not found...\n" % argv[0]) + +def clearvalues(resource, attribs): + targpath = fullpath_target(resource) + keydata = {} + for attrib in attribs: + keydata[attrib] = None + for res in send_request('update', targpath, server, keydata): + if 'error' in res: + if 'errorcode' in res: + exitcode = res['errorcode'] + sys.stderr.write('Error: ' + res['error'] + '\n') + + def setvalues(attribs): if '=' in attribs[0]: # going straight to attribute resource = attribs[0][:attribs[0].index("=")] diff --git a/plugins/configuration/attributes.py b/plugins/configuration/attributes.py index 55c8aa14..3f0cb7c8 100644 --- a/plugins/configuration/attributes.py +++ b/plugins/configuration/attributes.py @@ -125,12 +125,20 @@ def update_nodegroup(group, element, configmanager, inputdata): except ValueError: raise exc.InvalidArgumentException() return retrieve_nodegroup(group, element, configmanager, inputdata) - + def update_nodes(nodes, element, configmanager, inputdata): updatedict = {} for node in nodes: updatenode = inputdata.get_attributes(node) + clearattribs = [] if updatenode: + for attrib in updatenode.iterkeys(): + if updatenode[attrib] is None: + clearattribs.append(attrib) + if len(clearattribs) > 0: + for attrib in clearattribs: + del updatenode[attrib] + configmanager.clear_node_attributes([node], clearattribs) updatedict[node] = updatenode try: configmanager.set_node_attributes(updatedict)