virtigo/dump.go

90 lines
2.3 KiB
Go
Raw Normal View History

package main
import (
"fmt"
"net/http"
"strings"
"time"
"go.wit.com/lib/gui/shell"
pb "go.wit.com/lib/protobuf/virtbuf"
)
/*
debugging code to see the state of the
cluster via http
*/
func dumpCluster(w http.ResponseWriter) {
umap, macs, err := ValidateDroplets(me.cluster)
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])
}
if err != nil {
fmt.Fprintln(w, "ValidateDroplets() failed:", err)
}
}
// list running droplets and droplets that should be running
func dumpDroplets(w http.ResponseWriter, full bool) {
for _, d := range me.cluster.Droplets {
var macs []string
for _, n := range d.Networks {
macs = append(macs, n.Mac)
}
// this line in golang could replace 80 lines of COBOL
header := fmt.Sprintf("%-3s %20s %-8s", d.Current.State, strings.Join(macs, " "), d.Current.Hypervisor)
var filenames string
for _, disk := range d.Disks {
filenames += disk.Filename
}
if d.Current.State == pb.DropletState_ON {
fmt.Fprintln(w, header, d.Hostname)
continue
}
if d.StartState == pb.DropletState_ON {
fmt.Fprintln(w, header, d.Hostname, "(should be on)")
continue
}
if full {
fmt.Fprintln(w, header, d.Hostname, filenames)
}
}
}
// status of the hypervisors
func dumpHypervisors(w http.ResponseWriter) {
var totalDroplets int
var totalUnknownDroplets int
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)
totalDroplets += 1
d := me.cluster.FindDropletByName(name)
if d == nil {
totalUnknownDroplets += 1
fmt.Fprintln(w, "\t", h.pb.Hostname, "name =", name, "lastpoll:", tmp)
} else {
fmt.Fprintln(w, "\t", h.pb.Hostname, "name =", name, "lastpoll:", tmp, d.Current.State)
}
}
}
if totalUnknownDroplets == 0 {
fmt.Fprintln(w, "\tTotal Droplets", totalDroplets)
} else {
fmt.Fprintln(w, "\tTotal Droplets", totalDroplets, "total libvirt only droplets =", totalUnknownDroplets)
}
}