api

package
v0.7.2 Latest Latest
Warning

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

Go to latest
Published: Oct 18, 2026 License: AGPL-3.0 Imports: 57 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package api exposes VirtoMir's HTTP/JSON API (versioned under /api/v1) and serves the web UI.

Index

Constants

View Source
const SIEMConfigFile = "siem.json"

SIEMConfigFile holds the audit forwarding settings in -state-dir.

Variables

This section is empty.

Functions

This section is empty.

Types

type BMCLink struct {
	Driver string `json:"driver"` // ipmi, redfish
	URL    string `json:"url"`
}

type Backend

type Backend interface {
	HostInfo() (virt.HostInfo, error)
	ListDomains() ([]virt.Domain, error)
	DomainDetail(uuid string) (virt.DomainDetail, error)
	DomainXML(uuid string, inactive bool) (string, error)
	DomainAction(uuid string, action virt.Action) error

	CreateDomain(spec virt.CreateSpec) (virt.CreateResult, error)
	DefineXML(uuid, xml string) (virt.DefineResult, error)
	SetAutostart(uuid string, on bool) error
	Rename(uuid, name string) error
	Delete(uuid string, removeStorage bool) (virt.DeleteResult, error)
	Clone(ctx context.Context, uuid, name string, report func(string)) (string, error)

	ChangeMedia(uuid, target, source string) error
	AttachDisk(uuid string, spec virt.DiskSpec) (string, error)
	AttachInterface(uuid string, spec virt.NICSpec) error
	DetachDevice(uuid string, ref virt.DeviceRef) (virt.DeviceResult, error)

	ListSnapshots(uuid string) ([]virt.Snapshot, error)
	CreateSnapshot(uuid string, spec virt.SnapshotSpec) (string, error)
	RevertSnapshot(uuid, name string) error
	DeleteSnapshot(uuid, name string) error

	ListPools() ([]virt.Pool, error)
	CreatePool(spec virt.PoolSpec) error
	DeletePool(name string) error
	PoolAction(name, action string) error
	SetPoolAutostart(name string, on bool) error
	ListVolumes(pool string) ([]virt.Volume, error)
	CreateVolume(pool string, spec virt.VolumeSpec) (virt.Volume, error)
	DeleteVolume(pool, name string) error
	UploadVolume(ctx context.Context, pool, name string, size int64, r io.Reader) (virt.Volume, error)

	ListNetworks() ([]virt.VNetwork, error)
	CreateNetwork(spec virt.NetworkSpec) error
	DeleteNetwork(name string) error
	NetworkAction(name, action string) error
	SetNetworkAutostart(name string, on bool) error
	NetworkLeases(name string) ([]virt.Lease, error)

	GetSettings(uuid string) (virt.SettingsView, error)
	PreviewSettings(uuid string, s virt.Settings) (virt.Preview, error)
	SaveSettings(uuid string, s virt.Settings) (virt.SaveResult, error)
	ResizeDisk(uuid, target string, sizeGiB uint64) error
	SetDiskQoS(uuid, target string, qos virt.DiskIoTune) error
	ResizeVolume(pool, name string, sizeGiB uint64) error
	AddDHCPHost(network string, h virt.DHCPHost) error
	DeleteDHCPHost(network, mac string) error
}

Backend is what the API needs from the virtualization layer (implemented by *virt.Client).

type Backupper

type Backupper interface {
	ListBackups(dir virt.BackupDir, uuid string) ([]virt.Backup, error)
	BackupDomain(ctx context.Context, dir virt.BackupDir, uuid string, automatic bool, report func(string)) (virt.Backup, error)
	DeleteBackup(dir virt.BackupDir, id string) error
	RestoreBackup(ctx context.Context, dir virt.BackupDir, id, name, pool string, report func(string)) (string, error)
}

Backupper is the backup part of the backend (implemented by *virt.Client).

type ChassisView

type ChassisView struct {
	hostinfo.Chassis
	BMC *BMCLink `json:"bmc,omitempty"`
}

ChassisView is the chassis plus how to reach the host's management controller (BMC), if one is configured for fencing (HA): that is the only BMC address VirtoMir knows for sure.

type ClusterDomainSummary added in v0.7.0

type ClusterDomainSummary struct {
	virt.Domain
	HostID   string `json:"hostId"`
	HostName string `json:"hostName"`
}

ClusterDomainSummary is a domain with its physical host information for the unified view.

type Consoler

type Consoler interface {
	ConsoleInfo(uuid string) (virt.ConsoleInfo, error)
	DialVNC(ctx context.Context, uuid string) (net.Conn, error)
	DialVNCHead(ctx context.Context, uuid string, head int) (net.Conn, error)
	SerialConsole(ctx context.Context, uuid, device string, in io.Reader, out io.Writer) error
}

