[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 09/10] scripts: qmp-shell: add transaction subshell
From: |
Luiz Capitulino |
Subject: |
[Qemu-devel] [PULL 09/10] scripts: qmp-shell: add transaction subshell |
Date: |
Fri, 8 May 2015 09:34:10 -0400 |
From: John Snow <address@hidden>
Add a special processing mode to craft transactions.
By entering "transaction(" the shell will enter a special
mode where each subsequent command will be saved as a transaction
instead of executed as an individual command.
The transaction can be submitted by entering ")" on a line by itself.
Examples:
Separate lines:
(QEMU) transaction(
TRANS> block-dirty-bitmap-add node=drive0 name=bitmap1
TRANS> block-dirty-bitmap-clear node=drive0 name=bitmap0
TRANS> )
With a transaction action included on the first line:
(QEMU) transaction( block-dirty-bitmap-add node=drive0 name=bitmap2
TRANS> block-dirty-bitmap-add node=drive0 name=bitmap3
TRANS> )
As a one-liner, with just one transaction action:
(QEMU) transaction( block-dirty-bitmap-add node=drive0 name=bitmap0 )
As a side-effect of this patch, blank lines are now parsed as no-ops,
regardless of which shell mode you are in.
Signed-off-by: John Snow <address@hidden>
Reviewed-by: Eric Blake <address@hidden>
Tested-by: Kashyap Chamarthy <address@hidden>
Signed-off-by: Luiz Capitulino <address@hidden>
---
scripts/qmp/qmp-shell | 42 +++++++++++++++++++++++++++++++++++++++++-
1 file changed, 41 insertions(+), 1 deletion(-)
diff --git a/scripts/qmp/qmp-shell b/scripts/qmp/qmp-shell
index 7f2c554..1df2ca7 100755
--- a/scripts/qmp/qmp-shell
+++ b/scripts/qmp/qmp-shell
@@ -73,6 +73,8 @@ class QMPShell(qmp.QEMUMonitorProtocol):
self._greeting = None
self._completer = None
self._pp = pp
+ self._transmode = False
+ self._actions = list()
def __get_address(self, arg):
"""
@@ -159,6 +161,36 @@ class QMPShell(qmp.QEMUMonitorProtocol):
< command-name > [ arg-name1=arg1 ] ... [ arg-nameN=argN ]
"""
cmdargs = cmdline.split()
+
+ # Transactional CLI entry/exit:
+ if cmdargs[0] == 'transaction(':
+ self._transmode = True
+ cmdargs.pop(0)
+ elif cmdargs[0] == ')' and self._transmode:
+ self._transmode = False
+ if len(cmdargs) > 1:
+ raise QMPShellError("Unexpected input after close of
Transaction sub-shell")
+ qmpcmd = { 'execute': 'transaction',
+ 'arguments': { 'actions': self._actions } }
+ self._actions = list()
+ return qmpcmd
+
+ # Nothing to process?
+ if not cmdargs:
+ return None
+
+ # Parse and then cache this Transactional Action
+ if self._transmode:
+ finalize = False
+ action = { 'type': cmdargs[0], 'data': {} }
+ if cmdargs[-1] == ')':
+ cmdargs.pop(-1)
+ finalize = True
+ self.__cli_expr(cmdargs[1:], action['data'])
+ self._actions.append(action)
+ return self.__build_cmd(')') if finalize else None
+
+ # Standard command: parse and return it to be executed.
qmpcmd = { 'execute': cmdargs[0], 'arguments': {} }
self.__cli_expr(cmdargs[1:], qmpcmd['arguments'])
return qmpcmd
@@ -171,6 +203,9 @@ class QMPShell(qmp.QEMUMonitorProtocol):
print 'command format: <command-name> ',
print '[arg-name1=arg1] ... [arg-nameN=argN]'
return True
+ # For transaction mode, we may have just cached the action:
+ if qmpcmd is None:
+ return True
resp = self.cmd_obj(qmpcmd)
if resp is None:
print 'Disconnected'
@@ -191,6 +226,11 @@ class QMPShell(qmp.QEMUMonitorProtocol):
version = self._greeting['QMP']['version']['qemu']
print 'Connected to QEMU %d.%d.%d\n' %
(version['major'],version['minor'],version['micro'])
+ def get_prompt(self):
+ if self._transmode:
+ return "TRANS> "
+ return "(QEMU) "
+
def read_exec_command(self, prompt):
"""
Read and execute a command.
@@ -330,7 +370,7 @@ def main():
die('Could not connect to %s' % addr)
qemu.show_banner()
- while qemu.read_exec_command('(QEMU) '):
+ while qemu.read_exec_command(qemu.get_prompt()):
pass
qemu.close()
--
1.9.3
- [Qemu-devel] [PULL 00/10] QMP queue, Luiz Capitulino, 2015/05/08
- [Qemu-devel] [PULL 03/10] qobject: Clean up around qtype_code, Luiz Capitulino, 2015/05/08
- [Qemu-devel] [PULL 02/10] QJSON: Use OBJECT_CHECK, Luiz Capitulino, 2015/05/08
- [Qemu-devel] [PULL 05/10] json-parser: Accept 'null' in QMP, Luiz Capitulino, 2015/05/08
- [Qemu-devel] [PULL 04/10] qobject: Add a special null QObject, Luiz Capitulino, 2015/05/08
- [Qemu-devel] [PULL 07/10] scripts: qmp-shell: refactor helpers, Luiz Capitulino, 2015/05/08
- [Qemu-devel] [PULL 06/10] MAINTAINERS: New maintainer for QMP and QAPI, Luiz Capitulino, 2015/05/08
- [Qemu-devel] [PULL 01/10] monitor: add memory search commands s, sp, Luiz Capitulino, 2015/05/08
- [Qemu-devel] [PULL 08/10] scripts: qmp-shell: Expand support for QMP expressions, Luiz Capitulino, 2015/05/08
- [Qemu-devel] [PULL 09/10] scripts: qmp-shell: add transaction subshell,
Luiz Capitulino <=
- [Qemu-devel] [PULL 10/10] scripts: qmp-shell: Add verbose flag, Luiz Capitulino, 2015/05/08
- Re: [Qemu-devel] [PULL 00/10] QMP queue, Peter Maydell, 2015/05/11