diff options
| author | Jeff Carr <[email protected]> | 2024-10-30 12:30:34 -0500 |
|---|---|---|
| committer | Jeff Carr <[email protected]> | 2024-10-30 12:30:34 -0500 |
| commit | 2a18f506c7e37903e58b838e52b6b6554e7e039c (patch) | |
| tree | 074fca97694ef9fc76acc2218be874d625560e31 /validate.go | |
| parent | 410015c33e7d905ee03fab29d24961aab9df093f (diff) | |
simple unique mac
Signed-off-by: Jeff Carr <[email protected]>
Diffstat (limited to 'validate.go')
| -rw-r--r-- | validate.go | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/validate.go b/validate.go index a4caa52..4105c6f 100644 --- a/validate.go +++ b/validate.go @@ -15,6 +15,7 @@ package main import ( "errors" + "fmt" "path/filepath" "github.com/google/uuid" @@ -133,7 +134,7 @@ func ValidateDiskFilenames(cluster *pb.Cluster) []*pb.Event { return alle } -func getNewMac() (string, error) { +func getNewMac() string { // mac address map to check for duplicates var macs map[string]string macs = make(map[string]string) @@ -145,21 +146,25 @@ func getNewMac() (string, error) { // 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]) + return "" } macs[n.Mac] = d.Hostname } } - var mac string = "22:22:22:22:22:09" + var i int = 9 + var mac string for { + mac = fmt.Sprintf("22:22:22:22:22:%02d", i) if _, ok := macs[mac]; ok { log.Info("MAC already defined", mac, macs[mac]) + i += 1 continue } - return mac, nil + log.Info("using new MAC:", mac) + return mac } - return mac, nil + return "" } // runs on startup. dies if there are duplicates |
