diff options
| author | Jeff Carr <[email protected]> | 2024-10-30 12:16:08 -0500 |
|---|---|---|
| committer | Jeff Carr <[email protected]> | 2024-10-30 12:16:08 -0500 |
| commit | 410015c33e7d905ee03fab29d24961aab9df093f (patch) | |
| tree | 9597ef87a0dc4add212e5924caaee6a7d5d925ae /validate.go | |
| parent | c8a69bdb73fedb7bd7afd05318021e487b47bd17 (diff) | |
more work on create() droplet
Signed-off-by: Jeff Carr <[email protected]>
Diffstat (limited to 'validate.go')
| -rw-r--r-- | validate.go | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/validate.go b/validate.go index a95ce29..a4caa52 100644 --- a/validate.go +++ b/validate.go @@ -133,6 +133,35 @@ func ValidateDiskFilenames(cluster *pb.Cluster) []*pb.Event { return alle } +func getNewMac() (string, error) { + // mac address map to check for duplicates + var macs map[string]string + macs = make(map[string]string) + + for _, d := range me.cluster.Droplets { + 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]) + log.Info("duplicate MAC", n.Mac, d.Hostname) + return "", errors.New("duplicate MAC: " + d.Hostname + " and " + macs[n.Mac]) + } + macs[n.Mac] = d.Hostname + } + } + + var mac string = "22:22:22:22:22:09" + for { + if _, ok := macs[mac]; ok { + log.Info("MAC already defined", mac, macs[mac]) + continue + } + return mac, nil + } + return mac, nil +} + // 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) { |
