vmhost

package
v0.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 6, 2026 License: AGPL-3.0 Imports: 9 Imported by: 0

Documentation

Overview

Package vmhost implements the control protocol between the mb daemon and per-VM vmhost child processes. Each vmhost process manages exactly one VM and exposes a JSON-RPC control socket (vmhost.sock) for lifecycle operations.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client communicates with a vmhost process over its control socket.

func NewClient

func NewClient(socketPath string) *Client

NewClient creates a new vmhost client for the given socket path.

func (*Client) ForceStop

func (c *Client) ForceStop() (*Response, error)

ForceStop sends an immediate termination request.

func (*Client) Info

func (c *Client) Info() (*Response, error)

Info queries detailed VM information from the vmhost process.

func (*Client) IsAlive

func (c *Client) IsAlive() bool

IsAlive checks if the vmhost process is reachable by sending a status request. Returns true if the vmhost responds, false otherwise.

func (*Client) Status

func (c *Client) Status() (*Response, error)

Status queries the VM state from the vmhost process.

func (*Client) Stop

func (c *Client) Stop(timeoutSeconds int) (*Response, error)

Stop sends a graceful shutdown request with the given timeout.

type Method

type Method string

Method identifies an RPC call from the daemon to a vmhost process.

const (
	MethodStatus    Method = "status"
	MethodStop      Method = "stop"
	MethodForceStop Method = "force_stop"
	MethodInfo      Method = "info"
)

type Request

type Request struct {
	Method Method `json:"method"`

	// Stop parameters
	TimeoutSeconds int `json:"timeout_seconds,omitempty"`
}

Request is the wire format for daemon -> vmhost RPC calls.

type Response

type Response struct {
	OK    bool   `json:"ok"`
	Error string `json:"error,omitempty"`

	// Status/Info fields
	State   string `json:"state,omitempty"`
	SSHPort int    `json:"ssh_port,omitempty"`
	Backend string `json:"backend,omitempty"`
}

Response is the wire format for vmhost -> daemon responses.

type Server

type Server struct {
	// contains filtered or unexported fields
}

Server is the vmhost control socket server. It listens on vmhost.sock and dispatches requests to the VMController.

func NewServer

func NewServer(socketPath, pidPath string, controller VMController, logger *log.Logger) *Server

NewServer creates a new vmhost control server.

func (*Server) Run

func (s *Server) Run(ctx context.Context) error

Run starts the control socket server and blocks until the context is cancelled or the VM exits. It writes the PID file on startup and cleans up the socket and PID file on exit.

type VMController

type VMController interface {
	// State returns the current VM lifecycle state as a string
	// ("running", "stopped", "error").
	State() string

	// Stop gracefully shuts down the VM within the given timeout.
	// It should attempt stereosd shutdown, then ACPI, then force kill.
	Stop(ctx context.Context, timeout time.Duration) error

	// ForceStop immediately terminates the VM.
	ForceStop(ctx context.Context) error

	// SSHPort returns the host-side SSH port for this VM.
	SSHPort() int

	// Backend returns the backend name ("qemu" or "applevirt").
	Backend() string

	// Wait blocks until the VM exits. It returns nil on clean exit
	// or an error if the VM crashed.
	Wait() error
}

VMController is the interface that the vmhost server uses to interact with the underlying VM. Each backend (QEMU, Apple Virt) implements this to provide lifecycle control.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL