add /dumpdroplets
Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
parent
71f83d4000
commit
d948581300
26
dump.go
26
dump.go
|
@ -3,6 +3,9 @@ package main
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
pb "go.wit.com/lib/protobuf/virtbuf"
|
||||||
)
|
)
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -11,7 +14,7 @@ import (
|
||||||
*/
|
*/
|
||||||
|
|
||||||
func dumpCluster(w http.ResponseWriter) {
|
func dumpCluster(w http.ResponseWriter) {
|
||||||
umap, macs := safeValidateDroplets(me.cluster)
|
umap, macs, err := ValidateDroplets(me.cluster)
|
||||||
for u, hostname := range umap {
|
for u, hostname := range umap {
|
||||||
fmt.Fprintln(w, "uuid:", u, "hostname:", hostname)
|
fmt.Fprintln(w, "uuid:", u, "hostname:", hostname)
|
||||||
}
|
}
|
||||||
|
@ -19,4 +22,25 @@ func dumpCluster(w http.ResponseWriter) {
|
||||||
for mac, uuid := range macs {
|
for mac, uuid := range macs {
|
||||||
fmt.Fprintln(w, "mac:", mac, "uuid", uuid, "hostname:", umap[uuid])
|
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)")
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
5
http.go
5
http.go
|
@ -114,6 +114,11 @@ func okHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if route == "/dumpdroplets" {
|
||||||
|
dumpDroplets(w)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
if route == "/dumplibvirtxml" {
|
if route == "/dumplibvirtxml" {
|
||||||
virtigoxml.DumpLibvirtxmlDomainNames()
|
virtigoxml.DumpLibvirtxmlDomainNames()
|
||||||
return
|
return
|
||||||
|
|
2
main.go
2
main.go
|
@ -72,7 +72,7 @@ func main() {
|
||||||
var newEvents []*pb.Event
|
var newEvents []*pb.Event
|
||||||
|
|
||||||
// sanity check the cluster & droplets
|
// sanity check the cluster & droplets
|
||||||
if err := ValidateDroplets(me.cluster); err != nil {
|
if _, _, err := ValidateDroplets(me.cluster); err != nil {
|
||||||
log.Info("todo: add flag to ignore. for now, fix problems in the config file.")
|
log.Info("todo: add flag to ignore. for now, fix problems in the config file.")
|
||||||
os.Exit(0)
|
os.Exit(0)
|
||||||
}
|
}
|
||||||
|
|
45
validate.go
45
validate.go
|
@ -71,41 +71,6 @@ func lookupFilename(cluster *pb.Cluster, filename string) *pb.Droplet {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
func InsertFilename(cluster *pb.Cluster, d *pb.Droplet, filename string) (*pb.Event, error) {
|
|
||||||
dupd := lookupFilename(cluster, filename)
|
|
||||||
if dupd != nil {
|
|
||||||
log.Info("file", filename, "already on droplet", dupd.Hostname)
|
|
||||||
log.Info("file", filename, "on new droplet", d.Hostname)
|
|
||||||
if os.Getenv("VIRTIGO_IGNORE_DISKDUP") == "" {
|
|
||||||
log.Info("duplicate disk names (--xml-ignore-disk to ignore)")
|
|
||||||
return nil, errors.New("duplicate disk names")
|
|
||||||
} else {
|
|
||||||
log.Info("ignore duplicate disk names (--xml-ignore-disk=true)")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
filebase := filepath.Base(filename)
|
|
||||||
dir := filepath.Dir(filename)
|
|
||||||
for _, disk := range d.Disks {
|
|
||||||
if disk.Filename == filebase {
|
|
||||||
log.Info("already have disk", filename)
|
|
||||||
return nil, nil
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// make a new Add Event
|
|
||||||
e := d.NewChangeEvent("Add Disk", "", filename)
|
|
||||||
|
|
||||||
// add the disk protobuf entry
|
|
||||||
var disk *pb.Disk
|
|
||||||
disk = new(pb.Disk)
|
|
||||||
disk.Filename = filebase
|
|
||||||
disk.Filepath = dir
|
|
||||||
d.Disks = append(d.Disks, disk)
|
|
||||||
log.Info("New filename", filebase, dir)
|
|
||||||
return e, nil
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
func ValidateUniqueFilenames(cluster *pb.Cluster) bool {
|
func ValidateUniqueFilenames(cluster *pb.Cluster) bool {
|
||||||
var ok bool = true
|
var ok bool = true
|
||||||
var disks map[string]string
|
var disks map[string]string
|
||||||
|
@ -170,7 +135,7 @@ func ValidateDiskFilenames(cluster *pb.Cluster) []*pb.Event {
|
||||||
|
|
||||||
// runs on startup. dies if there are duplicates
|
// runs on startup. dies if there are duplicates
|
||||||
// the config file must then be edited by hand
|
// the config file must then be edited by hand
|
||||||
func ValidateDroplets(cluster *pb.Cluster) error {
|
func ValidateDroplets(cluster *pb.Cluster) (map[string]string, map[string]string, error) {
|
||||||
// uuid map to check for duplicates
|
// uuid map to check for duplicates
|
||||||
var umap map[string]string
|
var umap map[string]string
|
||||||
umap = make(map[string]string)
|
umap = make(map[string]string)
|
||||||
|
@ -191,7 +156,7 @@ func ValidateDroplets(cluster *pb.Cluster) error {
|
||||||
// UUID already exists
|
// UUID already exists
|
||||||
log.Info("duplicate UUID", d.Uuid, umap[d.Uuid])
|
log.Info("duplicate UUID", d.Uuid, umap[d.Uuid])
|
||||||
log.Info("duplicate UUID", d.Uuid, d.Hostname)
|
log.Info("duplicate UUID", d.Uuid, d.Hostname)
|
||||||
return errors.New("duplicate UUID: " + d.Uuid)
|
return umap, macs, errors.New("duplicate UUID: " + d.Uuid)
|
||||||
}
|
}
|
||||||
umap[d.Uuid] = d.Hostname
|
umap[d.Uuid] = d.Hostname
|
||||||
|
|
||||||
|
@ -201,7 +166,7 @@ func ValidateDroplets(cluster *pb.Cluster) error {
|
||||||
// UUID already exists
|
// UUID already exists
|
||||||
log.Info("duplicate MAC", n.Mac, macs[n.Mac], umap[macs[n.Mac]])
|
log.Info("duplicate MAC", n.Mac, macs[n.Mac], umap[macs[n.Mac]])
|
||||||
log.Info("duplicate MAC", n.Mac, d.Hostname)
|
log.Info("duplicate MAC", n.Mac, d.Hostname)
|
||||||
return errors.New("duplicate MAC: " + n.Mac)
|
return umap, macs, errors.New("duplicate MAC: " + n.Mac)
|
||||||
}
|
}
|
||||||
macs[n.Mac] = d.Uuid
|
macs[n.Mac] = d.Uuid
|
||||||
}
|
}
|
||||||
|
@ -209,9 +174,10 @@ func ValidateDroplets(cluster *pb.Cluster) error {
|
||||||
log.Println("validated okay: no duplicate MAC addr")
|
log.Println("validated okay: no duplicate MAC addr")
|
||||||
log.Println("validated okay: no duplicate UUID")
|
log.Println("validated okay: no duplicate UUID")
|
||||||
|
|
||||||
return nil
|
return umap, macs, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
func safeValidateDroplets(cluster *pb.Cluster) (map[string]string, map[string]string) {
|
func safeValidateDroplets(cluster *pb.Cluster) (map[string]string, map[string]string) {
|
||||||
// uuid map to check for duplicates
|
// uuid map to check for duplicates
|
||||||
var umap map[string]string
|
var umap map[string]string
|
||||||
|
@ -253,3 +219,4 @@ func safeValidateDroplets(cluster *pb.Cluster) (map[string]string, map[string]st
|
||||||
|
|
||||||
return umap, macs
|
return umap, macs
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
Loading…
Reference in New Issue