2024-10-27 02:55:08 -05:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"net/http"
|
2024-10-27 03:17:34 -05:00
|
|
|
"strings"
|
2024-10-27 11:02:50 -05:00
|
|
|
"time"
|
2024-10-27 03:17:34 -05:00
|
|
|
|
2024-10-27 11:02:50 -05:00
|
|
|
"go.wit.com/lib/gui/shell"
|
2024-10-27 03:17:34 -05:00
|
|
|
pb "go.wit.com/lib/protobuf/virtbuf"
|
2024-10-27 02:55:08 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
/*
|
|
|
|
debugging code to see the state of the
|
|
|
|
cluster via http
|
|
|
|
*/
|
|
|
|
|
|
|
|
func dumpCluster(w http.ResponseWriter) {
|
2024-10-27 03:17:34 -05:00
|
|
|
umap, macs, err := ValidateDroplets(me.cluster)
|
2024-10-27 02:55:08 -05:00
|
|
|
for u, hostname := range umap {
|
|
|
|
fmt.Fprintln(w, "uuid:", u, "hostname:", hostname)
|
|
|
|
}
|
|
|
|
|
|
|
|
for mac, uuid := range macs {
|
|
|
|
fmt.Fprintln(w, "mac:", mac, "uuid", uuid, "hostname:", umap[uuid])
|
|
|
|
}
|
2024-10-27 03:17:34 -05:00
|
|
|
if err != nil {
|
|
|
|
fmt.Fprintln(w, "ValidateDroplets() failed:", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// list running droplets and droplets that should be running
|
2024-10-29 09:00:40 -05:00
|
|
|
func dumpDroplets(w http.ResponseWriter, full bool) {
|
2024-10-27 03:17:34 -05:00
|
|
|
for i, d := range me.cluster.Droplets {
|
|
|
|
var macs []string
|
|
|
|
for _, n := range d.Networks {
|
|
|
|
macs = append(macs, n.Mac)
|
|
|
|
}
|
2024-10-29 22:55:28 -05:00
|
|
|
|
|
|
|
// this line in golang could replace 80 lines of COBOL
|
|
|
|
header := fmt.Sprintf("%3d %20s %3s %8s", i, strings.Join(macs, " "), d.CurrentState, d.CurrentHypervisor)
|
2024-10-29 09:00:40 -05:00
|
|
|
|
|
|
|
var filenames string
|
|
|
|
for _, disk := range d.Disks {
|
|
|
|
filenames += disk.Filename
|
|
|
|
}
|
|
|
|
|
2024-10-27 03:17:34 -05:00
|
|
|
if d.CurrentState == pb.DropletState_ON {
|
2024-10-29 22:55:28 -05:00
|
|
|
fmt.Fprintln(w, header, d.Hostname)
|
2024-10-27 03:17:34 -05:00
|
|
|
continue
|
|
|
|
}
|
|
|
|
if d.StartState == pb.DropletState_ON {
|
2024-10-29 22:55:28 -05:00
|
|
|
fmt.Fprintln(w, header, d.Hostname, "(should be on)")
|
2024-10-29 09:00:40 -05:00
|
|
|
continue
|
|
|
|
}
|
|
|
|
if full {
|
2024-10-29 22:55:28 -05:00
|
|
|
fmt.Fprintln(w, header, d.Hostname, filenames)
|
2024-10-27 03:17:34 -05:00
|
|
|
}
|
|
|
|
}
|
2024-10-27 02:55:08 -05:00
|
|
|
}
|
2024-10-27 11:02:50 -05:00
|
|
|
|
|
|
|
// status of the hypervisors
|
|
|
|
func dumpHypervisors(w http.ResponseWriter) {
|
2024-10-28 11:44:53 -05:00
|
|
|
var totalDroplets int
|
|
|
|
var totalUnknownDroplets int
|
2024-10-27 11:02:50 -05:00
|
|
|
for _, h := range me.hypers {
|
|
|
|
// lastpoll time.Time // the last time the hypervisor polled
|
|
|
|
dur := time.Since(h.lastpoll)
|
|
|
|
tmp := shell.FormatDuration(dur)
|
|
|
|
fmt.Fprintln(w, h.pb.Hostname, "killcount =", h.killcount, "lastpoll:", tmp)
|
|
|
|
for name, t := range h.lastDroplets {
|
|
|
|
dur := time.Since(t)
|
|
|
|
tmp := shell.FormatDuration(dur)
|
2024-10-28 11:44:53 -05:00
|
|
|
totalDroplets += 1
|
2024-10-27 11:02:50 -05:00
|
|
|
d := findDroplet(name)
|
|
|
|
if d == nil {
|
2024-10-28 11:44:53 -05:00
|
|
|
totalUnknownDroplets += 1
|
2024-10-27 11:02:50 -05:00
|
|
|
fmt.Fprintln(w, "\t", h.pb.Hostname, "name =", name, "lastpoll:", tmp)
|
|
|
|
} else {
|
|
|
|
fmt.Fprintln(w, "\t", h.pb.Hostname, "name =", name, "lastpoll:", tmp, d.CurrentState)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2024-10-28 11:44:53 -05:00
|
|
|
if totalUnknownDroplets == 0 {
|
|
|
|
fmt.Fprintln(w, "\tTotal Droplets", totalDroplets)
|
|
|
|
} else {
|
|
|
|
fmt.Fprintln(w, "\tTotal Droplets", totalDroplets, "total libvirt only droplets =", totalUnknownDroplets)
|
|
|
|
}
|
2024-10-27 11:02:50 -05:00
|
|
|
}
|