Skip to content

Daemon

Go

The VM Registry Daemon (vm-registry-daemon) is the central orchestrator running on each host machine. It exposes a gRPC service over a Unix domain socket and manages all local VM operations — image storage, VM lifecycle through libvirt, virtual networking, VMCompose orchestration, and communication with the remote registry and auth servers.

Overview

The daemon is the bridge between the user-facing CLI and the underlying infrastructure. It receives gRPC requests from the CLI, translates them into libvirt API calls, filesystem operations, and HTTP requests to remote servers, then returns structured responses.

text
CLI ──gRPC/Unix Socket──► Daemon ──libvirt API──► QEMU/KVM

                              ├──HTTP──► Registry Server
                              ├──HTTP──► Auth Server
                              └──Filesystem/S3──► Image Store

Running the Daemon

bash
cd vm-registry-daemon
go run server/main.go [FLAGS]

Configuration Flags

FlagEnv VariableDefaultDescription
-socketVM_REGISTRY_SOCKET_PATH/var/run/vm-registry.sockUnix socket path for gRPC
-registry-urlVM_REGISTRY_SERVER_URLRemote registry server URL
-auth-urlVM_AUTH_SERVER_URLRemote auth server URL
-storagefilesystemStorage backend: filesystem or s3
-fs-pathVM_REGISTRY_STORAGE_PATH/var/lib/vm-registryLocal filesystem storage path
-log-levelVM_REGISTRY_LOG_LEVELinfoLog verbosity level
-s3-bucketS3 bucket name
-s3-regionus-east-1S3 region
-s3-endpointS3-compatible endpoint URL
-s3-access-keyAWS_ACCESS_KEY_IDS3 access key
-s3-secret-keyAWS_SECRET_ACCESS_KEYS3 secret key
-s3-skip-bucket-creationfalseSkip automatic bucket creation

Examples

bash
go run server/main.go \
  -socket /tmp/vm-registry-daemon.sock \
  -registry-url http://127.0.0.1:8080 \
  -auth-url http://127.0.0.1:4078

go run server/main.go \
  -storage s3 \
  -s3-bucket vm-images \
  -s3-endpoint http://127.0.0.1:9000 \
  -s3-access-key admin \
  -s3-secret-key admin

Internal Structure

The daemon is organized into the following internal packages:

PackageResponsibility
internal/servicegRPC service implementations — one file per domain (auth, compose, context, images, vm, network, etc.)
internal/libvirtLibvirt wrapper — domain creation, network management, bridge configuration, cloud-init ISO generation, disk handling
internal/vmfileVMFile parser and validator — parses YAML, resolves paths, validates schema
internal/vmcomposeVMCompose parser and validator — parses multi-VM compose files, validates structure
internal/storageStorage interface definition for pluggable backends
internal/configConfiguration loading from flags and environment variables
internal/clientHTTP client for communicating with the registry and auth servers
internal/protoGenerated gRPC/protobuf Go code
internal/logsStructured logging with gRPC interceptors
internal/utilsShared utility functions

gRPC Service

The daemon implements the VMService gRPC service defined in vm-registry-proto. The service is registered on a Unix domain socket with reflection enabled for debugging with tools like grpcurl.

The gRPC server is configured with:

  • 4 GiB max message size for both send and receive — necessary for streaming large disk images during import
  • Unary interceptor for request/response logging
  • Stream interceptor for streaming call logging

Libvirt Integration

The daemon uses the libvirt.org/go/libvirt and libvirt.org/go/libvirtxml Go bindings for direct interaction with the libvirt hypervisor API. Key capabilities include:

Domain Management

  • Creating libvirt domains from image specs (CPU, memory, bootloader, disk)
  • Starting, stopping (graceful ACPI shutdown or forced destroy), restarting, and undefining domains
  • Listing running and defined domains with resource and status information

Network Management

  • Creating virtual networks in all supported modes: NAT, isolated, routed, bridged, open, and macvtap
  • Activating, deactivating, and deleting networks
  • Bridge interface configuration for bridged networking
  • DHCP range configuration for NAT and isolated networks

Cloud-Init

  • Generating cloud-init ISO images from user-data, meta-data, and network-config sources
  • Attaching cloud-init ISOs to VM domains for guest provisioning at first boot

Disk Management

  • Creating overlay disks (copy-on-write) for ephemeral VM storage
  • Resizing disk images when diskSize overrides are specified in VMCompose services

Image Storage

The daemon stores images locally in a content-addressable layout:

text
/var/lib/vm-registry/
├── manifests/
│   └── <repository>/
│       └── <tag>/
│           └── manifest.json
├── blobs/
│   └── sha256/
│       └── <digest>
└── runtime/
    └── <vm-name>/
  • manifests/ — Image manifests indexed by repository and tag, containing references to content-addressed blobs
  • blobs/ — Content-addressed storage for disk images and configuration blobs, keyed by SHA-256 digest
  • runtime/ — Ephemeral state for running VMs (cloud-init ISOs, overlay disks)

VMFile Processing

When a vmr import command is received, the daemon:

  1. Receives the VMFile metadata and disk image chunks over a gRPC stream
  2. Parses and validates the VMFile YAML structure
  3. Computes the SHA-256 digest of the disk image
  4. Stores the disk image blob in content-addressable storage
  5. Creates an image configuration blob from the VMFile spec
  6. Generates a manifest referencing both blobs
  7. Stores the manifest under the specified repository and tags

VMCompose Orchestration

When a vmr compose up command is received, the daemon:

  1. Parses and validates the VMCompose YAML
  2. Creates any networks defined in the networks section that don't already exist
  3. Resolves the service dependency graph using topological sorting
  4. For each service in dependency order:
    • Resolves the image reference to a local manifest
    • Applies resource overrides (CPU, memory, disk size)
    • Loads cloud-init configuration (inline or from files)
    • Creates and starts a libvirt domain with the appropriate network attachments
  5. Returns the status of all services

Dependencies

DependencyPurpose
google.golang.org/grpcgRPC server framework
google.golang.org/protobufProtocol Buffer runtime
gopkg.in/yaml.v3YAML parsing for VMFile and VMCompose
libvirt.org/go/libvirtLibvirt C API bindings
libvirt.org/go/libvirtxmlLibvirt XML domain/network generation
aws-sdk-go-v2S3 storage backend

Built with Go and Rust