summaryrefslogtreecommitdiff
path: root/validate.go
diff options
context:
space:
mode:
Diffstat (limited to 'validate.go')
-rw-r--r--validate.go56
1 files changed, 45 insertions, 11 deletions
diff --git a/validate.go b/validate.go
index 5343c34..274033c 100644
--- a/validate.go
+++ b/validate.go
@@ -15,7 +15,6 @@ package main
import (
"errors"
- "os"
"path/filepath"
"github.com/google/uuid"
@@ -72,6 +71,7 @@ func lookupFilename(cluster *pb.Cluster, filename string) *pb.Droplet {
return nil
}
+/*
func InsertFilename(cluster *pb.Cluster, d *pb.Droplet, filename string) (*pb.Event, error) {
dupd := lookupFilename(cluster, filename)
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)
return e, nil
}
+*/
func ValidateUniqueFilenames(cluster *pb.Cluster) bool {
var ok bool = true
@@ -167,8 +168,9 @@ func ValidateDiskFilenames(cluster *pb.Cluster) []*pb.Event {
return alle
}
-// this doesn't run often
-func ValidateDroplets(cluster *pb.Cluster, dump bool) bool {
+// runs on startup. dies if there are duplicates
+// the config file must then be edited by hand
+func ValidateDroplets(cluster *pb.Cluster) error {
// uuid map to check for duplicates
var umap map[string]string
umap = make(map[string]string)
@@ -189,7 +191,7 @@ func ValidateDroplets(cluster *pb.Cluster, dump bool) bool {
// UUID already exists
log.Info("duplicate UUID", d.Uuid, umap[d.Uuid])
log.Info("duplicate UUID", d.Uuid, d.Hostname)
- os.Exit(-1)
+ return errors.New("duplicate UUID: " + d.Uuid)
}
umap[d.Uuid] = d.Hostname
@@ -199,7 +201,7 @@ func ValidateDroplets(cluster *pb.Cluster, dump bool) bool {
// 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)
+ return errors.New("duplicate MAC: " + n.Mac)
}
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 UUID")
- if dump {
- for u, hostname := range umap {
- log.Println("uuid:", u, "hostname:", hostname)
+ return nil
+}
+
+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()
+ }
+
+ // seconds, ok := timeZone[tz]; ok {
+ 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 mac, uuid := range macs {
- log.Println("mac:", mac, "uuid", uuid, "hostname:", umap[uuid])
+ 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
}