aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFam Zheng <famz@redhat.com>2014-02-12 11:05:13 +0800
committerLuiz Capitulino <lcapitulino@redhat.com>2014-02-28 11:41:43 -0500
commitcd159d0954f65df61864a85e355acdf7ae7fe0f9 (patch)
tree4e58e16b1d00cf521236687d7e5d7d0e97f0091f
parentd844a7b6569fb2b5252773444b18841426e5b906 (diff)
QMP: Allow dot separated dict path arguments in qmp-shell
As another convenience to allow using commands that expect a dict as argument, this patch adds support for foo.bar=value syntax, similar to command line argument style: (QEMU) blockdev-add options.driver=file options.id=drive1 options.filename=... Signed-off-by: Fam Zheng <famz@redhat.com> Reviewed-by: Eric Blake <eblake@redhat.com> Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com> Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
-rwxr-xr-xscripts/qmp/qmp-shell20
1 files changed, 18 insertions, 2 deletions
diff --git a/scripts/qmp/qmp-shell b/scripts/qmp/qmp-shell
index d374b357aa..e0e848bc30 100755
--- a/scripts/qmp/qmp-shell
+++ b/scripts/qmp/qmp-shell
@@ -112,13 +112,29 @@ class QMPShell(qmp.QEMUMonitorProtocol):
value = json.loads(opt[1])
else:
value = opt[1]
- qmpcmd['arguments'][opt[0]] = value
+ optpath = opt[0].split('.')
+ parent = qmpcmd['arguments']
+ curpath = []
+ for p in optpath[:-1]:
+ curpath.append(p)
+ d = parent.get(p, {})
+ if type(d) is not dict:
+ raise QMPShellError('Cannot use "%s" as both leaf and non-leaf key' % '.'.join(curpath))
+ parent[p] = d
+ parent = d
+ if optpath[-1] in parent:
+ if type(parent[optpath[-1]]) is dict:
+ raise QMPShellError('Cannot use "%s" as both leaf and non-leaf key' % '.'.join(curpath))
+ else:
+ raise QMPShellError('Cannot set "%s" multiple times' % opt[0])
+ parent[optpath[-1]] = value
return qmpcmd
def _execute_cmd(self, cmdline):
try:
qmpcmd = self.__build_cmd(cmdline)
- except:
+ except Exception, e:
+ print 'Error while parsing command line: %s' % e
print 'command format: <command-name> ',
print '[arg-name1=arg1] ... [arg-nameN=argN]'
return True