From: Eduardo Habkost <ehabkost@redhat.com>
To: Markus Armbruster <armbru@redhat.com>
Cc: qemu-devel@nongnu.org, John Snow <jsnow@redhat.com>,
Stefan Hajnoczi <stefanha@redhat.com>
Subject: Re: [Qemu-devel] [PATCH for-2.11 v2 4/5] qmp-shell: Accept QMP command as argument
Date: Tue, 15 Aug 2017 17:39:09 -0300 [thread overview]
Message-ID: <20170815203909.GY3108@localhost.localdomain> (raw)
In-Reply-To: <87fuctp2pi.fsf@dusky.pond.sub.org>
On Tue, Aug 15, 2017 at 12:03:53PM +0200, Markus Armbruster wrote:
> Eduardo Habkost <ehabkost@redhat.com> writes:
>
> Suggest to insert here:
>
> If additional arguments QMP-COMMAND ARG=VAL... are given, run just
> that QMP command instead of the REPL.
>
> Question: is this limited to simple arguments? If no, how would I write
> an object argument? For instance, how would I do
>
> { "execute": "blockdev-add", "arguments": { "node-name": "foo", "driver": "nbd", "server": { "type": "inet", "host": "localhost", "port": "12345" } } }
>
> ?
Exactly the same way you would write it when running qmp-shell in
interactive mode. e.g.:
$ ./scripts/qmp/qmp-shell /tmp/qmp blockdev-add driver=qcow2 node-name=node-E 'file={"driver":"file","filename":"/path/to/file.qcow2"}'
>
> > This is useful for testing QMP commands in scripts.
> >
> > Example usage, combined with 'jq' for filtering the results:
> >
> > $ ./scripts/qmp/qmp-shell /tmp/qmp qom-list path=/ | jq -r .return[].name
> > machine
> > type
> > chardevs
> > backend
>
> What's jq?
https://stedolan.github.io/jq/
"like sed for JSON data"
>
> > $
>
> Let's drop this line.
Will do it.
>
> >
> > Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
> > ---
> > Changes v1 -> v2:
> > * Rewritten using optparse module
> > ---
> > scripts/qmp/qmp-shell | 14 +++++++++-----
> > 1 file changed, 9 insertions(+), 5 deletions(-)
> >
> > diff --git a/scripts/qmp/qmp-shell b/scripts/qmp/qmp-shell
> > index 4b9a420..4b7374e 100755
> > --- a/scripts/qmp/qmp-shell
> > +++ b/scripts/qmp/qmp-shell
> > @@ -400,7 +400,7 @@ def die(msg):
> >
> > def main():
> > parser = optparse.OptionParser(description='QMP shell utility')
> > - parser.set_usage("%prog [options] <UNIX socket path> | <TCP address:port>")
> > + parser.set_usage("%prog [options] <UNIX socket path> | <TCP address:port> [COMMAND [ARG=VALUE]...]")
> > parser.add_option('-v', action='store_true', dest='verbose',
> > help='Verbose (echo command sent and received)')
> > parser.add_option('-p', action='store_true', dest='pretty',
> > @@ -411,10 +411,11 @@ def main():
> > default=True, help='Skip negotiate (for qemu-ga)')
> > opts,args = parser.parse_args()
> >
> > - if len(args) != 1:
> > + if len(args) < 1:
> > parser.print_help(sys.stderr)
> > sys.exit(1)
> > addr = args[0]
> > + cmdargs = args[1:]
> >
> > try:
> > if opts.hmp:
> > @@ -433,10 +434,13 @@ def main():
> > except qemu.error:
> > die('Could not connect to %s' % addr)
> >
> > - qemu.show_banner()
> > qemu.set_verbosity(opts.verbose)
> > - while qemu.read_exec_command(qemu.get_prompt()):
> > - pass
> > + if len(cmdargs):
>
> Superfluous len().
Will fix it in the next version.
>
> > + qemu.execute_cmdargs(cmdargs)
> > + else:
> > + qemu.show_banner()
> > + while qemu.read_exec_command(qemu.get_prompt()):
> > + pass
> > qemu.close()
> >
> > if __name__ == '__main__':
--
Eduardo
next prev parent reply other threads:[~2017-08-15 20:39 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-08-08 20:39 [Qemu-devel] [PATCH for-2.11 v2 0/5] qmp-shell non-interactive mode, delete scripts/qmp/qmp Eduardo Habkost
2017-08-08 20:39 ` [Qemu-devel] [PATCH for-2.11 v2 1/5] qmp-shell: Use optparse module Eduardo Habkost
2017-08-09 9:17 ` Stefan Hajnoczi
2017-08-15 9:47 ` Markus Armbruster
2017-08-15 9:56 ` Daniel P. Berrange
2017-08-15 20:06 ` Eduardo Habkost
2017-08-18 15:42 ` Stefan Hajnoczi
2017-08-15 9:59 ` Daniel P. Berrange
2017-08-08 20:39 ` [Qemu-devel] [PATCH for-2.11 v2 2/5] qmp-shell: Pass split cmdargs to __build_cmd() Eduardo Habkost
2017-08-08 20:39 ` [Qemu-devel] [PATCH for-2.11 v2 3/5] qmp-shell: execute_cmdargs() method Eduardo Habkost
2017-08-08 20:39 ` [Qemu-devel] [PATCH for-2.11 v2 4/5] qmp-shell: Accept QMP command as argument Eduardo Habkost
2017-08-09 9:15 ` Stefan Hajnoczi
2017-08-15 10:03 ` Markus Armbruster
2017-08-15 20:39 ` Eduardo Habkost [this message]
2017-08-16 6:25 ` Markus Armbruster
2017-08-18 17:05 ` Eduardo Habkost
2017-08-21 9:22 ` Markus Armbruster
2017-08-08 20:39 ` [Qemu-devel] [PATCH for-2.11 v2 5/5] Remove scripts/qmp/qmp Eduardo Habkost
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20170815203909.GY3108@localhost.localdomain \
--to=ehabkost@redhat.com \
--cc=armbru@redhat.com \
--cc=jsnow@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=stefanha@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).