summaryrefslogtreecommitdiff
path: root/validate.go
diff options
context:
space:
mode:
authorJeff Carr <[email protected]>2024-10-24 18:55:35 -0500
committerJeff Carr <[email protected]>2024-10-24 18:55:35 -0500
commitfea819956f4c8cfd43623ad7d0c1992b0305291d (patch)
treeaf9cbba0d50f2e710b504ecade546bd3dec0f0b7 /validate.go
parent78fbc9631cff4b6feb2e1de7b376c5ccc2c2dda6 (diff)
cleanup instructions
Signed-off-by: Jeff Carr <[email protected]>
Diffstat (limited to 'validate.go')
-rw-r--r--validate.go70
1 files changed, 70 insertions, 0 deletions
diff --git a/validate.go b/validate.go
new file mode 100644
index 0000000..337422d
--- /dev/null
+++ b/validate.go
@@ -0,0 +1,70 @@
+package main
+
+/*
+ validate / sanity check / consistancy check the data
+
+ here is some code to do smart things like:
+
+ * check mac addresses are unique
+ * check uuid's are unique
+ * double check filenames are unique
+ * return a unique mac address
+ * return a unique uuid
+
+*/
+
+import (
+ "os"
+
+ "github.com/google/uuid"
+
+ "go.wit.com/log"
+)
+
+func checkDroplets() bool {
+ // 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 me.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 _, 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
+ }
+ }
+
+ for u, hostname := range umap {
+ log.Println("uuid:", u, "hostname:", hostname)
+ }
+
+ for mac, uuid := range macs {
+ log.Println("mac:", mac, "uuid", uuid, "hostname:", umap[uuid])
+ }
+
+ return false
+}