Consoler is the console part of the backend (implemented by *virt.Client).

type DiskSizer added in v0.6.0

type DiskSizer interface {
	DiskBytes(uuids []string) (map[string]uint64, error)
}

DiskSizer reports the size of machines' own disks for the disk quota (ADR-0044).

type ExtraDevicer

type ExtraDevicer interface {
	AddDevice(uuid string, spec virt.DeviceSpec) (virt.DeviceResult, error)
	GetQEMUArgs(uuid string) (virt.QEMUArgs, error)
	SetQEMUArgs(uuid string, q virt.QEMUArgs) (virt.DefineResult, error)
	CreateMDev(spec virt.MDevSpec) (string, error)
	DeleteMDev(uuid string) error
}

ExtraDevicer adds watchdogs, TPMs, shared folders, vGPU slices and the like, edits the QEMU command line and manages the host's mediated devices (implemented by *virt.Client). All writes are admin-only (requiredRole's default) and stay out of operator self-service: shared folders, mdevs and QEMU arguments reach past the host's safety checks.

type Firewaller

type Firewaller interface {
	Firewall(uuid string) (virt.Firewall, error)
	SetFirewall(uuid string, fw virt.Firewall) (virt.FirewallResult, error)
	RemoveFirewall(uuid string) error
}

Firewaller manages a machine's firewall (implemented by *virt.Client, ADR-0033).

type HistoryQuerier

type HistoryQuerier interface {
	Query(names []string, rng time.Duration, now time.Time) (history.Result, error)
}

HistoryQuerier answers history queries (implemented by *history.Store).

type HostDevicer

type HostDevicer interface {
	HostHardware() (virt.HostHardware, error)
	AttachHostdev(uuid string, spec virt.HostdevSpec) (string, error)
}

HostDevicer lists host hardware and passes devices to machines (implemented by *virt.Client).

type HostResult

type HostResult struct {
	Host  string `json:"host"`
	OK    bool   `json:"ok"`
	Error string `json:"error,omitempty"`
}

HostResult is the outcome of one step of a cluster-wide action on one member.

type Live

type Live interface {
	Subscribe() (backlog [][]byte, updates <-chan []byte, unsubscribe func())
	Refresh()
}

Live is the snapshot stream (implemented by *live.Hub).

type MemberStatus

type MemberStatus struct {
	ID          string `json:"id"`
	Name        string `json:"name"`
	Address     string `json:"address"`
	Fingerprint string `json:"fingerprint"`
	Self        bool   `json:"self"`
	Reachable   bool   `json:"reachable"`
	Version     string `json:"version,omitempty"`
	Error       string `json:"error,omitempty"`
}

MemberStatus is a member as the UI sees it: reachable now, which version it runs.

type Migrator

type Migrator interface {
	PlanMigration(uuid string) (virt.MigrationSource, error)
	CheckPaths(paths []string) ([]virt.PathCheck, error)
	MigrateBegin(uuid string, flags libvirt.DomainMigrateFlags, disks []string) ([]byte, string, error)
	MigratePrepare(name, xml, uri string, cookie []byte, flags libvirt.DomainMigrateFlags, disks []string) ([]byte, string, error)
	MigratePerform(ctx context.Context, uuid, uri string, cookie []byte, flags libvirt.DomainMigrateFlags, disks []string, progress func(string)) ([]byte, error)
	MigrateFinish(name, uri string, cookie []byte, flags libvirt.DomainMigrateFlags, disks []string, cancelled bool) ([]byte, error)
	MigrateConfirm(uuid string, cookie []byte, flags libvirt.DomainMigrateFlags, disks []string, cancelled bool) error
	RemoveImage(path string) error
	HostCPU() (virt.HostCPU, error)
}

Migrator is the live-migration part of the backend (implemented by *virt.Client).

type Mover

type Mover interface {
	PlanMove(uuid string) (virt.MovePlan, error)
	AdoptDomain(xml string) (string, error)
}

Mover is the part of the backend that moves machines between hosts (ADR-0020).

type OVAImporter

type OVAImporter interface {
	ImportOVA(ctx context.Context, pool, name string, r io.Reader, report func(string)) (virt.CreateResult, error)
}

OVAImporter turns an OVA appliance into a machine (implemented by *virt.Client).

type ObjectXMLer added in v0.5.0

