> ## Documentation Index
> Fetch the complete documentation index at: https://mintlify.com/stratosphere-ve/ozone/llms.txt
> Use this file to discover all available pages before exploring further.

# vmparser Package — Ozone VM Config API

> Complete API reference for the vmparser package: types, parser functions, getter shortcuts, and writer functions for Ozone VM configuration files.

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.

```go theme={null}
import "github.com/stratosphere-ve/ozone/vmparser"
```

***

## 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.

<ResponseField name="VM" type="VMInfo">
  Identity and metadata for the virtual machine. Maps to the `"vm"` JSON key.
</ResponseField>

<ResponseField name="CPU" type="CPU">
  CPU topology configuration. Maps to the `"cpu"` JSON key.
</ResponseField>

<ResponseField name="Memory" type="Memory">
  Memory allocation configuration. Maps to the `"memory"` JSON key.
</ResponseField>

<ResponseField name="Network" type="Network">
  Network interface configuration. Maps to the `"network"` JSON key.
</ResponseField>

<ResponseField name="Disk" type="Disk">
  Primary disk configuration. Maps to the `"disk"` JSON key.
</ResponseField>

***

### VMInfo

`VMInfo` holds the identifying metadata for a VM.

<ResponseField name="Name" type="string">
  Human-readable name of the virtual machine. Also used as the filename stem (`vms/<Name>.json`). Maps to the `"name"` JSON key.
</ResponseField>

<ResponseField name="UUID" type="string">
  Universally unique identifier for the VM. Maps to the `"uuid"` JSON key.
</ResponseField>

<ResponseField name="CreatedAt" type="string">
  ISO 8601 timestamp recording when the VM was created. Maps to the `"created_at"` JSON key.
</ResponseField>

***

### CPU

`CPU` describes the processor configuration presented to the guest.

<ResponseField name="Cores" type="int">
  Number of virtual CPU cores allocated to the VM. Maps to the `"cores"` JSON key.
</ResponseField>

<ResponseField name="Type" type="string">
  CPU model string passed to QEMU (e.g. `"host"`, `"qemu64"`). Maps to the `"type"` JSON key.
</ResponseField>

***

### Memory

`Memory` describes the RAM allocation for the VM.

<ResponseField name="SizeMB" type="int">
  Amount of memory in mebibytes (MiB) allocated to the VM. Maps to the `"size_mb"` JSON key.
</ResponseField>

***

### Network

`Network` describes the virtual network interface attached to the VM.

<ResponseField name="Interface" type="string">
  Host network interface name (e.g. `"eth0"`, `"virbr0"`) bridged to the VM. Maps to the `"interface"` JSON key.
</ResponseField>

<ResponseField name="Type" type="string">
  QEMU network device model (e.g. `"virtio-net-pci"`, `"e1000"`). Maps to the `"type"` JSON key.
</ResponseField>

<ResponseField name="MAC" type="string">
  MAC address assigned to the VM's network interface (e.g. `"52:54:00:ab:cd:ef"`). Maps to the `"mac"` JSON key.
</ResponseField>

***

### Disk

`Disk` describes the primary block device attached to the VM.

<ResponseField name="Name" type="string">
  Logical name for the disk (e.g. `"primary"`). Maps to the `"name"` JSON key.
</ResponseField>

<ResponseField name="Path" type="string">
  Filesystem path to the disk image file (e.g. `"images/myvm.qcow2"`). Maps to the `"path"` JSON key.
</ResponseField>

<ResponseField name="SizeGB" type="float64">
  Provisioned size of the disk in gibibytes (GiB). Maps to the `"size_gb"` JSON key.
</ResponseField>

<ResponseField name="Format" type="string">
  Disk image format string (e.g. `"qcow2"`, `"raw"`). Maps to the `"format"` JSON key.
</ResponseField>

***

## 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

```go theme={null}
func VMParser(vmname string) (*VM, error)
```

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

```go theme={null}
func VMParserVMInfo(vmname string) (*VMInfo, error)
```

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

```go theme={null}
func VMParserCPU(vmname string) (*CPU, error)
```

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

***

### VMParserMemory

```go theme={null}
func VMParserMemory(vmname string) (*Memory, error)
```

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

***

### VMParserNetwork

```go theme={null}
func VMParserNetwork(vmname string) (*Network, error)
```

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

***

### VMParserDisk

```go theme={null}
func VMParserDisk(vmname string) (*Disk, error)
```

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

```go theme={null}
func GetVM(vmname string) (*VM, error)
```

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

***

### GetCPU

```go theme={null}
func GetCPU(vmname string) (*CPU, error)
```

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

***

### GetCPUCores

```go theme={null}
func GetCPUCores(vmname string) (int, error)
```

Returns the integer core count configured for the named VM.

***

### GetCPUType

```go theme={null}
func GetCPUType(vmname string) (string, error)
```

Returns the CPU model string configured for the named VM.

***

### GetMemory

```go theme={null}
func GetMemory(vmname string) (*Memory, error)
```

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

***

### GetMemorySizeMB

```go theme={null}
func GetMemorySizeMB(vmname string) (int, error)
```

Returns the allocated memory in MiB for the named VM.

***

### GetNetwork

```go theme={null}
func GetNetwork(vmname string) (*Network, error)
```

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

***

### GetMAC

```go theme={null}
func GetMAC(vmname string) (string, error)
```

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

***

### GetInterface

```go theme={null}
func GetInterface(vmname string) (string, error)
```

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

***

### GetDisk

```go theme={null}
func GetDisk(vmname string) (*Disk, error)
```

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

***

### GetDiskSizeGB

```go theme={null}
func GetDiskSizeGB(vmname string) (float64, error)
```

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

***

### GetDiskPath

```go theme={null}
func GetDiskPath(vmname string) (string, error)
```

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

***

### GetVMInfo

```go theme={null}
func GetVMInfo(vmname string) (*VMInfo, error)
```

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

***

### GetVMName

```go theme={null}
func GetVMName(vmname string) (string, error)
```

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

***

### GetVMUUID

```go theme={null}
func GetVMUUID(vmname string) (string, error)
```

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

```go theme={null}
func VMParserWriterInfo(info VMInfo) error
```

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

```go theme={null}
func VMParserWriterCPU(vmname string, cpu CPU) error
```

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

```go theme={null}
func VMParserWriterMemory(vmname string, memory Memory) error
```

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

```go theme={null}
func VMParserWriterDisk(vmname string, disk Disk) error
```

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

```go theme={null}
func VMParserWriterNetwork(vmname string, network Network) error
```

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.
