From 8dc0bf6facdb30a1775ed89321d124f7a0bb4970 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Fri, 25 Oct 2024 15:18:37 -0500 Subject: [PATCH] better mac addr checking Signed-off-by: Jeff Carr --- addDroplet.go | 41 +++++++++++++++++++++++++++-------------- 1 file changed, 27 insertions(+), 14 deletions(-) diff --git a/addDroplet.go b/addDroplet.go index 7f6a40a..c395406 100644 --- a/addDroplet.go +++ b/addDroplet.go @@ -250,26 +250,33 @@ func updateNetwork(d *DropletT, domcfg *libvirtxml.Domain) ([]*pb.Event, error) log.Info("Non-Standard Network XML Start") fmt.Println(string(updatedXML)) log.Info("Non-Standard Network XML End") - return nil, errors.New("non-standard network") + return nil, errors.New("non-standard network. source == nil") } if iface.Source.Bridge == nil { - // fmt.Printf("non-standard network: %+v\n", iface) - updatedXML, _ := xml.MarshalIndent(domcfg.Devices.Interfaces, "", " ") - log.Info("Non-Standard Network XML Start") - fmt.Println(string(updatedXML)) - log.Info("Non-Standard Network XML End") - return nil, errors.New("bridge is blank nil and no mac address") + if hwaddr == "" { + fmt.Printf("non-standard network: %+v\n", iface) + updatedXML, _ := xml.MarshalIndent(domcfg.Devices.Interfaces, "", " ") + log.Info("Non-Standard Network XML Start") + fmt.Println(string(updatedXML)) + log.Info("Non-Standard Network XML End") + return nil, errors.New("bridge is nil and no mac address") + } + brname = "" } if iface.Source.Bridge.Bridge == "" { - updatedXML, _ := xml.MarshalIndent(domcfg.Devices.Interfaces, "", " ") - log.Info("Non-Standard Network XML Start") - fmt.Println(string(updatedXML)) - log.Info("Non-Standard Network XML End") - return nil, errors.New("bridge is blank and no mac address") + if hwaddr == "" { + fmt.Printf("non-standard network: %+v\n", iface) + fmt.Printf("iface.Mac: %+v\n", iface) + updatedXML, _ := xml.MarshalIndent(domcfg.Devices.Interfaces, "", " ") + log.Info("Non-Standard Network XML Start") + fmt.Println(string(updatedXML)) + log.Info("Non-Standard Network XML End") + return nil, errors.New("bridge is blank and no mac address") + } + brname = iface.Source.Bridge.Bridge } // log.Info("network has bridge:", iface.Source.Bridge.Bridge) - brname = iface.Source.Bridge.Bridge if hwaddr == "" { hwaddr = "generate " + domcfg.Name log.Info("need to generate mac addr for bridge:", brname) @@ -285,9 +292,15 @@ func updateNetwork(d *DropletT, domcfg *libvirtxml.Domain) ([]*pb.Event, error) if eth.Mac == mac { // log.Info("OKAY. FOUND ETH:", eth.Mac, eth.Name, brname) found = true + if brname == "" { + // if new bridge name is blank, keep the old one + brname = eth.Name + } if eth.Name != brname { if argv.IgnoreBr { - log.Info("ignoring network changed bridge name:", eth.Mac, eth.Name, brname) + log.Info("network was:", eth.Mac, eth.Name) + log.Info("network now:", eth.Mac, brname) + log.Info("ignoring network change (--xml-ignore-net)") } else { return nil, errors.New("bridge name changed") }