Skip to main content
The vmparser package is the configuration backbone of Ozone. It reads, deserializes, and writes JSON-based VM definition files stored under the vms/ directory, exposing a structured Go API for every field of a virtual machine’s configuration — from CPU topology and memory allocation through network identity and disk layout.

Types

VM

VM is the top-level struct that represents a complete virtual machine configuration. It is the root object stored in each vms/<name>.json file and is returned by the full-parse functions.
VMInfo
Identity and metadata for the virtual machine. Maps to the "vm" JSON key.
CPU
CPU topology configuration. Maps to the "cpu" JSON key.
Memory
Memory allocation configuration. Maps to the "memory" JSON key.
Network
Network interface configuration. Maps to the "network" JSON key.
Disk
Primary disk configuration. Maps to the "disk" JSON key.

VMInfo

VMInfo holds the identifying metadata for a VM.
string
Human-readable name of the virtual machine. Also used as the filename stem (vms/<Name>.json). Maps to the "name" JSON key.
string
Universally unique identifier for the VM. Maps to the "uuid" JSON key.
string
ISO 8601 timestamp recording when the VM was created. Maps to the "created_at" JSON key.

CPU

CPU describes the processor configuration presented to the guest.
int
Number of virtual CPU cores allocated to the VM. Maps to the "cores" JSON key.
string
CPU model string passed to QEMU (e.g. "host", "qemu64"). Maps to the "type" JSON key.

Memory

Memory describes the RAM allocation for the VM.
int
Amount of memory in mebibytes (MiB) allocated to the VM. Maps to the "size_mb" JSON key.

Network

Network describes the virtual network interface attached to the VM.
string
Host network interface name (e.g. "eth0", "virbr0") bridged to the VM. Maps to the "interface" JSON key.
string
QEMU network device model (e.g. "virtio-net-pci", "e1000"). Maps to the "type" JSON key.
string
MAC address assigned to the VM’s network interface (e.g. "52:54:00:ab:cd:ef"). Maps to the "mac" JSON key.

Disk

Disk describes the primary block device attached to the VM.
string
Logical name for the disk (e.g. "primary"). Maps to the "name" JSON key.
string
Filesystem path to the disk image file (e.g. "images/myvm.qcow2"). Maps to the "path" JSON key.
float64
Provisioned size of the disk in gibibytes (GiB). Maps to the "size_gb" JSON key.
string
Disk image format string (e.g. "qcow2", "raw"). Maps to the "format" JSON key.

Parser Functions

Parser functions each open vms/<vmname>.json, unmarshal the full VM document, and return only the requested section. They return a pointer to the relevant struct together with an error; the error is non-nil if the file cannot be read or the JSON is malformed.

VMParser

Reads vms/<vmname>.json and deserializes the entire document into a VM struct. Returns a pointer to the populated struct, or an error if the file is missing or the JSON cannot be parsed. This is the primary entry point used by most other functions in the package.

VMParserVMInfo

Reads the VM config file and returns only the VMInfo section (name, UUID, creation timestamp), leaving all other fields unpopulated in the caller’s scope.

VMParserCPU

Reads the VM config file and returns only the CPU section (core count and CPU type string).

VMParserMemory

Reads the VM config file and returns only the Memory section (size in MiB).

VMParserNetwork

Reads the VM config file and returns only the Network section (interface name, device type, and MAC address).

VMParserDisk

Reads the VM config file and returns only the Disk section (name, path, size, and format).

Getter Shortcuts

Getter functions are thin convenience wrappers around VMParser. Each calls VMParser internally, checks the error, and returns either the requested value or a zero value alongside the propagated error. Use these when you need a single scalar field without constructing the full VM struct yourself.

GetVM

Returns the full VM struct for the named machine. Equivalent to calling VMParser directly.

GetCPU

Returns a pointer to the CPU struct for the named VM.

GetCPUCores

Returns the integer core count configured for the named VM.

GetCPUType

Returns the CPU model string configured for the named VM.

GetMemory

Returns a pointer to the Memory struct for the named VM.

GetMemorySizeMB

Returns the allocated memory in MiB for the named VM.

GetNetwork

Returns a pointer to the Network struct for the named VM.

GetMAC

Returns the MAC address string configured for the named VM’s network interface.

GetInterface

Returns the host network interface name configured for the named VM.

GetDisk

Returns a pointer to the Disk struct for the named VM.

GetDiskSizeGB

Returns the provisioned disk size in GiB for the named VM.

GetDiskPath

Returns the filesystem path to the disk image for the named VM.

GetVMInfo

Returns a pointer to the VMInfo struct (name, UUID, creation timestamp) for the named VM.

GetVMName

Returns the human-readable name stored inside the VM’s config file. Useful for verifying the filename matches the declared name.

GetVMUUID

Returns the UUID string stored in the VM’s config file.

Writer Functions

Writer functions perform a read-modify-write cycle: they load the existing vms/<vmname>.json (if it exists), replace only the targeted section with the supplied value, re-serialize the full VM struct with two-space indentation, and write the result back to disk. All sections not explicitly targeted are preserved unchanged.

VMParserWriterInfo

Merges the supplied VMInfo value into the existing config file for the VM identified by info.Name, then writes the updated document back to vms/<info.Name>.json. All other sections (CPU, Memory, Network, Disk) are left intact. Returns an error if marshaling or the write operation fails.

VMParserWriterCPU

Replaces the CPU section of vms/<vmname>.json with the provided CPU value. All other sections are preserved. Returns an error if marshaling or the write operation fails.

VMParserWriterMemory

Replaces the Memory section of vms/<vmname>.json with the provided Memory value. All other sections are preserved. Returns an error if marshaling or the write operation fails.

VMParserWriterDisk

Replaces the Disk section of vms/<vmname>.json with the provided Disk value. All other sections are preserved. Returns an error if marshaling or the write operation fails.

VMParserWriterNetwork

Replaces the Network section of vms/<vmname>.json with the provided Network value. All other sections are preserved. Returns an error if marshaling or the write operation fails.