If your QEMU instances are managed by Libvirt, you can use one of two drivers to proxy QMP requests through the Libvirt daemon:
- RPC Driver: A pure Go implementation of Libvirt's RPC protocol. You establish a connection using
net.DialTimeout and initialize the monitor using libvirtrpc.New. - virsh Driver: Proxies requests through the
virsh executable. You can initialize this using qmp.NewLibvirtMonitor.
Note: The RPC driver requires a connection object (e.g., via unix or tcp) and a domain name.
// RPC Driver example
//conn, err := net.DialTimeout("unix", "/var/run/libvirt/libvirt-sock", 2*time.Second)
conn, err := net.DialTimeout("tcp", "192.168.1.1:16509", 2*time.Second)
monitor := libvirtrpc.New("stage-lb-1", conn)
// virsh Driver example
monitor, err := qmp.NewLibvirtMonitor("qemu:///system", "stage-lb-1")