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

# How to Read VM Configuration Files in Ozone vmparser

> Learn how to use vmparser reader functions to load typed VM config structs from disk, from full VM objects down to individual field getter functions.

The `vmparser` package provides a suite of functions for reading VM configuration from `vms/<vmname>.json`. Every function accepts a VM name string, resolves the file path automatically, and returns a typed Go value. You can read the entire `VM` struct in one call, or use the targeted getter functions to retrieve a specific resource section or even a single field.

## Import

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

## Error handling

Every read function returns an error as its second return value. Always check it — the error wraps the underlying `os` or `encoding/json` failure with context about which file was being read.

```go theme={null}
vm, err := vmparser.VMParser("web-01")
if err != nil {
    log.Fatalf("failed to read VM config: %v", err)
}
```

<Note>
  Every read function opens and parses the full JSON file on each call. There is no in-memory cache. If you need multiple fields from the same VM in a tight loop, call `VMParser` or `GetVM` once and read from the returned struct directly.
</Note>

***

## Reading by resource

<Tabs>
  <Tab title="Full VM">
    Use `VMParser` or its alias `GetVM` to load the entire VM configuration into a `*VM` struct.

    ```go theme={null}
    // Using VMParser
    vm, err := vmparser.VMParser("web-01")
    if err != nil {
        return err
    }
    fmt.Println(vm.VM.Name)       // "web-01"
    fmt.Println(vm.CPU.Cores)     // 4
    fmt.Println(vm.Memory.SizeMB) // 2048

    // Using the GetVM alias (identical behaviour)
    vm, err = vmparser.GetVM("web-01")
    if err != nil {
        return err
    }
    ```

    Both functions return `(*VM, error)`. `GetVM` is a thin wrapper that calls `VMParser` internally.
  </Tab>

  <Tab title="VMInfo">
    Retrieve just the identity section of a VM using `VMParserVMInfo` or `GetVMInfo`. Individual field getters are also available.

    ```go theme={null}
    // Full VMInfo struct
    info, err := vmparser.VMParserVMInfo("web-01")
    if err != nil {
        return err
    }
    fmt.Println(info.Name)      // "web-01"
    fmt.Println(info.UUID)      // "550e8400-..."
    fmt.Println(info.CreatedAt) // "2024-06-01T12:00:00Z"

    // GetVMInfo alias
    info, err = vmparser.GetVMInfo("web-01")

    // Individual field getters
    name, err := vmparser.GetVMName("web-01")   // (string, error)
    uuid, err := vmparser.GetVMUUID("web-01")   // (string, error)
    ```
  </Tab>

  <Tab title="CPU">
    Retrieve the CPU section or individual CPU fields.

    ```go theme={null}
    // Full CPU struct
    cpu, err := vmparser.VMParserCPU("web-01")
    if err != nil {
        return err
    }
    fmt.Println(cpu.Cores) // 4
    fmt.Println(cpu.Type)  // "host"

    // GetCPU alias
    cpu, err = vmparser.GetCPU("web-01") // (*CPU, error)

    // Individual field getters
    cores, err := vmparser.GetCPUCores("web-01") // (int, error)
    cpuType, err := vmparser.GetCPUType("web-01") // (string, error)
    ```
  </Tab>

  <Tab title="Memory">
    Retrieve the memory section or the size field directly.

    ```go theme={null}
    // Full Memory struct
    mem, err := vmparser.VMParserMemory("web-01")
    if err != nil {
        return err
    }
    fmt.Println(mem.SizeMB) // 2048

    // GetMemory alias
    mem, err = vmparser.GetMemory("web-01") // (*Memory, error)

    // Individual field getter
    sizeMB, err := vmparser.GetMemorySizeMB("web-01") // (int, error)
    ```
  </Tab>

  <Tab title="Network">
    Retrieve the network section or individual network fields.

    ```go theme={null}
    // Full Network struct
    net, err := vmparser.VMParserNetwork("web-01")
    if err != nil {
        return err
    }
    fmt.Println(net.Interface) // "eth0"
    fmt.Println(net.Type)      // "virtio"
    fmt.Println(net.MAC)       // "52:54:00:ab:cd:ef"

    // GetNetwork alias
    net, err = vmparser.GetNetwork("web-01") // (*Network, error)

    // Individual field getters
    mac, err := vmparser.GetMAC("web-01")       // (string, error)
    iface, err := vmparser.GetInterface("web-01") // (string, error)
    ```
  </Tab>

  <Tab title="Disk">
    Retrieve the disk section or individual disk fields.

    ```go theme={null}
    // Full Disk struct
    disk, err := vmparser.VMParserDisk("web-01")
    if err != nil {
        return err
    }
    fmt.Println(disk.Name)   // "web-01-disk"
    fmt.Println(disk.Path)   // "/var/lib/ozone/images/web-01.qcow2"
    fmt.Println(disk.SizeGB) // 20.0
    fmt.Println(disk.Format) // "qcow2"

    // GetDisk alias
    disk, err = vmparser.GetDisk("web-01") // (*Disk, error)

    // Individual field getters
    sizeGB, err := vmparser.GetDiskSizeGB("web-01") // (float64, error)
    path, err   := vmparser.GetDiskPath("web-01")   // (string, error)
    ```
  </Tab>
</Tabs>
