From nobody Thu May 2 16:41:40 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1664967080; cv=none; d=zohomail.com; s=zohoarc; b=ILDoFJpwSlRBAY87jl/g3XpYczuxaqQB9hUdTn8IPQ33/31ZvnzTOlz6YWgunRpY0Mlvm4gPHsdz6wrwjAHY1WmgX6tzvBcmq+JhD3b4hxqezFlv46KSbYjVd/0/H4FNxdZbog7BZYg0D6JmV3GcHiycQxVYEw41deF4UL9fULk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1664967080; h=Content-Type:Content-Transfer-Encoding:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=ah9M4HJzy1JXDVdRF2XrIsjuPX+/vd4wWQucuFmGB+Y=; b=MBQX3tVjXmKJiI7rjXASqiffaixH0dkePrDTTYRRCNYT438baUJEU9xYklJPqOid6gteH1cYSZ6wJkRUEIZ5fIGiPHBjo36UNjaRdjpOygzGUAkR3taK+5TYwJN4gny0gXbLN61OnEw0xzLS4NWQE18CRdnwKTbxVXC2TtVYpAU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.zohomail.com with SMTPS id 166496708011417.63049125924522; Wed, 5 Oct 2022 03:51:20 -0700 (PDT) Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-572-67zxf7tKNB6PMpcQ2UIbyg-1; Wed, 05 Oct 2022 06:51:15 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 0452C91887C; Wed, 5 Oct 2022 10:51:13 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (unknown [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5393142220; Wed, 5 Oct 2022 10:51:11 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 128511946A5A; Wed, 5 Oct 2022 10:51:10 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id CD1A61946A4E for ; Wed, 5 Oct 2022 10:51:08 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 89FBD4A9254; Wed, 5 Oct 2022 10:51:08 +0000 (UTC) Received: from localhost.localdomain.com (unknown [10.33.36.54]) by smtp.corp.redhat.com (Postfix) with ESMTP id EBB5149BB60; Wed, 5 Oct 2022 10:51:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1664967079; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=ah9M4HJzy1JXDVdRF2XrIsjuPX+/vd4wWQucuFmGB+Y=; b=C/8VCf/U23yG2wcOBWlMWpyxEoDfsS+u4FN/Kbqn93UWi2RKYX0JNKOb3JKm58VUXZjaam 06mzCRdgECobWGMXJJg+wsTvs2COpH1j9QeRN8VMaeVT1kAYCXQwv+RkKGUlJR4bOV2JLL JKTjxSvoqO7YAgk0j6Kqc/2/29SdHMA= X-MC-Unique: 67zxf7tKNB6PMpcQ2UIbyg-1 X-Original-To: libvir-list@listman.corp.redhat.com From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Subject: [libvirt PATCH v3] tools: add virt-qemu-qmp-proxy for proxying QMP via libvirt QEMU guests Date: Wed, 5 Oct 2022 11:51:05 +0100 Message-Id: <20221005105105.1169638-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.9 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 3.1 on 10.11.54.5 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1664967081221100001 Libvirt provides QMP passthrough APIs for the QEMU driver and these are exposed in virsh. It is not especially pleasant, however, using the raw QMP JSON syntax. QEMU has a tool 'qmp-shell' which can speak QMP and exposes a human friendly interactive shell. It is not possible to use this with libvirt managed guest, however, since only one client can attach to the QMP socket at any point in time. While it would be possible to configure a second QMP socket for a VM, it may not be an known requirement at the time the guest is provisioned. The virt-qmp-proxy tool aims to solve this problem. It opens a UNIX socket and listens for incoming client connections, speaking QMP on the connected socket. It will forward any QMP commands received onto the running libvirt QEMU guest, and forward any replies back to the QMP client. It will also forward back events. $ virsh start demo $ virt-qmp-proxy demo demo.qmp & $ qmp-shell demo.qmp Welcome to the QMP low-level shell! Connected to QEMU 6.2.0 (QEMU) query-kvm { "return": { "enabled": true, "present": true } } Note this tool of course has the same risks as the raw libvirt QMP passthrough. It is safe to run query commands to fetch information but commands which change the QEMU state risk disrupting libvirt's management of QEMU, potentially resulting in data loss/corruption in the worst case. Any use of this tool will cause the guest to be marked as tainted as an warning that it could be in an unexpected state. Since this tool introduces a python dependency it is not desirable to include it in any of the existing RPMs in libvirt. This tool is also QEMU specific, so isn't appropriate to bundle with the generic tools. Thus a new RPM is introduced 'libvirt-clients-qemu', to contain additional QEMU specific tools, with extra external deps. Signed-off-by: Daniel P. Berrang=C3=A9 Reviewed-by: Michal Privoznik --- In v3: - Added to libvirt-clients-qemu RPM - Renamed to virt-qemu-qmp-proxy docs/manpages/meson.build | 1 + docs/manpages/virt-qemu-qmp-proxy.rst | 120 +++++++++ libvirt.spec.in | 15 ++ tools/meson.build | 5 + tools/virt-qemu-qmp-proxy | 360 ++++++++++++++++++++++++++ 5 files changed, 501 insertions(+) create mode 100644 docs/manpages/virt-qemu-qmp-proxy.rst create mode 100755 tools/virt-qemu-qmp-proxy diff --git a/docs/manpages/meson.build b/docs/manpages/meson.build index ba673cf472..83933227d9 100644 --- a/docs/manpages/meson.build +++ b/docs/manpages/meson.build @@ -18,6 +18,7 @@ docs_man_files =3D [ { 'name': 'virt-pki-query-dn', 'section': '1', 'install': true }, { 'name': 'virt-pki-validate', 'section': '1', 'install': true }, { 'name': 'virt-qemu-run', 'section': '1', 'install': conf.has('WITH_QEM= U') }, + { 'name': 'virt-qemu-qmp-proxy', 'section': '1', 'install': conf.has('WI= TH_QEMU') }, { 'name': 'virt-xml-validate', 'section': '1', 'install': true }, =20 { 'name': 'libvirt-guests', 'section': '8', 'install': conf.has('WITH_LI= BVIRTD') }, diff --git a/docs/manpages/virt-qemu-qmp-proxy.rst b/docs/manpages/virt-qem= u-qmp-proxy.rst new file mode 100644 index 0000000000..b387474b19 --- /dev/null +++ b/docs/manpages/virt-qemu-qmp-proxy.rst @@ -0,0 +1,120 @@ +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D +virt-qemu-qmp-proxy +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + +-------------------------------------------------- +Expose a QMP proxy server for a libvirt QEMU guest +-------------------------------------------------- + +:Manual section: 1 +:Manual group: Virtualization Support + +.. contents:: + + +SYNOPSIS +=3D=3D=3D=3D=3D=3D=3D=3D + +``virt-qemu-qmp-proxy`` [*OPTION*]... *DOMAIN* *QMP-SOCKET-PATH* + + +DESCRIPTION +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + +This tool provides a way to expose a QMP proxy server that communicates +with a QEMU guest managed by libvirt. This enables standard QMP client +tools to interact with libvirt managed guests. + +**NOTE: use of this tool will result in the running QEMU guest being +marked as tainted.** It is strongly recommended that this tool *only be +used to send commands which query information* about the running guest. +If this tool is used to make changes to the state of the guest, this +may have negative interactions with the QEMU driver, resulting in an +inability to manage the guest operation thereafter, and in the worst +case **potentially lead to data loss or corruption**. + +The ``virt-qemu-qmp-proxy`` program will listen on a UNIX socket for incom= ing +client connections, and run the QMP protocol over the connection. Any +commands received will be sent to the running libvirt guest, and replies +sent back. + +The ``virt-qemu-qmp-proxy`` program may be interrupted (eg Ctrl-C) when it +is no longer required. The libvirt QEMU guest will continue running. + + +OPTIONS +=3D=3D=3D=3D=3D=3D=3D + +*DOMAIN* + +The ID or UUID or Name of the libvirt QEMU guest. + +*QMP-SOCKET-PATH* + +The filesystem path at which to run the QMP server, listening for +incoming connections. + +``-c`` *CONNECTION-URI* +``--connect``\ =3D\ *CONNECTION-URI* + +The URI for the connection to the libvirt QEMU driver. If omitted, +a URI will be auto-detected. + +``-v``, ``--verbose`` + +Run in verbose mode, printing all QMP commands and replies that +are handled. + +``-h``, ``--help`` + +Display the command line help. + + +EXIT STATUS +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + +Upon successful shutdown, an exit status of 0 will be set. Upon +failure a non-zero status will be set. + + +AUTHOR +=3D=3D=3D=3D=3D=3D + +Daniel P. Berrang=C3=A9 + + +BUGS +=3D=3D=3D=3D + +Please report all bugs you discover. This should be done via either: + +#. the mailing list + + `https://libvirt.org/contact.html `_ + +#. the bug tracker + + `https://libvirt.org/bugs.html `_ + +Alternatively, you may report bugs to your software distributor / vendor. + +COPYRIGHT +=3D=3D=3D=3D=3D=3D=3D=3D=3D + +Copyright (C) 2022 by Red Hat, Inc. + + +LICENSE +=3D=3D=3D=3D=3D=3D=3D + +``virt-qemu-qmp-proxy`` is distributed under the terms of the GNU LGPL v2+. +This is free software; see the source for copying conditions. There +is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR +PURPOSE + + +SEE ALSO +=3D=3D=3D=3D=3D=3D=3D=3D + +virsh(1), `https://libvirt.org/ `_, +`QMP reference `_ diff --git a/libvirt.spec.in b/libvirt.spec.in index 950c5a3b6d..3082285dc0 100644 --- a/libvirt.spec.in +++ b/libvirt.spec.in @@ -899,6 +899,15 @@ Obsoletes: libvirt-bash-completion < 7.3.0 The client binaries needed to access the virtualization capabilities of recent versions of Linux (and other OSes). =20 +%package client-qemu +Summary: Additional client side utilities for QEMU +Requires: %{name}-libs =3D %{version}-%{release} +Requires: python3-libvirt >=3D %{version}-%{release} + +%description client-qemu +The additional client binaries are used to interact +with some QEMU specific features of libvirt. + %package libs Summary: Client side libraries # So remote clients can access libvirt over SSH tunnel @@ -2159,6 +2168,12 @@ exit 0 =20 %{_datadir}/bash-completion/completions/virsh =20 +%if %{with_qemu} +%files client-qemu +%{_mandir}/man1/virt-qemu-qmp-proxy.1* +%{_bindir}/virt-qemu-qmp-proxy +%endif + %files libs -f %{name}.lang %license COPYING COPYING.LESSER %dir %attr(0700, root, root) %{_sysconfdir}/libvirt/ diff --git a/tools/meson.build b/tools/meson.build index bb28a904dc..20509906af 100644 --- a/tools/meson.build +++ b/tools/meson.build @@ -320,6 +320,11 @@ if conf.has('WITH_LIBVIRTD') endif endif =20 +if conf.has('WITH_QEMU') + install_data('virt-qemu-qmp-proxy', + install_dir: bindir) +endif + if bash_completion_dep.found() subdir('bash-completion') endif diff --git a/tools/virt-qemu-qmp-proxy b/tools/virt-qemu-qmp-proxy new file mode 100755 index 0000000000..d85342bd2b --- /dev/null +++ b/tools/virt-qemu-qmp-proxy @@ -0,0 +1,360 @@ +#!/usr/bin/env python3 + +import argparse +import array +import libvirt +import libvirt_qemu +import os +import re +import socket +import sys +import traceback +import json +import fcntl + + +debug =3D False + +def get_domain(uri, domstr): + conn =3D libvirt.open(uri) + + dom =3D None + saveex =3D None + + def try_lookup(cb): + try: + return cb() + except libvirt.libvirtError as ex: + nonlocal saveex + if saveex is None: + saveex =3D ex + + if re.match(r'^\d+$', domstr): + dom =3D try_lookup(lambda: conn.lookupByID(int(domstr))) + + if dom is None and re.match(r'^[-a-f0-9]{36}|[a-f0-9]{32}$', domstr): + dom =3D try_lookup(lambda: conn.lookupByUUIDString(domstr)) + + if dom is None: + dom =3D try_lookup(lambda: conn.lookupByName(domstr)) + + if dom is None: + raise saveex + + if not dom.isActive(): + raise Exception("Domain must be running to use QMP") + + return conn, dom + + +class QMPProxy(object): + + def __init__(self, conn, dom, serversock, verbose): + self.conn =3D conn + self.dom =3D dom + self.verbose =3D verbose + + self.serversock =3D serversock + self.serverwatch =3D 0 + + self.clientsock =3D None + self.clientwatch =3D 0 + + self.api2sock =3D bytes([]) + self.api2sockfds =3D [] + + self.sock2api =3D bytes([]) + self.sock2apifds =3D [] + + self.serverwatch =3D libvirt.virEventAddHandle( + self.serversock.fileno(), libvirt.VIR_EVENT_HANDLE_READABLE, + self.handle_server_io, self) + + libvirt_qemu.qemuMonitorEventRegister(self.conn, self.dom, + None, + self.handle_qmp_event, + self) + + + @staticmethod + def handle_qmp_event(conn, dom, event, secs, usecs, details, self): + evdoc =3D { + "event": event, + "timestamp": {"seconds": secs, "microseconds": usecs } + } + if details is not None: + evdoc["data"] =3D details + + ev =3D json.dumps(evdoc) + if self.verbose: + print(ev) + ev +=3D "\r\n" + self.api2sock +=3D ev.encode("utf-8") + self.update_client_events() + + + def recv_with_fds(self): + # Match VIR_NET_MESSAGE_NUM_FDS_MAX in virnetprotocol.x + maxfds =3D 32 + fds =3D array.array('i') + cmsgdatalen =3D socket.CMSG_LEN(maxfds * fds.itemsize) + + data, cmsgdata, flags, addr =3D self.clientsock.recvmsg(1024, + cmsgdatalen) + for cmsg_level, cmsg_type, cmsg_data in cmsgdata: + if (cmsg_level =3D=3D socket.SOL_SOCKET and + cmsg_type =3D=3D socket.SCM_RIGHTS): + fds.frombytes(cmsg_data[:len(cmsg_data) - + (len(cmsg_data) % fds.itemsize)]) + else: + raise Exception("Unexpected CMSGDATA level %d type %d" % ( + cmsg_level, cmsg_type)) + + return data, [self.make_file(fd) for fd in fds] + + + def send_with_fds(self, data, fds): + cfds =3D [fd.fileno() for fd in fds] + + cmsgdata =3D [(socket.SOL_SOCKET, socket.SCM_RIGHTS, + array.array("i", cfds))] + + return self.clientsock.sendmsg([data], cmsgdata) + + + @staticmethod + def make_file(fd): + flags =3D fcntl.fcntl(fd, fcntl.F_GETFL) + + mask =3D os.O_RDONLY | os.O_WRONLY | os.O_RDWR | os.O_APPEND + flags =3D flags & mask + mode =3D "" + if flags =3D=3D os.O_RDONLY: + mode =3D "rb" + elif flags =3D=3D os.O_WRONLY: + mode =3D "wb" + elif flags =3D=3D os.O_RDWR: + mode =3D "r+b" + elif flags =3D=3D (os.O_WRONLY | os.O_APPEND): + mode =3D "ab" + elif flags =3D=3D (os.O_RDWR | os.O_APPEND): + mode =3D "a+b" + + return os.fdopen(fd, mode) + + + def add_client(self, sock): + ver =3D self.conn.getVersion() + major =3D int(ver / 1000000) % 1000 + minor =3D int(ver / 1000) % 1000 + micro =3D ver % 1000 + + greetingobj =3D { + "QMP": { + "version": { + "qemu": { + "major": major, + "minor": minor, + "micro": micro, + }, + "package": f"qemu-{major}.{minor}.{micro}", + }, + "capabilities": [ + "oob" + ], + } + } + greeting =3D json.dumps(greetingobj) + if self.verbose: + print(greeting) + greeting +=3D "\r\n" + + self.clientsock =3D sock + self.clientwatch =3D libvirt.virEventAddHandle( + self.clientsock.fileno(), libvirt.VIR_EVENT_HANDLE_WRITABLE, + self.handle_client_io, self) + self.api2sock +=3D greeting.encode("utf-8") + self.update_server_events() + + + def remove_client(self): + libvirt.virEventRemoveHandle(self.clientwatch) + self.clientsock.close() + self.clientsock =3D None + self.clientwatch =3D 0 + self.update_server_events() + + self.api2sock =3D bytes([]) + self.api2sockfds =3D [] + + self.sock2api =3D bytes([]) + self.sock2apifds =3D [] + + + def update_client_events(self): + # For simplicity of tracking distinct QMP cmds and their passed FDs + # we don't try to support "pipelining", only a single cmd may be + # inflight + if len(self.api2sock) > 0: + events =3D libvirt.VIR_EVENT_HANDLE_WRITABLE + else: + events =3D libvirt.VIR_EVENT_HANDLE_READABLE + + libvirt.virEventUpdateHandle(self.clientwatch, events) + + + def update_server_events(self): + if self.clientsock is not None: + libvirt.virEventUpdateHandle(self.serverwatch, 0) + else: + libvirt.virEventUpdateHandle(self.serverwatch, + libvirt.VIR_EVENT_HANDLE_READABLE) + + + def try_command(self): + try: + cmdstr =3D self.sock2api.decode("utf-8") + cmd =3D json.loads(cmdstr) + + if self.verbose: + cmdstr =3D cmdstr.strip() + print(cmdstr) + except Exception as ex: + if debug: + print("Incomplete %s: %s" % ( self.sock2api, ex)) + return + + id =3D None + if "id" in cmd: + id =3D cmd["id"] + del cmd["id"] + + if cmd.get("execute", "") =3D=3D "qmp_capabilities": + resobj =3D { + "return": {}, + } + resfds =3D [] + else: + if hasattr(libvirt_qemu, "qemuMonitorCommandWithFiles"): + res, resfds =3D libvirt_qemu.qemuMonitorCommandWithFiles( + self.dom, json.dumps(cmd), [f.fileno() for f in self.s= ock2apifds]) + resobj =3D json.loads(res) + else: + if len(self.sock2apifds) > 0: + raise Exception("FD passing not supported") + res =3D libvirt_qemu.qemuMonitorCommand( + self.dom, json.dumps(cmd)) + resfds =3D [] + resobj =3D json.loads(res) + + if "id" in resobj: + del resobj["id"] + if id is not None: + resobj["id"] =3D id + + res =3D json.dumps(resobj) + if self.verbose: + print(res) + res +=3D "\r\n" + + self.sock2api =3D bytes([]) + self.sock2apifds =3D [] + self.api2sock +=3D res.encode("utf-8") + self.api2sockfds =3D resfds + + + @staticmethod + def handle_client_io(watch, fd, events, self): + error =3D False + try: + if events & libvirt.VIR_EVENT_HANDLE_WRITABLE: + done =3D self.send_with_fds(self.api2sock, self.api2sockfd= s) + if done > 0: + self.api2sock =3D self.api2sock[done:] + self.api2sockfds =3D [] + elif events & libvirt.VIR_EVENT_HANDLE_READABLE: + data, fds =3D self.recv_with_fds() + if len(data) =3D=3D 0: + error =3D True + else: + self.sock2api +=3D data + if len(fds): + self.sock2apifds +=3D fds + + self.try_command() + else: + error =3D True + except Exception as e: + global debug + if debug: + print("%s: %s" % (sys.argv[0], str(e))) + print(traceback.format_exc()) + error =3D True + + if error: + self.remove_client() + else: + self.update_client_events() + + + @staticmethod + def handle_server_io(watch, fd, events, self): + if self.clientsock is None: + sock, addr =3D self.serversock.accept() + self.add_client(sock) + else: + self.update_server_events() + + +def parse_commandline(): + parser =3D argparse.ArgumentParser(description=3D"Libvirt QMP proxy") + parser.add_argument("--connect", "-c", + help=3D"Libvirt QEMU driver connection URI") + parser.add_argument("--debug", "-d", action=3D'store_true', + help=3D"Display debugging information") + parser.add_argument("--verbose", "-v", action=3D'store_true', + help=3D"Display QMP traffic") + parser.add_argument("domain", metavar=3D"DOMAIN", + help=3D"Libvirt guest domain ID/UUID/Name") + parser.add_argument("sockpath", metavar=3D"QMP-SOCK-PATH", + help=3D"UNIX socket path for QMP server") + + return parser.parse_args() + + +def main(): + args =3D parse_commandline() + global debug + debug =3D args.debug + + if not debug: + libvirt.registerErrorHandler(lambda opaque, error: None, None) + + libvirt.virEventRegisterDefaultImpl() + + conn, dom =3D get_domain(args.connect, args.domain) + + if conn.getType() !=3D "QEMU": + raise Exception("QMP proxy requires a QEMU driver connection not %= s" % + conn.getType()) + + sock =3D socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) + if os.path.exists(args.sockpath): + os.unlink(args.sockpath) + sock.bind(args.sockpath) + sock.listen(1) + + proxy =3D QMPProxy(conn, dom, sock, args.verbose) + + while True: + libvirt.virEventRunDefaultImpl() + + +try: + main() + sys.exit(0) +except Exception as e: + print("%s: %s" % (sys.argv[0], str(e))) + if debug: + print(traceback.format_exc()) + sys.exit(1) --=20 2.37.3