fails on imports with duplicate mac addrs

Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
Jeff Carr 2024-10-25 15:46:49 -05:00
parent 7cc0bd9b2c
commit b6dd67b73d
3 changed files with 28 additions and 0 deletions

View File

@ -308,6 +308,11 @@ func updateNetwork(d *DropletT, domcfg *libvirtxml.Domain) ([]*pb.Event, error)
}
}
if !found {
if checkUniqueMac(mac) {
} else {
log.Info("droplet", d.pb.Hostname, "duplicate mac address", mac)
return nil, errors.New("duplicate mac address")
}
var eth *pb.Network
eth = new(pb.Network)
eth.Mac = mac

10
main.go
View File

@ -60,6 +60,10 @@ func main() {
// parsing the libvirt xml file failed
log.Info("error:", filename, err)
ok = false
log.Info("readXml() error", filename)
log.Info("readXml() error", err)
log.Info("libvirt XML will have to be fixed by hand")
os.Exit(-1)
continue
}
// see if the libvirt xml droplet is already here
@ -68,6 +72,10 @@ func main() {
// some error. probably UUID mismatch or hostname duplication
// this has to be fixed by hand
ok = false
log.Info("findDomain() error", filename)
log.Info("findDomain() error", err)
log.Info("libvirt XML will have to be fixed by hand")
os.Exit(-1)
continue
}
if d == nil {
@ -78,6 +86,8 @@ func main() {
ok = false
log.Info("addDomainDroplet() error", filename)
log.Info("addDomainDroplet() error", err)
log.Info("libvirt XML will have to be fixed by hand")
os.Exit(-1)
}
} else {
// this droplet is already here

View File

@ -21,6 +21,19 @@ import (
"go.wit.com/log"
)
// will make sure the mac address is unique
func checkUniqueMac(mac string) bool {
for _, d := range me.cluster.Droplets {
for _, n := range d.Networks {
if n.Mac == mac {
log.Info("duplicate MAC", n.Mac, "in droplet", d.Hostname)
return false
}
}
}
return true
}
func checkDroplets(dump bool) bool {
// uuid map to check for duplicates
var umap map[string]string