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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
|
package main
import (
"fmt"
"net/http"
"time"
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()
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) {
loop := me.cluster.DropletsAll() // get the list of droplets
for loop.Scan() {
d := loop.Droplet()
fmt.Println(w, "Droplet UUID:", d.Uuid)
// this line in golang could replace 80 lines of COBOL
header := d.SprintDumpHeader() + " "
// check if this is a locally defined libvirt domain that needs to be imported
if d.LocalOnly != "" {
header += "(local)"
}
header += d.Hostname
if d.Current.State == pb.DropletState_ON {
// everything is as it should be with this vm
fmt.Fprintln(w, header)
continue
}
if d.StartState == pb.DropletState_ON {
// this is supposed to be ON and needs to be turned on
fmt.Fprintln(w, header, "(should be on). todo: start() here")
continue
}
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
}
if full {
var filenames string
for _, disk := range d.Disks {
filenames += disk.Filename
}
// this needs to be turned on
fmt.Fprintln(w, header, 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 := pb.FormatDuration(dur)
fmt.Fprintln(w, h.pb.Hostname, "killcount =", h.killcount, "lastpoll:", tmp)
for name, t := range h.lastDroplets {
dur := time.Since(t)
tmp := pb.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)
}
}
|