prepare to validate spice ports
Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
parent
d0767eb984
commit
71f83d4000
|
@ -0,0 +1,22 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"net/http"
|
||||||
|
)
|
||||||
|
|
||||||
|
/*
|
||||||
|
debugging code to see the state of the
|
||||||
|
cluster via http
|
||||||
|
*/
|
||||||
|
|
||||||
|
func dumpCluster(w http.ResponseWriter) {
|
||||||
|
umap, macs := safeValidateDroplets(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])
|
||||||
|
}
|
||||||
|
}
|
3
event.go
3
event.go
|
@ -110,7 +110,8 @@ func Start(name string) (bool, string) {
|
||||||
dur := time.Since(me.unstable) // how long has the cluster been stable?
|
dur := time.Since(me.unstable) // how long has the cluster been stable?
|
||||||
result = fmt.Sprintln("should start droplet", name, "here. grid stable for:", shell.FormatDuration(dur))
|
result = fmt.Sprintln("should start droplet", name, "here. grid stable for:", shell.FormatDuration(dur))
|
||||||
if dur < me.unstableTimeout {
|
if dur < me.unstableTimeout {
|
||||||
result += "grid is still too unstable"
|
tmp := shell.FormatDuration(me.unstableTimeout)
|
||||||
|
result += "grid is still too unstable (unstable timeout = " + tmp + ")"
|
||||||
return false, result
|
return false, result
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
26
http.go
26
http.go
|
@ -76,11 +76,6 @@ func okHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if route == "/dumplibvirtxml" {
|
|
||||||
virtigoxml.DumpLibvirtxmlDomainNames()
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if route == "/uptime" {
|
if route == "/uptime" {
|
||||||
ok, s := clusterHealthy()
|
ok, s := clusterHealthy()
|
||||||
if ok {
|
if ok {
|
||||||
|
@ -104,10 +99,23 @@ func okHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
fmt.Fprintln(w, "hostname is", hostname)
|
fmt.Fprintln(w, "hostname is", hostname)
|
||||||
|
|
||||||
// log.Warn("Handling URL:", tmp, "start droplet", start)
|
// log.Warn("Handling URL:", tmp, "start droplet", start)
|
||||||
b, result := Start(hostname)
|
ok, result := Start(hostname)
|
||||||
log.Warn("Start returned =", b, "result =", result)
|
if ok {
|
||||||
fmt.Fprintln(w, "Start() returned", b)
|
fmt.Fprintln(w, hostname, "started ok")
|
||||||
fmt.Fprintln(w, "result:", result)
|
} else {
|
||||||
|
fmt.Fprintln(w, result)
|
||||||
|
fmt.Fprintln(w, hostname, "start failed")
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if route == "/dumpcluster" {
|
||||||
|
dumpCluster(w)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if route == "/dumplibvirtxml" {
|
||||||
|
virtigoxml.DumpLibvirtxmlDomainNames()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
7
main.go
7
main.go
|
@ -48,7 +48,7 @@ func main() {
|
||||||
me.unstableTimeout = 17 * time.Second
|
me.unstableTimeout = 17 * time.Second
|
||||||
|
|
||||||
// how long the cluster must be stable before new droplets can be started
|
// how long the cluster must be stable before new droplets can be started
|
||||||
me.clusterStableDuration = 37 * time.Second
|
me.clusterStableDuration = 37 * time.Second
|
||||||
|
|
||||||
// read in the config file
|
// read in the config file
|
||||||
me.cluster = new(pb.Cluster)
|
me.cluster = new(pb.Cluster)
|
||||||
|
@ -72,7 +72,10 @@ func main() {
|
||||||
var newEvents []*pb.Event
|
var newEvents []*pb.Event
|
||||||
|
|
||||||
// sanity check the cluster & droplets
|
// sanity check the cluster & droplets
|
||||||
ValidateDroplets(me.cluster, false)
|
if err := ValidateDroplets(me.cluster); err != nil {
|
||||||
|
log.Info("todo: add flag to ignore. for now, fix problems in the config file.")
|
||||||
|
os.Exit(0)
|
||||||
|
}
|
||||||
newe := ValidateDiskFilenames(me.cluster)
|
newe := ValidateDiskFilenames(me.cluster)
|
||||||
for _, e := range newe {
|
for _, e := range newe {
|
||||||
newEvents = append(newEvents, e)
|
newEvents = append(newEvents, e)
|
||||||
|
|
18
structs.go
18
structs.go
|
@ -20,15 +20,15 @@ func (b *virtigoT) Enable() {
|
||||||
|
|
||||||
// this app's variables
|
// this app's variables
|
||||||
type virtigoT struct {
|
type virtigoT struct {
|
||||||
cluster *pb.Cluster // basic cluster settings
|
cluster *pb.Cluster // basic cluster settings
|
||||||
delay time.Duration // how often to poll the hypervisors
|
delay time.Duration // how often to poll the hypervisors
|
||||||
hmap map[*pb.Hypervisor]*HyperT // map to the local struct
|
hmap map[*pb.Hypervisor]*HyperT // map to the local struct
|
||||||
names []string
|
names []string
|
||||||
hypers []*HyperT
|
hypers []*HyperT
|
||||||
killcount int
|
killcount int
|
||||||
unstable time.Time // the last time the cluster was incorrect
|
unstable time.Time // the last time the cluster was incorrect
|
||||||
changed bool
|
changed bool
|
||||||
unstableTimeout time.Duration // how long a droplet can be missing until it's declared dead
|
unstableTimeout time.Duration // how long a droplet can be missing until it's declared dead
|
||||||
clusterStableDuration time.Duration // how long the cluster must be stable before new droplets can be started
|
clusterStableDuration time.Duration // how long the cluster must be stable before new droplets can be started
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
56
validate.go
56
validate.go
|
@ -15,7 +15,6 @@ package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"os"
|
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
|
@ -72,6 +71,7 @@ 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) {
|
func InsertFilename(cluster *pb.Cluster, d *pb.Droplet, filename string) (*pb.Event, error) {
|
||||||
dupd := lookupFilename(cluster, filename)
|
dupd := lookupFilename(cluster, filename)
|
||||||
if dupd != nil {
|
if dupd != nil {
|
||||||
|
@ -104,6 +104,7 @@ func InsertFilename(cluster *pb.Cluster, d *pb.Droplet, filename string) (*pb.Ev
|
||||||
log.Info("New filename", filebase, dir)
|
log.Info("New filename", filebase, dir)
|
||||||
return e, nil
|
return e, nil
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
func ValidateUniqueFilenames(cluster *pb.Cluster) bool {
|
func ValidateUniqueFilenames(cluster *pb.Cluster) bool {
|
||||||
var ok bool = true
|
var ok bool = true
|
||||||
|
@ -167,8 +168,9 @@ func ValidateDiskFilenames(cluster *pb.Cluster) []*pb.Event {
|
||||||
return alle
|
return alle
|
||||||
}
|
}
|
||||||
|
|
||||||
// this doesn't run often
|
// runs on startup. dies if there are duplicates
|
||||||
func ValidateDroplets(cluster *pb.Cluster, dump bool) bool {
|
// the config file must then be edited by hand
|
||||||
|
func ValidateDroplets(cluster *pb.Cluster) 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)
|
||||||
|
@ -189,7 +191,7 @@ func ValidateDroplets(cluster *pb.Cluster, dump bool) bool {
|
||||||
// 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)
|
||||||
os.Exit(-1)
|
return errors.New("duplicate UUID: " + d.Uuid)
|
||||||
}
|
}
|
||||||
umap[d.Uuid] = d.Hostname
|
umap[d.Uuid] = d.Hostname
|
||||||
|
|
||||||
|
@ -199,7 +201,7 @@ func ValidateDroplets(cluster *pb.Cluster, dump bool) bool {
|
||||||
// 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)
|
||||||
os.Exit(-1)
|
return errors.New("duplicate MAC: " + n.Mac)
|
||||||
}
|
}
|
||||||
macs[n.Mac] = d.Uuid
|
macs[n.Mac] = d.Uuid
|
||||||
}
|
}
|
||||||
|
@ -207,15 +209,47 @@ func ValidateDroplets(cluster *pb.Cluster, dump bool) bool {
|
||||||
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")
|
||||||
|
|
||||||
if dump {
|
return nil
|
||||||
for u, hostname := range umap {
|
}
|
||||||
log.Println("uuid:", u, "hostname:", hostname)
|
|
||||||
|
func safeValidateDroplets(cluster *pb.Cluster) (map[string]string, map[string]string) {
|
||||||
|
// uuid map to check for duplicates
|
||||||
|
var umap map[string]string
|
||||||
|
umap = make(map[string]string)
|
||||||
|
|
||||||
|
// mac address map to check for duplicates
|
||||||
|
var macs map[string]string
|
||||||
|
macs = make(map[string]string)
|
||||||
|
|
||||||
|
for _, d := range cluster.Droplets {
|
||||||
|
// Generate a new UUID
|
||||||
|
if d.Uuid == "" {
|
||||||
|
u := uuid.New()
|
||||||
|
d.Uuid = u.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
for mac, uuid := range macs {
|
// seconds, ok := timeZone[tz]; ok {
|
||||||
log.Println("mac:", mac, "uuid", uuid, "hostname:", umap[uuid])
|
if _, ok := umap[d.Uuid]; ok {
|
||||||
|
// UUID already exists
|
||||||
|
log.Info("duplicate UUID", d.Uuid, umap[d.Uuid])
|
||||||
|
log.Info("duplicate UUID", d.Uuid, d.Hostname)
|
||||||
|
// os.Exit(-1)
|
||||||
|
}
|
||||||
|
umap[d.Uuid] = d.Hostname
|
||||||
|
|
||||||
|
for _, n := range d.Networks {
|
||||||
|
// log.Println("network:", n.Mac, d.Uuid, d.Hostname)
|
||||||
|
if _, ok := macs[n.Mac]; ok {
|
||||||
|
// UUID already exists
|
||||||
|
log.Info("duplicate MAC", n.Mac, macs[n.Mac], umap[macs[n.Mac]])
|
||||||
|
log.Info("duplicate MAC", n.Mac, d.Hostname)
|
||||||
|
// os.Exit(-1)
|
||||||
|
}
|
||||||
|
macs[n.Mac] = d.Uuid
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
log.Println("validated okay: no duplicate MAC addr")
|
||||||
|
log.Println("validated okay: no duplicate UUID")
|
||||||
|
|
||||||
return false
|
return umap, macs
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue