From patchwork Fri Oct 29 14:28:34 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luiz Capitulino X-Patchwork-Id: 69595 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 88225B70DC for ; Sat, 30 Oct 2010 01:36:15 +1100 (EST) Received: from localhost ([127.0.0.1]:48279 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PBq3v-00011g-B1 for incoming@patchwork.ozlabs.org; Fri, 29 Oct 2010 10:36:11 -0400 Received: from [140.186.70.92] (port=50482 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PBpwq-00057p-FA for qemu-devel@nongnu.org; Fri, 29 Oct 2010 10:28:54 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PBpwj-0006vU-6f for qemu-devel@nongnu.org; Fri, 29 Oct 2010 10:28:52 -0400 Received: from mx1.redhat.com ([209.132.183.28]:14523) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PBpwj-0006uy-0M for qemu-devel@nongnu.org; Fri, 29 Oct 2010 10:28:45 -0400 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o9TESiET020588 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Fri, 29 Oct 2010 10:28:44 -0400 Received: from localhost (ovpn-113-85.phx2.redhat.com [10.3.113.85]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o9TEShA9012375; Fri, 29 Oct 2010 10:28:43 -0400 From: Luiz Capitulino To: qemu-devel@nongnu.org Date: Fri, 29 Oct 2010 12:28:34 -0200 Message-Id: <1288362514-31407-4-git-send-email-lcapitulino@redhat.com> In-Reply-To: <1288362514-31407-1-git-send-email-lcapitulino@redhat.com> References: <1288362514-31407-1-git-send-email-lcapitulino@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.12 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. Cc: aliguori@us.ibm.com, armbru@redhat.com Subject: [Qemu-devel] [PATCH 3/3] QMP/qmp-shell: Introduce HMP mode X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org In which qmp-shell will exclusively use the HMP passthrough feature, this is useful for testing. Example: (QEMU) info network VLAN 0 devices: user.0: net=10.0.2.0, restricted=n e1000.0: model=e1000,macaddr=52:54:00:12:34:56 Devices not on any VLAN: (QEMU) Signed-off-by: Luiz Capitulino --- QMP/qmp-shell | 70 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 70 insertions(+), 0 deletions(-) diff --git a/QMP/qmp-shell b/QMP/qmp-shell index 1fb7e76..8eb5b3e 100755 --- a/QMP/qmp-shell +++ b/QMP/qmp-shell @@ -145,6 +145,72 @@ class QMPShell(qmp.QEMUMonitorProtocol): else: return self._execute_cmd(cmdline) +class HMPShell(QMPShell): + def __init__(self, address): + QMPShell.__init__(self, address) + self.__cpu_index = 0 + + def __cmd_completion(self): + for cmd in self.__cmd_passthrough('help')['return'].split('\r\n'): + if cmd and cmd[0] != '[' and cmd[0] != '\t': + name = cmd.split()[0] # drop help text + if name == 'info': + continue + if name.find('|') != -1: + # Command in the form 'foobar|f' or 'f|foobar', take the + # full name + opt = name.split('|') + if len(opt[0]) == 1: + name = opt[1] + else: + name = opt[0] + self._completer.append(name) + self._completer.append('help ' + name) # help completion + + def __info_completion(self): + for cmd in self.__cmd_passthrough('info')['return'].split('\r\n'): + if cmd: + self._completer.append('info ' + cmd.split()[1]) + + def __other_completion(self): + # special cases + self._completer.append('help info') + + def _fill_completion(self): + self.__cmd_completion() + self.__info_completion() + self.__other_completion() + + def __cmd_passthrough(self, cmdline): + return self.cmd_obj({ 'execute': 'hmp_passthrough', 'arguments': + { 'command-line': cmdline, + 'cpu-index': self.__cpu_index } }) + + def _execute_cmd(self, cmdline): + if cmdline.split()[0] == "cpu": + # trap the cpu command, it requires special setting + try: + self.__cpu_index = int(cmdline.split()[1]) + except ValueError: + print 'cpu command takes an integer argument' + return True + resp = self.__cmd_passthrough(cmdline) + if resp is None: + print 'Disconnected' + return False + assert 'return' in resp or 'error' in resp + if 'return' in resp: + # Success + if len(resp['return']) > 0: + print resp['return'], + else: + # Error + print '%s: %s' % (resp['error']['class'], resp['error']['desc']) + return True + + def show_banner(self): + QMPShell.show_banner(self, msg='Welcome to the HMP shell!') + def die(msg): sys.stderr.write('ERROR: %s\n' % msg) sys.exit(1) @@ -159,6 +225,10 @@ def main(): try: if len(sys.argv) == 2: qemu = QMPShell(sys.argv[1]) + elif len(sys.argv) == 3: + if sys.argv[1] != '-H': + fail_cmdline(sys.argv[1]) + qemu = HMPShell(sys.argv[2]) else: fail_cmdline() except QMPShellBadPort: