go-qemu: github.com/digitalocean/go-qemu/qmp Index | Files | Directories

package qmp

import "github.com/digitalocean/go-qemu/qmp"

Package qmp enables interaction with QEMU instances via the QEMU Machine Protocol (QMP).

Index

Package Files

qmp.go rpc.go socket.go

Variables

var ErrEventsNotSupported = errors.New("event monitor is not supported")

ErrEventsNotSupported is returned by Events() if event streams are unsupported by either QEMU or libvirt.

type Command Uses

type Command struct {
    // Name of the command to run
    Execute string `json:"execute"`

    // Optional arguments for the above command.
    Args interface{} `json:"arguments,omitempty"`
}

Command represents a QMP command.

type Event Uses

type Event struct {
    // Event name, e.g., BLOCK_JOB_COMPLETE
    Event string `json:"event"`

    // Arbitrary event data
    Data map[string]interface{} `json:"data"`

    // Event timestamp, provided by QEMU.
    Timestamp struct {
        Seconds      int64 `json:"seconds"`
        Microseconds int64 `json:"microseconds"`
    }   `json:"timestamp"`
}

Event represents a QEMU QMP event. See http://wiki.qemu.org/QMP

type LibvirtRPCMonitor Uses

type LibvirtRPCMonitor struct {

    // Domain name as seen by libvirt, e.g., stage-lb-1
    Domain string
    // contains filtered or unexported fields
}

A LibvirtRPCMonitor implements LibVirt's remote procedure call protocol.

func NewLibvirtRPCMonitor Uses

func NewLibvirtRPCMonitor(domain string, conn net.Conn) *LibvirtRPCMonitor

NewLibvirtRPCMonitor configures a new Libvirt RPC Monitor connection. The provided domain should be the name of the domain as seen by libvirt, e.g., stage-lb-1.

func (*LibvirtRPCMonitor) Connect Uses

func (rpc *LibvirtRPCMonitor) Connect() error

Connect establishes communication with the libvirt server. The underlying libvirt socket connection must be previously established.

func (*LibvirtRPCMonitor) Disconnect Uses

func (rpc *LibvirtRPCMonitor) Disconnect() error

Disconnect shuts down communication with the libvirt server and closes the underlying net.Conn.

func (*LibvirtRPCMonitor) Events Uses

func (rpc *LibvirtRPCMonitor) Events() (<-chan Event, error)

Events streams QEMU QMP Events. If a problem is encountered setting up the event monitor connection an error will be returned. Errors encountered during streaming will cause the returned event channel to be closed.

func (*LibvirtRPCMonitor) Run Uses

func (rpc *LibvirtRPCMonitor) Run(cmd []byte) ([]byte, error)

Run executes the given QAPI command against a domain's QEMU instance. For a list of available QAPI commands, see:

http://git.qemu.org/?p=qemu.git;a=blob;f=qapi-schema.json;hb=HEAD

type Monitor Uses

type Monitor interface {
    Connect() error
    Disconnect() error
    Run(command []byte) (out []byte, err error)
    Events() (events <-chan Event, err error)
}

Monitor represents a QEMU Machine Protocol socket. See: http://wiki.qemu.org/QMP

type SocketMonitor Uses

type SocketMonitor struct {
    // QEMU version reported by a connected monitor socket.
    Version *Version
    // contains filtered or unexported fields
}

A SocketMonitor is a Monitor which speaks directly to a QEMU Machine Protocol (QMP) socket. Communication is performed directly using a QEMU monitor socket, typically using a UNIX socket or TCP connection. Multiple connections to the same domain are not permitted, and will result in the monitor blocking until the existing connection is closed.

func Listen Uses

func Listen(network, addr string) (*SocketMonitor, error)

Listen creates a new SocketMonitor listening for a single connection to the provided socket file or address. An error is returned if unable to listen at the specified file path or port.

Listen will wait for a QEMU socket connection using a variety connection types:

Listen("unix", "/var/lib/qemu/example.monitor")
Listen("tcp", "0.0.0.0:4444")

func NewSocketMonitor Uses

func NewSocketMonitor(network, addr string, timeout time.Duration) (*SocketMonitor, error)

NewSocketMonitor configures a connection to the provided QEMU monitor socket. An error is returned if the socket cannot be successfully dialed, or the dial attempt times out.

NewSocketMonitor may dial the QEMU socket using a variety of connection types:

NewSocketMonitor("unix", "/var/lib/qemu/example.monitor", 2 * time.Second)
NewSocketMonitor("tcp", "8.8.8.8:4444", 2 * time.Second)

func (*SocketMonitor) Connect Uses

func (mon *SocketMonitor) Connect() error

Connect sets up a QEMU QMP connection by connecting directly to the QEMU monitor socket. An error is returned if the capabilities handshake does not succeed.

func (*SocketMonitor) Disconnect Uses

func (mon *SocketMonitor) Disconnect() error

Disconnect closes the QEMU monitor socket connection.

func (*SocketMonitor) Events Uses

func (mon *SocketMonitor) Events() (<-chan Event, error)

Events streams QEMU QMP Events. Events should only be called once per Socket. If used with a qemu.Domain, qemu.Domain.Events should be called to retrieve events instead.

func (*SocketMonitor) Run Uses

func (mon *SocketMonitor) Run(command []byte) ([]byte, error)

Run executes the given QAPI command against a domain's QEMU instance. For a list of available QAPI commands, see:

http://git.qemu.org/?p=qemu.git;a=blob;f=qapi-schema.json;hb=HEAD

type Version Uses

type Version struct {
    Package string `json:"package"`
    QEMU    struct {
        Major int `json:"major"`
        Micro int `json:"micro"`
        Minor int `json:"minor"`
    }   `json:"qemu"`
}

Version is the QEMU version structure returned when a QMP connection is initiated.

func (Version) String Uses

func (v Version) String() string

Directories

PathSynopsis
qmptestPackage qmptest provides types which assist in testing interactions with package qmp.
rawPackage raw provides automatically generated QMP types based on the QMP schema.

Package qmp imports 10 packages (graph) and is imported by 16 packages. Updated 2018-11-13. Refresh now. Tools for package owners.