function to dump all droplets

Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
Jeff Carr 2024-10-29 09:00:40 -05:00
parent c26699571d
commit 8724a07b0d
2 changed files with 17 additions and 21 deletions

12
dump.go
View File

@ -30,19 +30,29 @@ func dumpCluster(w http.ResponseWriter) {
}
// list running droplets and droplets that should be running
func dumpDroplets(w http.ResponseWriter) {
func dumpDroplets(w http.ResponseWriter, full bool) {
for i, d := range me.cluster.Droplets {
var macs []string
for _, n := range d.Networks {
macs = append(macs, n.Mac)
}
arp := strings.Join(macs, " ")
var filenames string
for _, disk := range d.Disks {
filenames += disk.Filename
}
if d.CurrentState == pb.DropletState_ON {
fmt.Fprintln(w, i, "droplet:", arp, d.Hostname, d.StartState, d.CurrentState, d.CurrentHypervisor)
continue
}
if d.StartState == pb.DropletState_ON {
fmt.Fprintln(w, i, "droplet:", arp, d.Hostname, d.StartState, d.CurrentState, "(should be on)")
continue
}
if full {
fmt.Fprintln(w, i, "droplet:", arp, d.Hostname, d.StartState, d.CurrentState, filenames)
}
}
}

26
http.go
View File

@ -21,25 +21,6 @@ func okHandler(w http.ResponseWriter, r *http.Request) {
var route string
route = cleanURL(r.URL.Path)
// is the cluster running what it should?
if route == "/droplets" {
for _, d := range me.cluster.Droplets {
var msg string
if d.StartState == pb.DropletState_ON {
msg = "(should be on)"
}
switch d.CurrentState {
case pb.DropletState_ON:
fmt.Fprintln(w, d.Hostname, "ON")
case pb.DropletState_OFF:
fmt.Fprintln(w, d.Hostname, msg)
default:
fmt.Fprintln(w, d.Hostname, "? state:", d.CurrentState, msg)
}
}
return
}
// show only what droplets should be running but are missing
if route == "/missing" {
var count int
@ -132,7 +113,12 @@ func okHandler(w http.ResponseWriter, r *http.Request) {
}
if route == "/dumpdroplets" {
dumpDroplets(w)
dumpDroplets(w, false)
return
}
if route == "/dumpdropletsfull" {
dumpDroplets(w, true)
return
}