From bab4f2506b9a97d44263acbf99a78da7d730f2de Mon Sep 17 00:00:00 2001 From: Matthew Stobbs Date: Sun, 10 Mar 2024 00:15:49 -0700 Subject: [PATCH] Added ability to check domains on host super simple example to show it can work --- go.mod | 5 +++++ go.sum | 2 ++ main.go | 24 ++++++++++++++++++++++++ 3 files changed, 31 insertions(+) create mode 100644 go.mod create mode 100644 go.sum create mode 100644 main.go diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..8dca580 --- /dev/null +++ b/go.mod @@ -0,0 +1,5 @@ +module git.staur.ca/stobbsm/clustvirt + +go 1.22.1 + +require libvirt.org/go/libvirt v1.10001.0 // indirect diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..5306274 --- /dev/null +++ b/go.sum @@ -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= diff --git a/main.go b/main.go new file mode 100644 index 0000000..634696b --- /dev/null +++ b/main.go @@ -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)) +}