aboutsummaryrefslogtreecommitdiff
path: root/scripts/qmp/qmp-shell
AgeCommit message (Collapse)Author
2022-04-21python: rename qemu.aqmp to qemu.qmpJohn Snow
Now that we are fully switched over to the new QMP library, move it back over the old namespace. This is being done primarily so that we may upload this package simply as "qemu.qmp" without introducing confusion over whether or not "aqmp" is a new protocol or not. The trade-off is increased confusion inside the QEMU developer tree. Sorry! Note: the 'private' member "_aqmp" in legacy.py also changes to "_qmp"; not out of necessity, but just to remove any traces of the "aqmp" name. Signed-off-by: John Snow <jsnow@redhat.com> Reviewed-by: Beraldo Leal <bleal@redhat.com> Acked-by: Hanna Reitz <hreitz@redhat.com> Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@openvz.org> Message-id: 20220330172812.3427355-8-jsnow@redhat.com Signed-off-by: John Snow <jsnow@redhat.com>
2022-01-21python: move qmp-shell under the AQMP packageJohn Snow
Signed-off-by: John Snow <jsnow@redhat.com> Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> Reviewed-by: Beraldo Leal <bleal@redhat.com>
2021-06-18scripts/qmp-shell: add redirection shimJohn Snow
qmp-shell has a new home, add a redirect for a little while as the dust settles. Signed-off-by: John Snow <jsnow@redhat.com> Message-id: 20210607200649.1840382-43-jsnow@redhat.com Signed-off-by: John Snow <jsnow@redhat.com>
2021-06-18scripts/qmp-shell: move to python/qemu/qmp/qmp_shell.pyJohn Snow
The script will be unavailable for a commit or two, which will help preserve development history attached to the new file. A forwarder will be added shortly afterwards. With qmp_shell in the python qemu.qmp package, now it is fully type checked, linted, etc. via the Python CI. It will be quite a bit harder to accidentally break it again in the future. Signed-off-by: John Snow <jsnow@redhat.com> Message-id: 20210607200649.1840382-41-jsnow@redhat.com Signed-off-by: John Snow <jsnow@redhat.com>
2021-06-18scripts/qmp-shell: add docstringsJohn Snow
Signed-off-by: John Snow <jsnow@redhat.com> Message-id: 20210607200649.1840382-40-jsnow@redhat.com Signed-off-by: John Snow <jsnow@redhat.com>
2021-06-18scripts/qmp-shell: make QMPShellError inherit QMPErrorJohn Snow
In preparation for moving qmp-shell into the qemu.qmp package, make QMPShellError inherit from QMPError so that all custom errors in this package all derive from QMPError. Signed-off-by: John Snow <jsnow@redhat.com> Message-id: 20210607200649.1840382-39-jsnow@redhat.com Signed-off-by: John Snow <jsnow@redhat.com>
2021-06-18scripts/qmp-shell: remove double-underscoresJohn Snow
They're not needed; single underscore is enough to express intent that these methods are "internal". double underscore is used as a weak name mangling, but that isn't beneficial for us here. Signed-off-by: John Snow <jsnow@redhat.com> Message-id: 20210607200649.1840382-38-jsnow@redhat.com Signed-off-by: John Snow <jsnow@redhat.com>
2021-06-18scripts/qmp-shell: convert usage comment to docstringJohn Snow
The nice usage comment should be a docstring instead of a comment, so that it's visible from other python tooling. Signed-off-by: John Snow <jsnow@redhat.com> Message-id: 20210607200649.1840382-37-jsnow@redhat.com Signed-off-by: John Snow <jsnow@redhat.com>
2021-06-18scripts/qmp-shell: Remove too-broad-exceptionJohn Snow
We are only anticipating QMPShellErrors here, for syntax we weren't able to understand. Other errors, if any, should be allowed to percolate upwards. Signed-off-by: John Snow <jsnow@redhat.com> Message-id: 20210607200649.1840382-36-jsnow@redhat.com Signed-off-by: John Snow <jsnow@redhat.com>
2021-06-18scripts/qmp-shell: Fix empty-transaction invocationJohn Snow
calling "transaction( )" is pointless, but valid. Rework the parser to allow this kind of invocation. This helps clean up exception handling later by removing accidental breakages of the parser that aren't explicitly forbidden. Signed-off-by: John Snow <jsnow@redhat.com> Message-id: 20210607200649.1840382-35-jsnow@redhat.com Signed-off-by: John Snow <jsnow@redhat.com>
2021-06-18scripts/qmp-shell: remove TODOJohn Snow
We still want to revamp qmp-shell again, but there's much more to the idea than the comment now intuits. Remove it. Signed-off-by: John Snow <jsnow@redhat.com> Message-id: 20210607200649.1840382-34-jsnow@redhat.com Signed-off-by: John Snow <jsnow@redhat.com>
2021-06-18scripts/qmp-shell: use logging to show warningsJohn Snow
A perfect candidate is non-fatal shell history messages. Signed-off-by: John Snow <jsnow@redhat.com> Message-id: 20210607200649.1840382-33-jsnow@redhat.com Signed-off-by: John Snow <jsnow@redhat.com>
2021-06-18scripts/qmp-shell: Use context manager instead of atexitJohn Snow
We can invoke the shell history writing when we leave the QMPShell scope instead of relying on atexit. Doing so may be preferable to avoid global state being registered from within a class instead of from the application logic directly. Use QMP's context manager to hook this history saving at close time, which gets invoked when we leave the context block. Signed-off-by: John Snow <jsnow@redhat.com> Message-id: 20210607200649.1840382-32-jsnow@redhat.com Signed-off-by: John Snow <jsnow@redhat.com>
2021-06-18scripts/qmp-shell: unprivatize 'pretty' propertyJohn Snow
Similar to verbose, there's no reason this needs to be hidden. Signed-off-by: John Snow <jsnow@redhat.com> Message-id: 20210607200649.1840382-30-jsnow@redhat.com Signed-off-by: John Snow <jsnow@redhat.com>
2021-06-18scripts/qmp-shell: Accept SocketAddrT instead of stringJohn Snow
Don't "extend" QEMUMonitorProtocol by changing the argument types. Move the string parsing just outside of the class instead. Signed-off-by: John Snow <jsnow@redhat.com> Message-id: 20210607200649.1840382-29-jsnow@redhat.com Signed-off-by: John Snow <jsnow@redhat.com>
2021-06-18scripts/qmp-shell: add mypy typesJohn Snow
As per my usual, this patch is annotations only. Any changes with side effects are done elsewhere. Note: pylint does not understand the subscripts for Collection in Python 3.6, so use the stronger Sequence type as a workaround. Signed-off-by: John Snow <jsnow@redhat.com> Message-id: 20210607200649.1840382-28-jsnow@redhat.com Signed-off-by: John Snow <jsnow@redhat.com>
2021-06-18scripts/qmp-shell: initialize completer earlyJohn Snow
Add an empty completer as a more type-safe placeholder instead of 'None'. Signed-off-by: John Snow <jsnow@redhat.com> Message-id: 20210607200649.1840382-26-jsnow@redhat.com Signed-off-by: John Snow <jsnow@redhat.com>
2021-06-18scripts/qmp-shell: refactor QMPCompleterJohn Snow
list is a generic type, but we expect to use strings directly. We could subclass list[str], but pylint does not presently understand that invocation. Change this class to envelop a list instead of *being* a list, for simpler mypy typing. Signed-off-by: John Snow <jsnow@redhat.com> Message-id: 20210607200649.1840382-25-jsnow@redhat.com Signed-off-by: John Snow <jsnow@redhat.com>
2021-06-18scripts/qmp-shell: Fix "FuzzyJSON" parserJohn Snow
I'm not sure when this regressed (Or maybe if it was ever working right to begin with?), but the Python AST requires you to change "Names" to "Constants" in order to truly convert `false` to `False`. Signed-off-by: John Snow <jsnow@redhat.com> Message-id: 20210607200649.1840382-24-jsnow@redhat.com Signed-off-by: John Snow <jsnow@redhat.com>
2021-06-18scripts/qmp-shell: move the REPL functionality into QMPShellJohn Snow
Instead of doing this in main, move it into the class itself. (This makes it easier to put into the qemu.qmp package later by removing as much as we can from the main() function.) Signed-off-by: John Snow <jsnow@redhat.com> Message-id: 20210607200649.1840382-23-jsnow@redhat.com Signed-off-by: John Snow <jsnow@redhat.com>
2021-06-18scripts/qmp-shell: remove prompt argument from read_exec_commandJohn Snow
It's only ever used by one caller, we can just absorb that logic. Signed-off-by: John Snow <jsnow@redhat.com> Message-id: 20210607200649.1840382-22-jsnow@redhat.com Signed-off-by: John Snow <jsnow@redhat.com>
2021-06-18scripts/qmp-shell: move get_prompt() to prompt propertyJohn Snow
Small tidying; treat "prompt" like an immutable property instead of function/method/routine. Signed-off-by: John Snow <jsnow@redhat.com> Message-id: 20210607200649.1840382-21-jsnow@redhat.com Signed-off-by: John Snow <jsnow@redhat.com>
2021-06-18scripts/qmp-shell: Make verbose a public attributeJohn Snow
No real reason to hide this behind an underscore; make it part of the initializer and make it a regular RW attribute. Signed-off-by: John Snow <jsnow@redhat.com> Message-id: 20210607200649.1840382-20-jsnow@redhat.com Signed-off-by: John Snow <jsnow@redhat.com>
2021-06-18scripts/qmp-shell: Add pretty attribute to HMP shellJohn Snow
It's less useful, but it makes the initialization methods LSP consistent, which quiets a mypy complaint. Signed-off-by: John Snow <jsnow@redhat.com> Message-id: 20210607200649.1840382-19-jsnow@redhat.com Signed-off-by: John Snow <jsnow@redhat.com>
2021-06-18scripts/qmp-shell: use argparseJohn Snow
Use argparse instead of an open-coded CLI parser, for consistency with everything else. Signed-off-by: John Snow <jsnow@redhat.com> Message-id: 20210607200649.1840382-18-jsnow@redhat.com Signed-off-by: John Snow <jsnow@redhat.com>
2021-06-18scripts/qmp-shell: use isinstance() instead of type()John Snow
A bit more idiomatic, and quiets some linter warnings. Signed-off-by: John Snow <jsnow@redhat.com> Message-id: 20210607200649.1840382-17-jsnow@redhat.com Signed-off-by: John Snow <jsnow@redhat.com>
2021-06-18scripts/qmp-shell: remove if-raise-else patternsJohn Snow
Shushes pylint. I don't always mind these patterns personally, but I'm not as sure that I want to remove the warning from pylint's repertoire entirely. Oh well. Signed-off-by: John Snow <jsnow@redhat.com> Message-id: 20210607200649.1840382-16-jsnow@redhat.com Signed-off-by: John Snow <jsnow@redhat.com>
2021-06-18scripts/qmp-shell: fix shell history exception handlingJohn Snow
We want to remove exceptions that are too broad here; we only want to catch IOErrors that get raised as a direct result of the open call. Signed-off-by: John Snow <jsnow@redhat.com> Message-id: 20210607200649.1840382-15-jsnow@redhat.com Signed-off-by: John Snow <jsnow@redhat.com>
2021-06-18scripts/qmp-shell: rename one and two-letter variablesJohn Snow
A bit of churn and housekeeping for pylint, flake8 et al. Signed-off-by: John Snow <jsnow@redhat.com> Message-id: 20210607200649.1840382-14-jsnow@redhat.com Signed-off-by: John Snow <jsnow@redhat.com>
2021-06-18scripts/qmp-shell: make QMPCompleter returns explicitJohn Snow
This function returns None when it doesn't find a match; do that explicitly. Signed-off-by: John Snow <jsnow@redhat.com> Message-id: 20210607200649.1840382-13-jsnow@redhat.com Signed-off-by: John Snow <jsnow@redhat.com>
2021-06-18scripts/qmp-shell: ignore visit_Name nameJohn Snow
Not something I control, sorry, pylint. Signed-off-by: John Snow <jsnow@redhat.com> Message-id: 20210607200649.1840382-12-jsnow@redhat.com Signed-off-by: John Snow <jsnow@redhat.com>
2021-06-18scripts/qmp-shell: use triple-double-quote docstring styleJohn Snow
(2014 me had never written python before.) Signed-off-by: John Snow <jsnow@redhat.com> Message-id: 20210607200649.1840382-11-jsnow@redhat.com Signed-off-by: John Snow <jsnow@redhat.com>
2021-06-18scripts/qmp-shell: declare verbose in __init__John Snow
Linters get angry when we don't define state at init time. Signed-off-by: John Snow <jsnow@redhat.com> Message-id: 20210607200649.1840382-10-jsnow@redhat.com Signed-off-by: John Snow <jsnow@redhat.com>
2021-06-18scripts/qmp-shell: Use python3-style super()John Snow
Signed-off-by: John Snow <jsnow@redhat.com> Message-id: 20210607200649.1840382-9-jsnow@redhat.com Signed-off-by: John Snow <jsnow@redhat.com>
2021-06-18scripts/qmp-shell: use @classmethod where appropriateJohn Snow
Methods with no self-use should belong to the class. Signed-off-by: John Snow <jsnow@redhat.com> Message-id: 20210607200649.1840382-8-jsnow@redhat.com Signed-off-by: John Snow <jsnow@redhat.com>
2021-06-18scripts/qmp-shell: remove shadowed variable from _print()John Snow
Don't use 'qmp' here, which shadows the qmp module. Signed-off-by: John Snow <jsnow@redhat.com> Message-id: 20210607200649.1840382-7-jsnow@redhat.com Signed-off-by: John Snow <jsnow@redhat.com>
2021-06-18scripts/qmp-shell: fix connect method signatureJohn Snow
It needs to match the parent's signature -- the negotiate parameter must be optional. Signed-off-by: John Snow <jsnow@redhat.com> Message-id: 20210607200649.1840382-6-jsnow@redhat.com Signed-off-by: John Snow <jsnow@redhat.com>
2021-06-18scripts/qmp-shell: fix exception handlingJohn Snow
Fixes: 50d189c Signed-off-by: John Snow <jsnow@redhat.com> Message-id: 20210607200649.1840382-5-jsnow@redhat.com Signed-off-by: John Snow <jsnow@redhat.com>
2021-06-18scripts/qmp-shell: fix show_banner signatureJohn Snow
The signatures need to match. Signed-off-by: John Snow <jsnow@redhat.com> Message-id: 20210607200649.1840382-4-jsnow@redhat.com Signed-off-by: John Snow <jsnow@redhat.com>
2021-06-18scripts/qmp-shell: Apply flake8 rulesJohn Snow
A lot of fiddling around to get us below 80 columns. Signed-off-by: John Snow <jsnow@redhat.com> Message-id: 20210607200649.1840382-3-jsnow@redhat.com Signed-off-by: John Snow <jsnow@redhat.com>
2021-06-18scripts/qmp-shell: apply isort rulesJohn Snow
Signed-off-by: John Snow <jsnow@redhat.com> Message-id: 20210607200649.1840382-2-jsnow@redhat.com Signed-off-by: John Snow <jsnow@redhat.com>
2021-06-18python/qmp: add parse_address classmethodJohn Snow
This takes the place of qmp-shell's __get_address function. It also allows other utilities to share the same parser and syntax for specifying QMP locations. Signed-off-by: John Snow <jsnow@redhat.com> Message-id: 20210603003719.1321369-4-jsnow@redhat.com Signed-off-by: John Snow <jsnow@redhat.com>
2020-10-27qmp-shell: Sort by key when pretty-printingDavid Edmondson
If the user selects pretty-printing (-p) the contents of any dictionaries in the output are sorted by key. Signed-off-by: David Edmondson <david.edmondson@oracle.com> Message-Id: <20201013141414.18398-1-david.edmondson@oracle.com> Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com> Signed-off-by: Markus Armbruster <armbru@redhat.com>
2020-05-31python: remove more instances of sys.version_infoJohn Snow
We guarantee 3.5+ everywhere; remove more dead checks. In general, try to avoid using version checks and instead prefer to attempt behavior when possible. Signed-off-by: John Snow <jsnow@redhat.com> Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com> Message-Id: <20200514035230.25756-1-jsnow@redhat.com> Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
2020-02-07drop "from __future__ import print_function"Paolo Bonzini
This is only needed for Python 2, which we do not support anymore. Cc: Philippe Mathieu-Daudé <philmd@redhat.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com> Acked-by: Alex Bennée <alex.bennee@linaro.org> Acked-by: Markus Armbruster <armbru@redhat.com> Message-Id: <20200204160604.19883-1-pbonzini@redhat.com> Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
2020-02-07scripts: Explicit usage of Python 3 (scripts with __main__)Philippe Mathieu-Daudé
Use the program search path to find the Python 3 interpreter. Patch created mechanically by running: $ sed -i "s,^#\!/usr/bin/\(env\ \)\?python$,#\!/usr/bin/env python3," \ $(git grep -l 'if __name__.*__main__') Reported-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> Suggested-by: Daniel P. Berrangé <berrange@redhat.com> Suggested-by: Stefan Hajnoczi <stefanha@redhat.com> Reviewed-by: Juan Quintela <quintela@redhat.com> Acked-by: Stefan Hajnoczi <stefanha@redhat.com> Acked-by: Paolo Bonzini <pbonzini@redhat.com> Message-Id: <20200130163232.10446-6-philmd@redhat.com> Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
2019-07-01qmp: make qmp-shell work with python3Igor Mammedov
python3 doesn't have raw_input(), so qmp-shell breaks. Use input() instead and override it with raw_input() if running on python2. Signed-off-by: Igor Mammedov <imammedo@redhat.com> Message-Id: <20190620154035.30989-1-imammedo@redhat.com> Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
2019-03-11qmp-shell: fix nested json regressionMarc-André Lureau
Commit fcfab7541 ("qmp-shell: learn to send commands with quoted arguments") introduces the usage of Python 'shlex' to handle quoted arguments, but it accidentally broke generation of nested JSON structs. shlex drops quotes, which breaks parsing of the nested struct. cmd='blockdev-create job-id="job0 foo" options={"driver":"qcow2","size":16384,"file":{"driver":"file","filename":"foo.qcow2"}}' shlex.split(cmd) ['blockdev-create', 'job-id=job0 foo', 'options={driver:qcow2,size:16384,file:{driver:file,filename:foo.qcow2}}'] Replace with a regexp to split while respecting quoted strings and preserving quotes: re.findall(r'''(?:[^\s"']|"(?:\\.|[^"])*"|'(?:\\.|[^'])*')+''', cmd) ['blockdev-create', 'job-id="job0 foo"', 'options={"driver":"qcow2","size":16384,"file":{"driver":"file","filename":"foo.qcow2"}}'] Fixes: fcfab7541 ("qmp-shell: learn to send commands with quoted arguments") Reported-by: Kashyap Chamarthy <kchamart@redhat.com> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com> Message-Id: <20190205134926.8312-1-marcandre.lureau@redhat.com> Tested-by: Kashyap Chamarthy <kchamart@redhat.com> Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
2019-02-22Introduce a Python module structureCleber Rosa
This is a simple move of Python code that wraps common QEMU functionality, and are used by a number of different tests and scripts. By treating that code as a real Python module, we can more easily: * reuse code * have a proper place for the module's own unittests * apply a more consistent style * generate documentation Signed-off-by: Cleber Rosa <crosa@redhat.com> Reviewed-by: Caio Carrara <ccarrara@redhat.com> Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com> Message-Id: <20190206162901.19082-2-crosa@redhat.com> Signed-off-by: Cleber Rosa <crosa@redhat.com>
2018-08-15qmp-shell: learn to send commands with quoted argumentsMarc-André Lureau
Use shlex to split the CLI command, respecting quoted arguments, and also comments. This allows to call for ex: (QEMU) human-monitor-command command-line="screendump /dev/null" {"execute": "human-monitor-command", "arguments": {"command-line": "screendump /dev/null"}} Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com> Message-Id: <20180326150916.9602-3-marcandre.lureau@redhat.com> Reviewed-by: Eduardo Habkost <ehabkost@redhat.com> Signed-off-by: Markus Armbruster <armbru@redhat.com>