summaryrefslogtreecommitdiff
path: root/dump.go
blob: 57a3404a821402dcbaa616817c6053ef33e09a1f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package main

import (
	"fmt"
	"net/http"
	"strings"

	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) {
	for i, d := range me.cluster.Droplets {
		var macs []string
		for _, n := range d.Networks {
			macs = append(macs, n.Mac)
		}
		arp := strings.Join(macs, " ")
		if d.CurrentState == pb.DropletState_ON {
			fmt.Fprintln(w, i, "droplet:", arp, d.Hostname, d.StartState, d.CurrentState)
			continue
		}
		if d.StartState == pb.DropletState_ON {
			fmt.Fprintln(w, i, "droplet:", arp, d.Hostname, d.StartState, d.CurrentState, "(should be on)")
		}
	}
}