2024-10-27 02:55:08 -05:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"net/http"
|
2024-10-27 11:02:50 -05:00
|
|
|
"time"
|
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-31 13:37:00 -05:00
|
|
|
umap, macs, err := ValidateDroplets()
|
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-31 13:37:00 -05:00
|
|
|
loop := me.cluster.DropletsAll() // get the list of droplets
|
|
|
|
for loop.Scan() {
|
|
|
|
d := loop.Droplet()
|
|
|
|
fmt.Println(w, "Droplet UUID:", d.Uuid)
|
|
|
|
|
2024-10-29 22:55:28 -05:00
|
|
|
// this line in golang could replace 80 lines of COBOL
|
2024-11-01 00:58:28 -05:00
|
|
|
header := d.SprintDumpHeader() + " "
|
2024-10-29 09:00:40 -05:00
|
|
|
|
2024-11-01 00:41:00 -05:00
|
|
|
// check if this is a locally defined libvirt domain that needs to be imported
|
|
|
|
if d.LocalOnly != "" {
|
|
|
|
header += "(local)"
|
2024-10-29 09:00:40 -05:00
|
|
|
}
|
2024-11-01 00:41:00 -05:00
|
|
|
header += d.Hostname
|
2024-10-29 09:00:40 -05:00
|
|
|
|
2024-10-31 06:41:30 -05:00
|
|
|
if d.Current.State == pb.DropletState_ON {
|
2024-11-01 00:41:00 -05:00
|
|
|
// everything is as it should be with this vm
|
|
|
|
fmt.Fprintln(w, header)
|
2024-10-27 03:17:34 -05:00
|
|
|
continue
|
|
|
|
}
|
|
|
|
if d.StartState == pb.DropletState_ON {
|
2024-11-01 00:41:00 -05:00
|
|
|
// this is supposed to be ON and needs to be turned on
|
|
|
|
fmt.Fprintln(w, header, "(should be on). todo: start() here")
|
2024-10-29 09:00:40 -05:00
|
|
|
continue
|
|
|
|
}
|
2024-11-01 02:00:46 -05:00
|
|
|
|
|
|
|
if d.LocalOnly != "" {
|
|
|
|
// this is supposed to be ON and needs to be turned on
|
|
|
|
fmt.Fprintln(w, header, "this libvirt/domain/xml needs to be imported")
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
2024-10-29 09:00:40 -05:00
|
|
|
if full {
|
2024-11-01 00:41:00 -05:00
|
|
|
var filenames string
|
|
|
|
for _, disk := range d.Disks {
|
|
|
|
filenames += disk.Filename
|
|
|
|
}
|
|
|
|
|
|
|
|
// this needs to be turned on
|
|
|
|
fmt.Fprintln(w, header, 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)
|
2024-11-01 00:41:00 -05:00
|
|
|
tmp := pb.FormatDuration(dur)
|
2024-10-27 11:02:50 -05:00
|
|
|
fmt.Fprintln(w, h.pb.Hostname, "killcount =", h.killcount, "lastpoll:", tmp)
|
|
|
|
for name, t := range h.lastDroplets {
|
|
|
|
dur := time.Since(t)
|
2024-11-01 00:41:00 -05:00
|
|
|
tmp := pb.FormatDuration(dur)
|
2024-10-28 11:44:53 -05:00
|
|
|
totalDroplets += 1
|
2024-10-31 06:41:30 -05:00
|
|
|
d := me.cluster.FindDropletByName(name)
|
2024-10-27 11:02:50 -05:00
|
|
|
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 {
|
2024-10-31 06:41:30 -05:00
|
|
|
fmt.Fprintln(w, "\t", h.pb.Hostname, "name =", name, "lastpoll:", tmp, d.Current.State)
|
2024-10-27 11:02:50 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
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
|
|
|
}
|