From nobody Fri May 3 06:50:07 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1501883032602378.53029373352774; Fri, 4 Aug 2017 14:43:52 -0700 (PDT) Received: from localhost ([::1]:54495 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ddkNr-00035g-1P for importer@patchew.org; Fri, 04 Aug 2017 17:43:51 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38759) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ddkM9-0002IL-P0 for qemu-devel@nongnu.org; Fri, 04 Aug 2017 17:42:06 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ddkM6-0005lJ-J8 for qemu-devel@nongnu.org; Fri, 04 Aug 2017 17:42:05 -0400 Received: from mx1.redhat.com ([209.132.183.28]:56368) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ddkM6-0005k9-AQ for qemu-devel@nongnu.org; Fri, 04 Aug 2017 17:42:02 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 80F5A6147D for ; Fri, 4 Aug 2017 21:36:29 +0000 (UTC) Received: from localhost (ovpn-116-46.gru2.redhat.com [10.97.116.46]) by smtp.corp.redhat.com (Postfix) with ESMTP id 143D869510; Fri, 4 Aug 2017 21:36:28 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 80F5A6147D Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=ehabkost@redhat.com From: Eduardo Habkost To: qemu-devel@nongnu.org Date: Fri, 4 Aug 2017 18:36:21 -0300 Message-Id: <20170804213625.3756-2-ehabkost@redhat.com> In-Reply-To: <20170804213625.3756-1-ehabkost@redhat.com> References: <20170804213625.3756-1-ehabkost@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Fri, 04 Aug 2017 21:36:29 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH for-2.11 1/5] qmp-shell: Use argparse module X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: armbru@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" It makes command-line parsing and generation of help text much simpler. Signed-off-by: Eduardo Habkost Reviewed-by: John Snow Tested-by: John Snow --- scripts/qmp/qmp-shell | 61 +++++++++++++++++------------------------------= ---- 1 file changed, 20 insertions(+), 41 deletions(-) diff --git a/scripts/qmp/qmp-shell b/scripts/qmp/qmp-shell index 860ffb2..c276b90 100755 --- a/scripts/qmp/qmp-shell +++ b/scripts/qmp/qmp-shell @@ -73,6 +73,7 @@ import sys import os import errno import atexit +import argparse =20 class QMPCompleter(list): def complete(self, text, state): @@ -393,61 +394,39 @@ def die(msg): sys.stderr.write('ERROR: %s\n' % msg) sys.exit(1) =20 -def fail_cmdline(option=3DNone): - if option: - sys.stderr.write('ERROR: bad command-line option \'%s\'\n' % optio= n) - sys.stderr.write('qmp-shell [ -v ] [ -p ] [ -H ] [ -N ] < UNIX socket = path> | < TCP address:port >\n') - sys.stderr.write(' -v Verbose (echo command sent and received)\= n') - sys.stderr.write(' -p Pretty-print JSON\n') - sys.stderr.write(' -H Use HMP interface\n') - sys.stderr.write(' -N Skip negotiate (for qemu-ga)\n') - sys.exit(1) - def main(): - addr =3D '' - qemu =3D None - hmp =3D False - pretty =3D False - verbose =3D False - negotiate =3D True + parser =3D argparse.ArgumentParser(description=3D'QMP shell utility') + parser.add_argument('-v', action=3D'store_true', dest=3D'verbose', + help=3D'Verbose (echo command sent and received)') + parser.add_argument('-p', action=3D'store_true', dest=3D'pretty', + help=3D'Pretty-print JSON') + parser.add_argument('-H', action=3D'store_true', dest=3D'hmp', + help=3D'Use HMP interface') + parser.add_argument('-N', action=3D'store_false', dest=3D'negotiate', + default=3DTrue, help=3D'Skip negotiate (for qemu-ga)') + parser.add_argument('addr', metavar=3D'ADDRESS', + help=3D'QMP socket address (Unix socket path or TCP address:port)') + args =3D parser.parse_args() =20 try: - for arg in sys.argv[1:]: - if arg =3D=3D "-H": - if qemu is not None: - fail_cmdline(arg) - hmp =3D True - elif arg =3D=3D "-p": - pretty =3D True - elif arg =3D=3D "-N": - negotiate =3D False - elif arg =3D=3D "-v": - verbose =3D True - else: - if qemu is not None: - fail_cmdline(arg) - if hmp: - qemu =3D HMPShell(arg) - else: - qemu =3D QMPShell(arg, pretty) - addr =3D arg - - if qemu is None: - fail_cmdline() + if args.hmp: + qemu =3D HMPShell(args.addr) + else: + qemu =3D QMPShell(args.addr, args.pretty) except QMPShellBadPort: die('bad port number in command-line') =20 try: - qemu.connect(negotiate) + qemu.connect(args.negotiate) except qmp.QMPConnectError: die('Didn\'t get QMP greeting message') except qmp.QMPCapabilitiesError: die('Could not negotiate capabilities') except qemu.error: - die('Could not connect to %s' % addr) + die('Could not connect to %s' % args.addr) =20 qemu.show_banner() - qemu.set_verbosity(verbose) + qemu.set_verbosity(args.verbose) while qemu.read_exec_command(qemu.get_prompt()): pass qemu.close() --=20 2.9.4 From nobody Fri May 3 06:50:07 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 150188310202885.45464428090065; Fri, 4 Aug 2017 14:45:02 -0700 (PDT) Received: from localhost ([::1]:54498 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ddkOy-00047Q-MS for importer@patchew.org; Fri, 04 Aug 2017 17:45:00 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:39484) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ddkNT-0002zM-80 for qemu-devel@nongnu.org; Fri, 04 Aug 2017 17:43:28 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ddkNQ-0006hL-4M for qemu-devel@nongnu.org; Fri, 04 Aug 2017 17:43:27 -0400 Received: from mx1.redhat.com ([209.132.183.28]:43466) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ddkNP-0006gU-Uy for qemu-devel@nongnu.org; Fri, 04 Aug 2017 17:43:24 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 6533B4629B for ; Fri, 4 Aug 2017 21:36:31 +0000 (UTC) Received: from localhost (ovpn-116-46.gru2.redhat.com [10.97.116.46]) by smtp.corp.redhat.com (Postfix) with ESMTP id E9FDD5D9C0; Fri, 4 Aug 2017 21:36:30 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 6533B4629B Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=ehabkost@redhat.com From: Eduardo Habkost To: qemu-devel@nongnu.org Date: Fri, 4 Aug 2017 18:36:22 -0300 Message-Id: <20170804213625.3756-3-ehabkost@redhat.com> In-Reply-To: <20170804213625.3756-1-ehabkost@redhat.com> References: <20170804213625.3756-1-ehabkost@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Fri, 04 Aug 2017 21:36:31 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH for-2.11 2/5] qmp-shell: Pass split cmdargs to __build_cmd() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: armbru@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" This will allow us to implement a method to run a command that is already split in a list. Signed-off-by: Eduardo Habkost Reviewed-by: John Snow Reviewed-by: Stefan Hajnoczi Tested-by: John Snow --- scripts/qmp/qmp-shell | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/scripts/qmp/qmp-shell b/scripts/qmp/qmp-shell index c276b90..5fe6162 100755 --- a/scripts/qmp/qmp-shell +++ b/scripts/qmp/qmp-shell @@ -212,15 +212,13 @@ class QMPShell(qmp.QEMUMonitorProtocol): raise QMPShellError('Cannot set "%s" multiple times' %= key) parent[optpath[-1]] =3D value =20 - def __build_cmd(self, cmdline): + def __build_cmd(self, cmdargs): """ Build a QMP input object from a user provided command-line in the following format: =20 < command-name > [ arg-name1=3Darg1 ] ... [ arg-nameN=3DargN ] """ - cmdargs =3D cmdline.split() - # Transactional CLI entry/exit: if cmdargs[0] =3D=3D 'transaction(': self._transmode =3D True @@ -247,7 +245,7 @@ class QMPShell(qmp.QEMUMonitorProtocol): finalize =3D True self.__cli_expr(cmdargs[1:], action['data']) self._actions.append(action) - return self.__build_cmd(')') if finalize else None + return self.__build_cmd([')']) if finalize else None =20 # Standard command: parse and return it to be executed. qmpcmd =3D { 'execute': cmdargs[0], 'arguments': {} } @@ -262,8 +260,9 @@ class QMPShell(qmp.QEMUMonitorProtocol): print str(jsobj) =20 def _execute_cmd(self, cmdline): + cmdargs =3D cmdline.split() try: - qmpcmd =3D self.__build_cmd(cmdline) + qmpcmd =3D self.__build_cmd(cmdargs) except Exception as e: print 'Error while parsing command line: %s' % e print 'command format: ', --=20 2.9.4 From nobody Fri May 3 06:50:07 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1501882703324864.823105244291; Fri, 4 Aug 2017 14:38:23 -0700 (PDT) Received: from localhost ([::1]:54480 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ddkIX-0008Sn-NT for importer@patchew.org; Fri, 04 Aug 2017 17:38:21 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33714) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ddkGr-0007CP-1H for qemu-devel@nongnu.org; Fri, 04 Aug 2017 17:36:37 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ddkGq-0001kc-7G for qemu-devel@nongnu.org; Fri, 04 Aug 2017 17:36:37 -0400 Received: from mx1.redhat.com ([209.132.183.28]:34434) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ddkGq-0001in-1D for qemu-devel@nongnu.org; Fri, 04 Aug 2017 17:36:36 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 388E2883C1 for ; Fri, 4 Aug 2017 21:36:33 +0000 (UTC) Received: from localhost (ovpn-116-46.gru2.redhat.com [10.97.116.46]) by smtp.corp.redhat.com (Postfix) with ESMTP id C333A5D9C0; Fri, 4 Aug 2017 21:36:32 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 388E2883C1 Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=ehabkost@redhat.com From: Eduardo Habkost To: qemu-devel@nongnu.org Date: Fri, 4 Aug 2017 18:36:23 -0300 Message-Id: <20170804213625.3756-4-ehabkost@redhat.com> In-Reply-To: <20170804213625.3756-1-ehabkost@redhat.com> References: <20170804213625.3756-1-ehabkost@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Fri, 04 Aug 2017 21:36:33 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH for-2.11 3/5] qmp-shell: execute_cmdargs() method X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: armbru@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" This will allow us to execute a command that was already split in a list. Signed-off-by: Eduardo Habkost Reviewed-by: John Snow Reviewed-by: Stefan Hajnoczi Tested-by: John Snow --- scripts/qmp/qmp-shell | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/scripts/qmp/qmp-shell b/scripts/qmp/qmp-shell index 5fe6162..6113aaf 100755 --- a/scripts/qmp/qmp-shell +++ b/scripts/qmp/qmp-shell @@ -260,7 +260,9 @@ class QMPShell(qmp.QEMUMonitorProtocol): print str(jsobj) =20 def _execute_cmd(self, cmdline): - cmdargs =3D cmdline.split() + return self.execute_cmdargs(cmdline.split()) + + def execute_cmdargs(self, cmdargs): try: qmpcmd =3D self.__build_cmd(cmdargs) except Exception as e: @@ -386,6 +388,9 @@ class HMPShell(QMPShell): print '%s: %s' % (resp['error']['class'], resp['error']['desc'= ]) return True =20 + def execute_cmdargs(self, cmdargs): + return self._execute_cmd(' '.join(cmdargs)) + def show_banner(self): QMPShell.show_banner(self, msg=3D'Welcome to the HMP shell!') =20 --=20 2.9.4 From nobody Fri May 3 06:50:07 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1501882703236212.75003551414613; Fri, 4 Aug 2017 14:38:23 -0700 (PDT) Received: from localhost ([::1]:54479 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ddkIX-0008S9-71 for importer@patchew.org; Fri, 04 Aug 2017 17:38:21 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33720) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ddkGr-0007CZ-6w for qemu-devel@nongnu.org; Fri, 04 Aug 2017 17:36:38 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ddkGq-0001ki-AD for qemu-devel@nongnu.org; Fri, 04 Aug 2017 17:36:37 -0400 Received: from mx1.redhat.com ([209.132.183.28]:38644) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ddkGq-0001jx-45 for qemu-devel@nongnu.org; Fri, 04 Aug 2017 17:36:36 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 2269580468 for ; Fri, 4 Aug 2017 21:36:35 +0000 (UTC) Received: from localhost (ovpn-116-46.gru2.redhat.com [10.97.116.46]) by smtp.corp.redhat.com (Postfix) with ESMTP id A139160603; Fri, 4 Aug 2017 21:36:34 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 2269580468 Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=ehabkost@redhat.com From: Eduardo Habkost To: qemu-devel@nongnu.org Date: Fri, 4 Aug 2017 18:36:24 -0300 Message-Id: <20170804213625.3756-5-ehabkost@redhat.com> In-Reply-To: <20170804213625.3756-1-ehabkost@redhat.com> References: <20170804213625.3756-1-ehabkost@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Fri, 04 Aug 2017 21:36:35 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH for-2.11 4/5] qmp-shell: Accept QMP command as argument X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: armbru@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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=3D/ | jq -r .return[].na= me machine type chardevs backend $ Signed-off-by: Eduardo Habkost Reviewed-by: John Snow Reviewed-by: Stefan Hajnoczi Tested-by: John Snow --- scripts/qmp/qmp-shell | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/scripts/qmp/qmp-shell b/scripts/qmp/qmp-shell index 6113aaf..947fc36 100755 --- a/scripts/qmp/qmp-shell +++ b/scripts/qmp/qmp-shell @@ -410,6 +410,10 @@ def main(): default=3DTrue, help=3D'Skip negotiate (for qemu-ga)') parser.add_argument('addr', metavar=3D'ADDRESS', help=3D'QMP socket address (Unix socket path or TCP address:port)') + parser.add_argument('cmd', metavar=3D'COMMAND', nargs=3D'?', + help=3D'QMP command to be exeucted') + parser.add_argument('cmdargs', metavar=3D'ARG=3DVALUE', nargs=3D'*', + help=3D'Argument to QMP command') args =3D parser.parse_args() =20 try: @@ -429,10 +433,13 @@ def main(): except qemu.error: die('Could not connect to %s' % args.addr) =20 - qemu.show_banner() qemu.set_verbosity(args.verbose) - while qemu.read_exec_command(qemu.get_prompt()): - pass + if args.cmd: + qemu.execute_cmdargs([args.cmd] + args.cmdargs) + else: + qemu.show_banner() + while qemu.read_exec_command(qemu.get_prompt()): + pass qemu.close() =20 if __name__ =3D=3D '__main__': --=20 2.9.4 From nobody Fri May 3 06:50:07 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1501882706764323.589098880468; Fri, 4 Aug 2017 14:38:26 -0700 (PDT) Received: from localhost ([::1]:54481 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ddkIb-0008Va-CV for importer@patchew.org; Fri, 04 Aug 2017 17:38:25 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33827) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ddkGt-0007EE-J7 for qemu-devel@nongnu.org; Fri, 04 Aug 2017 17:36:40 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ddkGs-0001nJ-FF for qemu-devel@nongnu.org; Fri, 04 Aug 2017 17:36:39 -0400 Received: from mx1.redhat.com ([209.132.183.28]:34464) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ddkGs-0001m4-6T for qemu-devel@nongnu.org; Fri, 04 Aug 2017 17:36:38 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 20CC8883AB for ; Fri, 4 Aug 2017 21:36:37 +0000 (UTC) Received: from localhost (ovpn-116-46.gru2.redhat.com [10.97.116.46]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9DA5C69505; Fri, 4 Aug 2017 21:36:36 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 20CC8883AB Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=ehabkost@redhat.com From: Eduardo Habkost To: qemu-devel@nongnu.org Date: Fri, 4 Aug 2017 18:36:25 -0300 Message-Id: <20170804213625.3756-6-ehabkost@redhat.com> In-Reply-To: <20170804213625.3756-1-ehabkost@redhat.com> References: <20170804213625.3756-1-ehabkost@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Fri, 04 Aug 2017 21:36:37 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH for-2.11 5/5] Remove scripts/qmp/qmp X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: armbru@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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. Signed-off-by: Eduardo Habkost Reviewed-by: John Snow Reviewed-by: Stefan Hajnoczi Tested-by: John Snow --- 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 -# -# 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=3D[]): - if type(rsp) =3D=3D list: - i =3D 0 - for item in rsp: - if prefix =3D=3D []: - prefix =3D ['item'] - print_response(item, prefix[:-1] + ['%s[%d]' % (prefix[-1], i)= ]) - i +=3D 1 - elif type(rsp) =3D=3D 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 =3D None - - # Use QMP_PATH if it's set - if os.environ.has_key('QMP_PATH'): - path =3D os.environ['QMP_PATH'] - - while len(args): - arg =3D args[0] - - if arg.startswith('--'): - arg =3D arg[2:] - if arg.find('=3D') =3D=3D -1: - value =3D True - else: - arg, value =3D arg.split('=3D', 1) - - if arg in ['path']: - if type(value) =3D=3D str: - path =3D value - elif arg in ['help']: - os.execlp('man', 'man', 'qmp') - else: - print 'Unknown argument "%s"' % arg - - args =3D args[1:] - else: - break - - if not path: - print "QMP path isn't set, use --path=3Dqmp-monitor-address or set= QMP_PATH" - return 1 - - if len(args): - command, args =3D args[0], args[1:] - else: - print 'No command found' - print 'Usage: "qmp [--path=3Dqmp-monitor-address] qmp-cmd argument= s"' - return 1 - - if command in ['help']: - os.execlp('man', 'man', 'qmp') - - srv =3D QEMUMonitorProtocol(path) - srv.connect() - - def do_command(srv, cmd, **kwds): - rsp =3D srv.cmd(cmd, kwds) - if rsp.has_key('error'): - raise Exception(rsp['error']['desc']) - return rsp['return'] - - commands =3D map(lambda x: x['name'], do_command(srv, 'query-commands'= )) - - srv.close() - - if command not in commands: - fullcmd =3D 'qmp-%s' % command - try: - os.environ['QMP_PATH'] =3D path - os.execvp(fullcmd, [fullcmd] + args) - except OSError as exc: - if exc.errno =3D=3D 2: - print 'Command "%s" not found.' % (fullcmd) - return 1 - raise - return 0 - - srv =3D QEMUMonitorProtocol(path) - srv.connect() - - arguments =3D {} - for arg in args: - if not arg.startswith('--'): - print 'Unknown argument "%s"' % arg - return 1 - - arg =3D arg[2:] - if arg.find('=3D') =3D=3D -1: - value =3D True - else: - arg, value =3D arg.split('=3D', 1) - - if arg in ['help']: - os.execlp('man', 'man', 'qmp-%s' % command) - return 1 - - arguments[arg] =3D value - - rsp =3D do_command(srv, command, **arguments) - print_response(rsp) - -if __name__ =3D=3D '__main__': - sys.exit(main(sys.argv[1:])) --=20 2.9.4