|
| 1 | +# Cloud Hypervisor VMM Client |
| 2 | + |
| 3 | +Thin Go wrapper around Cloud Hypervisor's HTTP API with embedded binaries. |
| 4 | + |
| 5 | +Supports multiple versions of the Cloud Hypervisor VMM because instances are version-locked to cloud hypervisor if they are in standby. We can switch them to the latest version if we shutdown / reboot the VM. |
| 6 | + |
| 7 | +Embeds the binaries to make it easier to install, instead of managing multiple versions of the Cloud Hypervisor CLI externally + configuring it. |
| 8 | + |
| 9 | +## Features |
| 10 | + |
| 11 | +- Embedded Cloud Hypervisor binaries of multiple versions |
| 12 | +- Generated HTTP client from official OpenAPI spec |
| 13 | +- Automatic binary extraction to data directory |
| 14 | +- Unix socket communication |
| 15 | +- Version detection and validation |
| 16 | + |
| 17 | +## Requirements |
| 18 | + |
| 19 | +**System:** |
| 20 | +- Linux with KVM support (`/dev/kvm`) |
| 21 | +- User must be in `kvm` group or run as root |
| 22 | + |
| 23 | +**Add user to kvm group:** |
| 24 | +```bash |
| 25 | +sudo usermod -aG kvm $USER |
| 26 | +# Then log out and back in, or use: sg kvm -c "your-command" |
| 27 | +``` |
| 28 | + |
| 29 | +## Usage |
| 30 | + |
| 31 | +### Start a VMM Process |
| 32 | + |
| 33 | +```go |
| 34 | +import "github.com/onkernel/hypeman/lib/vmm" |
| 35 | + |
| 36 | +ctx := context.Background() |
| 37 | +dataDir := "/var/lib/hypeman" |
| 38 | +socketPath := "/tmp/vmm.sock" |
| 39 | + |
| 40 | +// Start Cloud Hypervisor VMM (extracts binary if needed) |
| 41 | +err := vmm.StartProcess(ctx, dataDir, vmm.V48_0, socketPath) |
| 42 | +if err != nil { |
| 43 | + log.Fatal(err) |
| 44 | +} |
| 45 | +``` |
| 46 | + |
| 47 | +### Connect to Existing VMM |
| 48 | + |
| 49 | +```go |
| 50 | +// Create client for existing VMM socket |
| 51 | +client, err := vmm.NewVMM(socketPath) |
| 52 | +if err != nil { |
| 53 | + log.Fatal(err) |
| 54 | +} |
| 55 | + |
| 56 | +// All generated API methods available directly |
| 57 | +resp, err := client.GetVmmPingWithResponse(ctx) |
| 58 | +``` |
| 59 | + |
| 60 | +### Check Binary Version |
| 61 | + |
| 62 | +```go |
| 63 | +binaryPath, _ := vmm.GetBinaryPath(dataDir, vmm.V48_0) |
| 64 | +version, err := vmm.ParseVersion(binaryPath) |
| 65 | +fmt.Println(version) // "v48.0" |
| 66 | +``` |
| 67 | + |
| 68 | +## Architecture |
| 69 | + |
| 70 | +``` |
| 71 | +lib/vmm/ |
| 72 | +├── vmm.go # Generated from OpenAPI spec (DO NOT EDIT) |
| 73 | +├── client.go # Thin wrapper: NewVMM, StartProcess |
| 74 | +├── binaries.go # Binary embedding and extraction |
| 75 | +├── version.go # Version parsing utilities |
| 76 | +├── binaries/ # Embedded Cloud Hypervisor binaries |
| 77 | +│ └── cloud-hypervisor/ |
| 78 | +│ ├── v48.0/ |
| 79 | +│ │ ├── x86_64/cloud-hypervisor (4.5MB) |
| 80 | +│ │ └── aarch64/cloud-hypervisor (3.3MB) |
| 81 | +│ └── v49.0/ |
| 82 | +│ ├── x86_64/cloud-hypervisor (4.5MB) |
| 83 | +│ └── aarch64/cloud-hypervisor (3.3MB) |
| 84 | +| # There will be additional versions in the future... |
| 85 | +└── client_test.go # Tests with real Cloud Hypervisor |
| 86 | +``` |
| 87 | + |
| 88 | +## Supported Versions |
| 89 | + |
| 90 | +- Cloud Hypervisor v48.0 (API v0.3.0) |
| 91 | +- Cloud Hypervisor v49.0 (API v0.3.0) |
| 92 | + |
| 93 | +There may be additional versions in the future. Cloud hypervisor versions may update frequently, while the API updates less frequently. |
| 94 | + |
| 95 | +## Regenerating Client |
| 96 | + |
| 97 | +```bash |
| 98 | +# Download latest spec (if needed) |
| 99 | +make download-ch-spec |
| 100 | + |
| 101 | +# Regenerate client from spec |
| 102 | +make generate-vmm-client |
| 103 | +``` |
| 104 | + |
| 105 | +## Testing |
| 106 | + |
| 107 | +Tests run against real Cloud Hypervisor binaries (not mocked). |
| 108 | + |
| 109 | +```bash |
| 110 | +# Must be in kvm group |
| 111 | +sg kvm -c "go test ./lib/vmm/..." |
| 112 | +``` |
| 113 | + |
| 114 | +## Binary Extraction |
| 115 | + |
| 116 | +Binaries are automatically extracted from embedded FS to: |
| 117 | +``` |
| 118 | +{dataDir}/system/binaries/{version}/{arch}/cloud-hypervisor |
| 119 | +``` |
| 120 | + |
| 121 | +Extraction happens once per version. Subsequent calls reuse the extracted binary. |
| 122 | + |
| 123 | +## API Methods |
| 124 | + |
| 125 | +All Cloud Hypervisor API methods available via embedded `*ClientWithResponses`: |
| 126 | + |
| 127 | +- `GetVmmPingWithResponse()` - Check VMM health |
| 128 | +- `ShutdownVMMWithResponse()` - Shutdown VMM |
| 129 | +- `CreateVMWithResponse()` - Create VM configuration |
| 130 | +- `BootVMWithResponse()` - Boot configured VM |
| 131 | +- `PauseVMWithResponse()` - Pause running VM |
| 132 | +- `ResumeVMWithResponse()` - Resume paused VM |
| 133 | +- `VmSnapshotPutWithResponse()` - Create VM snapshot |
| 134 | +- `VmRestorePutWithResponse()` - Restore from snapshot |
| 135 | +- `VmInfoGetWithResponse()` - Get VM info |
| 136 | +- And many more... |
| 137 | + |
| 138 | +See generated `vmm.go` for full API surface. |
0 commit comments