Skip to content

Repository files navigation

Stateless Libvirt REST API Node Controller

A lightweight, stateless Golang service exposing libvirt hypervisors over a simple REST API.
Great as a building block for custom cloud control-planes, auto-scaling clusters or edge-compute node agents.


Features

  • Stateless: no local database, all state lives in libvirt
  • Full libvirt domain lifecycle: define, start, stop, reboot, undefine
  • Snapshot management
  • Pluggable auth (e.g. Bearer token)
  • Cached image downloads

Prerequisites

  • Go 1.18+
  • Libvirt (client libraries and daemon)

Quick Start

git clone https://github.com/UltraSive/libvirt-hypervisor-controller.git
cd libvirt-hypervisor-controller
chmod +x packages.sh
./packages.sh
make build
# Set your libvirt URI (e.g. qemu:///system)export LIBVIRT_URI=qemu:///system
# Optional: listening address (default :8080)export LISTEN_ADDR=:9090
./main

Configuration

ENV VariableRequiredDefaultDescription
NODE_IDfalseNODE_1The node ID for webhook events
LIBVIRT_URIfalseqemu:///systemlibvirt connection URI (required)
PORTfalse8080HTTP bind address
DEFINITIONS_DIRfalse/data/vmPath where libvirt domain xml stored
AUTH_TOKENfalseStatic bearer token for simple auth
WEBHOOK_ENDPOINTfalseHTTP endpoint for events
CACHE_DIRfalseCache for VM image templates
CACHE_SECONDSfalseHow long should VM images be cached

API Reference

Swagger OpenAPI Docs


Webhook Events

When WEBHOOK_ENDPOINT is set, the controller will emit HTTP POST requests to the specified endpoint on major domain lifecycle changes. Each event contains the domain_id and event_type.

Event Payload Format

{
"object": "event",
"node_id": "NODE_1",
"domain_id": "vm-123",
"type": "domain.defined",
"data": {},
"timestamp": "2024-05-23T18:25:43.511Z"
}

Event Types

Event TypeDescription
domain.definedDomain was defined (created)
domain.startedDomain was started
domain.stoppedDomain was gracefully stopped
domain.shutdownDomain shutdown was initiated
domain.rebootedDomain was rebooted
domain.undefinedDomain was deleted/undefined
domain.snapshot_createdA snapshot was created
domain.snapshot_deletedA snapshot was deleted

License

This project is licensed under the MIT License. See LICENSE for details.

About

Stateless way to control libvirt hypervisors via a REST API.

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages