From: Eduardo Habkost <ehabkost@redhat.com>
To: qemu-devel@nongnu.org
Cc: Markus Armbruster <armbru@redhat.com>,
Stefan Hajnoczi <stefanha@redhat.com>,
"Daniel P. Berrange" <berrange@redhat.com>,
John Snow <jsnow@redhat.com>
Subject: [Qemu-devel] [PATCH for-2.11 v2 5/5] Remove scripts/qmp/qmp
Date: Tue, 8 Aug 2017 17:39:35 -0300 [thread overview]
Message-ID: <20170808203935.30021-6-ehabkost@redhat.com> (raw)
In-Reply-To: <20170808203935.30021-1-ehabkost@redhat.com>
The only purpose of scripts/qmp/qmp was the ability to run QMP
commands non-interactively. Now it is possible to run qmp-shell
non-interactively by providing a QMP command a command-line
argument, making scripts/qmp/qmp obsolete.
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
Tested-by: John Snow <jsnow@redhat.com>
Reviewed-by: John Snow <jsnow@redhat.com>
Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
---
Changes v1 -> v2:
* (none)
---
scripts/qmp/qmp | 126 --------------------------------------------------------
1 file changed, 126 deletions(-)
delete mode 100755 scripts/qmp/qmp
diff --git a/scripts/qmp/qmp b/scripts/qmp/qmp
deleted file mode 100755
index 514b539..0000000
--- a/scripts/qmp/qmp
+++ /dev/null
@@ -1,126 +0,0 @@
-#!/usr/bin/python
-#
-# QMP command line tool
-#
-# Copyright IBM, Corp. 2011
-#
-# Authors:
-# Anthony Liguori <aliguori@us.ibm.com>
-#
-# This work is licensed under the terms of the GNU GPLv2 or later.
-# See the COPYING file in the top-level directory.
-
-import sys, os
-from qmp import QEMUMonitorProtocol
-
-def print_response(rsp, prefix=[]):
- if type(rsp) == list:
- i = 0
- for item in rsp:
- if prefix == []:
- prefix = ['item']
- print_response(item, prefix[:-1] + ['%s[%d]' % (prefix[-1], i)])
- i += 1
- elif type(rsp) == dict:
- for key in rsp.keys():
- print_response(rsp[key], prefix + [key])
- else:
- if len(prefix):
- print '%s: %s' % ('.'.join(prefix), rsp)
- else:
- print '%s' % (rsp)
-
-def main(args):
- path = None
-
- # Use QMP_PATH if it's set
- if os.environ.has_key('QMP_PATH'):
- path = os.environ['QMP_PATH']
-
- while len(args):
- arg = args[0]
-
- if arg.startswith('--'):
- arg = arg[2:]
- if arg.find('=') == -1:
- value = True
- else:
- arg, value = arg.split('=', 1)
-
- if arg in ['path']:
- if type(value) == str:
- path = value
- elif arg in ['help']:
- os.execlp('man', 'man', 'qmp')
- else:
- print 'Unknown argument "%s"' % arg
-
- args = args[1:]
- else:
- break
-
- if not path:
- print "QMP path isn't set, use --path=qmp-monitor-address or set QMP_PATH"
- return 1
-
- if len(args):
- command, args = args[0], args[1:]
- else:
- print 'No command found'
- print 'Usage: "qmp [--path=qmp-monitor-address] qmp-cmd arguments"'
- return 1
-
- if command in ['help']:
- os.execlp('man', 'man', 'qmp')
-
- srv = QEMUMonitorProtocol(path)
- srv.connect()
-
- def do_command(srv, cmd, **kwds):
- rsp = srv.cmd(cmd, kwds)
- if rsp.has_key('error'):
- raise Exception(rsp['error']['desc'])
- return rsp['return']
-
- commands = map(lambda x: x['name'], do_command(srv, 'query-commands'))
-
- srv.close()
-
- if command not in commands:
- fullcmd = 'qmp-%s' % command
- try:
- os.environ['QMP_PATH'] = path
- os.execvp(fullcmd, [fullcmd] + args)
- except OSError as exc:
- if exc.errno == 2:
- print 'Command "%s" not found.' % (fullcmd)
- return 1
- raise
- return 0
-
- srv = QEMUMonitorProtocol(path)
- srv.connect()
-
- arguments = {}
- for arg in args:
- if not arg.startswith('--'):
- print 'Unknown argument "%s"' % arg
- return 1
-
- arg = arg[2:]
- if arg.find('=') == -1:
- value = True
- else:
- arg, value = arg.split('=', 1)
-
- if arg in ['help']:
- os.execlp('man', 'man', 'qmp-%s' % command)
- return 1
-
- arguments[arg] = value
-
- rsp = do_command(srv, command, **arguments)
- print_response(rsp)
-
-if __name__ == '__main__':
- sys.exit(main(sys.argv[1:]))
--
2.9.4
prev parent reply other threads:[~2017-08-08 20:40 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
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 ` Eduardo Habkost [this message]
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=20170808203935.30021-6-ehabkost@redhat.com \
--to=ehabkost@redhat.com \
--cc=armbru@redhat.com \
--cc=berrange@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).