type ObjectXMLer interface {
	NetworkXML(name string) (string, error)
	DefineNetworkXML(name, doc string) (virt.ObjectSaveResult, error)
	PoolXML(name string) (string, error)
	DefinePoolXML(name, doc string) (virt.ObjectSaveResult, error)
}

ObjectXMLer reads and redefines networks and storage pools as raw XML (implemented by *virt.Client). P4: every libvirt setting is reachable, not only what the forms offer.

type Options

type Options struct {
	Backend Backend
	Live    Live
	Jobs    *jobs.Manager
	// Auth nil means no sign-in (development only; virtomird warns loudly).
	Auth    *auth.Manager
	UI      fs.FS // nil: no UI bundled
	Version string
	Log     *slog.Logger
	// History nil: no metric history (GET /api/v1/history answers 404).
	History HistoryQuerier
	// Tokens nil: no API tokens. Activity nil: changes are only logged, not kept.
	Tokens   *auth.Tokens
	Activity *activity.Log
	// Alerts nil: no alert engine. Schedules nil: no schedules and no backups.
	Alerts    *alerts.Engine
	Schedules *schedule.Scheduler
	// Cluster nil: this host cannot join others (no TLS). Fingerprint is this host's TLS
	// certificate, HostName how members call it, ListenPort where it listens (ADR-0020).
	// Quotas nil: only admins create machines. GroupsOf names a user's groups for group
	// rules (default: the Linux groups).
	Quotas   *quota.Store
	GroupsOf func(user string) []string
	// ConfigHistory nil: machine definitions are not versioned.
	ConfigHistory *confighist.Store
	Cluster       *cluster.Store
	Fingerprint   string
	HostName      string
	ListenPort    string

	// HA nil: no high availability (the manager is connected later with SetHA).
	HA       *ha.Store
	Reports  *reports.Store
	Respools *respool.Store
	// HostInfo nil: no chassis, sensors, GPU load, interfaces or packet capture.
	HostInfo *hostinfo.Reader
	// Updater nil: no update check. StateDir is where downloads go.
	Updater  *update.Checker
	StateDir string
	// HostNet nil: no bridges, bonds or VLAN interfaces from the UI (ADR-0042).
	HostNet *hostnet.Manager
	// Offsite nil: no off-site copies of backups (ADR-0043).
	Offsite *offsite.Store
	// DRS nil: no distributed resource scheduler.
	DRS *drs.Engine
	// RateLimiter nil: standard token-bucket limiter (60/min) is used.
	RateLimiter *auth.RateLimiter
}

type Placer added in v0.5.0

type Placer interface {
	Placements() ([]virt.Placement, error)
}

Placer reports where running machines' vCPUs sit (for the topology view).

type PoolView

type PoolView struct {
	respool.ResourcePool
	Usage respool.Usage `json:"usage"`
}

PoolView is a pool with what its machines use.

type Server

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

func NewServer

func NewServer(o Options) *Server

func (*Server) HATransport

func (s *Server) HATransport() ha.Transport

HATransport is how the HA manager reaches the other members: over the pinned peer links.

func (*Server) Handler

func (s *Server) Handler() http.Handler

func (*Server) RunReportSchedules

func (s *Server) RunReportSchedules(ctx context.Context)

RunReportSchedules makes this host's scheduled reports until ctx ends. Schedules are kept per host, but every report covers the whole cluster, so one host's schedules are enough.

func (*Server) SetHA

func (s *Server) SetHA(m *ha.Manager)

SetHA connects the HA manager (it needs the server as its transport, so it comes later).

func (*Server) SyncMembers

func (s *Server) SyncMembers(ctx context.Context)

SyncMembers pulls the member list from every peer and keeps the newest; run it now and then so a host that was down during a change catches up. A host that every other member refuses was removed while it was away: it becomes standalone.

type SetupCheck added in v0.6.0

type SetupCheck struct {
	ID     string `json:"id"`
	OK     bool   `json:"ok"`
	Needed bool   `json:"needed"` // without it, machines cannot work (otherwise: recommended)
	Title  string `json:"title"`
	Detail string `json:"detail"`
}

SetupCheck is one thing the host needs, or should have.

type Spicer added in v0.6.0

type Spicer interface {
	DialSPICE(ctx context.Context, uuid string) (net.Conn, error)
	SetDisplay(uuid, protocol string) error
}

Spicer is the SPICE part of the backend (ADR-0046); a backend without it keeps VNC and the serial console.

type Templater

type Templater interface {
	SetTemplate(uuid string, on bool) error
	Deploy(ctx context.Context, template string, spec virt.DeploySpec, report func(string)) (string, error)
}

Templater is the template part of the backend (implemented by *virt.Client).

Jump to

Keyboard shortcuts

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