Added ability to check domains on host

super simple example to show it can work
This commit is contained in:
Matthew Stobbs 2024-03-10 00:15:49 -07:00
parent 9ce8b81e06
commit bab4f2506b
3 changed files with 31 additions and 0 deletions

5
go.mod Normal file
View File

@ -0,0 +1,5 @@
module git.staur.ca/stobbsm/clustvirt
go 1.22.1
require libvirt.org/go/libvirt v1.10001.0 // indirect

2
go.sum Normal file
View File

@ -0,0 +1,2 @@
libvirt.org/go/libvirt v1.10001.0 h1:lEVDNE7xfzmZXiDEGIS8NvJSuaz11OjRXw+ufbQEtPY=
libvirt.org/go/libvirt v1.10001.0/go.mod h1:1WiFE8EjZfq+FCVog+rvr1yatKbKZ9FaFMZgEqxEJqQ=

24
main.go Normal file
View File

@ -0,0 +1,24 @@
package main
import (
"log"
"libvirt.org/go/libvirt"
)
func main() {
log.Println("Starting clustvirt, the libvirt cluster manager")
// Try connecting to libvirt
conn, err := libvirt.NewConnect("qemu+ssh://earth.staur.ca/system")
if err != nil {
log.Fatal(err)
}
defer conn.Close()
doms, err := conn.ListAllDomains(libvirt.CONNECT_LIST_DOMAINS_ACTIVE | libvirt.CONNECT_LIST_DOMAINS_INACTIVE)
if err != nil {
log.Fatal(err)
}
log.Printf("Domains on earth: %d", len(doms))
}