2
0
mirror of https://github.com/xcat2/confluent.git synced 2024-11-22 17:43:14 +00:00

Implement 'set' in CLI

While testing set, it was noted that JSON loads does unicode.  Modified configmanager
to treat unicode like str type.
This commit is contained in:
Jarrod Johnson 2014-02-22 20:10:13 -05:00
parent e236260c3b
commit 387523f46b
2 changed files with 27 additions and 6 deletions

View File

@ -166,10 +166,10 @@ def do_command(command, server):
argv = parse_command(command)
if len(argv) == 0:
return
if argv[0] == "exit":
if argv[0] == 'exit':
server.close()
sys.exit(0)
elif argv[0] == "cd":
elif argv[0] == 'cd':
otarget = target
if len(argv) > 1:
target = fullpath_target(argv[1], forcepath=True)
@ -216,7 +216,6 @@ def do_command(command, server):
notestr = '(' + ', '.join(notes) + ')'
output = '{0:<40} {1:>39}'.format(attrstr, notestr)
print output
elif argv[0] == 'start':
targpath = fullpath_target(argv[1])
currconsole = targpath
@ -230,9 +229,29 @@ def do_command(command, server):
print '[console session started]'
startconsole()
return
elif argv[0] == 'set':
setvalues(argv[1:])
else:
sys.stderr.write("%s: command not found...\n" % argv[0])
def setvalues(attribs):
if '=' in attribs[0]: # going straight to attribute
resource = attribs[0][:attribs[0].index("=")]
else: # an actual resource
resource = attribs[0]
attribs = attribs[1:]
keydata = {}
for attrib in attribs:
if '=' not in attrib:
sys.stderr.write("Invalid syntax %s" % attrib)
return
key = attrib[:attrib.index("=")]
value = attrib[attrib.index("=") + 1:]
keydata[key] = value
targpath = fullpath_target(resource)
tlvdata.send_tlvdata(server, {'operation': 'update', 'path': targpath, 'parameters': keydata})
def fullpath_target(path, forcepath=False):
global target

View File

@ -441,7 +441,7 @@ class ConfigManager(object):
if 'nodes' not in self._cfgstore:
return None
retdict = {}
if isinstance(nodelist,str):
if isinstance(nodelist,str) or isinstance(nodelist, unicode):
nodelist = [nodelist]
for node in nodelist:
if node not in self._cfgstore['nodes']:
@ -575,7 +575,8 @@ class ConfigManager(object):
if not isinstance(attribmap[group][attr], list):
raise ValueError
newdict = set(attribmap[group][attr])
elif (isinstance(attribmap[group][attr], str)):
elif (isinstance(attribmap[group][attr], str) or
isinstance(attribmap[group][attr], unicode)):
newdict = { 'value': attribmap[group][attr] }
else:
newdict = attribmap[group][attr]
@ -655,7 +656,8 @@ class ConfigManager(object):
not isinstance(attribmap[node][attrname],allattributes.node[attrname]['type']))):
raise ValueError
newdict = {}
if (isinstance(attribmap[node][attrname], str)):
if (isinstance(attribmap[node][attrname], str) or
isinstance(attribmap[node][attrname], unicode)):
newdict = {'value': attribmap[node][attrname] }
else:
newdict = attribmap[node][attrname]