Files
jagacloud/pkg/compute/libvirt/libvirt.go
2025-11-23 22:37:27 +07:00

54 lines
1.6 KiB
Go

package libvirt
// Client abstracts libvirt operations needed by the node-agent.
type Client interface {
ListVMs() ([]VM, error)
CreateVM(spec VMSpec) (VM, error)
StartVM(id string) error
StopVM(id string) error
RebootVM(id string) error
DeleteVM(id string) error
}
type VMSpec struct {
ID string `json:"id" yaml:"id"`
Name string `json:"name" yaml:"name"`
CPU int `json:"cpus" yaml:"cpus"`
MemoryMB int `json:"memory_mb" yaml:"memory_mb"`
Disks []DiskSpec `json:"disks" yaml:"disks"`
NICs []NICSpec `json:"nics" yaml:"nics"`
CloudInit *CloudInitSpec `json:"cloud_init" yaml:"cloud_init"`
CloudInitISO string `json:"cloud_init_iso" yaml:"cloud_init_iso"`
}
type DiskSpec struct {
Name string `json:"name" yaml:"name"`
Pool string `json:"pool" yaml:"pool"`
SizeGB int `json:"size_gb" yaml:"size_gb"`
Bus string `json:"bus" yaml:"bus"`
Path string `json:"path" yaml:"path"`
Prealloc string `json:"prealloc" yaml:"prealloc"` // "", "metadata", "full"
}
type NICSpec struct {
Bridge string `json:"bridge" yaml:"bridge"`
VLAN int `json:"vlan" yaml:"vlan"`
Model string `json:"model" yaml:"model"`
}
type CloudInitSpec struct {
User string `json:"user" yaml:"user"`
SSHKeys []string `json:"ssh_keys" yaml:"ssh_keys"`
UserData string `json:"user_data" yaml:"user_data"`
}
type VM struct {
ID string
Name string
Status string
CPU int
MemoryMB int
}
// TODO: implement a real libvirt-go backed client that renders domain XML from templates.