diff options
| author | Jeff Carr <[email protected]> | 2024-10-31 13:37:00 -0500 |
|---|---|---|
| committer | Jeff Carr <[email protected]> | 2024-10-31 13:37:00 -0500 |
| commit | 3c520003edb286deec57ce62c447373912787829 (patch) | |
| tree | 29b819f09a0147f39eba997dab0979698cf68635 /validate.go | |
| parent | 913b18737b9cb25636eea44355ddc680ff1c45c0 (diff) | |
compiles again
Signed-off-by: Jeff Carr <[email protected]>
Diffstat (limited to 'validate.go')
| -rw-r--r-- | validate.go | 85 |
1 files changed, 65 insertions, 20 deletions
diff --git a/validate.go b/validate.go index 49b2088..ac2712d 100644 --- a/validate.go +++ b/validate.go @@ -16,6 +16,7 @@ package main import ( "errors" "fmt" + "os" "path/filepath" "strings" @@ -26,8 +27,10 @@ import ( ) // will make sure the mac address is unique -func ValidateUniqueMac(cluster *pb.Cluster, mac string) bool { - for _, d := range cluster.Droplets { +func ValidateUniqueMac(mac string) bool { + loop := me.cluster.DropletsAll() // get the list of droplets + for loop.Scan() { + d := loop.Droplet() for _, n := range d.Networks { if n.Mac == mac { log.Info("duplicate MAC", n.Mac, "in droplet", d.Hostname) @@ -39,10 +42,10 @@ func ValidateUniqueMac(cluster *pb.Cluster, mac string) bool { } // records all the known paths. this should go in the protobuf -func addClusterFilepath(cluster *pb.Cluster, dir string) *pb.Event { +func addClusterFilepath(dir string) *pb.Event { var found bool = false var e *pb.Event - for _, d := range cluster.Dirs { + for _, d := range me.cluster.Dirs { if d == dir { // found dir found = true @@ -53,17 +56,19 @@ func addClusterFilepath(cluster *pb.Cluster, dir string) *pb.Event { if dir != "." { // make a new Add Event e = pb.NewAddEvent(nil, "Add Cluster Directory", dir) - cluster.Dirs = append(cluster.Dirs, dir) + me.cluster.Dirs = append(me.cluster.Dirs, dir) } } return e } // returns the droplet using a filename -func lookupFilename(cluster *pb.Cluster, filename string) *pb.Droplet { +func lookupFilename(filename string) *pb.Droplet { filebase := filepath.Base(filename) - for _, d := range cluster.Droplets { + loop := me.cluster.DropletsAll() // get the list of droplets + for loop.Scan() { + d := loop.Droplet() for _, disk := range d.Disks { if filebase == disk.Filename { return d @@ -73,15 +78,17 @@ func lookupFilename(cluster *pb.Cluster, filename string) *pb.Droplet { return nil } -func ValidateUniqueFilenames(cluster *pb.Cluster) bool { +func ValidateUniqueFilenames() bool { var ok bool = true var disks map[string]string disks = make(map[string]string) - for _, d := range cluster.Droplets { + loop := me.cluster.DropletsAll() // get the list of droplets + for loop.Scan() { + d := loop.Droplet() for _, disk := range d.Disks { filename := disk.Filename - addClusterFilepath(cluster, disk.Filepath) + addClusterFilepath(disk.Filepath) if _, ok := disks[filename]; ok { /* if argv.IgnDisk { @@ -103,16 +110,18 @@ func ValidateUniqueFilenames(cluster *pb.Cluster) bool { return ok } -func ValidateDiskFilenames(cluster *pb.Cluster) ([]*pb.Event, error) { +func ValidateDiskFilenames() ([]*pb.Event, error) { var alle []*pb.Event - for _, d := range cluster.Droplets { + loop := me.cluster.DropletsAll() // get the list of droplets + for loop.Scan() { + d := loop.Droplet() var found bool = false for _, disk := range d.Disks { filename := disk.Filename filebase := filepath.Base(filename) dir := filepath.Dir(filename) - addClusterFilepath(cluster, dir) + addClusterFilepath(dir) if disk.Filename != filebase { // update filename e := d.NewChangeEvent("Disk.Filename", disk.Filename, filebase) @@ -159,7 +168,9 @@ func getNewMac() string { var macs map[string]string macs = make(map[string]string) - for _, d := range me.cluster.Droplets { + loop := me.cluster.DropletsAll() // get the list of droplets + for loop.Scan() { + d := loop.Droplet() for _, n := range d.Networks { // log.Println("network:", n.Mac, d.Uuid, d.Hostname) if _, ok := macs[n.Mac]; ok { @@ -189,7 +200,7 @@ func getNewMac() string { // runs on startup. dies if there are duplicates // the config file must then be edited by hand -func ValidateDroplets(cluster *pb.Cluster) (map[string]string, map[string]string, error) { +func ValidateDroplets() (map[string]string, map[string]string, error) { // uuid map to check for duplicates var umap map[string]string umap = make(map[string]string) @@ -198,7 +209,9 @@ func ValidateDroplets(cluster *pb.Cluster) (map[string]string, map[string]string var macs map[string]string macs = make(map[string]string) - for _, d := range cluster.Droplets { + loop := me.cluster.DropletsAll() // get the list of droplets + for loop.Scan() { + d := loop.Droplet() // Generate a new UUID if d.Uuid == "" { u := uuid.New() @@ -231,6 +244,26 @@ func ValidateDroplets(cluster *pb.Cluster) (map[string]string, map[string]string return umap, macs, nil } +func searchForDuplicateUUIDs() { + // var broken int +} + +/* +// remove from the slice +func deleteDroplet(bad int) { + var all *pb.Droplets + all = me.cluster.DeleteDroplet(b *db.Droplet) + + fmt.Println("deleting", bad, all.Droplets[bad].Hostname) + + // Check if the index is within bounds + if bad >= 0 && bad < len(all.Droplets) { + // Remove element at targetIndex + all.Droplets = append(all.Droplets[:bad], all.Droplets[bad+1:]...) + } +} +*/ + // checks a droplet right before a start event // verify ethernet mac address // verify uuid (but probably can ignore this since it's not used) @@ -239,7 +272,9 @@ func ValidateDroplets(cluster *pb.Cluster) (map[string]string, map[string]string // check filenames func ValidateDroplet(check *pb.Droplet) error { // check for duplicate uuid's - for _, d := range me.cluster.Droplets { + loop := me.cluster.DropletsAll() // get the list of droplets + for loop.Scan() { + d := loop.Droplet() if check == d { continue } @@ -247,13 +282,21 @@ func ValidateDroplet(check *pb.Droplet) error { // UUID already exists log.Info("duplicate UUID", d.Uuid, d.Hostname) log.Info("duplicate UUID", d.Uuid, check.Hostname) + // d.Archive = new(pb.DropletArchive) + if d.Archive == nil { + log.Info("d.Archive == nil") + os.Exit(-1) + } + d.Archive.Reason = pb.DropletArchive_DUP return errors.New("duplicate UUID: " + d.Uuid) } } // check for duplicate mac addresses for _, checkn := range check.Networks { - for _, d := range me.cluster.Droplets { + loop := me.cluster.DropletsAll() // get the list of droplets + for loop.Scan() { + d := loop.Droplet() if check == d { continue } @@ -280,7 +323,9 @@ func setUniqueSpicePort(check *pb.Droplet) error { // check spice ports // checkn.SpicePort = getUniqueSpicePort() - for _, d := range me.cluster.Droplets { + loop := me.cluster.DropletsAll() // get the list of droplets + for loop.Scan() { + d := loop.Droplet() if d.SpicePort == 0 { continue } @@ -330,7 +375,7 @@ func setUniqueSpicePort(check *pb.Droplet) error { // generate change port event log.Info("going to try port", start, "on", check.Hostname) e := check.NewChangeEvent("SpicePort", check.SpicePort, start) - me.cluster.E.Events = append(me.cluster.E.Events, e) + me.cluster.AddEvent(e) // set port to start check.SpicePort = start |
