From patchwork Fri Jul 22 08:00:49 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amit Shah X-Patchwork-Id: 651565 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3rwjzX28FXz9srZ for ; Fri, 22 Jul 2016 18:11:52 +1000 (AEST) Received: from localhost ([::1]:45743 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bQVYk-0001Kx-3w for incoming@patchwork.ozlabs.org; Fri, 22 Jul 2016 04:11:50 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52848) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bQVOY-0000RI-Ps for qemu-devel@nongnu.org; Fri, 22 Jul 2016 04:01:19 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bQVOW-0006i3-PO for qemu-devel@nongnu.org; Fri, 22 Jul 2016 04:01:17 -0400 Received: from mx1.redhat.com ([209.132.183.28]:46913) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bQVOW-0006hx-Jy for qemu-devel@nongnu.org; Fri, 22 Jul 2016 04:01:16 -0400 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 270CA73057; Fri, 22 Jul 2016 08:01:16 +0000 (UTC) Received: from localhost (ovpn-116-64.phx2.redhat.com [10.3.116.64]) by int-mx14.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u6M81E16027661; Fri, 22 Jul 2016 04:01:15 -0400 From: Amit Shah To: qemu list Date: Fri, 22 Jul 2016 13:30:49 +0530 Message-Id: <991e7c46504807bd89ba8debeccc5211e0b7f221.1469174334.git.amit.shah@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.68 on 10.5.11.27 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Fri, 22 Jul 2016 08:01:16 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 3/7] scripts: add a 'debug' parameter to QEMUMonitorProtocol 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: Amit Shah , Peter Maydell , "Dr. David Alan Gilbert" , Juan Quintela Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: "Daniel P. Berrange" Add a 'debug' parameter to the QEMUMonitorProtocol class which will cause it to print out all JSON strings on sys.stderr Signed-off-by: Daniel P. Berrange Message-Id: <1469020993-29426-3-git-send-email-berrange@redhat.com> Signed-off-by: Amit Shah --- scripts/qmp/qmp.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/scripts/qmp/qmp.py b/scripts/qmp/qmp.py index 779332f..70e927e 100644 --- a/scripts/qmp/qmp.py +++ b/scripts/qmp/qmp.py @@ -11,6 +11,7 @@ import json import errno import socket +import sys class QMPError(Exception): pass @@ -25,7 +26,7 @@ class QMPTimeoutError(QMPError): pass class QEMUMonitorProtocol: - def __init__(self, address, server=False): + def __init__(self, address, server=False, debug=False): """ Create a QEMUMonitorProtocol class. @@ -39,6 +40,7 @@ class QEMUMonitorProtocol: """ self.__events = [] self.__address = address + self._debug = debug self.__sock = self.__get_sock() if server: self.__sock.bind(self.__address) @@ -68,6 +70,8 @@ class QEMUMonitorProtocol: return resp = json.loads(data) if 'event' in resp: + if self._debug: + print >>sys.stderr, "QMP:<<< %s" % resp self.__events.append(resp) if not only_event: continue @@ -148,13 +152,18 @@ class QEMUMonitorProtocol: @return QMP response as a Python dict or None if the connection has been closed """ + if self._debug: + print >>sys.stderr, "QMP:>>> %s" % qmp_cmd try: self.__sock.sendall(json.dumps(qmp_cmd)) except socket.error as err: if err[0] == errno.EPIPE: return raise socket.error(err) - return self.__json_read() + resp = self.__json_read() + if self._debug: + print >>sys.stderr, "QMP:<<< %s" % resp + return resp def cmd(self, name, args=None, id=None): """